#!/bin/bash # Company: PowerCraft Technology # Author: Copyright Jelle de Jong # Note: Please send me an email if you enhanced the script # Date: 2009-01-03 / 2009-01-09 / 2009-01-26 / 2009-06-13 # This program 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 program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=pct-support-admin SYSCONF="/etc/pct-support-scripts.conf" SYSDIR="/etc/pct-support-scripts.conf.d/" version="0.1.6" author="Jelle de Jong " donation="http://www.tuxcrafter.net/pages/contact.html#paypal-donation" homepage="https://secure.powercraft.nl/svn/packages/trunk/source/pct-support-scripts/" licence="http://www.gnu.org/licenses/gpl-3.0.html" unset PASSWORD unset MODE unset CONFIG function version() { echo $"Usage: $0 --help" echo $"Version: $version" echo $"Author: $author" echo $"Donation: $donation" echo $"Homepage: $homepage" echo $"Licence: $licence" } function usage() { echo "Program to start X11 forwarded remote vnc support session" echo echo "Usage: $0 [options]" echo echo "Options:" echo " -p, --password ... password for vnc server" echo " -m, --mode ... mode (1, 2, 3, 4 or 5)" echo " -c, --config ... name of id-string used in configuration file" echo " -h, --help, -? show this help information" echo " -v, --version show the version and author information" echo echo "Example:" echo " pct-support-admin -p password01" echo " pct-support-admin --password password01 --mode 2" echo " pct-support-admin --config config0" echo echo "Mode:" echo " 1=xtightvncviewer -shared -fullscreen -compresslevel 9 -quality 0 -bgr233 localhost:0" echo " 2=xvnc4viewer -FullScreen -LowColourLevel=1 -AutoSelect=0 -Shared localhost:0" echo " 3=xvnc4viewer -FullScreen -LowColourLevel -Shared localhost:0" echo " 4=vinagre" echo " 5=tsclient" echo echo "How-to use:" echo " /usr/share/doc/pct-support-scripts/README" echo echo "Configuration:" echo " $SYSCONF" echo " $SYSDIR" echo echo " In the configuration files the default password and mode can" echo " be set. Pleae look inside the files to get a better idea" echo " of how to configure them. The --config option can be used to" echo " select additional configurations. For example using" echo " --config config0 will use the section [config0]." echo echo "Notes:" echo " Only use this program through an X11 forwarded ssh session." echo echo " This program is the admin side of the pct-support-login program." echo " Don't run this program without a ssh session with X11 forwarding" echo " enabled. This program is used to provide remote vnc support for" echo " GNU/Linux systems and is developed by PowerCraft Technology." echo echo "Website:" echo " https://secure.powercraft.nl/svn/packages/" echo "Mailinglist:" echo " http://www.powercraft.nl/cgi-bin/mailman/listinfo/packages-commit" echo " http://www.powercraft.nl/cgi-bin/mailman/listinfo/packages-devel" } while [[ "$1" == -* ]]; do case "$1" in -h|--help|-\?) usage; exit 0;; -p|--password) PASSWORD="$2"; shift; shift;; -m|--mode) MODE="$2"; shift; shift;; -c|--config) CONFIG="$2"; shift; shift;; -v|--version) version; exit 0;; --) shift; break;; -*) echo 1>&2 $"invalid option: $1"; usage; exit 1;; esac done function scan_configuration() { file="$1" unset options [ ! -z "$PASSWORD" ] && options+=("PASSWORD") [ ! -z "$MODE" ] && options+=("MODE") for value in "${options[@]}" do sed -n -i -e "/$value/!p" "$file" done } function get_configuration() { section="$1" if [ ! -z "$section" ] && [ ! -z "$CONFIG" ]; then section+="-$CONFIG" elif [ -z "$section" ] && [ ! -z "$CONFIG" ]; then section="$CONFIG" fi [ ! -d "$SYSDIR" ] && mkdir --parents --verbose "$SYSDIR" tempfile=$(mktemp -p "/tmp/" tempfile.XXXXXXXXXX) trap "rm -f $tempfile" 0 1 2 3 15 [ -z "$tempfile" ] && exit 1 files="$SYSCONF" files+=$'\n' files+=$(run-parts --list "$SYSDIR" ) if [ -n "$files" ]; then while read file; do set +e [ ! -r "$file" ] && continue sed -n '/^\['"$section"'\]$/,/^\[.*\]$/{//!p}' "$file" > "$tempfile" scan_configuration "$tempfile" . "$tempfile" set -e done < <(echo "$files") fi } function program() { PASSWORD="$1" if [ -z $(which x11vnc) ] || [ -z $(which xtightvncviewer) ] || [ -z $(which xvnc4viewer) ] || [ -z $(which screen) ] then echo 1>&2 $"please install the xtightvncviewer x11vnc xvnc4viewer screen packages" exit 1 fi echo $"initializing vncserver with the password: $PASSWORD" x11vnc -remote shutdown && sleep 1 screen -x vncserver -X quit > /dev/null || true [ ! -d $HOME/.vnc/ ] && mkdir $HOME/.vnc/ x11vnc -storepasswd "$PASSWORD" ~/.vnc/passwd echo $"starting the x11vnc server" screen -d -m -S vncserver x11vnc -rfbauth ~/.vnc/passwd -shared -forever -localhost -noxrandr -display :0 # screen -r vncserver # C-a a d sleep 3 && echo $"please standby..." # note: when running x11vnc inside a screen the shutdown command does not work # screen -d support-admin } if [ ! -z $CONFIG ]; then get_configuration else get_configuration pct-support-admin fi if [ -z "$PASSWORD" ]; then echo 1>&2 $"password not set, try adding --password support01, closing now" exit 1 fi if [ -z "$MODE" ]; then echo 1>&2 $"mode not set, try adding --mode 1, closing now" exit 1 fi program "$PASSWORD" # export -f program; # screen -d -m -S support-admin bash -c "program $PASSWORD; read" # admin0 logs into the local vnc and shares the same desktop as the client0 # admin0 gives password: $PASSWORD echo $"trying to connect to vnc server, please standby..." # recommended applications from high to low: case "$MODE" in 1) xtightvncviewer -shared -fullscreen -compresslevel 9 -quality 0 -bgr233 localhost:0 ;; 2) xvnc4viewer -FullScreen -LowColourLevel=1 -AutoSelect=0 -Shared localhost:0 ;; 3) xvnc4viewer -FullScreen -LowColourLevel -Shared localhost:0 ;; 4) if [ -z $(which vinagre) ]; then echo 1>&2 $"vinagre not found, please install the vinagre packages" else vinagre fi ;; 5) if [ -z $(which tsclient) ]; then echo 1>&2 $"tsclient not found, please install the tsclient packages" else tsclient fi ;; *) echo "unknown option used for mode argument: $MODE" ;; esac echo $"closing the x11vnc server" x11vnc -remote shutdown && sleep 1 screen -x vncserver -X quit || true echo $"bye" exit