Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rpm package build script #436

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions rpm/SOURCES/etc/init.d/shadowsocks-rust.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: shadowsocks-rust
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: lightweight secured socks5 proxy
# Description: Rust port of shadowsocks.
# shadowsocks is a fast tunnel proxy that helps you bypass firewalls.
### END INIT INFO

# Author: Simon Shi <[email protected]>

# PATH should only include /usr/ if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=shadowsocks-rust # Introduce a short description here
NAME=shadowsocks-rust # Introduce the short server's name here
DAEMON=/usr/bin/ssserver # Introduce the server's location here
DAEMON_ARGS="-u --log-without-time" # Arguments to run the daemon with
PIDFILE=/var/run/$NAME/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

[ "$START" = "yes" ] || exit 0

: ${USER:="nobody"}
: ${GROUP:="nogroup"}

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
# Modify the file descriptor limit
ulimit -n ${MAXFD}

# Take care of pidfile permissions
mkdir /var/run/$NAME 2>/dev/null || true
chown "$USER:$GROUP" /var/run/$NAME

# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON -- \
-c "$CONFFILE" -u -f $PIDFILE $DAEMON_ARGS \
|| return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/5 --pidfile $PIDFILE --exec $DAEMON
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}


case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

:
19 changes: 19 additions & 0 deletions rpm/SOURCES/systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is part of shadowsocks-rust.
#
# 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-rust Custom Client Service for %I
Documentation=https://github.com/shadowsocks/shadowsocks-rust
After=network.target

[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/sslocal --log-without-time -c /etc/shadowsocks-rust/%i.json

[Install]
WantedBy=multi-user.target

19 changes: 19 additions & 0 deletions rpm/SOURCES/systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is part of shadowsocks-rust.
#
# 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-rust Custom Server Service for %I
Documentation=https://github.com/shadowsocks/shadowsocks-rust
After=network.target

[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ssserver --log-without-time -c /etc/shadowsocks-rust/%i.json

[Install]
WantedBy=multi-user.target

25 changes: 25 additions & 0 deletions rpm/SOURCES/systemd/shadowsocks-rust.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Defaults for shadowsocks initscript
# sourced by /etc/init.d/shadowsocks-rust
# installed at /etc/default/shadowsocks-rust 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-rust/config.json"

# Extra command line arguments
DAEMON_ARGS="-u"

# User and group to run the server as
USER=nobody
GROUP=nogroup

# Number of maximum file descriptors
MAXFD=32768
21 changes: 21 additions & 0 deletions rpm/SOURCES/systemd/shadowsocks-rust.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is part of shadowsocks-rust.
#
# This file is default for Debian packaging. See also
# /etc/default/shadowsocks-rust for environment variables.

[Unit]
Description=Shadowsocks-rust Default Server Service
Documentation=https://github.com/shadowsocks/shadowsocks-rust
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/default/shadowsocks-rust
User=nobody
Group=nogroup
LimitNOFILE=32768
ExecStart=/usr/bin/ssserver --log-without-time -c ${CONFFILE} ${DAEMON_ARGS}

[Install]
WantedBy=multi-user.target

128 changes: 128 additions & 0 deletions rpm/SPECS/shadowsocks-rust.spec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
Name: @NAME@
Version: @VERSION@
Release: @RELEASE@%{?dist}
Summary: A Rust port of shadowsocks

Group: Applications/Internet
License: GPLv3+
URL: https://github.com/shadowsocks/%{name}
Source0: @SOURCE@

AutoReq: no
Conflicts: python-shadowsocks python3-shadowsocks
#BuildRequires: make gcc pcre-devel libtool mbedtls-devel libsodium-devel >= 1.0.7 libev-devel udns-devel rust cargo llvm7.0-libs
Requires: pcre libcap


%if 0%{?suse_version}
Requires: libopenssl1_0_0
BuildRequires: libopenssl-devel
%else
Requires: openssl
BuildRequires: openssl-devel
%endif

%if 0%{?fedora} >= 15 || 0%{?rhel} >=7 || 0%{?suse_version} >= 1210
%global use_systemd 1
%else
%global use_systemd 0
%endif

%if 0%{?use_systemd}
%{?systemd_requires}
%if 0%{?suse_version}
BuildRequires: systemd-rpm-macros
%else
BuildRequires: systemd
%endif
%endif


%description
shadowsocks-rust is a rust port of lightweight secured scoks5 proxy.


%prep
#%setup -q
%setup -q -n @NAME_VERSION@

%build
SODIUM_BUILD_STATIC=yes make TARGET=release


%install
mkdir -p %{buildroot}%{_initddir}
make install TARGET=release PREFIX=/usr/bin DESTDIR=%{buildroot}
mkdir -p %{buildroot}/etc/shadowsocks-rust
%if ! 0%{?use_systemd}
#mkdir -p %{buildroot}%{_initddir}
install -m 755 %{_builddir}/%{buildsubdir}/rpm/SOURCES/etc/init.d/shadowsocks-rust.init %{buildroot}%{_initddir}/shadowsocks-rust
%else
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
mkdir -p %{buildroot}%{_unitdir}
install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-rust.default %{buildroot}%{_sysconfdir}/sysconfig/shadowsocks-rust
install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-rust.service %{buildroot}%{_unitdir}/shadowsocks-rust.service
install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-rust-*.service %{buildroot}%{_unitdir}/
%endif
install -m 644 %{_builddir}/%{buildsubdir}/debian/config.json %{buildroot}%{_sysconfdir}/shadowsocks-rust/config.json
%if 0%{?use_systemd} && 0%{?suse_version}
%service_add_pre shadowsocks-rust.service
%endif

%post
%if ! 0%{?use_systemd}
/sbin/chkconfig --add shadowsocks-rust > /dev/null 2>&1 || :
%else
%if 0%{?suse_version}
%service_add_post shadowsocks-rust.service
%else
%systemd_post shadowsocks-rust.service
%endif
%endif
setcap cap_net_bind_service+ep %{_bindir}/sslocal \
cap_net_bind_service+ep %{_bindir}/ssserver \

%preun
%if ! 0%{?use_systemd}
if [ $1 -eq 0 ]; then
/sbin/service shadowsocks-rust stop > /dev/null 2>&1 || :
/sbin/chkconfig --del shadowsocks-rust > /dev/null 2>&1 || :
fi
%else
%if 0%{?suse_version}
%service_del_preun shadowsocks-rust.service
%else
%systemd_preun shadowsocks-rust.service
%preif [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl stop shadowsocks-rust-server@'*'.service > /dev/null 2>&1 || :
systemctl stop shadowsocks-rust-local@'*'.service > /dev/null 2>&1 || :
systemctl --no-reload disable [email protected] > /dev/null 2>&1 || :
systemctl --no-reload disable [email protected] > /dev/null 2>&1 || :
fi
%endif
%endif

%postun
%if 0%{?use_systemd}
%if 0%{?suse_version}
%service_del_postun shadowsocks-rust.service
%else
%systemd_postun_with_restart shadowsocks-rust.service
%systemd_postun_with_restart shadowsocks-rust-server@'*'.service
%systemd_postun_with_restart shadowsocks-rust-local@'*'.service
%endif
%endif

%files
%{_bindir}/*
%config(noreplace) %{_sysconfdir}/shadowsocks-rust/config.json
%if ! 0%{?use_systemd}
%{_initddir}/shadowsocks-rust
%else
%{_unitdir}/shadowsocks-rust.service
%{_unitdir}/shadowsocks-rust-*.service
%config(noreplace) %{_sysconfdir}/sysconfig/shadowsocks-rust
%endif

%changelog
Loading