You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
6.7 KiB

  1. #!/bin/sh
  2. # Copyright 2017 Roger Shimizu <rogershimizu@gmail.com>
  3. #
  4. # This is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. help_usage() {
  9. cat << EOT
  10. Build shadowsocks-libev and its dependencies
  11. Usage:
  12. $(basename $0) [--help|-h] [lib|bin|all]
  13. --help|-h Show this usage.
  14. lib Build library packages only.
  15. bin Build binary packages only.
  16. However, you need the libraries built previously, in current working directory.
  17. For advanced user only.
  18. all Build both binary and library packages (default).
  19. The safe choice for everyone.
  20. Please run this script in a clean place.
  21. e.g.
  22. mkdir -p ~/build-area
  23. cd ~/build-area
  24. ln -s $(readlink -f $0) .
  25. ./$(basename $0)
  26. EOT
  27. exit
  28. }
  29. help_lib() {
  30. cat << EOT
  31. Failed to install required library:
  32. $1
  33. You can try to fix it by:
  34. $0 lib
  35. EOT
  36. exit
  37. }
  38. apt_init() {
  39. DEPS="$1"
  40. DEPS_BPO="$2"
  41. if [ -n "$DEPS_BPO" ]; then
  42. BPO=${OSVER}-backports
  43. case "$OSID" in
  44. debian)
  45. REPO=http://httpredir.debian.org/debian
  46. ;;
  47. ubuntu)
  48. REPO=http://archive.ubuntu.com/ubuntu
  49. ;;
  50. esac
  51. sudo sh -c "printf \"deb $REPO ${OSVER}-backports main\" > /etc/apt/sources.list.d/${OSVER}-backports.list"
  52. sudo apt-get update
  53. sudo apt-get install -y -t $BPO $DEPS_BPO
  54. else
  55. sudo apt-get update
  56. fi
  57. sudo apt-get install -y $DEPS
  58. }
  59. # Cleanup
  60. apt_clean() {
  61. sudo apt-get purge -y $DEPS $DEPS_BPO debhelper \
  62. libbloom-dev libcork-dev libcorkipset-dev libmbedtls-dev libsodium-dev
  63. sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps \
  64. libbloom-build-deps libsodium-build-deps mbedtls-build-deps
  65. sudo apt-get purge -y simple-obfs-build-deps shadowsocks-libev-build-deps
  66. sudo apt-get autoremove -y
  67. }
  68. gbp_build() {
  69. REPO=$1
  70. BRANCH=$2
  71. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  72. gbp clone --pristine-tar $REPO
  73. cd $PROJECT_NAME
  74. git checkout $BRANCH
  75. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  76. rm ${PROJECT_NAME}-build-deps_*.deb
  77. gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar
  78. git clean -fdx
  79. git reset --hard HEAD
  80. cd -
  81. }
  82. git_build() {
  83. REPO=$1
  84. BRANCH=$2
  85. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  86. git clone $REPO
  87. cd $PROJECT_NAME
  88. git checkout $BRANCH
  89. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  90. rm ${PROJECT_NAME}-build-deps_*.deb
  91. gbp buildpackage -us -uc --git-ignore-branch
  92. git clean -fdx
  93. git reset --hard HEAD
  94. cd -
  95. }
  96. dsc_build() {
  97. DSC=$1
  98. DSC_FILE=$(basename $1)
  99. dget -ux $DSC
  100. PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2)
  101. echo cd ${PROJECT_NAME}-*
  102. cd ${PROJECT_NAME}-*
  103. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  104. rm ${PROJECT_NAME}-build-deps_*.deb
  105. dpkg-buildpackage -us -uc
  106. cd -
  107. }
  108. # Build and install libcork deb
  109. build_install_libcork() {
  110. BRANCH=$1
  111. if [ $BUILD_LIB -eq 1 ]; then
  112. gbp_build https://github.com/rogers0/libcork $BRANCH
  113. else
  114. ls libcork-dev_*.deb libcork16_*.deb 2>&1 > /dev/null ||
  115. help_lib "libcork-dev libcork16"
  116. fi
  117. sudo dpkg -i libcork-dev_*.deb libcork16_*.deb
  118. }
  119. # Build and install libcorkipset deb
  120. build_install_libcorkipset() {
  121. BRANCH=$1
  122. if [ $BUILD_LIB -eq 1 ]; then
  123. gbp_build https://github.com/rogers0/libcorkipset $BRANCH
  124. else
  125. ls libcorkipset-dev_*.deb libcorkipset1_*.deb 2>&1 > /dev/null ||
  126. help_lib "libcorkipset-dev libcorkipset1"
  127. fi
  128. sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb
  129. }
  130. # Build libmbedtls deb
  131. build_install_libmbedtls() {
  132. BRANCH=$1
  133. if [ $BUILD_LIB -eq 1 ]; then
  134. gbp_build https://anonscm.debian.org/git/collab-maint/mbedtls.git $BRANCH
  135. else
  136. ls libmbed*.deb 2>&1 > /dev/null ||
  137. help_lib libmbedtls
  138. fi
  139. sudo dpkg -i libmbed*.deb
  140. }
  141. # Build libsodium deb
  142. build_install_libsodium() {
  143. if [ $BUILD_LIB -eq 1 ]; then
  144. dsc_build http://httpredir.debian.org/debian/pool/main/libs/libsodium/libsodium_1.0.11-1~bpo8+1.dsc
  145. else
  146. ls libsodium*.deb 2>&1 > /dev/null ||
  147. help_lib libsodium
  148. fi
  149. sudo dpkg -i libsodium*.deb
  150. }
  151. # Build libbloom deb
  152. build_install_libbloom() {
  153. BRANCH=$1
  154. if [ $BUILD_LIB -eq 1 ]; then
  155. gbp_build https://github.com/rogers0/libbloom $BRANCH
  156. else
  157. ls libbloom-dev_*.deb libbloom1_*.deb 2>&1 > /dev/null ||
  158. help_lib "libbloom-dev libbloom1"
  159. fi
  160. sudo dpkg -i libbloom-dev_*.deb libbloom1_*.deb
  161. }
  162. # Add patch to work on system with debhelper 9 only
  163. patch_sslibev_dh9() {
  164. if [ $BUILD_BIN -eq 1 ]; then
  165. BRANCH=$1
  166. gbp clone --pristine-tar https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git
  167. cd shadowsocks-libev
  168. git checkout $BRANCH
  169. sed -i 's/dh $@/dh $@ --with systemd,autoreconf/' debian/rules
  170. sed -i 's/debhelper (>= 10)/debhelper (>= 9), dh-systemd, dh-autoreconf/' debian/control
  171. echo 9 > debian/compat
  172. git add -u
  173. git commit -m "Patch to work with ubuntu trusty (14.04)"
  174. cd -
  175. fi
  176. }
  177. # Build and install shadowsocks-libev deb
  178. build_install_sslibev() {
  179. if [ $BUILD_BIN -eq 1 ]; then
  180. BRANCH=$1
  181. gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git $BRANCH
  182. sudo dpkg -i shadowsocks-libev_*.deb
  183. sudo apt-get install -fy
  184. fi
  185. }
  186. # Build and install simple-obfs
  187. build_install_simpleobfs() {
  188. if [ $BUILD_BIN -eq 1 ]; then
  189. BRANCH=$1
  190. git_build https://github.com/rogers0/simple-obfs $BRANCH
  191. sudo dpkg -i simple-obfs_*.deb
  192. sudo apt-get install -fy
  193. fi
  194. }
  195. export XZ_DEFAULTS=--memlimit=128MiB
  196. OSID=$(grep ^ID= /etc/os-release|cut -d= -f2)
  197. OSVER=$(lsb_release -cs)
  198. BUILD_LIB=0
  199. BUILD_BIN=0
  200. case "$1" in
  201. --help|-h)
  202. help_usage
  203. ;;
  204. lib)
  205. BUILD_LIB=1
  206. ;;
  207. bin)
  208. BUILD_BIN=1
  209. ;;
  210. all|"")
  211. BUILD_LIB=1
  212. BUILD_BIN=1
  213. ;;
  214. *)
  215. echo Parameter error, exiting ...
  216. exit
  217. esac
  218. # Exit if in a git repo
  219. [ -d .git ] && help_usage
  220. case "$OSVER" in
  221. jessie)
  222. BPO="debhelper libsodium-dev"
  223. ;;
  224. xenial)
  225. BPO=debhelper
  226. ;;
  227. esac
  228. apt_init "git-buildpackage equivs" "$BPO"
  229. case "$OSVER" in
  230. wheezy|precise)
  231. echo Sorry, your system $OSID/$OSVER is not supported.
  232. ;;
  233. jessie|stretch|unstable|sid|zesty)
  234. build_install_libbloom exp1
  235. build_install_sslibev exp1
  236. build_install_simpleobfs exp1
  237. apt_clean
  238. ;;
  239. trusty)
  240. build_install_libcork trusty
  241. build_install_libcorkipset trusty
  242. build_install_libmbedtls debian/jessie-backports
  243. build_install_libsodium
  244. build_install_libbloom exp1_trusty
  245. patch_sslibev_dh9 exp1
  246. build_install_sslibev exp1
  247. build_install_simpleobfs exp1_trusty
  248. apt_clean
  249. ;;
  250. xenial|yakkety)
  251. build_install_libcork debian
  252. build_install_libcorkipset debian
  253. build_install_libbloom exp1
  254. build_install_sslibev exp1
  255. build_install_simpleobfs exp1
  256. apt_clean
  257. ;;
  258. *)
  259. echo Your system $OSID/$OSVER is not supported yet.
  260. echo Please report issue:
  261. echo " https://github.com/shadowsocks/shadowsocks-libev/issues/new"
  262. ;;
  263. esac