delete crypt_usb feature

This commit is contained in:
Ste Vaidis 2023-05-22 14:19:45 +03:00
parent 9c94ebca1f
commit fd1ea2676e
2 changed files with 45 additions and 12 deletions

View File

@ -11,5 +11,5 @@ USB_DISK=""
USB_PARTITION=""
USB_MOUNT="/mnt/usb"
MAIL_RECIPIENT="ste.vaidis@gmail.com"
MAIL_RECIPIENT="ffilippidou@gmail.com"

View File

@ -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