#!/bin/sh
# 
# file   urmagic_x11vnc.sh
# author Damien LETARD <dle@pygmatec.com>
#  
# Script d'installation du serveur vnc en service
# 
LOGGER=/usr/bin/logger


log() {
    $LOGGER -p user.info -t "$0[$$]" -- "$1"
}

if [ "$1" = "" ] ; then
    log "no mountpoint supplied, exiting."
    exit 1 ; fi

MOUNTPOINT=$1

log "Point de montage : $MOUNTPOINT" 

# Warn user not to remove USB key
echo "! Install VNC ... !" | DISPLAY=:0 aosd_cat -R red -x 130 -y -210 -n "Arial Black 40"

for FILE in `find $MOUNTPOINT/package/ -name *.deb`; do
  log "Package trouve : $FILE"
done 

# installation des packages 
su -c "dpkg -i $MOUNTPOINT/package/*.deb"

# Creation du dossier pour stocker le mot de passe
su -c "mkdir /root/.vnc"
# Génération du mot de passe 
su -c "/usr/bin/x11vnc -storepasswd pygmatec /root/.vnc/passwd"

# copy du script dans le dossier /etc/init.d 
su -c "cp $MOUNTPOINT/script/x11vnc /etc/init.d/"
su -c "chmod u+x /etc/init.d/x11vnc"

# enregistrement du service 
su -c "update-rc.d x11vnc defaults"

# Lancement du service 
su -c "/etc/init.d/x11vnc start"


# Make sure data is written to the USB key
sync
sync

# Notify user it is ok to remove USB key
echo "Install VNC OK" | DISPLAY=:0 aosd_cat -x 130 -y -210 -n "Arial Black 40"
