diff --git a/sshpiperd/deb/build.sh b/sshpiperd/deb/build.sh new file mode 100755 index 00000000..278c1b07 --- /dev/null +++ b/sshpiperd/deb/build.sh @@ -0,0 +1,84 @@ +#!/bin/bash +set -e + +BASEDIR=$(dirname $(readlink -f $0)) + +DIST_BIN=${1:-$GOPATH/bin/sshpiperd} +DIST_BIN=`readlink -f $DIST_BIN` + +if [ ! -x $DIST_BIN ];then + echo "can not find sshpiper bin" + exit +fi + +echo "packing bin:$DIST_BIN" + +VERSION=`$DIST_BIN --version | grep -Po "ver: .*? " | sed "s/ver: *//g" | sed "s/ *$//g"` +VERSION=${VERSION#v} ## remove v + +echo "building .deb for ver: $VERSION" + +DIST_DIR=`mktemp -d` + + +## copy from docker +cat > $DIST_DIR/postinst <<'EOF' +#!/bin/sh +set -e +set -u + +update-rc.d sshpiperd defaults > /dev/null || true +if [ -n "$2" ]; then + _dh_action=restart +else + _dh_action=start +fi +service sshpiperd $_dh_action 2>/dev/null || true +#DEBHELPER# +EOF + +cat > $DIST_DIR/prerm <<'EOF' +#!/bin/sh +set -e +set -u +service sshpiperd stop 2>/dev/null || true +#DEBHELPER# +EOF + +chmod +x $DIST_DIR/postinst $DIST_DIR/prerm + + +mkdir -p $DIST_DIR/root/var/sshpiper +mkdir -p $DIST_DIR/root/etc/ +mkdir -p $DIST_DIR/root/usr/local/bin + +cp $DIST_BIN $DIST_DIR/root/usr/local/bin +cp $BASEDIR/sshpiperd.conf $DIST_DIR/root/etc + + +NAME=sshpiperd +MAINTAINER=tgic +CATEGORY=net +DESCRIPTION="Username based SSH Reverse Proxy" +LICENSE="The MIT License (MIT)" +HOMEPAGE="https://github.com/tg123/sshpiper" + +echo $BASEDIR + +fpm -f -s dir -t deb -n "$NAME" -v "$VERSION" \ + --deb-init $BASEDIR/init.d/sshpiperd \ + --deb-priority optional \ + --after-install $DIST_DIR/postinst \ + --before-remove $DIST_DIR/prerm \ + --prefix / \ + --maintainer "$MAINTAINER" \ + --description "$DESCRIPTION" \ + --category "$CATEGORY" \ + --depends libpam0g \ + --provides sshpiperd \ + --url "$HOMEPAGE" \ + --license "$LICENSE" \ + --config-files /etc/sshpiperd.conf \ + -C $DIST_DIR/root . + +rm -rf $DIST_DIR diff --git a/sshpiperd/deb/init.d/sshpiperd b/sshpiperd/deb/init.d/sshpiperd new file mode 100644 index 00000000..5abb9eda --- /dev/null +++ b/sshpiperd/deb/init.d/sshpiperd @@ -0,0 +1,47 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: sshpiperd +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Username based SSH Reverse Proxy +### END INIT INFO + +. /lib/lsb/init-functions + +SSHPIPERD_BIN=/usr/local/bin/sshpiperd +SSHPIPERD_PID=/var/run/sshpiperd.pid + +touch $SSHPIPERD_PID + +case "$1" in + start) + log_begin_msg "Starting SSHPiperd" + start-stop-daemon --start --background \ + --exec "$SSHPIPERD_BIN" \ + --pidfile "$SSHPIPERD_PID" --make-pidfile + log_end_msg $? + ;; + + stop) + log_begin_msg "Stopping SSHPiperd" + start-stop-daemon --stop --pidfile "$SSHPIPERD_PID" + log_end_msg $? + ;; + + restart) + $0 stop + $0 start + ;; + + status) + status_of_proc -p "$SSHPIPERD_PID" "$SSHPIPERD_BIN" "SSHPiperd" + ;; + + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac diff --git a/sshpiperd/deb/sshpiperd.conf b/sshpiperd/deb/sshpiperd.conf new file mode 100644 index 00000000..2a3e2525 --- /dev/null +++ b/sshpiperd/deb/sshpiperd.conf @@ -0,0 +1,23 @@ +## SSH Piper +## Username based SSH Reverse Proxy +## see https://github.com/tg123/sshpiper#configuration + +## log path +LOG=/var/log/sshpiperd.log + +## Additional challenger name +## https://github.com/tg123/sshpiper#additional-challenge +#CHALLENGER=pam + +# Server Key file for SSH Piper +#SERVER_KEY=/etc/ssh/ssh_host_rsa_key + +## Listening Address +#LISTEN_ADDR=0.0.0.0 + +## Listening Port +#PORT=2222 + +## Working Dir +## https://github.com/tg123/sshpiper#files-inside-working-dir +#WORKING_DIR=/var/sshpiper