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.

443 lines
11 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. kcp Build kcptun package (with its dependencies) only.
  15. lib Build library packages only.
  16. bin Build binary packages only.
  17. However, you need the libraries built previously, in current working directory.
  18. For advanced user only.
  19. all Build both binary and library packages (default).
  20. The safe choice for everyone.
  21. Please run this script in a clean place.
  22. e.g.
  23. mkdir -p ~/build-area
  24. cd ~/build-area
  25. ln -s $(readlink -f $0) .
  26. ./$(basename $0)
  27. EOT
  28. exit
  29. }
  30. help_lib() {
  31. cat << EOT
  32. Failed to install required library:
  33. $1
  34. You can try to fix it by:
  35. $0 lib
  36. EOT
  37. exit
  38. }
  39. apt_init() {
  40. DEPS="$1"
  41. DEPS_BPO="$2"
  42. if [ -n "$DEPS_BPO" ]; then
  43. BPO=${OSVER}-backports
  44. case "$OSID" in
  45. debian)
  46. REPO=http://httpredir.debian.org/debian
  47. ;;
  48. ubuntu)
  49. REPO=http://archive.ubuntu.com/ubuntu
  50. ;;
  51. esac
  52. sudo sh -c "printf \"deb $REPO ${OSVER}-backports main\" > /etc/apt/sources.list.d/${OSVER}-backports.list"
  53. sudo apt-get update
  54. sudo apt-get install --no-install-recommends -y -t $BPO $DEPS_BPO
  55. else
  56. sudo apt-get update
  57. fi
  58. sudo apt-get install -y $DEPS
  59. }
  60. # Cleanup
  61. apt_clean() {
  62. sudo apt-get purge -y $DEPS $DEPS_BPO debhelper \
  63. libbloom-dev libcork-dev libcorkipset-dev libmbedtls-dev libsodium-dev
  64. sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps \
  65. libbloom-build-deps libsodium-build-deps mbedtls-build-deps
  66. sudo apt-get purge -y simple-obfs-build-deps shadowsocks-libev-build-deps
  67. sudo apt-get purge -y golang-github-klauspost-reedsolomon-build-deps \
  68. golang-github-xtaci-kcp-build-deps golang-github-xtaci-smux-build-deps \
  69. kcptun-build-deps
  70. sudo apt-get purge -y golang-github-urfave-cli-build-deps
  71. sudo apt-get purge -y golang-github-golang-snappy-build-deps \
  72. dh-golang-build-deps golang-github-pkg-errors-build-deps
  73. sudo apt-get purge -y golang-github-klauspost-reedsolomon-dev \
  74. golang-github-xtaci-kcp-dev golang-github-xtaci-smux-dev
  75. sudo apt-get purge -y golang-github-urfave-cli-dev
  76. sudo apt-get purge -y golang-github-pkg-errors-dev \
  77. golang-github-golang-snappy-dev dh-golang
  78. sudo apt-get autoremove -y
  79. }
  80. gbp_build() {
  81. REPO=$1
  82. BRANCH=$2
  83. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  84. gbp clone --pristine-tar $REPO
  85. cd $PROJECT_NAME
  86. [ -n "$BRANCH" ] && git checkout $BRANCH
  87. [ -n "$DEPS_BPO" ] && BPO_REPO="-t ${OSVER}-backports"
  88. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y $BPO_REPO"
  89. rm -f ${PROJECT_NAME}-build-deps_*.deb
  90. gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar
  91. git clean -fdx
  92. git reset --hard HEAD
  93. cd -
  94. }
  95. git_build() {
  96. REPO=$1
  97. BRANCH=$2
  98. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  99. git clone $REPO
  100. cd $PROJECT_NAME
  101. [ -n "$BRANCH" ] && git checkout $BRANCH
  102. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  103. rm ${PROJECT_NAME}-build-deps_*.deb
  104. gbp buildpackage -us -uc --git-ignore-branch
  105. git clean -fdx
  106. git reset --hard HEAD
  107. cd -
  108. }
  109. dsc_build() {
  110. DSC=$1
  111. DSC_FILE=$(basename $1)
  112. dget -ux $DSC
  113. PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2)
  114. echo cd ${PROJECT_NAME}-*
  115. cd ${PROJECT_NAME}-*
  116. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  117. rm ${PROJECT_NAME}-build-deps_*.deb
  118. dpkg-buildpackage -us -uc
  119. cd -
  120. }
  121. # Build and install libcork deb
  122. build_install_libcork() {
  123. if [ $BUILD_LIB -eq 1 -o $BUILD_BIN -eq 1 ]; then
  124. BRANCH=$1
  125. if [ $BUILD_LIB -eq 1 ]; then
  126. gbp_build https://github.com/rogers0/libcork $BRANCH
  127. else
  128. ls libcork-dev_*.deb libcork16_*.deb 2>&1 > /dev/null ||
  129. help_lib "libcork-dev libcork16"
  130. fi
  131. sudo dpkg -i libcork-dev_*.deb libcork16_*.deb
  132. fi
  133. }
  134. # Build and install libcorkipset deb
  135. build_install_libcorkipset() {
  136. if [ $BUILD_LIB -eq 1 -o $BUILD_BIN -eq 1 ]; then
  137. BRANCH=$1
  138. if [ $BUILD_LIB -eq 1 ]; then
  139. gbp_build https://github.com/rogers0/libcorkipset $BRANCH
  140. else
  141. ls libcorkipset-dev_*.deb libcorkipset1_*.deb 2>&1 > /dev/null ||
  142. help_lib "libcorkipset-dev libcorkipset1"
  143. fi
  144. sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb
  145. fi
  146. }
  147. # Build libmbedtls deb
  148. build_install_libmbedtls() {
  149. if [ $BUILD_LIB -eq 1 -o $BUILD_BIN -eq 1 ]; then
  150. BRANCH=$1
  151. if [ $BUILD_LIB -eq 1 ]; then
  152. gbp_build https://anonscm.debian.org/git/collab-maint/mbedtls.git $BRANCH
  153. else
  154. ls libmbed*.deb 2>&1 > /dev/null ||
  155. help_lib libmbedtls
  156. fi
  157. sudo dpkg -i libmbed*.deb
  158. fi
  159. }
  160. # Build libsodium deb
  161. build_install_libsodium() {
  162. if [ $BUILD_LIB -eq 1 -o $BUILD_BIN -eq 1 ]; then
  163. if [ $BUILD_LIB -eq 1 ]; then
  164. dsc_build http://httpredir.debian.org/debian/pool/main/libs/libsodium/libsodium_1.0.11-2.dsc
  165. else
  166. ls libsodium*.deb 2>&1 > /dev/null ||
  167. help_lib libsodium
  168. fi
  169. sudo dpkg -i libsodium*.deb
  170. fi
  171. }
  172. # Build libbloom deb
  173. build_install_libbloom() {
  174. if [ $BUILD_LIB -eq 1 -o $BUILD_BIN -eq 1 ]; then
  175. BRANCH=$1
  176. if [ $BUILD_LIB -eq 1 ]; then
  177. gbp_build https://anonscm.debian.org/git/collab-maint/libbloom.git $BRANCH
  178. else
  179. ls libbloom-dev_*.deb libbloom1_*.deb 2>&1 > /dev/null ||
  180. help_lib "libbloom-dev libbloom1"
  181. fi
  182. sudo dpkg -i libbloom-dev_*.deb libbloom1_*.deb
  183. fi
  184. }
  185. # Add patch to work on system with debhelper 9 only
  186. patch_sslibev_dh9() {
  187. if [ $BUILD_BIN -eq 1 ]; then
  188. BRANCH=$1
  189. gbp clone --pristine-tar https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git
  190. cd shadowsocks-libev
  191. [ -n "$BRANCH" ] && git checkout $BRANCH
  192. sed -i 's/dh $@/dh $@ --with systemd,autoreconf/' debian/rules
  193. sed -i 's/debhelper (>= 10)/debhelper (>= 9), dh-systemd, dh-autoreconf/' debian/control
  194. echo 9 > debian/compat
  195. git add -u
  196. git commit -m "Patch to work with ubuntu trusty (14.04)"
  197. cd -
  198. fi
  199. }
  200. # Build and install shadowsocks-libev deb
  201. build_install_sslibev() {
  202. if [ $BUILD_BIN -eq 1 ]; then
  203. BRANCH=$1
  204. gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git $BRANCH
  205. sudo dpkg -i shadowsocks-libev_*.deb
  206. sudo apt-get install -fy
  207. fi
  208. }
  209. # Build and install simple-obfs
  210. build_install_simpleobfs() {
  211. if [ $BUILD_BIN -eq 1 ]; then
  212. BRANCH=$1
  213. git_build https://anonscm.debian.org/git/collab-maint/simple-obfs.git $BRANCH
  214. sudo dpkg -i simple-obfs_*.deb
  215. sudo apt-get install -fy
  216. fi
  217. }
  218. # Build and install dh-golang deb
  219. build_install_dhgolang() {
  220. if [ $BUILD_KCP -eq 1 ]; then
  221. BRANCH=$1
  222. gbp_build https://anonscm.debian.org/cgit/pkg-go/packages/dh-golang.git $BRANCH
  223. sudo dpkg -i dh-golang_*.deb
  224. sudo apt-get install -fy
  225. fi
  226. }
  227. # Build and install golang-github-klauspost-reedsolomon deb
  228. build_install_reedsolomondev() {
  229. if [ $BUILD_KCP -eq 1 ]; then
  230. BRANCH=$1
  231. gbp_build https://anonscm.debian.org/git/pkg-go/packages/golang-github-klauspost-reedsolomon.git $BRANCH
  232. sudo dpkg -i golang-github-klauspost-reedsolomon-dev_*.deb
  233. sudo apt-get install -fy
  234. fi
  235. }
  236. # Build and install golang-github-pkg-errors deb
  237. build_install_errorsdev() {
  238. if [ $BUILD_KCP -eq 1 ]; then
  239. BRANCH=$1
  240. gbp_build https://anonscm.debian.org/git/pkg-go/packages/golang-github-pkg-errors.git $BRANCH
  241. sudo dpkg -i golang-github-pkg-errors-dev_*.deb
  242. sudo apt-get install -fy
  243. fi
  244. }
  245. # Add patch to work on system with xenial
  246. patch_urfaveclidev_xenial() {
  247. if [ $BUILD_KCP -eq 1 ]; then
  248. BRANCH=$1
  249. gbp clone --pristine-tar https://anonscm.debian.org/git/pkg-go/packages/golang-github-urfave-cli.git
  250. cd golang-github-urfave-cli
  251. [ -n "$BRANCH" ] && git checkout $BRANCH
  252. sed -i 's/golang-github-burntsushi-toml-dev/golang-toml-dev/; s/golang-gopkg-yaml.v2-dev/golang-yaml.v2-dev/' debian/control
  253. git add -u
  254. git commit -m "Patch to work with ubuntu xenial (16.04)"
  255. cd -
  256. fi
  257. }
  258. # Build and install golang-github-urfave-cli-dev deb
  259. build_install_urfaveclidev() {
  260. if [ $BUILD_KCP -eq 1 ]; then
  261. BRANCH=$1
  262. gbp_build https://anonscm.debian.org/git/pkg-go/packages/golang-github-urfave-cli.git $BRANCH
  263. sudo dpkg -i build-area/golang-github-urfave-cli-dev_*.deb
  264. sudo apt-get install -fy
  265. fi
  266. }
  267. # Build and install golang-github-golang-snappy deb
  268. build_install_snappydev() {
  269. if [ $BUILD_KCP -eq 1 ]; then
  270. BRANCH=$1
  271. gbp_build https://anonscm.debian.org/git/pkg-go/packages/golang-github-golang-snappy.git $BRANCH
  272. sudo dpkg -i golang-github-golang-snappy-dev_*.deb
  273. sudo apt-get install -fy
  274. fi
  275. }
  276. # Build and install golang-github-xtaci-kcp deb
  277. build_install_kcpdev() {
  278. if [ $BUILD_KCP -eq 1 ]; then
  279. BRANCH=$1
  280. gbp_build https://anonscm.debian.org/git/pkg-go/packages/golang-github-xtaci-kcp.git $BRANCH
  281. sudo dpkg -i golang-github-xtaci-kcp-dev_*.deb
  282. sudo apt-get install -fy
  283. fi
  284. }
  285. # Build and install golang-github-xtaci-smux deb
  286. build_install_smuxdev() {
  287. if [ $BUILD_KCP -eq 1 ]; then
  288. BRANCH=$1
  289. gbp_build https://anonscm.debian.org/git/pkg-go/packages/golang-github-xtaci-smux.git $BRANCH
  290. sudo dpkg -i golang-github-xtaci-smux-dev_*.deb
  291. sudo apt-get install -fy
  292. fi
  293. }
  294. # Build and install kcptun deb
  295. build_install_kcptun() {
  296. if [ $BUILD_KCP -eq 1 ]; then
  297. BRANCH=$1
  298. gbp_build https://anonscm.debian.org/git/pkg-go/packages/kcptun.git $BRANCH
  299. sudo dpkg -i kcptun_*.deb
  300. sudo apt-get install -fy
  301. fi
  302. }
  303. export XZ_DEFAULTS=--memlimit=128MiB
  304. OSID=$(grep ^ID= /etc/os-release|cut -d= -f2)
  305. OSVER=$(lsb_release -cs)
  306. BUILD_KCP=0
  307. BUILD_LIB=0
  308. BUILD_BIN=0
  309. case "$1" in
  310. --help|-h)
  311. help_usage
  312. ;;
  313. kcp)
  314. BUILD_KCP=1
  315. ;;
  316. lib)
  317. BUILD_LIB=1
  318. ;;
  319. bin)
  320. BUILD_BIN=1
  321. ;;
  322. all|"")
  323. BUILD_LIB=1
  324. BUILD_BIN=1
  325. ;;
  326. *)
  327. echo Parameter error, exiting ...
  328. exit
  329. esac
  330. # Exit if in a git repo
  331. [ -d .git ] && help_usage
  332. case "$OSVER" in
  333. jessie)
  334. BPO="debhelper libsodium-dev"
  335. ;;
  336. xenial)
  337. BPO=debhelper
  338. ;;
  339. esac
  340. apt_init "git-buildpackage pristine-tar equivs" "$BPO"
  341. [ $BUILD_KCP -eq 1 ] && case "$OSVER" in
  342. wheezy|precise|trusty)
  343. echo Sorry, your system $OSID/$OSVER is not supported.
  344. ;;
  345. jessie)
  346. build_install_urfaveclidev
  347. build_install_reedsolomondev
  348. build_install_kcpdev
  349. build_install_smuxdev
  350. build_install_kcptun
  351. ;;
  352. stretch|unstable|sid|yakkety|zesty)
  353. build_install_reedsolomondev
  354. build_install_kcpdev
  355. build_install_smuxdev
  356. build_install_kcptun
  357. ;;
  358. xenial)
  359. build_install_dhgolang debian/jessie-backports
  360. build_install_reedsolomondev
  361. build_install_errorsdev
  362. patch_urfaveclidev_xenial
  363. build_install_urfaveclidev
  364. build_install_snappydev debian/jessie-backports
  365. build_install_kcpdev
  366. build_install_smuxdev
  367. build_install_kcptun
  368. ;;
  369. esac
  370. [ $BUILD_LIB -eq 1 -o $BUILD_BIN -eq 1 ] && case "$OSVER" in
  371. wheezy|precise)
  372. echo Sorry, your system $OSID/$OSVER is not supported.
  373. ;;
  374. jessie|stretch|unstable|sid|zesty)
  375. build_install_libbloom
  376. build_install_sslibev
  377. build_install_simpleobfs
  378. ;;
  379. trusty)
  380. build_install_libcork trusty
  381. build_install_libcorkipset trusty
  382. build_install_libmbedtls debian/jessie-backports
  383. build_install_libsodium
  384. build_install_libbloom trusty
  385. patch_sslibev_dh9
  386. build_install_sslibev
  387. build_install_simpleobfs trusty
  388. ;;
  389. xenial|yakkety)
  390. build_install_libcork debian
  391. build_install_libcorkipset debian
  392. build_install_libbloom
  393. build_install_sslibev
  394. build_install_simpleobfs
  395. ;;
  396. *)
  397. echo Your system $OSID/$OSVER is not supported yet.
  398. echo Please report issue:
  399. echo " https://github.com/shadowsocks/shadowsocks-libev/issues/new"
  400. ;;
  401. esac
  402. apt_clean