diff --git a/bin/desktop-wallpaper b/bin/desktop-wallpaper new file mode 100755 index 0000000000000000000000000000000000000000..aadebd41f97431ccdedc71b899d7845f3c88a3d2 --- /dev/null +++ b/bin/desktop-wallpaper @@ -0,0 +1,36 @@ +#!/bin/bash + +stop() { + : +} + +start() { + if [ "z${ESAME_DESKTOP_WALLPAPER_URL}" != "z" -a "z${ESAME_DESKTOP_WM}" != "z" ]; then + if [[ ${ESAME_DESKTOP_WM} == "xfce4" ]] + then + sed -i 's@\(image-path.*value="\)\([^"]*\)\("\)@\1'"`echo "${ESAME_DESKTOP_WALLPAPER_URL}"`"'\3@g' /local/${ESAME_USER}/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml + echo "Desktop wallpaper set to ${ESAME_DESKTOP_WALLPAPER_URL}" + fi + fi +} + + +args=("$@") + +case "$1" in + 'start') + start + ;; + 'stop') + stop + ;; + 'restart') + stop + start + ;; + *) + echo "Usage: $0 { start | stop | restart }"; + exit 1; + ;; +esac +exit 0 diff --git a/bin/esamesync-esame.sh b/bin/esamesync-esame.sh new file mode 100755 index 0000000000000000000000000000000000000000..7c90c25cded0ffa8155e1392e004a9b890a49304 --- /dev/null +++ b/bin/esamesync-esame.sh @@ -0,0 +1,39 @@ +#!/bin/bash +#/usr/local/sbin/esamesync-esame.sh + +# Host for the sync operation +# (A different value can be specified in /etc/sysconfig/esamesync-esame) +ESAMESYNCHOST=master2.edu-al.unipmn.it + +# Max delay in case of errors (a random delay will be used, calculated +# between 0 and this value). +# (A different value can be specified in /etc/sysconfig/esamesync-esame) +MAXSLEEP=30 + +# Configuration override can go to: +. /etc/sysconfig/esamesync-esame + +/usr/local/bin/bta-netwait ${ESAMESYNCHOST} + +/bin/cat <<MSG +Starting /opt/esame syncronization (if it seems to be stuck, please wait for +a few minutes for your updates to take place; they can require a long time) + + DON'T TURN OFF THIS MACHINE NOW, JUST WAIT UNTIL FINISHED + +MSG + +DST=/opt/esame/ +SRC=rsync://${ESAMESYNCHOST}/opt/esame/ + +cd ${DST} + +# To fix spurious errors, we pause and repeat the sync if necessary. +# Note: excluding /opt/google as that is installed locally with RPMs. +# Note: excluding /opt/esame as it is already syncronized on every boot. +# +while ! rsync -avq --sparse --progress --delete --whole-file ${SRC} . ; do + SLEEPTIME="$(expr $RANDOM % $MAXSLEEP)" + echo "Error from rsync, sleeping for ${SLEEPTIME} seconds." + sleep ${SLEEPTIME} +done diff --git a/bin/get-config b/bin/get-config index e8a50991038bb9609ec6a8b9c8dcea113bec379a..be73cbe42ada8ee23190f74118b005761df8e075 100755 --- a/bin/get-config +++ b/bin/get-config @@ -3,7 +3,21 @@ API_BASE_URL=https://labmanager-api.edu-al.unipmn.it/api/1.0 function getTokenJSON() { - echo `curl -s -k --max-time 10 -X POST -H "Content-Type: application/json" -d "{\"login\":\"guest\",\"pwd\":\"\"}" ${API_BASE_URL}/login` + # store the whole response with the status at the end + HTTP_RESPONSE=$(curl -s -k -w "HTTPSTATUS:%{http_code}" --max-time 10 -X POST -H "Content-Type: application/json" -d "{\"login\":\"guest\",\"pwd\":\"\"}" ${API_BASE_URL}/login) + # extract the body + HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + # extract the status + HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + + # check the status + if [[ $HTTP_STATUS -ne 200 ]] + then + echo "Error authenticating to server (http_status=$HTTP_STATUS)" + exit 1 + else + echo $HTTP_BODY + fi } @@ -19,41 +33,27 @@ stop() { } -start() { - echo "START ESAME-GET-CONFIG" - +getConfigVars() { TOKEN_JSON=$(getTokenJSON) TOKEN=`echo ${TOKEN_JSON} | jsonValue token 1` MACHINE_NAME=`hostname` MACHINE_JSON=`/usr/bin/curl -s -k --max-time 10 -H "Authorization: Bearer ${TOKEN}" -X GET ${API_BASE_URL}/machines/name/${MACHINE_NAME}` MACHINE_ID=`echo $MACHINE_JSON | jsonValue id 1` MACHINE_CONFIGS_ID=`echo $MACHINE_JSON | jsonValue configs_id 1` + CONFIG_NAME=`echo $MACHINE_JSON | jsonValue name 2` + MACHINE_CONFIGS_ID_PREV='' - if [[ -e /local/config_id ]] + CONFIG_NAME_PREV='' + if [[ -e /local/config_name ]] then - MACHINE_CONFIGS_ID_PREV=`cat /local/config_id` - fi - - echo "TOKEN_JSON: $TOKEN_JSON" - echo "TOKEN: $TOKEN" - echo "MACHINE_NAME: $MACHINE_NAME" - echo "MACHINE_JSON: $MACHINE_JSON" - echo "MACHINE_ID: $MACHINE_ID" - echo "MACHINE_CONFIGS_ID: $MACHINE_CONFIGS_ID" - echo "MACHINE_CONFIGS_ID_PREV: $MACHINE_CONFIGS_ID_PREV" + CONFIG_NAME_PREV=`cat /local/config_name` - # non sono riuscito a contattatare il ws - if [[ "$MACHINE_CONFIGS_ID" == "" ]] - then - echo "Error: WS unreachable or wrong credentials" - exit 1 fi +} - # back config files up - cp -f /local/esame-machine.conf /local/esame-machine.conf.prev 2>&1 - cp -f /local/iptables /local/iptables.prev 2>&1 +getConfigFile() { # get configuration file HTTP_STATUS=`/usr/bin/curl -s -k -w "%{http_code}" -o /local/esame-machine.conf --max-time 10 --header "Authorization: Bearer ${TOKEN}" -X GET ${API_BASE_URL}/machines/${MACHINE_ID}/configfile` if [[ $HTTP_STATUS -ne 200 ]] @@ -63,7 +63,10 @@ start() { else echo "Downloaded config file (http_status=$HTTP_STATUS)" fi +} + +getIpConfigFile() { # get ipconfig file HTTP_STATUS=`/usr/bin/curl -s -k -w "%{http_code}" -o /local/iptables --max-time 10 --header "Authorization: Bearer ${TOKEN}" -X GET ${API_BASE_URL}/machines/${MACHINE_ID}/ipconfigfile` if [[ $HTTP_STATUS -ne 200 ]] @@ -73,51 +76,107 @@ start() { else echo "Downloaded iptables config file (http_status=$HTTP_STATUS)" fi +} + + +updateCurrentConfigId() { + # Update this machine's current config id + HTTP_STATUS=`/usr/bin/curl -s -k -w "%{http_code}" -o /dev/null --max-time 10 -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" \ + -X PUT -d "{\"current_configs_id\":\"$MACHINE_CONFIGS_ID\"}" ${API_BASE_URL}/machines/${MACHINE_ID}/currentconfig` + + if [[ $HTTP_STATUS -ne 200 ]] + then + echo "Error updating current config (http_status=$HTTP_STATUS)" + exit 1 + else + echo "Updated current config (http_status=$HTTP_STATUS)" + fi +} + + +start() { + echo "START ESAME-GET-CONFIG" + + getConfigVars + + #echo "TOKEN_JSON: $TOKEN_JSON" + #echo "TOKEN: $TOKEN" + #echo "MACHINE_NAME: $MACHINE_NAME" + #echo "MACHINE_JSON: $MACHINE_JSON" + #echo "MACHINE_ID: $MACHINE_ID" + #echo "MACHINE_CONFIGS_ID: $MACHINE_CONFIGS_ID" + #echo "MACHINE_CONFIGS_ID_PREV: $MACHINE_CONFIGS_ID_PREV" + echo "Configuration: $CONFIG_NAME" + + # non sono riuscito a contattare il ws + if [[ "$CONFIG_NAME" == "" ]] + then + echo "Error: WS unreachable or wrong credentials" + exit 1 + fi + + # back config files up + cp -f /local/esame-machine.conf /local/esame-machine.conf.prev 2>&1 + cp -f /local/iptables /local/iptables.prev 2>&1 + + getConfigFile + + getIpConfigFile # configuration profile is changed - if [[ "$MACHINE_CONFIGS_ID" != "$MACHINE_CONFIGS_ID_PREV" ]] + if [[ "$CONFIG_NAME" != "$CONFIG_NAME_PREV" ]] then # stop the timer to avoid executing this script again before the boot - /usr/bin/systemctl stop esame-apply-config.timer - - # update config_id file - echo ${MACHINE_CONFIGS_ID} > /local/config_id + #/usr/bin/systemctl stop esame-apply-config.timer + # update config_name file + echo ${CONFIG_NAME} > /local/config_name + # no exam, set normal target - if [[ "$MACHINE_CONFIGS_ID" -eq "0" ]] + if [[ "$CONFIG_NAME" == "normale" ]] then # stop some services to revert system files - /usr/bin/systemctl stop esame-kioskmode - /usr/bin/systemctl stop esame-kdm-autologin - /usr/bin/systemctl stop esame-virtualbox + #/usr/bin/systemctl stop esame-kioskmode + #/usr/bin/systemctl stop esame-kdm-autologin + #/usr/bin/systemctl stop esame-virtualbox rm /local/esame-machine.conf 2>&1 rm /local/esame-machine.conf.prev 2>&1 rm /local/iptables 2>&1 rm /local/iptables.prev 2>&1 - echo "Normal!" - /usr/bin/systemctl set-default graphical.target - /usr/bin/systemctl reboot --force + echo "Normal!" + #systemctl isolate graphical && exit 0 + #/usr/bin/systemctl set-default graphical.target + /usr/bin/systemctl reboot + #--force else echo "Exam!" - /usr/bin/systemctl set-default esame.target - /usr/bin/systemctl reboot --force + #systemctl isolate esame.target && exit 0 + #/usr/bin/systemctl set-default esame.target + /usr/bin/systemctl reboot + #--force fi else - # Update this machine's current config id - HTTP_STATUS=`/usr/bin/curl -s -k -w "%{http_code}" -o /dev/null --max-time 10 -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" \ - -X PUT -d "{\"current_configs_id\":\"$MACHINE_CONFIGS_ID\"}" ${API_BASE_URL}/machines/${MACHINE_ID}/currentconfig` - - if [[ $HTTP_STATUS -ne 200 ]] + # at boot time choose the correct target + if [[ "$1" == "boot" ]] then - echo "Error updating current config (http_status=$HTTP_STATUS)" - exit 1 - else - echo "Updated current config (http_status=$HTTP_STATUS)" + # we have just rebooted, update the current configuration via web service + updateCurrentConfigId + case "$CONFIG_NAME" in + 'normale') # normal + systemctl isolate graphical.target && exit 0 + ;; + 'kiosk-dir' | 'kiosk-dir-esami' | 'kiosk-escher' | 'kiosk-freebrowsing' | 'kiosk-teco') # kiosk mode + systemctl isolate esamekiosk.target && exit 0 + ;; + *) # all full desktop exams + systemctl isolate esame.target && exit 0 + ;; + esac fi fi # Runtime parameters - if [[ "$MACHINE_CONFIGS_ID" -ne "0" ]] + if [[ "$CONFIG_NAME" != "normale" ]] then # check if parameters are changed cmp --silent /local/esame-machine.conf /local/esame-machine.conf.prev @@ -126,15 +185,33 @@ start() { /usr/bin/systemctl daemon-reload echo "Configuration parameters changed: restart some services... " # restart some exam services - echo -n "USB..." - /usr/bin/systemctl restart esame-usb - echo " done." - echo -n "Firefox home..." - /usr/bin/systemctl restart esame-firefox-home - echo " done." + #echo -n "USB..." + #/usr/bin/systemctl restart esame-usb + #echo " done." + KIOSK_URL_CHANGED=$(diff /local/esame-machine.conf /local/esame-machine.conf.prev | grep ESAME_KIOSK_URL -c) + if [[ $KIOSK_URL_CHANGED -ne 0 ]] + then + echo -n "Firefox Home..." + FIREFOX_PID=$(pgrep firefox) + if [[ "${FIREFOX_PID}" != "" ]] + then + FIREFOX_USER=$(ps -o user= -p ${FIREFOX_PID}) + rm -f /local/${FIREFOX_USER}/.mozilla/firefox/44bu2eyb.default/lock + pkill firefox + sleep 2 + /usr/bin/systemctl restart esame-firefox-home + echo " done." + # no way to restart firefox, I must miss something :( + #echo -n "Restarting Firefox..." + #su - ${FIREFOX_USER} -c 'nohup /usr/bin/firefox --display=:0.0 &' + #echo " done." + else + /usr/bin/systemctl restart esame-firefox-home + echo " done." + fi + fi echo echo "All done." - exit 0 fi fi } @@ -143,6 +220,9 @@ start() { args=("$@") case "$1" in +'boot') + start "boot" + ;; 'start') start ;; @@ -154,7 +234,7 @@ case "$1" in start ;; *) - echo "Usage: $0 { start | stop | restart }"; + echo "Usage: $0 { boot | start | stop | restart }"; exit 1; ;; esac diff --git a/bin/iptables-rules b/bin/iptables-rules index 35d022315a17a99316c567569b5c77f4f505e8e6..1d473a550e1ca0471fcec94b4d34011345dba083 100755 --- a/bin/iptables-rules +++ b/bin/iptables-rules @@ -1,8 +1,6 @@ #!/bin/bash stop() { - #/etc/init.d/iptables-esame stop - #/etc/init.d/iptables restart # se facciamo reboot tutte le volte questo non serve, ma si potrebbe prevedere #/usr/sbin/iptables-restore </etc/sysconfig/iptables : diff --git a/bin/kdm-autologin b/bin/kdm-autologin index 3c4865f90cfa368692ee53e43f11f873592518fb..0ee0df714a52b66988c08badbe59ab56f651821c 100755 --- a/bin/kdm-autologin +++ b/bin/kdm-autologin @@ -1,7 +1,7 @@ #!/bin/bash clear() { - sed -i '/AutoLoginEnable=/s/.*/#\0/' /etc/kde/kdm/kdmrc + sed -i '/AutoLoginEnable=/s/.*/#\0/' /etc/kde/kdm/kdmrc sed -i '/AutoLoginAgain=/s/.*/#\0/' /etc/kde/kdm/kdmrc sed -i '/AutoLoginUser=/s/.*/#\0/' /etc/kde/kdm/kdmrc } diff --git a/bin/mk-homedir b/bin/mk-homedir index 234a814a4381d1f537b346816bd6a2929b88f55c..26d0839f5af3a5b660f9b689691866c77368f879 100755 --- a/bin/mk-homedir +++ b/bin/mk-homedir @@ -16,7 +16,6 @@ start() { 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} ${ESAME_USER} cp -a /opt/esame/home/${ESAME_USER} ./ chown -Rh ${ESAME_USER}:esame ${ESAME_USER} fi diff --git a/bin/old/apply-config b/bin/old/apply-config deleted file mode 100755 index 8568b601c8b9b5ffbe34f555ca2ed5137834a5dc..0000000000000000000000000000000000000000 --- a/bin/old/apply-config +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash -# obsolete - -stop() { - echo "STOP ESAME-APPLY-CONFIG" - #rm /local/esame-machine.conf - #rm /local/iptables -} - - -start() { - . /opt/esame/bin/get-config start - - echo "START ESAME-APPLY-CONFIG" - - # configuration profile is changed - if [[ "$MACHINE_CONFIGS_ID" != "$MACHINE_CONFIGS_ID_PREV" ]] - then - # update config_id file - echo ${MACHINE_CONFIGS_ID} > /local/config_id - - # no exam, set normal target - if [[ "$MACHINE_CONFIGS_ID" -eq "0" ]] - then - # stop some services to revert system files - /usr/bin/systemctl stop esame-kioskmode - /usr/bin/systemctl stop esame-kdm-autologin - rm /local/esame-machine.conf 2>&1 - rm /local/esame-machine.conf.prev 2>&1 - rm /local/iptables 2>&1 - rm /local/iptables.prev 2>&1 - echo "Normal!" - /usr/bin/systemctl set-default graphical.target - reboot - else - echo "Exam!" - /usr/bin/systemctl set-default esame.target - reboot - fi - fi - - if [[ "$MACHINE_CONFIGS_ID" -ne "0" ]] - then - # check if parameters are changed - cmp --silent /local/esame-machine.conf /local/esame-machine.conf.prev - if [[ $? -ne 0 ]] - then - /usr/bin/systemctl daemon-reload - echo "Configuration parameters changed: restart services... " - # restart some exam services - echo -n "USB..." - /usr/bin/systemctl start esame-usb - echo " done." - echo -n "Firefox home..." - /usr/bin/systemctl start esame-firefox-home - echo " done." - echo - echo "All done." - fi - fi -} - - -args=("$@") - -case "$1" in -'start') - start - ;; -'stop') - stop - ;; -'restart') - stop - start - ;; -*) - echo "Usage: $0 { start | stop | restart }"; - exit 1; - ;; -esac -exit 0 - diff --git a/bin/old/user-sessions b/bin/old/user-sessions deleted file mode 100755 index 4c10964e7777bfeef9042715c2532af869e7a2b6..0000000000000000000000000000000000000000 --- a/bin/old/user-sessions +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -find_regular_user_sessions() { - ESAME_KILL_USERS=`loginctl list-sessions -l | awk '{print $3}' | egrep -v 'root|labsync|esame|moodle|vbconsole|listed|USER'` -} - -find_esame_user_sessions() { - ESAME_KILL_USERS=`loginctl list-sessions -l | awk '{print $3}' | egrep 'esame|moodle|vbconsole'` -} - -kill_sessions() { - for a in ${ESAME_KILL_USERS}; do - echo loginctl kill-user "$a" - loginctl kill-user "$a" - done -} - -start() { - # We kill user sessions when the exam starts. - find_regular_user_sessions - kill_sessions -} - -stop() { - # We kill exam session when the exam ends. - find_esame_user_sessions - kill_sessions -} - -case "$1" in -'start') - start - ;; -'stop') - stop - ;; -'restart') - stop - start - ;; -*) - echo "Usage: $0 { start | stop | restart }"; - exit 1; - ;; -esac -exit 0 diff --git a/bin/usb b/bin/usb index c500bc589380eb8397ef4ae1258a53080cdbe99e..acf22db49bfd467b880e8dd443b0e931c502f596 100755 --- a/bin/usb +++ b/bin/usb @@ -1,9 +1,5 @@ #!/bin/bash -getconf() { - ESAME_USB=${args[1]} -} - # Un'idea alternativa sarebbe impedire il caricamento del modulo # usb-storage. Occorre pero' rimuoverlo dai moduli gia' caricati, # e fare qualcosa nel caso in cui sia impossibile rimuoverlo @@ -34,9 +30,9 @@ riabilitamodulo() { } stop() { - #pkill -ALRM bta-no-usbpen - #riabilitamodulo - #echo "STOP ESAME-USB" + pkill -ALRM bta-no-usbpen + riabilitamodulo + echo "STOP ESAME-USB" : } diff --git a/bin/virtualbox b/bin/virtualbox index 12135bfb397e7f18f30e1c45b8b4c45418eb5ae9..15d5a21a8f7e13a46080aa04d58f4f44a3e9e57a 100755 --- a/bin/virtualbox +++ b/bin/virtualbox @@ -2,20 +2,6 @@ ESAME_VB_CONFIG_FILE="/local/vbconsole/bin/kiosk.settings" -getconf() { - # Get the right config file -# . /opt/esame/bin/getconf - - # Source the current exam configuration -# . ${ESAME_CONF} - - # Check the syntax of the configuration file -# /opt/esame/bin/esame-check-config.sh || exit 1 - - ESAME_VIRTUALBOX=${args[1]} - ESAME_USER=${args[2]} -} - stop() { if [ -f ${ESAME_VB_CONFIG_FILE} ]; then echo "STOP VIRTUALBOX KIOSK"; diff --git a/install-labmanager.sh b/install-labmanager.sh index f0eab34671cb06b4dc523724f275cd8fbd2c7cdc..8f55d3cfff7319d222607844ac1661153c807744 100644 --- a/install-labmanager.sh +++ b/install-labmanager.sh @@ -1,80 +1,112 @@ #!/bin/bash +# LabManager: systemd units & scripts installer v2.0 GIT_URL=https://gitlab.di.unipmn.it -GIT_BASE_DIR=ulisse/labmanager-systemd/raw/v1.0 - -function askYesNo { - QUESTION=$1 - DEFAULT=$2 - if [ "$DEFAULT" = true ]; then - OPTIONS="[Y/n]" - DEFAULT="y" - else - OPTIONS="[y/N]" - DEFAULT="n" - fi - read -p "$QUESTION $OPTIONS " -n 1 -s -r INPUT - INPUT=${INPUT:-${DEFAULT}} - echo ${INPUT} - if [[ "$INPUT" =~ ^[yY]$ ]]; then - ANSWER=true - else - ANSWER=false - fi +GIT_BASE_DIR=ulisse/labmanager-systemd/raw +GIT_BRANCH=master + +BIN_FILES=( "desktop-wallpaper" "esamesync-esame.sh" "firefox-home" "get-config" "iptables-rules" "kdm-autologin" "kioskmode" "mk-homedir" "nfs" "usb" "virtualbox" ) + +SYSTEMD_FILES=( "esame-desktop-wallpaper.service" "esame-firefox-home.service" "esame-get-config-boot.service" "esame-get-config.service" "esame-iptables-rules.service" "esame-kdm-autologin.service" "esame-kioskmode.service" "esame-mk-homedir.service" "esame-nfs.service" "esame-usb.service" "esame-virtualbox.service" "esamesync-esame.service" "esame-get-config.timer" "esame-configurator.target" "esame.target" "esamekiosk.target" ) + +# DON'T TOUCH UNDER THIS LINE! ################################################# + +function downloadFiles { + local base_url="$1" + shift + local files=( "$@" ) + + i=1 + for f in "${files[@]}" + do + echo -e "\n$i/${#files[@]} - $base_url/$f" + curl -# --fail -O "$base_url/$f" + if [[ $? != 0 ]] + then + echo "curl exited with error code != 0, installation aborted." + exit 1 + fi + i=$(expr $i + 1) + done } +echo -e "\nLabManager: systemd units & scripts installer" + +if [ -z "$1" ]; then + echo -e "\nNo branch/tag specified, using branch 'master'." + echo -e "Please call '$0 <branch/tag>' to use a different source.\n" +else + GIT_BRANCH="$1" + echo -e "\nUsing branch/tag '$GIT_BRANCH'.\n" +fi + +# v1.0 has a different set of files, print warning and abort installation +if [[ "$GIT_BRANCH" == "v1.0" ]] +then + echo -e "\e[1mWARNING!\e[0m" + echo "Branch 'v1.0' has a different installation procedure, please get" + echo -e "the correct installation script here:\n" + echo -e "$GIT_URL/$GIT_BASE_DIR/v1.0\n" + exit 1 +fi + mkdir -p /usr/libexec/labmanager # script per i servizi systemd -echo "Downloading systemd script files..." +echo -e "\e[1mDownloading systemd script files...\e[0m" cd /usr/libexec/labmanager -curl -O $GIT_URL/$GIT_BASE_DIR/bin/bta-no-usbpen -curl -O $GIT_URL/$GIT_BASE_DIR/bin/get-config -curl -O $GIT_URL/$GIT_BASE_DIR/bin/kdm-autologin -curl -O $GIT_URL/$GIT_BASE_DIR/bin/mk-homedir -curl -O $GIT_URL/$GIT_BASE_DIR/bin/firefox-home -curl -O $GIT_URL/$GIT_BASE_DIR/bin/iptables-rules -curl -O $GIT_URL/$GIT_BASE_DIR/bin/kioskmode -curl -O $GIT_URL/$GIT_BASE_DIR/bin/nfs -curl -O $GIT_URL/$GIT_BASE_DIR/bin/usb -curl -O $GIT_URL/$GIT_BASE_DIR/bin/virtualbox +echo "Creating symlink bta-no-usbpen -> /bin/sleep..." +ln -s -f /bin/sleep bta-no-usbpen +echo +downloadFiles "$GIT_URL/$GIT_BASE_DIR/$GIT_BRANCH/bin" ${BIN_FILES[@]} chmod +x * -echo "OK." - -echo "" +echo +echo # servizi systemd -echo "Downloading systemd service files..." +echo -e "\e[1mDownloading systemd unit files...\e[0m" cd /etc/systemd/system -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-apply-config.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-apply-config.timer -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-firefox-home.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-get-config.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-iptables-rules.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-kdm-autologin.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-kioskmode.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-mk-homedir.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-nfs.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame.target -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-usb.service -curl -O $GIT_URL/$GIT_BASE_DIR/systemd/esame-virtualbox.service -echo "OK." - -echo "" - -# disable old esame service? -askYesNo "Disable old systemd esame.service?" false -DOIT=$ANSWER -if [ "$DOIT" = true ]; then - systemctl disable esame.service -fi +downloadFiles "$GIT_URL/$GIT_BASE_DIR/$GIT_BRANCH/systemd" ${SYSTEMD_FILES[@]} +echo +echo -echo -n "Reload systemd" +# following links should be not needed, specifying services as "Wants" directives should suffice + +# create symlinks for target esame and esamekiosk +#mkdir esame.target.wants +#cd esame.target.wants +#ln -s /usr/lib/systemd/system/accounts-daemon.service . +#ln -s /usr/lib/systemd/system/rtkit-daemon.service . +#ln -s /usr/lib/systemd/system/switcheroo-control.service . +#ln -s /usr/lib/systemd/system/systemd-update-utmp-runlevel.service . +#ln -s /usr/lib/systemd/system/udisks2.service . +#mkdir esamekiosk.target.wants +#cd esamekiosk.target.wants +#ln -s /usr/lib/systemd/system/accounts-daemon.service . +#ln -s /usr/lib/systemd/system/rtkit-daemon.service . +#ln -s /usr/lib/systemd/system/switcheroo-control.service . +#ln -s /usr/lib/systemd/system/systemd-update-utmp-runlevel.service . +#ln -s /usr/lib/systemd/system/udisks2.service . + +echo -e "\e[1mReload systemd...\e[0m" systemctl daemon-reload +echo +echo -echo -n "Enable systemd services..." +echo -e "\e[1mEnable systemd services...\e[0m" systemctl enable esame-*.service -systemctl enable esame-apply-config.timer -echo " OK." +systemctl enable esamesync-esame.service +systemctl enable esame-get-config.timer +echo +echo + +echo -e "\e[1mDisable unwanted systemd services...\e[0m" +systemctl disable esame-usb.service +echo +echo + +echo -e "\e[1mChange default target to esame-configurator.target...\e[0m" +systemctl set-default esame-configurator.target +echo +echo -echo "" -echo "All done!" +echo -e "\e[1mAll done!\e[0m" diff --git a/systemd/esame-configurator.target b/systemd/esame-configurator.target new file mode 100644 index 0000000000000000000000000000000000000000..5e2807c5bce422ae61acc4acdd134aa30780e462 --- /dev/null +++ b/systemd/esame-configurator.target @@ -0,0 +1,6 @@ +[Unit] +Description=Esame Configurator Target +Requires=basic.target network-online.target sshd.service abrtd.service +Conflicts=rescue.service rescue.target graphical.target esame.target esamekiosk.target +After=basic.target rescue.service rescue.target network-online.target sshd.service abrtd.service +AllowIsolate=yes diff --git a/systemd/esame-desktop-wallpaper.service b/systemd/esame-desktop-wallpaper.service new file mode 100644 index 0000000000000000000000000000000000000000..d59701905af143672436714d33451152f528ef58 --- /dev/null +++ b/systemd/esame-desktop-wallpaper.service @@ -0,0 +1,14 @@ +[Unit] +Description=Esame - Desktop Wallpaper +After=esame-mk-homedir.service + +[Service] +Type=oneshot +RemainAfterExit=yes +EnvironmentFile=-/local/esame-machine.conf +ExecStart=/usr/libexec/labmanager/desktop-wallpaper start +ExecStop=/usr/libexec/labmanager/desktop-wallpaper stop +ExecReload=/usr/libexec/labmanager/desktop-wallpaper restart + +[Install] +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-firefox-home.service b/systemd/esame-firefox-home.service index 717a68422d5548e6c2571867ea6913b7b756fadc..017ccee9b33245526631a042a02aab98fd029f7a 100644 --- a/systemd/esame-firefox-home.service +++ b/systemd/esame-firefox-home.service @@ -5,11 +5,10 @@ After=esame-mk-homedir.service [Service] Type=oneshot RemainAfterExit=yes -TimeoutSec=0 EnvironmentFile=-/local/esame-machine.conf ExecStart=/usr/libexec/labmanager/firefox-home start ExecStop=/usr/libexec/labmanager/firefox-home stop ExecReload=/usr/libexec/labmanager/firefox-home restart [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-apply-config.service b/systemd/esame-get-config-boot.service similarity index 62% rename from systemd/esame-apply-config.service rename to systemd/esame-get-config-boot.service index a332dbda62069a4ecdae329541b3eb718b8715b1..42603c06f65f55042ec829828c6b223e0ae6f5fe 100644 --- a/systemd/esame-apply-config.service +++ b/systemd/esame-get-config-boot.service @@ -5,5 +5,9 @@ Wants=network-online.target esamesync-esame.service [Service] Type=oneshot +RemainAfterExit=yes TimeoutSec=0 -ExecStart=/usr/libexec/labmanager/get-config start +ExecStart=/usr/libexec/labmanager/get-config boot + +[Install] +WantedBy=esame-configurator.target diff --git a/systemd/esame-get-config.service b/systemd/esame-get-config.service index 62634a95f7d6209eb16e732b02e2bf700907e1dc..a332dbda62069a4ecdae329541b3eb718b8715b1 100644 --- a/systemd/esame-get-config.service +++ b/systemd/esame-get-config.service @@ -5,9 +5,5 @@ Wants=network-online.target esamesync-esame.service [Service] Type=oneshot -RemainAfterExit=yes TimeoutSec=0 ExecStart=/usr/libexec/labmanager/get-config start - -[Install] -WantedBy=esame.target diff --git a/systemd/esame-apply-config.timer b/systemd/esame-get-config.timer similarity index 58% rename from systemd/esame-apply-config.timer rename to systemd/esame-get-config.timer index 81f6458a1ed197921e6193f2e4f51753fdd63580..e61545a731f3d68a78911617dc6d0dabcabe8363 100644 --- a/systemd/esame-apply-config.timer +++ b/systemd/esame-get-config.timer @@ -4,7 +4,7 @@ Description=Get and apply config files from web service (timer) [Timer] OnBootSec=60s OnUnitActiveSec=60s -#Unit=esame-apply-config.service +#Unit=esame-get-config.service [Install] -WantedBy=timers.target +WantedBy=esame.target esamekiosk.target graphical.target diff --git a/systemd/esame-iptables-rules.service b/systemd/esame-iptables-rules.service index 22ce0e332431c583418df8451832637f3352a098..43ac7061861537e6da4ead2016d7078b98bf9132 100644 --- a/systemd/esame-iptables-rules.service +++ b/systemd/esame-iptables-rules.service @@ -1,13 +1,13 @@ [Unit] Description=Apply iptables configuration -After=network-online.target esame-get-config.service +After=network-online.target esame-get-config-boot.service Wants=network-online.target [Service] Type=oneshot RemainAfterExit=yes -TimeoutSec=0 +#TimeoutSec=0 ExecStart=/usr/libexec/labmanager/iptables-rules start [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-kdm-autologin.service b/systemd/esame-kdm-autologin.service index a0d511d2a29f31858070a576642783236fcde18d..873b8ca591b952decefffff35de105cd676cf443 100644 --- a/systemd/esame-kdm-autologin.service +++ b/systemd/esame-kdm-autologin.service @@ -1,6 +1,6 @@ [Unit] Description=KDM Autologin -After=kdm.service esame-mk-homedir.service esame-firefox-home.service esame-virtualbox.service +After=kdm.service esame-mk-homedir.service esame-desktop-wallpaper.service esame-firefox-home.service esame-virtualbox.service [Service] Type=oneshot @@ -12,4 +12,4 @@ ExecStop=/usr/libexec/labmanager/kdm-autologin stop ExecReload=/usr/libexec/labmanager/kdm-autologin restart [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-kioskmode.service b/systemd/esame-kioskmode.service index 122d4fc56e36cd80a7e97d801ec9a90110edd0d0..bdcbd726e9ec387afdc5f3a6ad51f5d5e3849fe0 100644 --- a/systemd/esame-kioskmode.service +++ b/systemd/esame-kioskmode.service @@ -12,4 +12,4 @@ ExecStop=/usr/libexec/labmanager/kioskmode stop ExecReload=/usr/libexec/labmanager/kioskmode restart [Install] -WantedBy=esame.target +WantedBy=esamekiosk.target diff --git a/systemd/esame-mk-homedir.service b/systemd/esame-mk-homedir.service index f1a6ec7c2e3a6aa659f39b5dec15dda08cb6493d..6cc9686f41f0a4b2b06e1e7b758e3d6f384aa88f 100644 --- a/systemd/esame-mk-homedir.service +++ b/systemd/esame-mk-homedir.service @@ -1,13 +1,15 @@ [Unit] Description=Esame - Reset Home Dir -After=esame-get-config.service +After=esame-get-config-boot.service [Service] Type=oneshot RemainAfterExit=yes -TimeoutSec=0 +#TimeoutSec=0 EnvironmentFile=-/local/esame-machine.conf ExecStart=/usr/libexec/labmanager/mk-homedir start +ExecStop=/usr/libexec/labmanager/mk-homedir stop +ExecRestart=/usr/libexec/labmanager/mk-homedir restart [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-nfs.service b/systemd/esame-nfs.service index 6890dedab32a6b6252726405cbffbc19ccb56c9f..a418d671315b1a0a33b67f6861476941bb96ed32 100644 --- a/systemd/esame-nfs.service +++ b/systemd/esame-nfs.service @@ -1,16 +1,16 @@ [Unit] Description=Esame - Mount homes (NFS) Before=esame-iptables-rules.service -After=esame-get-config.service +After=esame-get-config-boot.service [Service] Type=oneshot RemainAfterExit=yes -TimeoutSec=0 +#TimeoutSec=0 EnvironmentFile=-/local/esame-machine.conf ExecStart=/usr/libexec/labmanager/nfs start -#ExecStop=/usr/libexec/labmanager/nfs stop -#ExecReload=/usr/libexec/labmanager/nfs restart +ExecStop=/usr/libexec/labmanager/nfs stop +ExecReload=/usr/libexec/labmanager/nfs restart [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-usb.service b/systemd/esame-usb.service index b3bb2789b818b0dab9ead289dbe1bf94f06d4f24..d7f3d3bc7242c5f5054665f8e238a01d3aefb8ac 100644 --- a/systemd/esame-usb.service +++ b/systemd/esame-usb.service @@ -1,14 +1,14 @@ [Unit] Description=Enable/disable USB ports -After=esame-get-config.service +After=esame-get-config-boot.service [Service] Type=oneshot -TimeoutSec=0 +#TimeoutSec=0 EnvironmentFile=-/local/esame-machine.conf ExecStart=/usr/libexec/labmanager/usb start ExecStop=/usr/libexec/labmanager/usb stop ExecReload=/usr/libexec/labmanager/usb restart [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame-virtualbox.service b/systemd/esame-virtualbox.service index f2b28c8f9e84d4e1901fbde1e32f21e2419d0be0..23a9495ad4b77b56ad7224c88914047c8f64d644 100644 --- a/systemd/esame-virtualbox.service +++ b/systemd/esame-virtualbox.service @@ -12,4 +12,4 @@ ExecStop=/usr/libexec/labmanager/virtualbox stop ExecReload=/usr/libexec/labmanager/virtualbox restart [Install] -WantedBy=esame.target +WantedBy=esame.target esamekiosk.target diff --git a/systemd/esame.target b/systemd/esame.target index ea054665274785a1002c07281cda09a8746dc92c..7ae48d99385924a216960a6157461b2d8f0a44e7 100644 --- a/systemd/esame.target +++ b/systemd/esame.target @@ -1,11 +1,16 @@ -# Esame Target +# SPDX-License-Identifier: LGPL-2.1+ # +# This file is part of systemd. # +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. [Unit] -Description=Esame -#Documentation=man:systemd.special(7) -Requires=graphical.target -After=graphical.target -Conflicts=rescue.service rescue.target +Description=Esame Target +Requires=multi-user.target +Wants=display-manager.service accounts-daemon.service rtkit-daemon.service switcheroo-control.service udisks2.service systemd-update-utmp-runlevel.service +Conflicts=rescue.service rescue.target graphical.target esamekiosk.target +After=multi-user.target rescue.service rescue.target display-manager.service AllowIsolate=yes diff --git a/systemd/esamekiosk.target b/systemd/esamekiosk.target new file mode 100644 index 0000000000000000000000000000000000000000..258142e9855a1c109aadfedcf8dcd5be4b4558ca --- /dev/null +++ b/systemd/esamekiosk.target @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=EsameKiosk Target +Requires=multi-user.target +Wants=display-manager.service accounts-daemon.service rtkit-daemon.service switcheroo-control.service udisks2.service systemd-update-utmp-runlevel.service +Conflicts=rescue.service rescue.target graphical.target esame.target +After=multi-user.target rescue.service rescue.target display-manager.service +AllowIsolate=yes diff --git a/systemd/esamesync-esame.service b/systemd/esamesync-esame.service new file mode 100644 index 0000000000000000000000000000000000000000..63adf6f7f2509a409f7ee89c972c6cba443b7074 --- /dev/null +++ b/systemd/esamesync-esame.service @@ -0,0 +1,20 @@ +[Unit] +Description=esamesync esame +After=network.target +Before=kdm.service getty.target +Conflicts= + +[Service] +Environment=RUNLEVEL=3 +#ExecStartPre=-/bin/plymouth quit +#ExecStart=/etc/init.d/esamesync esame +User=esamesync +Group=esamesync +ExecStart=/usr/local/sbin/esamesync-esame.sh +TimeoutSec=0 +RemainAfterExit=yes +Type=oneshot +SysVStartPriority=99 + +[Install] +WantedBy=esame.target diff --git a/systemd/old/configurator.target b/systemd/old/configurator.target deleted file mode 100644 index 1aee60e4b8f94deffea5ddf2bb697c2375523416..0000000000000000000000000000000000000000 --- a/systemd/old/configurator.target +++ /dev/null @@ -1,11 +0,0 @@ -# Configurator Target -# -# - -[Unit] -Description=Configurator -#Documentation=man:systemd.special(7) -Requires=graphical.target -After=graphical.target -Conflicts=rescue.service rescue.target -AllowIsolate=yes diff --git a/systemd/old/esame-sa.target b/systemd/old/esame-sa.target deleted file mode 100644 index 2179e4c2158c9a1102cfe971f53309488c01e7c8..0000000000000000000000000000000000000000 --- a/systemd/old/esame-sa.target +++ /dev/null @@ -1,10 +0,0 @@ -# Esame Stand alone Target - -[Unit] -Description=Esame Standalone -#Documentation=man:systemd.special(7) -Requires=multi-user.target -Wants=display-manager.service -Conflicts=rescue.service rescue.target -After=multi-user.target rescue.service rescue.target display-manager.service -AllowIsolate=yes diff --git a/systemd/old/esame-user-sessions.service b/systemd/old/esame-user-sessions.service deleted file mode 100644 index 66e4cef9872fec31e69db1ca5a42b2761b8f22c1..0000000000000000000000000000000000000000 --- a/systemd/old/esame-user-sessions.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Kill regular/exam users sessions -After=esame-iptables-rules.service esame-get-config.service - -[Service] -Type=oneshot -RemainAfterExit=yes -EnvironmentFile=-/local/esame-machine.conf -ExecStart=/opt/labmanager/bin/user-sessions start -ExecStop=/opt/labmanager/bin/user-sessions stop -ExecReload=/opt/labmanager/bin/user-sessions restart - -[Install] -WantedBy=esame.target