#!/bin/bash

# Installer des applications locales au clients légers

usage(){
    echo
    echo $0 "<application à installer>"
    echo
    exit
}

error_msg(){
    echo "${1}"
    exit
}

if [ $UID != 0 ];then
    echo "Vous devez être root"
    exit
fi

APP_TO_INSTALL="${1}"

if [ -z $APP_TO_INSTALL ];then
    usage
fi

ltsp-chroot -m which "${APP_TO_INSTALL}" 2>&1 > /dev/null
if [ $? == 0 ];then
    error_msg "L'application ${APP_TO_INSTALL} semble être déjà installée"
fi

#Install app
ltsp-chroot -m apt-get install $APP_TO_INSTALL

if [ $? != 0 ];then
    error_msg "Impossible d'installer l'application ${APP_TO_INSTALL}"
fi

#Generate shortcut
/usr/share/eole/sbin/generate_shortcuts

#Rebuild image
ltsp-update-image
