Skip to content
Snippets Groups Projects
mk-homedir 1.41 KiB
Newer Older
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
#!/bin/bash

stop() {
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
}

start() {
    echo "ESAME_CLEAN_HOME = ${ESAME_CLEAN_HOME}"
    echo "ESAME_USER = ${ESAME_USER}"
    # Check if we started this service at least once since the exam has been started.
    # If the machine crashes or reboots, the home dir will not be cleaned anyway.
    # The home dir will be cleaned only when the machine will be set to normal and then
    # to exam mode again
    if [[ -f /local/mk-homedir ]]; then
        if [[ ${ESAME_CLEAN_HOME} -eq 1 ]]; then
            (echo -n "CLEANING HOME FOR ${ESAME_USER} at "; date ) >> /var/log/esame.log
            echo "CLEANING HOME FOR ${ESAME_USER}"
            # Start fresh (but keep the home, just in case)
            TIME=`date +%Y%m%d-%H%M`
            cd /local && mv ${ESAME_USER} "${ESAME_USER}.${TIME}"
            chown root:root "${ESAME_USER}.${TIME}"
            chmod 700 "${ESAME_USER}.${TIME}"
            cp -a /opt/esame/home/${ESAME_USER} ./
            chown -Rh ${ESAME_USER}:esame ${ESAME_USER}
        fi
        # remove the file to avoid cleaning the homedir on machine reboot
        rm /local/mk-homedir >/dev/null 2>&1
    else
        echo "ESAME_CLEAN_HOME value not applied."
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
}

args=("$@")

case "$1" in
'start')
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
'stop')
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
'restart')
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
*)
    echo "Usage: $0 { start | stop | restart } {0 | 1} { username }";
    exit 1;
    ;;
Alberto LIVIO BECCARIA's avatar
Alberto LIVIO BECCARIA committed
esac
exit 0