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.

218 lines
5.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. if [ -d .git ]; then
  9. echo Please run this script in a clean place.
  10. echo e.g.
  11. echo " mkdir -p ~/build-area/"
  12. echo " cp $0 ~/build-area/"
  13. echo " cd ~/build-area"
  14. echo " ./$(basename $0)"
  15. exit
  16. fi
  17. apt_init() {
  18. DEPS="$1"
  19. DEPS_BPO="$2"
  20. if [ -n "$DEPS_BPO" ]; then
  21. BPO=${OSVER}-backports
  22. case "$OSID" in
  23. debian)
  24. REPO=http://httpredir.debian.org/debian
  25. ;;
  26. ubuntu)
  27. REPO=http://archive.ubuntu.com/ubuntu
  28. ;;
  29. esac
  30. sudo sh -c "printf \"deb $REPO ${OSVER}-backports main\" > /etc/apt/sources.list.d/${OSVER}-backports.list"
  31. sudo apt-get update
  32. sudo apt-get install -y -t $BPO $DEPS_BPO
  33. else
  34. sudo apt-get update
  35. fi
  36. sudo apt-get install -y $DEPS
  37. }
  38. # Cleanup
  39. apt_clean() {
  40. sudo apt-get purge -y $DEPS $DEPS_BPO debhelper \
  41. libbloom-dev libcork-dev libcorkipset-dev libmbedtls-dev \
  42. libsodium-dev libbloom-build-deps simple-obfs-build-deps \
  43. shadowsocks-libev-build-deps
  44. sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps
  45. sudo apt-get purge -y libsodium-build-deps
  46. sudo apt-get purge -y mbedtls-build-deps
  47. sudo apt-get autoremove -y
  48. }
  49. gbp_build() {
  50. REPO=$1
  51. BRANCH=$2
  52. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  53. gbp clone --pristine-tar $REPO
  54. cd $PROJECT_NAME
  55. git checkout $BRANCH
  56. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  57. rm ${PROJECT_NAME}-build-deps_*.deb
  58. gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar
  59. git clean -fdx
  60. git reset --hard HEAD
  61. cd -
  62. }
  63. git_build() {
  64. REPO=$1
  65. BRANCH=$2
  66. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  67. git clone $REPO
  68. cd $PROJECT_NAME
  69. git checkout $BRANCH
  70. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  71. rm ${PROJECT_NAME}-build-deps_*.deb
  72. gbp buildpackage -us -uc --git-ignore-branch
  73. git clean -fdx
  74. git reset --hard HEAD
  75. cd -
  76. }
  77. dsc_build() {
  78. DSC=$1
  79. DSC_FILE=$(basename $1)
  80. dget -ux $DSC
  81. PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2)
  82. echo cd ${PROJECT_NAME}-*
  83. cd ${PROJECT_NAME}-*
  84. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  85. rm ${PROJECT_NAME}-build-deps_*.deb
  86. dpkg-buildpackage -us -uc
  87. cd -
  88. }
  89. # Build and install libcork deb
  90. build_install_libcork() {
  91. BRANCH=$1
  92. gbp_build https://github.com/rogers0/libcork $BRANCH
  93. sudo dpkg -i libcork-dev_*.deb libcork16_*.deb
  94. }
  95. # Build and install libcorkipset deb
  96. build_install_libcorkipset() {
  97. BRANCH=$1
  98. gbp_build https://github.com/rogers0/libcorkipset $BRANCH
  99. sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb
  100. }
  101. # Build libmbedtls deb
  102. build_install_libmbedtls() {
  103. BRANCH=$1
  104. gbp_build https://anonscm.debian.org/git/collab-maint/mbedtls.git $BRANCH
  105. sudo dpkg -i libmbed*.deb
  106. }
  107. # Build libsodium deb
  108. build_install_libsodium() {
  109. dsc_build http://httpredir.debian.org/debian/pool/main/libs/libsodium/libsodium_1.0.11-1~bpo8+1.dsc
  110. sudo dpkg -i libsodium*.deb
  111. }
  112. # Build libbloom deb
  113. build_install_libbloom() {
  114. BRANCH=$1
  115. gbp_build https://github.com/rogers0/libbloom $BRANCH
  116. sudo dpkg -i libbloom-dev_*.deb libbloom1_*.deb
  117. }
  118. # Add patch to work on system with debhelper 9 only
  119. patch_sslibev_dh9() {
  120. BRANCH=$1
  121. gbp clone --pristine-tar https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git
  122. cd shadowsocks-libev
  123. git checkout $BRANCH
  124. sed -i 's/dh $@/dh $@ --with systemd,autoreconf/' debian/rules
  125. sed -i 's/debhelper (>= 10)/debhelper (>= 9), dh-systemd, dh-autoreconf/' debian/control
  126. echo 9 > debian/compat
  127. git add -u
  128. git commit -m "Patch to work with ubuntu trusty (14.04)"
  129. cd -
  130. }
  131. # Build and install shadowsocks-libev deb
  132. build_install_sslibev() {
  133. BRANCH=$1
  134. gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git $BRANCH
  135. sudo dpkg -i shadowsocks-libev_*.deb
  136. sudo apt-get install -fy
  137. }
  138. # Build and install simple-obfs
  139. build_install_simpleobfs() {
  140. BRANCH=$1
  141. git_build https://github.com/rogers0/simple-obfs $BRANCH
  142. sudo dpkg -i simple-obfs_*.deb
  143. sudo apt-get install -fy
  144. }
  145. export XZ_DEFAULTS=--memlimit=128MiB
  146. OSID=$(grep ^ID= /etc/os-release|cut -d= -f2)
  147. OSVER=$(lsb_release -cs)
  148. case "$OSVER" in
  149. wheezy|precise)
  150. echo Sorry, your system $OSID/$OSVER is not supported.
  151. ;;
  152. jessie)
  153. apt_init "git-buildpackage equivs" "debhelper libsodium-dev"
  154. build_install_libbloom exp1
  155. build_install_sslibev exp1
  156. build_install_simpleobfs exp1
  157. apt_clean
  158. ;;
  159. stretch|unstable|sid)
  160. apt_init "git-buildpackage equivs"
  161. build_install_libbloom exp1
  162. build_install_sslibev exp1
  163. build_install_simpleobfs exp1
  164. apt_clean
  165. ;;
  166. trusty)
  167. apt_init "git-buildpackage equivs"
  168. build_install_libcork trusty
  169. build_install_libcorkipset trusty
  170. build_install_libmbedtls debian/jessie-backports
  171. build_install_libsodium
  172. build_install_libbloom exp1_trusty
  173. patch_sslibev_dh9 exp1
  174. build_install_sslibev exp1
  175. build_install_simpleobfs exp1_trusty
  176. apt_clean
  177. ;;
  178. xenial)
  179. apt_init "git-buildpackage equivs" debhelper
  180. build_install_libcork debian
  181. build_install_libcorkipset debian
  182. build_install_libbloom exp1
  183. build_install_sslibev exp1
  184. build_install_simpleobfs exp1
  185. apt_clean
  186. ;;
  187. yakkety)
  188. apt_init "git-buildpackage equivs"
  189. build_install_libcork debian
  190. build_install_libcorkipset debian
  191. build_install_libbloom exp1
  192. build_install_sslibev exp1
  193. build_install_simpleobfs exp1
  194. apt_clean
  195. ;;
  196. *)
  197. echo Your system $OSID/$OSVER is not supported yet.
  198. echo Please report issue:
  199. echo " https://github.com/shadowsocks/shadowsocks-libev/issues/new"
  200. ;;
  201. esac