From 89902cd8eb941ca4a82b97e98f3047066fd9f0df Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Tue, 1 Oct 2019 12:30:27 +0200 Subject: [PATCH] Optimized path variables and code --- .gitignore | 2 +- scripts/base.sh | 11 ++++++++--- scripts/export-data-to-system.sh | 4 +++- scripts/import-data-from-system.sh | 13 ++++++------- scripts/lock.sh | 7 +++---- scripts/system-setup.sh | 3 +++ scripts/unlock.sh | 13 ++++++------- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 79efc04..3c9b66f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -data/ +decrypted/ .encrypted/ diff --git a/scripts/base.sh b/scripts/base.sh index 34d2c74..fd615dd 100644 --- a/scripts/base.sh +++ b/scripts/base.sh @@ -2,6 +2,11 @@ # # This script contains the global program variables and functions # @author Kevin Veen-Birkenbach [aka. Frantz] -REPOSITORY_PATH="$(dirname "$(readlink -f "${0}")")" -ENCRYPTED=$(readlink -f "$REPOSITORY_PATH/../.encrypted"); -DECRYPTED=$(readlink -f "$REPOSITORY_PATH/../data"); +# +# shellcheck disable=SC2034 #Deactivate checking of unused variables +REPOSITORY_PATH=$(readlink -f "$(dirname "$(readlink -f "${0}")")/../") +ENCRYPTED_PATH="$REPOSITORY_PATH/.encrypted"; +DECRYPTED_PATH="$REPOSITORY_PATH/decrypted"; +SCRIPT_PATH="$REPOSITORY_PATH/scripts"; +DATA_PATH="$DECRYPTED_PATH/data"; +BACKUP_PATH="$DECRYPTED_PATH/backup"; diff --git a/scripts/export-data-to-system.sh b/scripts/export-data-to-system.sh index b9bf25a..0b00d4b 100644 --- a/scripts/export-data-to-system.sh +++ b/scripts/export-data-to-system.sh @@ -1,4 +1,6 @@ #!/bin/bash # Executes the import script in reverse mode # @author Kevin Veen-Birkenbach [aka. Frantz] -bash "$(dirname "$(readlink -f "${0}")")/import-data-from-system.sh" reverse +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/base.sh" +bash "$SCRIPT_PATH/import-data-from-system.sh" reverse diff --git a/scripts/import-data-from-system.sh b/scripts/import-data-from-system.sh index 604a57e..fb8adb3 100644 --- a/scripts/import-data-from-system.sh +++ b/scripts/import-data-from-system.sh @@ -4,19 +4,18 @@ # @author Kevin Veen-Birkenbach [aka. Frantz] # @param $1 If the first parameter is "reverse" the data will be exported to the system # -# Deactivate SC1090 -# shellcheck source=/dev/null +# shellcheck source=/dev/null # Deactivate SC1090 +# shellcheck disable=SC2143 # Comparing with -z allowed source "$(dirname "$(readlink -f "${0}")")/base.sh" -DATA_FOLDER=$ENCRYPTED -if [ -z "$(mount | grep $DATA_FOLDER)" ] +if [ -z "$(mount | grep "$DECRYPTED_PATH")" ] then - echo "The data folder $DATA_FOLDER is locked. You need to unlock it!" - bash "$(dirname "$(readlink -f "${0}")")/unlock.sh" || exit 1; + echo "The decrypted folder $DECRYPTED_PATH is locked. You need to unlock it!" + bash "$SCRIPT_PATH/unlock.sh" || exit 1; fi declare -a BACKUP_LIST=("$HOME/.ssh/" "$HOME/.gitconfig" "$HOME/.mozilla/firefox/" "$HOME/.atom/config.cson"); for system_item_path in "${BACKUP_LIST[@]}"; do - data_item_path="$DATA_FOLDER$system_item_path" + data_item_path="$DATA_PATH$system_item_path" if [ "$1" = "reverse" ] then destination="$system_item_path" diff --git a/scripts/lock.sh b/scripts/lock.sh index 4aca865..b1260cd 100644 --- a/scripts/lock.sh +++ b/scripts/lock.sh @@ -3,8 +3,7 @@ # Locks the data # @author Kevin Veen-Birkenbach [aka. Frantz] # -# Deactivate SC1090 -# shellcheck source=/dev/null +# shellcheck source=/dev/null # Deactivate SC1090 source "$(dirname "$(readlink -f "${0}")")/base.sh" -echo "Locking directory $DECRYPTED..." -fusermount -u "$DECRYPTED" && echo "Data is now encrypted." && echo "Removing directory $DECRYPTED..." && rmdir "$DECRYPTED" +echo "Locking directory $DECRYPTED_PATH..." +fusermount -u "$DECRYPTED_PATH" && echo "Data is now encrypted." && echo "Removing directory $DECRYPTED_PATH..." && rmdir "$DECRYPTED_PATH" diff --git a/scripts/system-setup.sh b/scripts/system-setup.sh index 7e0c493..ef026dc 100644 --- a/scripts/system-setup.sh +++ b/scripts/system-setup.sh @@ -2,6 +2,9 @@ # # Installs the core system # @author Kevin Veen-Birkenbach [aka. Frantz] +# +# shellcheck source=/dev/null # Deactivate SC1090 +source "$(dirname "$(readlink -f "${0}")")/base.sh" echo "Start setup of customized core software..." echo "Synchronising packages..." echo "Synchronizing programing languages..." diff --git a/scripts/unlock.sh b/scripts/unlock.sh index 569486a..e40bb61 100644 --- a/scripts/unlock.sh +++ b/scripts/unlock.sh @@ -3,11 +3,10 @@ # Unlocks the data # @author Kevin Veen-Birkenbach [aka. Frantz] # -# Deactivate SC1090 -# shellcheck source=/dev/null +# shellcheck source=/dev/null # Deactivate SC1090 source "$(dirname "$(readlink -f "${0}")")/base.sh" -echo "Unlocking directory $DECRYPTED..." -echo "Creating directory $DECRYPTED..." -mkdir "$DECRYPTED" -echo "Encrypting directory $DECRYPTED to $DECRYPTED..." -encfs "$ENCRYPTED" "$DECRYPTED" && echo "ATTENTION: DATA IS NOW DECRYPTED!" +echo "Unlocking directory $DECRYPTED_PATH..." +echo "Creating directory $DECRYPTED_PATH..." +mkdir "$DECRYPTED_PATH" +echo "Encrypting directory $DECRYPTED_PATH to $DECRYPTED_PATH..." +encfs "$ENCRYPTED_PATH" "$DECRYPTED_PATH" && echo "ATTENTION: DATA IS NOW DECRYPTED!"