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.

173 lines
4.5 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 shadowsocks-libev-build-deps \
  41. libcork-dev libcorkipset-dev debhelper
  42. sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps
  43. sudo apt-get purge -y mbedtls-build-deps libmbedtls-dev
  44. sudo apt-get purge -y libsodium-build-deps libsodium-dev
  45. sudo apt-get autoremove -y
  46. }
  47. gbp_build() {
  48. REPO=$1
  49. BRANCH=$2
  50. PROJECT_NAME=$(basename $1|sed s/\.git$//)
  51. gbp clone --pristine-tar $REPO
  52. cd $PROJECT_NAME
  53. git checkout $BRANCH
  54. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  55. rm ${PROJECT_NAME}-build-deps_*.deb
  56. gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar
  57. git clean -fdx
  58. git reset --hard HEAD
  59. cd -
  60. }
  61. dsc_build() {
  62. DSC=$1
  63. DSC_FILE=$(basename $1)
  64. dget -ux $DSC
  65. PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2)
  66. echo cd ${PROJECT_NAME}-*
  67. cd ${PROJECT_NAME}-*
  68. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  69. rm ${PROJECT_NAME}-build-deps_*.deb
  70. dpkg-buildpackage -us -uc
  71. cd -
  72. }
  73. # Build and install libcork deb
  74. build_install_libcork() {
  75. BRANCH=$1
  76. gbp_build https://github.com/rogers0/libcork $BRANCH
  77. sudo dpkg -i libcork-dev_*.deb libcork16_*.deb
  78. }
  79. # Build and install libcorkipset deb
  80. build_install_libcorkipset() {
  81. BRANCH=$1
  82. gbp_build https://github.com/rogers0/libcorkipset $BRANCH
  83. sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb
  84. }
  85. # Build libmbedtls deb
  86. build_install_libmbedtls() {
  87. gbp_build https://anonscm.debian.org/cgit/collab-maint/mbedtls.git debian/jessie-backports
  88. sudo dpkg -i libmbed*.deb
  89. }
  90. # Build libsodium deb
  91. build_install_libsodium() {
  92. dsc_build http://httpredir.debian.org/debian/pool/main/libs/libsodium/libsodium_1.0.11-1~bpo8+1.dsc
  93. sudo dpkg -i libsodium*.deb
  94. }
  95. # Add patch to work on system with debhelper 9 only
  96. patch_sslibev_dh9() {
  97. gbp clone --pristine-tar https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git
  98. cd shadowsocks-libev
  99. sed -i 's/dh $@/dh $@ --with systemd,autoreconf/' debian/rules
  100. sed -i 's/debhelper (>= 10)/debhelper (>= 9), dh-systemd, dh-autoreconf/' debian/control
  101. echo 9 > debian/compat
  102. git add -u
  103. git commit -m "Patch to work with ubuntu trusty (14.04)"
  104. cd -
  105. }
  106. # Build and install shadowsocks-libev deb
  107. build_install_sslibev() {
  108. gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git master
  109. sudo dpkg -i shadowsocks-libev_*.deb
  110. sudo apt-get install -fy
  111. }
  112. OSID=$(grep ^ID= /etc/os-release|cut -d= -f2)
  113. case "$OSID" in
  114. debian)
  115. OSVER=$(grep ^VERSION= /etc/os-release|cut -d\( -f2|cut -d\) -f1)
  116. ;;
  117. ubuntu)
  118. OSVER=$(grep DISTRIB_CODENAME /etc/lsb-release|cut -d= -f2)
  119. ;;
  120. *)
  121. OSVER=unknown
  122. ;;
  123. esac
  124. case "$OSVER" in
  125. wheezy|precise)
  126. echo Sorry, your system $OSID/$OSVER is not supported.
  127. ;;
  128. jessie)
  129. apt_init "git-buildpackage equivs" "debhelper libsodium-dev"
  130. build_install_sslibev
  131. apt_clean
  132. ;;
  133. stretch|unstable|sid|yakkety)
  134. apt_init "git-buildpackage equivs"
  135. build_install_sslibev
  136. apt_clean
  137. ;;
  138. trusty)
  139. apt_init "git-buildpackage equivs"
  140. build_install_libcork trusty
  141. build_install_libcorkipset trusty
  142. build_install_libmbedtls
  143. build_install_libsodium
  144. patch_sslibev_dh9
  145. build_install_sslibev
  146. apt_clean
  147. ;;
  148. xenial)
  149. apt_init "git-buildpackage equivs" debhelper
  150. build_install_libcork debian
  151. build_install_libcorkipset debian
  152. build_install_sslibev
  153. apt_clean
  154. ;;
  155. *)
  156. echo Your system $OSID/$OSVER is not supported yet.
  157. echo Please report issue:
  158. echo " https://github.com/shadowsocks/shadowsocks-libev/issues/new"
  159. ;;
  160. esac