12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- # Modalità "rotate"
- # Variabili e funzioni di supporto
- # a modalità rotate
- # Fai un backup compresso del db file
- # Assegna il nome del file di backup
- # alla variabile attesa come primo
- # argomento.
- bkcomp_dbfile(){
- local COMPBK_NAME="${SHIFT_FILE}.bk$(date +%F_%T).gz"
- gzip -c9 "$SHIFT_FILE" > "$COMPBK_NAME" 2>/dev/null ||\
- echoerr "Failed to backup shifts file ${SHIFT_FILE}."
- chgrp "$OPGROUP" "$COMPBK_NAME" &>/dev/null ||\
- echoerr "Failed to change group ownership of backed up shifts file $COMPBK_NAME to $OPGROUP."
- chmod g=wr,o= "$COMPBK_NAME" &>/dev/null ||\
- echoerr "Failed to change mode of backed up shifts file $COMPBK_NAME."
- eval $1="$COMPBK_NAME"
- return 0
- }
- # Chiede conferma della rotazione.
- ask_rotate(){
- echo -e "\n\e[0;33mWarning\e[0m: rotation of shifts file clears current shifts records."
- echo "This operation can only be reverted manually."
- echo "Proceed at your own risk."
- echo -n 'Enter "YES" to proceed, anything else to abort: '
-
- local ANSWER
- read ANSWER
-
- [ "$ANSWER" == "YES" ] ||\
- { echo -e "\nRotation aborted. You don't make me spin. :("; exit 0; }
- }
- # Ruota il file dei turni
- rotate_dbfile(){
- # Check esistenza
- check_dbfile exist ||\
- echoerr "There's nothing to rotate: $SHIFT_FILE does not exist."
-
- # Conferma
- ask_rotate
- # Backup
- local SHIFT_FILE_COMPBK
- bkcomp_dbfile SHIFT_FILE_COMPBK
- # Init nuovo file turni
- initialize_dbfile
- # Notifica
- echo -e "\n\e[0;32mRotation successful!\e[0m I feel dizzy. O.o"
- echo "Old shifts file backed up as ${SHIFT_FILE_COMPBK}."
- }
|