mirror of https://github.com/CIRCL/Circlean
Refactor init.sh to use functions
parent
9dd6b2c460
commit
66f2dd25f2
|
@ -28,3 +28,4 @@ readonly PUMOUNT="/usr/bin/pumount"
|
||||||
|
|
||||||
# Config flags
|
# Config flags
|
||||||
readonly DEBUG=false
|
readonly DEBUG=false
|
||||||
|
readonly MUSIC=true
|
||||||
|
|
|
@ -1,37 +1,49 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# set -e (exit when a line returns non-0 status) and -x (xtrace) flags
|
|
||||||
set -e
|
|
||||||
set -x
|
|
||||||
|
|
||||||
# Import constants from config file
|
|
||||||
source ./config.sh
|
|
||||||
|
|
||||||
if [ ${ID} -ne 0 ]; then
|
|
||||||
echo "GROOMER: This script has to be run as root."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
clean(){
|
clean(){
|
||||||
if [ ${DEBUG} = true ]; then
|
if [ "${DEBUG}" = true ]; then
|
||||||
sleep 20
|
sleep 20
|
||||||
fi
|
fi
|
||||||
echo "GROOMER: cleaning up after init.sh."
|
echo "GROOMER: cleaning up after init.sh."
|
||||||
${SYNC}
|
"${SYNC}"
|
||||||
# Stop the music from playing
|
# Stop the music from playing
|
||||||
kill -9 $(cat /tmp/music.pid)
|
kill -9 "$(cat /tmp/music.pid)"
|
||||||
rm -f /tmp/music.pid
|
rm -f /tmp/music.pid
|
||||||
}
|
}
|
||||||
|
|
||||||
trap clean EXIT TERM INT
|
check_is_root() {
|
||||||
|
if [ "${ID}" -ne 0 ]; then
|
||||||
|
echo "GROOMER: This script has to be run as root."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Start music
|
start_music() {
|
||||||
./music.sh &
|
./music.sh &
|
||||||
echo $! > /tmp/music.pid
|
echo $! > /tmp/music.pid
|
||||||
|
}
|
||||||
|
|
||||||
# List block storage devices for debugging
|
run_groomer() {
|
||||||
if [ ${DEBUG} = true ]; then
|
if [ "${DEBUG}" = true ]; then
|
||||||
lsblk |& tee -a ${DEBUG_LOG}
|
lsblk |& tee -a "${DEBUG_LOG}" # list block storage devices for debugging
|
||||||
|
su "${USERNAME}" -c ./mount_dest.sh |& tee -a "${DEBUG_LOG}"
|
||||||
|
else
|
||||||
|
su "${USERNAME}" -c ./mount_dest.sh
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
su ${USERNAME} -c ./mount_dest.sh |& tee -a ${DEBUG_LOG}
|
main() {
|
||||||
|
set -eu # exit when a line returns non-0 status, treat unset variables as errors
|
||||||
|
trap clean EXIT TERM INT # run clean when the script ends or is interrupted
|
||||||
|
check_is_root
|
||||||
|
source ./config.sh # get config values
|
||||||
|
if [ "${DEBUG}" = true ]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
if [ "${MUSIC}" = true ]; then
|
||||||
|
start_music
|
||||||
|
fi
|
||||||
|
run_groomer
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
|
|
Loading…
Reference in New Issue