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 | ||||
| readonly DEBUG=false | ||||
| readonly MUSIC=true | ||||
|  |  | |||
|  | @ -1,37 +1,49 @@ | |||
| #!/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(){ | ||||
|     if [ ${DEBUG} = true ]; then | ||||
|     if [ "${DEBUG}" = true ]; then | ||||
|         sleep 20 | ||||
|     fi | ||||
|     echo "GROOMER: cleaning up after init.sh." | ||||
|     ${SYNC} | ||||
|     "${SYNC}" | ||||
|     # Stop the music from playing | ||||
|     kill -9 $(cat /tmp/music.pid) | ||||
|     kill -9 "$(cat /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 | ||||
| ./music.sh & | ||||
| echo $! > /tmp/music.pid | ||||
| start_music() { | ||||
|     ./music.sh & | ||||
|     echo $! > /tmp/music.pid | ||||
| } | ||||
| 
 | ||||
| # List block storage devices for debugging | ||||
| if [ ${DEBUG} = true ]; then | ||||
|     lsblk |& tee -a ${DEBUG_LOG} | ||||
| fi | ||||
| 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 | ||||
| } | ||||
| 
 | ||||
| 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
	
	 Dan Puttick
						Dan Puttick