From 94a9924a780b715a553eaa28a2b6086d27bb123c Mon Sep 17 00:00:00 2001 From: Roger Shimizu Date: Sun, 19 Feb 2017 19:06:03 +0900 Subject: [PATCH] Update deb build script Now build script is able to auto detect system and choose libraries necessary to build. Also update the README accordingly. --- README.md | 7 +- scripts/build_deb.sh | 160 ++++++++++++++++++++++++++++++++++++++++++ scripts/deb4trusty.sh | 72 ------------------- scripts/deb4xenial.sh | 59 ---------------- 4 files changed, 164 insertions(+), 134 deletions(-) create mode 100755 scripts/build_deb.sh delete mode 100755 scripts/deb4trusty.sh delete mode 100755 scripts/deb4xenial.sh diff --git a/README.md b/README.md index 31d39850..69295937 100644 --- a/README.md +++ b/README.md @@ -132,9 +132,10 @@ Please follow the instructions on [Debian Backports Website](https://backports.d You can build shadowsocks-libev and all its dependencies by script: ```bash -./scripts/deb4trusty.sh # for 14.04 (Trusty) - - or - -./scripts/deb4xenial.sh # for 16.04 (Xenial) +mkdir -p ~/build-area/ +cp ./scripts/build_deb.sh ~/build-area/ +cd ~/build-area +./build_deb.sh ``` Otherwise, try to build and install directly from source. See the [Linux](#linux) diff --git a/scripts/build_deb.sh b/scripts/build_deb.sh new file mode 100755 index 00000000..1ca5663b --- /dev/null +++ b/scripts/build_deb.sh @@ -0,0 +1,160 @@ +#!/bin/sh +# Copyright 2017 Roger Shimizu +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +if [ -d .git ]; then + echo Please run this script in a clean place. + echo e.g. + echo " mkdir -p ~/build-area/" + echo " cp $0 ~/build-area/" + echo " cd ~/build-area" + echo " ./$(basename $0)" + exit +fi + +apt_init() { + DEPS="git-buildpackage equivs" + sudo apt-get update + sudo apt-get install -y $DEPS +} + +# Cleanup +apt_clean() { + sudo apt-get purge -y $DEPS $DEPS_BPO shadowsocks-libev-build-deps \ + libcork-dev libcorkipset-dev debhelper + sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps + sudo apt-get purge -y mbedtls-build-deps libmbedtls-dev + sudo apt-get purge -y libsodium-build-deps libsodium-dev + sudo apt-get autoremove -y +} + +gbp_build() { + REPO=$1 + BRANCH=$2 + PROJECT_NAME=$(basename $1|sed s/\.git$//) + gbp clone --pristine-tar $REPO + cd $PROJECT_NAME + git checkout $BRANCH + mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" + rm ${PROJECT_NAME}-build-deps_*.deb + gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar + git clean -fdx + git reset --hard HEAD + cd - +} + +dsc_build() { + DSC=$1 + DSC_FILE=$(basename $1) + dget -ux $DSC + PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2) + echo cd ${PROJECT_NAME}-* + cd ${PROJECT_NAME}-* + mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" + rm ${PROJECT_NAME}-build-deps_*.deb + dpkg-buildpackage -us -uc + cd - +} + +# Build and install libcork deb +build_install_libcork() { + BRANCH=$1 + gbp_build https://github.com/rogers0/libcork $BRANCH + sudo dpkg -i libcork-dev_*.deb libcork16_*.deb +} + +# Build and install libcorkipset deb +build_install_libcorkipset() { + BRANCH=$1 + gbp_build https://github.com/rogers0/libcorkipset $BRANCH + sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb +} + +# Build libmbedtls deb +build_install_libmbedtls() { + gbp_build https://anonscm.debian.org/cgit/collab-maint/mbedtls.git debian/jessie-backports + sudo dpkg -i libmbed*.deb +} + +# Build libsodium deb +build_install_libsodium() { + dsc_build http://httpredir.debian.org/debian/pool/main/libs/libsodium/libsodium_1.0.11-1~bpo8+1.dsc + sudo dpkg -i libsodium*.deb +} + +# Add patch to work on system with debhelper 9 only +patch_sslibev_dh9() { + gbp clone --pristine-tar https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git + cd shadowsocks-libev + sed -i 's/dh $@/dh $@ --with systemd,autoreconf/' debian/rules + sed -i 's/debhelper (>= 10)/debhelper (>= 9), dh-systemd, dh-autoreconf/' debian/control + echo 9 > debian/compat + git add -u + git commit -m "Patch to work with ubuntu trusty (14.04)" + cd - +} + +# Build and install shadowsocks-libev deb +build_install_sslibev() { + gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git master + sudo dpkg -i shadowsocks-libev_*.deb + sudo apt-get install -fy +} + +OSID=$(grep ^ID= /etc/os-release|cut -d= -f2) +case "$OSID" in +debian) + OSVER=$(grep ^VERSION= /etc/os-release|cut -d\( -f2|cut -d\) -f1) + ;; +ubuntu) + OSVER=$(grep DISTRIB_CODENAME /etc/lsb-release|cut -d= -f2) + ;; +*) + OSVER=unknown + ;; +esac + +case "$OSVER" in +wheezy|precise) + echo Sorry, your system $OSID/$OSVER is not supported. + ;; +jessie) + echo Please install from official backports repository: + echo " apt install -t jessie-backports shadowsocks-libev" + ;; +stretch|unstable|sid|yakkety) + echo Please install from official repository: + echo " apt install shadowsocks-libev" + ;; +trusty) + apt_init + build_install_libcork trusty + build_install_libcorkipset trusty + build_install_libmbedtls + build_install_libsodium + patch_sslibev_dh9 + build_install_sslibev + apt_clean + ;; +xenial) + DEPS_BPO="debhelper" + BPO=xenial-backports + sudo sh -c 'printf "deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse" > /etc/apt/sources.list.d/xenial-backports.list' + sudo apt-get update + sudo apt-get install -y -t $BPO $DEPS_BPO + apt_init + build_install_libcork debian + build_install_libcorkipset debian + build_install_sslibev + apt_clean + ;; +*) + echo Your system $OSID/$OSVER is not supported yet. + echo Please report issue: + echo " https://github.com/shadowsocks/shadowsocks-libev/issues/new" + ;; +esac diff --git a/scripts/deb4trusty.sh b/scripts/deb4trusty.sh deleted file mode 100755 index 52b52640..00000000 --- a/scripts/deb4trusty.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# Copyright 2017 Roger Shimizu -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. - -DEPS="git-buildpackage equivs" -sudo apt-get install -y $DEPS - -gbp_build() { - REPO=$1 - BRANCH=$2 - PROJECT_NAME=$(basename $1|sed s/\.git$//) - gbp clone --pristine-tar $REPO - cd $PROJECT_NAME - git checkout $BRANCH - mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" - rm ${PROJECT_NAME}-build-deps_*.deb - gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar - cd - -} - -dsc_build() { - DSC=$1 - DSC_FILE=$(basename $1) - dget -ux $DSC - PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2) - echo cd ${PROJECT_NAME}-* - cd ${PROJECT_NAME}-* - mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" - rm ${PROJECT_NAME}-build-deps_*.deb - dpkg-buildpackage -us -uc - cd - -} - -# Build libcork deb if you don't have -gbp_build https://github.com/rogers0/libcork trusty -sudo dpkg -i libcork-dev_*.deb libcork16_*.deb - -# Build libcorkipset deb if you don't have -gbp_build https://github.com/rogers0/libcorkipset trusty -sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb - -# Build libmbedtls deb if you don't have -gbp_build https://anonscm.debian.org/cgit/collab-maint/mbedtls.git debian/jessie-backports -sudo dpkg -i libmbed*.deb - -# Build libsodium deb if you don't have -dsc_build http://httpredir.debian.org/debian/pool/main/libs/libsodium/libsodium_1.0.11-1~bpo8+1.dsc -sudo dpkg -i libsodium*.deb - -# Build shadowsocks-libev -gbp clone --pristine-tar https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git -# Add patch to work with ubuntu trusty (14.04) -cd shadowsocks-libev -sed -i 's/dh $@/dh $@ --with systemd,autoreconf/' debian/rules -sed -i 's/debhelper (>= 10)/debhelper (>= 9), dh-systemd, dh-autoreconf/' debian/control -echo 9 > debian/compat -git add -u -git commit -m "Patch to work with ubuntu trusty (14.04)" -cd - -gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git master -sudo dpkg -i shadowsocks-libev_*.deb -sudo apt-get install -fy - -# Cleanup -sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps shadowsocks-libev-build-deps \ - mbedtls-build-deps libsodium-build-deps \ - $DEPS libcork-dev libcorkipset-dev libmbedtls-dev libsodium-dev debhelper -sudo apt-get autoremove -y diff --git a/scripts/deb4xenial.sh b/scripts/deb4xenial.sh deleted file mode 100755 index 13b9d28a..00000000 --- a/scripts/deb4xenial.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh -# Copyright 2017 Roger Shimizu -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. - -DEPS="git-buildpackage equivs" -sudo apt-get install -y $DEPS - -gbp_build() { - REPO=$1 - BRANCH=$2 - PROJECT_NAME=$(basename $1|sed s/\.git$//) - gbp clone --pristine-tar $REPO - cd $PROJECT_NAME - git checkout $BRANCH - mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" - rm ${PROJECT_NAME}-build-deps_*.deb - gbp buildpackage -us -uc --git-ignore-branch --git-pristine-tar - cd - -} - -dsc_build() { - DSC=$1 - DSC_FILE=$(basename $1) - dget -ux $DSC - PROJECT_NAME=$(grep ^Source: $DSC_FILE|cut -d" " -f2) - echo cd ${PROJECT_NAME}-* - cd ${PROJECT_NAME}-* - mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" - rm ${PROJECT_NAME}-build-deps_*.deb - dpkg-buildpackage -us -uc - cd - -} - -# Build libcork deb if you don't have -gbp_build https://github.com/rogers0/libcork debian -sudo dpkg -i libcork-dev_*.deb libcork16_*.deb - -# Build libcorkipset deb if you don't have -gbp_build https://github.com/rogers0/libcorkipset debian -sudo dpkg -i libcorkipset-dev_*.deb libcorkipset1_*.deb - -# Build shadowsocks-libev -DEPS_BPO="debhelper" -BPO=xenial-backports -sudo sh -c 'printf "deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse" > /etc/apt/sources.list.d/xenial-backports.list' -sudo apt-get update -sudo apt-get install -y -t $BPO $DEPS_BPO -gbp_build https://anonscm.debian.org/git/collab-maint/shadowsocks-libev.git master -sudo dpkg -i shadowsocks-libev_*.deb -sudo apt-get install -fy - -# Cleanup -sudo apt-get purge -y libcork-build-deps libcorkipset-build-deps shadowsocks-libev-build-deps \ - $DEPS $DEPS_BPO libcork-dev libcorkipset-dev -sudo apt-get autoremove -y