From fd1ea2676e892fa68d5fa1792a16517af1f33278 Mon Sep 17 00:00:00 2001 From: vaidis Date: Mon, 22 May 2023 14:19:45 +0300 Subject: [PATCH] delete crypt_usb feature --- backup.config | 2 +- backup.sh | 55 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/backup.config b/backup.config index 5f47a32..738ca4e 100644 --- a/backup.config +++ b/backup.config @@ -11,5 +11,5 @@ USB_DISK="" USB_PARTITION="" USB_MOUNT="/mnt/usb" -MAIL_RECIPIENT="ste.vaidis@gmail.com" +MAIL_RECIPIENT="ffilippidou@gmail.com" diff --git a/backup.sh b/backup.sh index 817cdf1..59f0730 100755 --- a/backup.sh +++ b/backup.sh @@ -30,6 +30,15 @@ function usage() { exit } +function another_instance() { + if [ $(ps | grep backup.sh) ];then + log "[FAIL] another instance is running" + return 1 + fi + return 0 +} + + function mount_smb() { if mkdir /mnt/${PID}; then log "[ OK ] creating /mnt/${PID}" @@ -78,7 +87,7 @@ function get_luks_password() { function find_luks() { for DEV in `ls -1 /dev/disk/by-id/usb*`; do - if cryptsetup isLuks ${DEV}; then + if /sbin/cryptsetup isLuks ${DEV}; then USB_DEV=${DEV} LOGDEV=$(echo $DEV | cut -c21- ) log "[ OK ] find encrypted ${LOGDEV}" @@ -89,12 +98,12 @@ function find_luks() { return 1 } -function mount_luks() { +function mount_luks2() { for n in `seq 0 9`; do waiting=$(grep 'Dirty\|Writeback' /proc/meminfo | grep Writeback: | awk {'print $2'}) if [[ wating -eq "0" ]]; then for n in `seq 0 9`; do - echo $1 | cryptsetup luksOpen $2 crypted_usb + echo $1 | /sbin/cryptsetup luksOpen $2 crypted_usb if [ $? = 0 ]; then log "[ OK ] luksOpen crypted_usb" return 0 @@ -110,6 +119,28 @@ function mount_luks() { return 1 } + +function mount_luks() { + if [[ -L /dev/mapper/crypted_usb ]]; then + log "[ !! ] founbd old crypted_usb" + dmsetup remove /dev/mapper/crypted_usb + if [ $? = 0 ]; then + log "[ !! ] old crypted_usb removed" + fi + fi + waiting=$(grep 'Dirty\|Writeback' /proc/meminfo | grep Writeback: | awk {'print $2'}) + if [[ wating -eq "0" ]]; then + echo $1 | /sbin/cryptsetup luksOpen $2 crypted_usb + if [ $? = 0 ]; then + log "[ OK ] luksOpen crypted_usb" + return 0 + fi + fi +} + + + + function mount_usb() { if mount /dev/mapper/crypted_usb /mnt/usb; then log "[ OK ] mount crypted_usb to /mnt/usb" @@ -280,14 +311,16 @@ function format() { } function main () { - if get_luks_password; then - if find_luks; then - if mount_luks $LUKS_PASS $USB_DEV; then - if mount_usb; then - sync_files - statistics_usb - if umount_usb; then - luks_close + if another_instance; then + if get_luks_password; then + if find_luks; then + if mount_luks $LUKS_PASS $USB_DEV; then + if mount_usb; then + sync_files + statistics_usb + if umount_usb; then + luks_close + fi fi fi fi