Circlean/circlean_fs/root_partition/opt/groomer/init.sh

50 lines
1.1 KiB
Bash
Raw Normal View History

2015-11-06 17:40:33 +01:00
#!/bin/bash
clean(){
2017-08-10 00:03:52 +02:00
if [ "${DEBUG}" = true ]; then
2017-01-31 21:44:13 +01:00
sleep 20
fi
echo "GROOMER: cleaning up after init.sh."
2017-08-10 00:03:52 +02:00
"${SYNC}"
2017-01-13 23:56:16 +01:00
# Stop the music from playing
2017-08-10 00:03:52 +02:00
kill -9 "$(cat /tmp/music.pid)"
2017-01-13 23:56:16 +01:00
rm -f /tmp/music.pid
2015-11-06 17:40:33 +01:00
}
2017-08-10 00:03:52 +02:00
check_is_root() {
if [ "${ID}" -ne 0 ]; then # -ne is an integer comparison instead of a string comparison
2017-08-10 00:03:52 +02:00
echo "GROOMER: This script has to be run as root."
exit
fi
}
start_music() {
./music.sh &
echo $! > /tmp/music.pid
}
2015-11-06 17:40:33 +01:00
2017-08-10 00:03:52 +02:00
run_groomer() {
if [ "${DEBUG}" = true ]; then
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
}
2017-01-13 23:56:16 +01:00
2017-08-10 00:03:52 +02:00
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
source ./config.sh # get config values
if [ "${DEBUG}" = true ]; then
set -x
fi
2017-08-10 17:51:05 +02:00
check_is_root
2017-08-10 00:03:52 +02:00
if [ "${MUSIC}" = true ]; then
start_music
fi
run_groomer
}
2017-01-12 20:00:51 +01:00
2017-08-10 00:03:52 +02:00
main