From feeaff85e156e09f1636ed3a47ac9375c81ceb87 Mon Sep 17 00:00:00 2001 From: Yuxiang Zhu Date: Mon, 21 Aug 2017 11:03:08 +0800 Subject: [PATCH] Provides separated service files for RPM packages As discussed with @librehat in #1604, maintaining a separate set of systemd files for RPM distributions will be convenient to build on Copr. This patch will also change some lines in rpm/genrpm.sh to archive the source code using `git archive` because the old logic doesn't respect `.gitignore`. --- .gitignore | 10 +++--- rpm/SOURCES/0001-systemd-services.patch | 36 ------------------- .../systemd/shadowsocks-libev-local.service | 27 ++++++++++++++ .../systemd/shadowsocks-libev-local@.service | 27 ++++++++++++++ .../systemd/shadowsocks-libev-redir@.service | 27 ++++++++++++++ .../systemd/shadowsocks-libev-server@.service | 27 ++++++++++++++ .../systemd/shadowsocks-libev-tunnel@.service | 27 ++++++++++++++ rpm/SOURCES/systemd/shadowsocks-libev.default | 25 +++++++++++++ rpm/SOURCES/systemd/shadowsocks-libev.service | 27 ++++++++++++++ rpm/SPECS/shadowsocks-libev.spec.in | 10 ++---- rpm/genrpm.sh | 31 ++++++++-------- 11 files changed, 212 insertions(+), 62 deletions(-) delete mode 100644 rpm/SOURCES/0001-systemd-services.patch create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev-local.service create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev-local@.service create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev-redir@.service create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev-server@.service create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev-tunnel@.service create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev.default create mode 100644 rpm/SOURCES/systemd/shadowsocks-libev.service diff --git a/.gitignore b/.gitignore index 6e0a48ab..7df17bd1 100644 --- a/.gitignore +++ b/.gitignore @@ -44,11 +44,12 @@ shadowsocks-libev.pc debian/libshadowsocks-libev*.symbols libsodium/src/libsodium/include/sodium/version.h rpm/SPECS/shadowsocks-libev.spec -rpm/SRPMS +rpm/SRPMS/ rpm/RPMS/ -rpm/SOURCES/ -!rpm/SOURCES/etc/init.d/shadowsocks-libev -rpm/BUILD +rpm/BUILD/ +rpm/BUILDROOT/ +*.rpm +*.deb # Ignore per-project vim config .vimrc @@ -87,6 +88,7 @@ doc/*.html *.so *.pcf.gz *.pdb +*.tar *.tar.bz2 *.tar.gz *.tgz diff --git a/rpm/SOURCES/0001-systemd-services.patch b/rpm/SOURCES/0001-systemd-services.patch deleted file mode 100644 index f9b241f7..00000000 --- a/rpm/SOURCES/0001-systemd-services.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff -ru shadowsocks-libev-orig/debian/shadowsocks-libev.default shadowsocks-libev/debian/shadowsocks-libev.default ---- shadowsocks-libev-orig/debian/shadowsocks-libev.default 2017-06-02 08:45:07.000000000 +0800 -+++ shadowsocks-libev/debian/shadowsocks-libev.default 2017-06-28 16:39:37.236474413 +0800 -@@ -19,7 +19,7 @@ - - # User and group to run the server as - USER=nobody --GROUP=nogroup -+GROUP=nobody - - # Number of maximum file descriptors - MAXFD=32768 -diff -ru shadowsocks-libev-orig/debian/shadowsocks-libev.service shadowsocks-libev/debian/shadowsocks-libev.service ---- shadowsocks-libev-orig/debian/shadowsocks-libev.service 2017-06-02 08:45:07.000000000 +0800 -+++ shadowsocks-libev/debian/shadowsocks-libev.service 2017-06-28 17:23:55.131822730 +0800 -@@ -6,7 +6,7 @@ - # (at your option) any later version. - # - # This file is default for Debian packaging. See also --# /etc/default/shadowsocks-libev for environment variables. -+# /etc/sysconfig/shadowsocks-libev for environment variables. - - [Unit] - Description=Shadowsocks-libev Default Server Service -@@ -15,9 +15,9 @@ - - [Service] - Type=simple --EnvironmentFile=/etc/default/shadowsocks-libev -+EnvironmentFile=/etc/sysconfig/shadowsocks-libev - User=nobody --Group=nogroup -+Group=nobody - LimitNOFILE=32768 - ExecStart=/usr/bin/ss-server -c $CONFFILE $DAEMON_ARGS - diff --git a/rpm/SOURCES/systemd/shadowsocks-libev-local.service b/rpm/SOURCES/systemd/shadowsocks-libev-local.service new file mode 100644 index 00000000..0768bce0 --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev-local.service @@ -0,0 +1,27 @@ +# This file is part of shadowsocks-libev. +# +# Shadowsocks-libev 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. +# +# This file is default for RPM packaging. See also +# /etc/sysconfig/shadowsocks-libev for environment variables. + +[Unit] +Description=Shadowsocks-libev Default Local Service +Documentation=man:shadowsocks-libev(8) +After=network.target + +[Service] +Type=simple +EnvironmentFile=/etc/sysconfig/shadowsocks-libev +User=nobody +Group=nobody +LimitNOFILE=32768 +ExecStart=/usr/bin/ss-local -c "$CONFFILE" $DAEMON_ARGS +CapabilityBoundingSet=CAP_NET_BIND_SERVICE + +[Install] +WantedBy=multi-user.target + diff --git a/rpm/SOURCES/systemd/shadowsocks-libev-local@.service b/rpm/SOURCES/systemd/shadowsocks-libev-local@.service new file mode 100644 index 00000000..c1f80be7 --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev-local@.service @@ -0,0 +1,27 @@ +# This file is part of shadowsocks-libev. +# +# Shadowsocks-libev 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. +# +# This is a template unit file. Users may copy and rename the file into +# config directories to make new service instances. See systemd.unit(5) +# for details. + +[Unit] +Description=Shadowsocks-Libev Custom Client Service for %I +Documentation=man:ss-local(1) +After=network.target + +[Service] +Type=simple +CapabilityBoundingSet=CAP_NET_BIND_SERVICE +ExecStart=/usr/bin/ss-local -c /etc/shadowsocks-libev/%i.json +User=nobody +Group=nobody +LimitNOFILE=32768 + +[Install] +WantedBy=multi-user.target + diff --git a/rpm/SOURCES/systemd/shadowsocks-libev-redir@.service b/rpm/SOURCES/systemd/shadowsocks-libev-redir@.service new file mode 100644 index 00000000..07cc74a8 --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev-redir@.service @@ -0,0 +1,27 @@ +# This file is part of shadowsocks-libev. +# +# Shadowsocks-libev 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. +# +# This is a template unit file. Users may copy and rename the file into +# config directories to make new service instances. See systemd.unit(5) +# for details. + +[Unit] +Description=Shadowsocks-Libev Custom Client Service Redir Mode for %I +Documentation=man:ss-redir(1) +After=network.target + +[Service] +Type=simple +CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE +ExecStart=/usr/bin/ss-redir -c /etc/shadowsocks-libev/%i.json +User=nobody +Group=nobody +LimitNOFILE=32768 + +[Install] +WantedBy=multi-user.target + diff --git a/rpm/SOURCES/systemd/shadowsocks-libev-server@.service b/rpm/SOURCES/systemd/shadowsocks-libev-server@.service new file mode 100644 index 00000000..7e7d298a --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev-server@.service @@ -0,0 +1,27 @@ +# This file is part of shadowsocks-libev. +# +# Shadowsocks-libev 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. +# +# This is a template unit file. Users may copy and rename the file into +# config directories to make new service instances. See systemd.unit(5) +# for details. + +[Unit] +Description=Shadowsocks-Libev Custom Server Service for %I +Documentation=man:ss-server(1) +After=network.target + +[Service] +Type=simple +CapabilityBoundingSet=CAP_NET_BIND_SERVICE +ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/%i.json +User=nobody +Group=nobody +LimitNOFILE=32768 + +[Install] +WantedBy=multi-user.target + diff --git a/rpm/SOURCES/systemd/shadowsocks-libev-tunnel@.service b/rpm/SOURCES/systemd/shadowsocks-libev-tunnel@.service new file mode 100644 index 00000000..fa6e30cd --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev-tunnel@.service @@ -0,0 +1,27 @@ +# This file is part of shadowsocks-libev. +# +# Shadowsocks-libev 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. +# +# This is a template unit file. Users may copy and rename the file into +# config directories to make new service instances. See systemd.unit(5) +# for details. + +[Unit] +Description=Shadowsocks-Libev Custom Client Service Tunnel Mode for %I +Documentation=man:ss-tunnel(1) +After=network.target + +[Service] +Type=simple +CapabilityBoundingSet=CAP_NET_BIND_SERVICE +ExecStart=/usr/bin/ss-tunnel -c /etc/shadowsocks-libev/%i.json +User=nobody +Group=nobody +LimitNOFILE=32768 + +[Install] +WantedBy=multi-user.target + diff --git a/rpm/SOURCES/systemd/shadowsocks-libev.default b/rpm/SOURCES/systemd/shadowsocks-libev.default new file mode 100644 index 00000000..389587f4 --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev.default @@ -0,0 +1,25 @@ +# Defaults for shadowsocks initscript +# sourced by /etc/init.d/shadowsocks-libev +# installed at /etc/default/shadowsocks-libev by the maintainer scripts + +# +# This is a POSIX shell fragment +# +# Note: `START', `GROUP' and `MAXFD' options are not recognized by systemd. +# Please change those settings in the corresponding systemd unit file. + +# Enable during startup? +START=yes + +# Configuration file +CONFFILE="/etc/shadowsocks-libev/config.json" + +# Extra command line arguments +DAEMON_ARGS="-u" + +# User and group to run the server as +USER=nobody +GROUP=nobody + +# Number of maximum file descriptors +MAXFD=32768 diff --git a/rpm/SOURCES/systemd/shadowsocks-libev.service b/rpm/SOURCES/systemd/shadowsocks-libev.service new file mode 100644 index 00000000..fd4cda7b --- /dev/null +++ b/rpm/SOURCES/systemd/shadowsocks-libev.service @@ -0,0 +1,27 @@ +# This file is part of shadowsocks-libev. +# +# Shadowsocks-libev 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. +# +# This file is default for RPM packaging. See also +# /etc/sysconfig/shadowsocks-libev for environment variables. + +[Unit] +Description=Shadowsocks-libev Default Server Service +Documentation=man:shadowsocks-libev(8) +After=network.target + +[Service] +Type=simple +EnvironmentFile=/etc/sysconfig/shadowsocks-libev +User=nobody +Group=nobody +LimitNOFILE=32768 +ExecStart=/usr/bin/ss-server -c "$CONFFILE" $DAEMON_ARGS +CapabilityBoundingSet=CAP_NET_BIND_SERVICE + +[Install] +WantedBy=multi-user.target + diff --git a/rpm/SPECS/shadowsocks-libev.spec.in b/rpm/SPECS/shadowsocks-libev.spec.in index 4abe1193..4ba6a78d 100644 --- a/rpm/SPECS/shadowsocks-libev.spec.in +++ b/rpm/SPECS/shadowsocks-libev.spec.in @@ -7,7 +7,6 @@ Group: Applications/Internet License: GPLv3+ URL: https://github.com/shadowsocks/%{name} Source0: %{url}/archive/v%{version}.tar.gz -Patch0: 0001-systemd-services.patch AutoReq: no Conflicts: python-shadowsocks python3-shadowsocks @@ -46,7 +45,6 @@ shadowsocks-libev is a lightweight secured scoks5 proxy for embedded devices and %prep %setup -q -%patch0 -p1 %build ./autogen.sh @@ -68,9 +66,8 @@ install -m 755 %{_builddir}/%{buildsubdir}/rpm/SOURCES/etc/init.d/shadowsocks-li %else mkdir -p %{buildroot}%{_sysconfdir}/sysconfig mkdir -p %{buildroot}%{_unitdir} -install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev.default %{buildroot}%{_sysconfdir}/sysconfig/shadowsocks-libev -install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev.service %{buildroot}%{_unitdir}/shadowsocks-libev.service -install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev-*.service %{buildroot}%{_unitdir}/ +install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-libev.default %{buildroot}%{_sysconfdir}/sysconfig/shadowsocks-libev +install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-libev*.service %{buildroot}%{_unitdir}/ %endif install -m 644 %{_builddir}/%{buildsubdir}/debian/config.json %{buildroot}%{_sysconfdir}/shadowsocks-libev/config.json @@ -134,8 +131,7 @@ fi %if ! 0%{?use_systemd} %{_initddir}/shadowsocks-libev %else -%{_unitdir}/shadowsocks-libev.service -%{_unitdir}/shadowsocks-libev-*.service +%{_unitdir}/shadowsocks-libev*.service %config(noreplace) %{_sysconfdir}/sysconfig/shadowsocks-libev %endif diff --git a/rpm/genrpm.sh b/rpm/genrpm.sh index 8e5190e3..877c66b7 100755 --- a/rpm/genrpm.sh +++ b/rpm/genrpm.sh @@ -34,10 +34,10 @@ do done # determine version and release number -GIT_DESCRIBE=$(git describe --tags --match 'v*' --long --dirty) +GIT_DESCRIBE=$(git describe --tags --match 'v*' --long) # GIT_DESCRIBE is like v3.0.3-11-g1e3f35c-dirty -if [[ ! "$GIT_DESCRIBE" =~ ^v([^-]+)-([0-9]+)-g([0-9a-f]+)(-dirty)?$ ]]; then +if [[ ! "$GIT_DESCRIBE" =~ ^v([^-]+)-([0-9]+)-g([0-9a-f]+)$ ]]; then >&2 echo 'ERROR - unrecognized `git describe` output: '"$GIT_DESCRIBE" exit 1 fi @@ -45,30 +45,31 @@ fi TARGET_VERSION=${BASH_REMATCH[1]} TARGET_COMMITS=${BASH_REMATCH[2]} TARGET_SHA1=${BASH_REMATCH[3]} -TARGET_DIRTY=${BASH_REMATCH[4]} TARGET_RELEASE=1 if [ "$TARGET_COMMITS" -gt 0 ]; then TARGET_RELEASE+=".$TARGET_COMMITS.git$TARGET_SHA1" fi -if [ -n "$TARGET_DIRTY" ]; then - TARGET_RELEASE+=.dirty -fi TARGET_VERREL=$TARGET_VERSION-$TARGET_RELEASE >&2 echo "INFO - RPM version-release is $TARGET_VERREL." - # archive tarball from Git workspace -TARGET_TARBALL_NAME=shadowsocks-libev-$TARGET_VERSION -TARGET_TARBALL_DIR=$HERE/SOURCES +export TARGET_TARBALL_NAME=shadowsocks-libev-$TARGET_VERSION +export TARGET_TARBALL_DIR=$HERE/SOURCES mkdir -p -- "$TARGET_TARBALL_DIR" -#git archive HEAD --format=tar --prefix="$TARGET_TARBALL_NAME/" \ -# -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" pushd "$HERE"/.. -make clean -tar --exclude './rpm' --exclude '.[^/]*' --transform "s,^\.,$TARGET_TARBALL_NAME," \ - -cvf "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" . +# archive this repo +git archive HEAD --format=tar --prefix="$TARGET_TARBALL_NAME/" \ + -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" +# archive submodules +git submodule update --init +git submodule foreach 'git archive HEAD --format=tar \ + --prefix="$TARGET_TARBALL_NAME/$path/" \ + -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME-submodule-$path-$sha1.tar" + tar -n --concatenate --file="$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" \ + "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME-submodule-$path-$sha1.tar"' +gzip -c "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" > "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar.gz" popd # generate spec file @@ -77,7 +78,7 @@ mkdir -p -- "$TARGET_SPEC_DIR" TARGET_SPEC_PATH=$TARGET_SPEC_DIR/shadowsocks-libev.spec sed -e "s/^\(Version:\).*$/\1 ${TARGET_VERSION}/" \ -e "s/^\(Release:\).*$/\1 ${TARGET_RELEASE}%{?dist}/" \ - -e "s/^\(Source0:\).*$/\1 ${TARGET_TARBALL_NAME}.tar/" \ + -e "s/^\(Source0:\).*$/\1 ${TARGET_TARBALL_NAME}.tar.gz/" \ "${TARGET_SPEC_PATH}".in > "${TARGET_SPEC_PATH}" # build rpms