significantly improved error handling, fixed bug that would make the program crash before the docker container was made

This commit is contained in:
Michael Scalzetti 2022-03-27 18:40:24 -04:00
parent 15345c21a5
commit f25bc45dd7

46
run.sh
View File

@ -1,35 +1,55 @@
DEV_USB=$1 DEV_USB=$1
MOUNT_NAME=priv MOUNT_NAME=priv
MOUNT_DIR=/media/michael/priv MOUNT_DIR=/media/michael/priv
LOC=0
echo "Locking db..." error(){
cryptsetup luksOpen $DEV_USB $MOUNT_NAME || \ echo $1
echo "Issue unlocking db... quitting" &&\
exit 1 exit 1
}
clear
echo "Unlocking db..."
cryptsetup luksOpen $DEV_USB $MOUNT_NAME ||\
error "Issue unlocking db... quitting..."
echo "Mounting db..." echo "Mounting db..."
mkdir $MOUNT_DIR
rm -rf $MOUNT_DIR rm -rf $MOUNT_DIR
mkdir $MOUNT_DIR &&\
mount /dev/mapper/$MOUNT_NAME $MOUNT_DIR ||\ mount /dev/mapper/$MOUNT_NAME $MOUNT_DIR ||\
echo "Issue mounting db... quiting..." &&\ error "Issue mounting db... quitting..."
exit 1
echo "Making link..."
rm -rf ./data.link rm -rf ./data.link
ln -s "$MOUNT_DIR/notes" ./data.link ln -s "$MOUNT_DIR/notes" ./data.link ||\
error "Issue mounting db... quitting..."
echo "Starting container..." echo "Starting container..."
docker run --name priv --rm -it -v `pwd`/data.link/:/notes `docker build -q .` docker run --name priv --rm -it -v `pwd`/data.link/:/notes `docker build -q .` ||\
error "Issue making docker container... quitting..."
echo "Unmounting db..." echo "Unmounting db..."
umount -f "$MOUNT_DIR" umount -f "$MOUNT_DIR" &&\
rm -rf $MOUNT_DIR rm -rf $MOUNT_DIR ||\
error "Issue unmounting and deleting mountpoint... quitting..."
echo "Removing link..." echo "Removing link..."
rm -rf ./data.link rm -rf ./data.link
error "Issue deleting link... quitting..."
echo "Locking db..." echo "Locking db..."
cryptsetup luksClose /dev/mapper/$MOUNT_NAME cryptsetup luksClose /dev/mapper/$MOUNT_NAME ||\
error "Issue locking db... quitting..."
echo "Exiting gracefully..."
exit 0
echo "Exiting..."