Skip to content

Instantly share code, notes, and snippets.

@turicas
Created March 21, 2012 18:24
Show Gist options
  • Select an option

  • Save turicas/2150763 to your computer and use it in GitHub Desktop.

Select an option

Save turicas/2150763 to your computer and use it in GitHub Desktop.
Starts a VNC server, automatically configuring password and display options
#!/bin/bash
# Options:
PASSWORD="mysecret"
DISPLAY=":10"
VNCSERVER_OPTIONS="-geometry 1024x768 -alwaysshared"
PASSWD_PATH="$HOME/.vnc/passwd"
XSTARTUP_PATH="$HOME/.vnc/xstartup"
VNCSERVER="tightvncserver"
VNCPASSWD="tightvncpasswd"
# NOTE: you can change `tightvncpasswd` by `vncpasswd` if you don't use
# TightVNC but it won't work in some VNC implementations
NEW_SESSION="exec gnome-session"
vncserver_stop() {
# Kill server for this display if is running
$VNCSERVER -clean -kill $DISPLAY
}
vncserver_start() {
echo "$PASSWORD" | $VNCPASSWD -f > $PASSWD_PATH
chmod 600 $PASSWD_PATH
echo "$NEW_SESSION" > $XSTARTUP_PATH
$VNCSERVER $DISPLAY $VNCSERVER_OPTIONS
}
case "$1" in
start)
vncserver_start
;;
stop)
vncserver_stop
;;
restart)
vncserver_stop
vncserver_start
;;
*)
echo "Usage: $0 <start|stop|restart>"
exit 1
esac
@walbon
Copy link
Copy Markdown

walbon commented Mar 22, 2012

restart)
    tightvnc_stop
    tightvnc_start
;;

@turicas
Copy link
Copy Markdown
Author

turicas commented Mar 22, 2012

@walbon, thank, you!
Corrected this bug and added more configuration in variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment