mirror of
https://github.com/kevinveenbirkenbach/linux-image-manager.git
synced 2024-11-10 01:51:03 +01:00
68 lines
2.2 KiB
Bash
68 lines
2.2 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Imports data from the system
|
|
# @author Kevin Veen-Birkenbach [aka. Frantz]
|
|
# @param $1 If the first parameter is "reverse" the data will be exported to the system
|
|
#
|
|
# shellcheck source=/dev/null # Deactivate SC1090
|
|
# shellcheck disable=SC2143 # Comparing with -z allowed
|
|
source "$(dirname "$(readlink -f "${0}")")/base.sh"
|
|
if [ -z "$(mount | grep "$DECRYPTED_PATH")" ]
|
|
then
|
|
echo "The decrypted folder $DECRYPTED_PATH is locked. You need to unlock it!"
|
|
bash "$SCRIPT_PATH/unlock.sh" || exit 1;
|
|
fi
|
|
if [ "$1" = "reverse" ]
|
|
then
|
|
MODE="export"
|
|
else
|
|
MODE="import"
|
|
fi
|
|
CONCRETE_BACKUP_FOLDER="$BACKUP_PATH/$MODE/$(date '+%Y%m%d%H%M%S')"
|
|
mkdir -p $CONCRETE_BACKUP_FOLDER
|
|
declare -a BACKUP_LIST=("$HOME/.ssh/" \
|
|
"$HOME/.gitconfig" \
|
|
"$HOME/.atom/config.cson" \
|
|
"$HOME/Documents/certificates/" \
|
|
"$HOME/Documents/recovery_codes/" \
|
|
"$HOME/Documents/identity/" \
|
|
"$HOME/Documents/passwords/" \
|
|
"$HOME/.local/share/rhythmbox/rhythmdb.xml" \
|
|
"$HOME/.config/keepassxc/keepassxc.ini");
|
|
for system_item_path in "${BACKUP_LIST[@]}";
|
|
do
|
|
data_item_path="$DATA_PATH$system_item_path"
|
|
if [ "$MODE" = "export" ]
|
|
then
|
|
destination="$system_item_path"
|
|
source="$data_item_path"
|
|
echo "Export data from $source to $destination..."
|
|
else
|
|
source="$system_item_path"
|
|
destination="$data_item_path"
|
|
echo "Import data from $source to $destination..."
|
|
fi
|
|
if [ -f "$destination" ]
|
|
then
|
|
echo "The destination file allready exists!";
|
|
echo "Difference:"
|
|
diff "$destination" "$source"
|
|
fi
|
|
destination_dir=$(dirname "$destination")
|
|
mkdir -p "$destination_dir"
|
|
if [ -f "$source" ]
|
|
then
|
|
echo "Copy data from $source to $destination..."
|
|
rsync -uWvabPE --update --times --backup-dir="$CONCRETE_BACKUP_FOLDER" "$source" "$destination"
|
|
else
|
|
if [ -d "$source" ]
|
|
then
|
|
mkdir -p "$destination"
|
|
echo "Copy data from directory $source to directory $destination..."
|
|
rsync -uWvabrPE --update --times --delete --backup-dir="$CONCRETE_BACKUP_FOLDER" "$source" "$destination"
|
|
else
|
|
echo "$source doesn't exist. Copying data is not possible."
|
|
fi
|
|
fi
|
|
done
|