2019-09-30 15:29:28 +02:00
|
|
|
#!/bin/bash
|
2019-10-01 11:59:31 +02:00
|
|
|
#
|
2019-09-30 15:29:28 +02:00
|
|
|
# Imports data from the system
|
|
|
|
# @param $1 If the first parameter is "reverse" the data will be exported to the system
|
2019-10-01 11:59:31 +02:00
|
|
|
#
|
2019-10-01 12:30:27 +02:00
|
|
|
# shellcheck source=/dev/null # Deactivate SC1090
|
|
|
|
# shellcheck disable=SC2143 # Comparing with -z allowed
|
2020-05-06 08:59:48 +02:00
|
|
|
# shellcheck disable=SC2015 # Deactivating bool hint
|
2020-05-02 12:39:00 +02:00
|
|
|
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
|
2020-05-15 19:57:25 +02:00
|
|
|
|
|
|
|
declare -a BACKUP_LIST=("$HOME/.ssh/" \
|
|
|
|
"$HOME/.gitconfig" \
|
|
|
|
"$HOME/.atom/config.cson" \
|
|
|
|
"$HOME/.local/share/rhythmbox/rhythmdb.xml" \
|
|
|
|
"$HOME/.config/keepassxc/keepassxc.ini" \
|
|
|
|
"$HOME/Documents/certificates/" \
|
|
|
|
"$HOME/Documents/recovery_codes/" \
|
|
|
|
"$HOME/Documents/identity/" \
|
|
|
|
"$HOME/Documents/passwords/" \
|
|
|
|
"$HOME/Documents/licenses/");
|
|
|
|
|
2019-10-01 12:30:27 +02:00
|
|
|
if [ -z "$(mount | grep "$DECRYPTED_PATH")" ]
|
2019-09-30 17:19:27 +02:00
|
|
|
then
|
2020-05-03 20:16:46 +02:00
|
|
|
info "The decrypted folder $DECRYPTED_PATH is locked. You need to unlock it!" &&
|
2020-05-03 20:32:57 +02:00
|
|
|
bash "$SCRIPT_PATH""encryption/unlock.sh" || error "Unlocking failed.";
|
2019-09-30 17:19:27 +02:00
|
|
|
fi
|
2019-11-02 09:43:27 +01:00
|
|
|
if [ "$1" = "reverse" ]
|
|
|
|
then
|
|
|
|
MODE="export"
|
|
|
|
else
|
|
|
|
MODE="import"
|
|
|
|
fi
|
|
|
|
CONCRETE_BACKUP_FOLDER="$BACKUP_PATH/$MODE/$(date '+%Y%m%d%H%M%S')"
|
2020-05-03 20:16:46 +02:00
|
|
|
mkdir -p "$CONCRETE_BACKUP_FOLDER" || error "Failed to create \"$CONCRETE_BACKUP_FOLDER\"."
|
2019-09-30 15:29:28 +02:00
|
|
|
for system_item_path in "${BACKUP_LIST[@]}";
|
|
|
|
do
|
2019-10-01 12:30:27 +02:00
|
|
|
data_item_path="$DATA_PATH$system_item_path"
|
2019-11-02 09:43:27 +01:00
|
|
|
if [ "$MODE" = "export" ]
|
2019-09-30 15:29:28 +02:00
|
|
|
then
|
|
|
|
destination="$system_item_path"
|
|
|
|
source="$data_item_path"
|
2020-05-03 20:16:46 +02:00
|
|
|
info "Export data from $source to $destination..."
|
2019-09-30 15:29:28 +02:00
|
|
|
else
|
|
|
|
source="$system_item_path"
|
|
|
|
destination="$data_item_path"
|
2020-05-03 20:16:46 +02:00
|
|
|
info "Import data from $source to $destination..."
|
2019-09-30 15:29:28 +02:00
|
|
|
fi
|
|
|
|
if [ -f "$destination" ]
|
|
|
|
then
|
2020-05-03 20:16:46 +02:00
|
|
|
info "The destination file allready exists!" &&
|
|
|
|
info "Difference:" &&
|
2019-10-01 07:55:33 +02:00
|
|
|
diff "$destination" "$source"
|
2019-09-30 15:29:28 +02:00
|
|
|
fi
|
2019-10-01 07:55:33 +02:00
|
|
|
destination_dir=$(dirname "$destination")
|
2020-05-03 20:16:46 +02:00
|
|
|
mkdir -p "$destination_dir" || error "Failed to create \"$destination_dir\"."
|
2019-09-30 16:13:26 +02:00
|
|
|
if [ -f "$source" ]
|
|
|
|
then
|
2019-12-03 14:22:10 +01:00
|
|
|
backup_dir=$(dirname "$CONCRETE_BACKUP_FOLDER/$system_item_path");
|
2020-05-03 20:16:46 +02:00
|
|
|
mkdir -p "$backup_dir" || error "Failed to create \"$backup_dir\"."
|
|
|
|
info "Copy data from $source to $destination..."
|
2020-05-15 11:18:19 +02:00
|
|
|
rsync -abcEPuvW --backup-dir="$backup_dir" "$source" "$destination" || error
|
2019-09-30 16:13:26 +02:00
|
|
|
else
|
|
|
|
if [ -d "$source" ]
|
2019-09-30 17:19:27 +02:00
|
|
|
then
|
2020-05-03 20:16:46 +02:00
|
|
|
mkdir -p "$destination" || error "Failed to create \"$destination\"."
|
2019-12-03 14:22:10 +01:00
|
|
|
backup_dir="$CONCRETE_BACKUP_FOLDER/$system_item_path";
|
2020-05-03 20:16:46 +02:00
|
|
|
mkdir -p "$backup_dir" || error "Failed to create \"$backup_dir\"."
|
|
|
|
info "Copy data from directory $source to directory $destination..."
|
2020-05-15 11:18:19 +02:00
|
|
|
rsync -abcEPuvW --delete --backup-dir="$backup_dir" "$source" "$destination" || error
|
2019-09-30 17:19:27 +02:00
|
|
|
else
|
2020-05-03 20:16:46 +02:00
|
|
|
warning "$source doesn't exist. Copying data is not possible."
|
2019-09-30 17:19:27 +02:00
|
|
|
fi
|
2019-09-30 16:13:26 +02:00
|
|
|
fi
|
2019-09-30 15:29:28 +02:00
|
|
|
done
|