From 05212deeeb2f27a4afc067b4882795e8190907e5 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Thu, 16 May 2013 10:42:04 +0800 Subject: [PATCH] Better debian packaging. Add conffiles to avoid config file being overwritten from update. --- deb/DEBIAN/conffiles | 2 ++ deb/DEBIAN/control | 2 +- deb/DEBIAN/postinst | 5 +++++ deb/DEBIAN/postrm | 7 +++++++ deb/DEBIAN/prerm | 7 +++++++ deb/etc/init.d/shadowsocks | 6 ++++-- script/createdeb.sh | 3 ++- 7 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 deb/DEBIAN/conffiles create mode 100755 deb/DEBIAN/postinst create mode 100755 deb/DEBIAN/postrm create mode 100755 deb/DEBIAN/prerm diff --git a/deb/DEBIAN/conffiles b/deb/DEBIAN/conffiles new file mode 100644 index 00000000..b41e606f --- /dev/null +++ b/deb/DEBIAN/conffiles @@ -0,0 +1,2 @@ +/etc/shadowsocks/config.json +/etc/init.d/shadowsocks diff --git a/deb/DEBIAN/control b/deb/DEBIAN/control index ce9cae28..ae2e2346 100644 --- a/deb/DEBIAN/control +++ b/deb/DEBIAN/control @@ -1,5 +1,5 @@ Package: shadowsocks-go -Version: 0.6.1-1 +Version: VER-1 Section: net Priority: optional Architecture: any diff --git a/deb/DEBIAN/postinst b/deb/DEBIAN/postinst new file mode 100755 index 00000000..dc7e7a93 --- /dev/null +++ b/deb/DEBIAN/postinst @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ -x "/etc/init.d/shadowsocks" ]; then + update-rc.d shadowsocks defaults >/dev/null +fi diff --git a/deb/DEBIAN/postrm b/deb/DEBIAN/postrm new file mode 100755 index 00000000..24af3a60 --- /dev/null +++ b/deb/DEBIAN/postrm @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_installinit +if [ "$1" = "purge" ] ; then + update-rc.d shadowsocks remove >/dev/null +fi +# End automatically added section diff --git a/deb/DEBIAN/prerm b/deb/DEBIAN/prerm new file mode 100755 index 00000000..82316e55 --- /dev/null +++ b/deb/DEBIAN/prerm @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_installinit +if [ -x "/etc/init.d/shadowsocks" ]; then + invoke-rc.d shadowsocks stop || exit $? +fi +# End automatically added section diff --git a/deb/etc/init.d/shadowsocks b/deb/etc/init.d/shadowsocks index ef3aaa20..99ae4179 100755 --- a/deb/etc/init.d/shadowsocks +++ b/deb/etc/init.d/shadowsocks @@ -8,7 +8,7 @@ # Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 -# Default-Stop: +# Default-Stop: 0 1 6 # Short-Description: shadowsocks is a lightweight tunneling proxy # Description: Modified from Linode's nginx fastcgi startup script ### END INIT INFO @@ -16,7 +16,7 @@ # Note: this script requires sudo in order to run shadowsocks as the specified # user. -BIN=/usr/bin/shadowsocks +BIN=/usr/bin/shadowsocks-server CONFIG_FILE=/etc/shadowsocks/config.json LOG_FILE=/var/log/shadowsocks USER=nobody @@ -25,6 +25,8 @@ PID_DIR=/var/run PID_FILE=$PID_DIR/shadowsocks.pid RET_VAL=0 +[ -x $BIN ] || exit 0 + check_running() { if [[ -r $PID_FILE ]]; then read PID <$PID_FILE diff --git a/script/createdeb.sh b/script/createdeb.sh index 9818389b..92a061c8 100755 --- a/script/createdeb.sh +++ b/script/createdeb.sh @@ -35,10 +35,11 @@ DEBDIR=shadowsocks-go_$ver-1-$arch rm -rf $DEBDIR cp -r deb $DEBDIR +sed -i -e "s/VER/$ver/" $DEBDIR/DEBIAN/control || exit 1 sed -i -e "s/^Architecture.*$/Architecture: $arch/" $DEBDIR/DEBIAN/control || exit 1 mkdir -p $DEBDIR/usr/bin -cp cmd/shadowsocks-server/shadowsocks-server $DEBDIR/usr/bin/shadowsocks +cp cmd/shadowsocks-server/shadowsocks-server $DEBDIR/usr/bin/ rm -f cmd/shadowsocks-server/shadowsocks-server fakeroot dpkg-deb --build $DEBDIR