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.

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