better messaging

This commit is contained in:
Ste Vaidis 2022-12-27 23:35:29 +02:00
parent 2933d89e95
commit 680b702922

View File

@ -6,7 +6,7 @@ cd $SCRIPT_DIR
. ./backup.config
function log() {
echo -e "`date +'%d/%m/%Y %H:%M:%S'` | $1"
echo -e "\e[96m`date +'%d/%m/%Y %H:%M:%S'` \e[39m| $1"
echo -e "`date +'%d/%m/%Y %H:%M:%S'` | $1" >> $LOG
}
@ -25,12 +25,15 @@ function usage() {
}
function get_luks_password() {
log " Ask for LUKS password"
log " from API $LUKS_PASS_URL"
LUKS_PASS=$(curl -s $LUKS_PASS_URL | jq -r ".password")
if [ -z "$LUKS_PASS" ]; then
log "[FAIL] to get LUKS password"
return 1
else
log "[ OK ] get LUKS password"
log "[ OK ] getting LUKS password"
return 0
fi
}
@ -55,18 +58,21 @@ function find_usb() {
function mount_luks() {
for n in `seq 0 9`; do
log " trying to mount /dev/mapper/crypted_usb"
log " trying create /dev/mapper/crypted_usb"
waiting=$(grep 'Dirty\|Writeback' /proc/meminfo | grep Writeback: | awk {'print $2'})
if [[ wating -eq "0" ]]; then
echo $1 | /usr/sbin/cryptsetup luksOpen $2 crypted_usb
log "[ OK ] mounted /dev/mapper/crypted_usb"
if [ $? = 0 ]; then
log "[ OK ] created /dev/mapper/crypted_usb"
return 0
else
log "[FAIL] mounted /dev/mapper/crypted_usb"
log "[FAIL] to create /dev/mapper/crypted_usb (error)"
return 1
fi
fi
sleep 2
done
echo "R1"
log "[FAIL] to create /dev/mapper/crypted_usb (timeout)"
return 1
}
@ -223,7 +229,6 @@ function send_mail() {
function main () {
rm $LOG -rf
log ""
log "BACKUP STARTED ===================="
log "SOURCE : $SRC"
log "DESTINATION : $USB_MOUNT$DST"
log "WITH DELETE : ${DELETE:-"No (default)"}"