wok rev 18869

shellinabox: add init script
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 03 17:03:06 2016 +0100 (2016-02-03)
parents 8d652865a08a
children 634b0d5e373d
files shellinabox/receipt shellinabox/stuff/10px.css shellinabox/stuff/12px.css shellinabox/stuff/14px.css shellinabox/stuff/16px.css shellinabox/stuff/object.css shellinabox/stuff/shellinabox
line diff
     1.1 --- a/shellinabox/receipt	Tue Feb 02 08:29:58 2016 +0100
     1.2 +++ b/shellinabox/receipt	Wed Feb 03 17:03:06 2016 +0100
     1.3 @@ -13,13 +13,14 @@
     1.4  
     1.5  DEPENDS="zlib"
     1.6  BUILD_DEPENDS="zlib-dev"
     1.7 +SUGGESTED="ssh knock"
     1.8  
     1.9  # Rules to configure and make the package.
    1.10  compile_rules()
    1.11  {
    1.12  	./configure --prefix=/usr \
    1.13 -	--mandir=/usr/share/man \
    1.14 -	$CONFIGURE_ARGS &&
    1.15 +		--mandir=/usr/share/man \
    1.16 +		$CONFIGURE_ARGS &&
    1.17  	make &&
    1.18  	make DESTDIR=$DESTDIR install
    1.19  }
    1.20 @@ -27,6 +28,26 @@
    1.21  # Rules to gen a SliTaz package suitable for Tazpkg.
    1.22  genpkg_rules()
    1.23  {
    1.24 -	mkdir -p $fs/usr/bin
    1.25 +	mkdir -p $fs/usr/bin $fs/usr/share/shellinabox $fs/etc/init.d
    1.26  	cp -a $install/usr/bin $fs/usr
    1.27 +	cp $install/usr/share/doc/shellinabox/*black*.css $fs/usr/share/shellinabox
    1.28 +	cp $stuff/*.css $fs/usr/share/shellinabox
    1.29 +	cp $stuff/shellinabox $fs/etc/init.d/
    1.30  }
    1.31 +
    1.32 +# Pre and post install commands for Tazpkg.
    1.33 +# We stop the server by default in case of upgarde.
    1.34 +pre_install()
    1.35 +{
    1.36 +	[ -z "$1" ] && [ -f /etc/init.d/$PACKAGE ] && /etc/init.d/$PACKAGE stop
    1.37 +}
    1.38 +
    1.39 +post_install()
    1.40 +{
    1.41 +	[ "$1" ] || /etc/init.d/$PACKAGE start
    1.42 +}
    1.43 +
    1.44 +pre_remove()
    1.45 +{
    1.46 +	[ "$1" ] || /etc/init.d/$PACKAGE stop
    1.47 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/shellinabox/stuff/10px.css	Wed Feb 03 17:03:06 2016 +0100
     2.3 @@ -0,0 +1,6 @@
     2.4 +#vt100 #reconnect input { font-size: small; }
     2.5 +#vt100 #scrollable { font-size: 10px; }
     2.6 +#vt100 #cursize { font-size: 10px; }
     2.7 +#vt100 #console { font-size: 10px; }
     2.8 +#vt100 #cursor { font-size: 10px; }
     2.9 +#vt100 #linheight { font-size: 10px; }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/shellinabox/stuff/12px.css	Wed Feb 03 17:03:06 2016 +0100
     3.3 @@ -0,0 +1,6 @@
     3.4 +#vt100 #reconnect input { font-size: small; }
     3.5 +#vt100 #scrollable { font-size: 12px; }
     3.6 +#vt100 #cursize { font-size: 12px; }
     3.7 +#vt100 #console { font-size: 12px; }
     3.8 +#vt100 #cursor { font-size: 12px; }
     3.9 +#vt100 #linheight { font-size: 12px; }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/shellinabox/stuff/14px.css	Wed Feb 03 17:03:06 2016 +0100
     4.3 @@ -0,0 +1,6 @@
     4.4 +#vt100 #reconnect input { font-size: small; }
     4.5 +#vt100 #scrollable { font-size: 14px; }
     4.6 +#vt100 #cursize { font-size: 14px; }
     4.7 +#vt100 #console { font-size: 14px; }
     4.8 +#vt100 #cursor { font-size: 14px; }
     4.9 +#vt100 #linheight { font-size: 14px; }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/shellinabox/stuff/16px.css	Wed Feb 03 17:03:06 2016 +0100
     5.3 @@ -0,0 +1,6 @@
     5.4 +#vt100 #reconnect input { font-size: small; }
     5.5 +#vt100 #scrollable { font-size: 16px; }
     5.6 +#vt100 #cursize { font-size: 16px; }
     5.7 +#vt100 #console { font-size: 16px; }
     5.8 +#vt100 #cursor { font-size: 16px; }
     5.9 +#vt100 #linheight { font-size: 16px; }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/shellinabox/stuff/object.css	Wed Feb 03 17:03:06 2016 +0100
     6.3 @@ -0,0 +1,3 @@
     6.4 +#vt100 #scrollable {
     6.5 +	overflow: hidden;
     6.6 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/shellinabox/stuff/shellinabox	Wed Feb 03 17:03:06 2016 +0100
     7.3 @@ -0,0 +1,103 @@
     7.4 +#!/bin/sh
     7.5 +
     7.6 +services="/"
     7.7 +
     7.8 +mkexe()
     7.9 +{
    7.10 +exe=$0
    7.11 +while true; do
    7.12 +	cd $(dirname $exe)
    7.13 +	exe=$(basename $exe)
    7.14 +	[ -L $exe ] || break
    7.15 +	exe=$(readlink $exe)
    7.16 +done
    7.17 +echo $(pwd)/$exe
    7.18 +}
    7.19 +exe=$(mkexe)
    7.20 +
    7.21 +services_arg()
    7.22 +{
    7.23 +for i in $services ; do
    7.24 +	echo -n "-s '$i:root:root:/tmp:LINES=25 /bin/sh -c \"$exe service $i "
    7.25 +	echo -n "\${peer} \${url} \${columns} \${lines}\"' "
    7.26 +done
    7.27 +}
    7.28 +
    7.29 +launch_ssh()
    7.30 +{
    7.31 +	server=""
    7.32 +	sequence=""
    7.33 +	for i in $(echo "$2" | sed 's/[?&,]/ /g'); do
    7.34 +		case "$i" in
    7.35 +		host=*)		server=${i#host=};;
    7.36 +		knock=*)	sequence=${i#knock=};;
    7.37 +		esac
    7.38 +	done
    7.39 +	if [ -z "$server" ]; then
    7.40 +		# Get SSH server
    7.41 +		echo "Expected format [!][telnet/][user@][host][:port], default local login."
    7.42 +		echo -n "TELNET/SSH server: "
    7.43 +		read -t 300 server
    7.44 +	fi
    7.45 +	[ -n "$server" ] || exec /bin/login
    7.46 +
    7.47 +	# Allow non default SSH port with format server:port
    7.48 +	port=""
    7.49 +	sshport=""
    7.50 +	case "$server" in
    7.51 +	*:*)	port="${server#*:}"
    7.52 +		sshport="-p $port"
    7.53 +		server=${server%:*};;
    7.54 +	esac
    7.55 +
    7.56 +	# heading ! in server name means open remote ssh port with a knock sequence
    7.57 +	if which knock > /dev/null; then
    7.58 +		case "$server" in
    7.59 +		!*)	server=${server#*!}
    7.60 +			if [ -z "$sequence" ]; then
    7.61 +				echo -n "Knock sequence (port[:proto]...): "
    7.62 +				read -t 30 sequence && 
    7.63 +				knock ${server#*@} ${sequence//-/ }
    7.64 +			else
    7.65 +				knock ${server#*@} ${sequence//-/ }
    7.66 +			fi
    7.67 +		esac
    7.68 +	fi
    7.69 +
    7.70 +	# Get SSH user if missing
    7.71 +	case "$server" in
    7.72 +	*/*|*@*)	;;
    7.73 +	*)	echo -n "$server login: "
    7.74 +		read -t 30 user || exit 1
    7.75 +		[ -n "$user" ] || exit 1
    7.76 +		server="$user@$server";;
    7.77 +	esac
    7.78 +
    7.79 +	# Launch OpenSSH or Dropbear
    7.80 +	sshargs="-oPreferredAuthentications=keyboard-interactive,password -oNoHostAuthenticationForLocalhost=yes -oLogLevel=FATAL -F/dev/null";
    7.81 +	[ -L /usr/bin/ssh ] && sshargs=""
    7.82 +	case "$server" in
    7.83 +	*/*)	exec ${server%/*} ${server#*/} $port ;;
    7.84 +	*)	exec ssh $sshport $sshargs $server ;;
    7.85 +	esac
    7.86 +}
    7.87 +
    7.88 +pidfile=/var/run/shellinaboxd.pid
    7.89 +case "$1" in
    7.90 +service)
    7.91 +	case "$2" in
    7.92 +	/)	shift 2; launch_ssh "$@" ;;
    7.93 +	esac
    7.94 +	;;
    7.95 +start)
    7.96 +	dir=$(dirname $exe)
    7.97 +	eval shellinaboxd --background=$pidfile --user=0 \
    7.98 +		--css=/usr/share/shellinabox/object.css \
    7.99 +		--user-css 10px:-/usr/share/shellinabox/10px.css,12px:+/usr/share/shellinabox/12px.css,14px:-/usr/share/shellinabox/14px.css,16px:-/usr/share/shellinabox/16px.css \
   7.100 +		--user-css Normal:+/usr/share/shellinabox/black-on-white.css,Reverse:-/usr/share/shellinabox/white-on-black.css \
   7.101 +		-s /login:LOGIN $(services_arg)
   7.102 +	;;
   7.103 +stop)
   7.104 +	[ -s $pidfile ] && kill $(cat $pidfile)
   7.105 +	;;
   7.106 +esac