linux-image-manager/scripts/import-data-from-system.sh

47 lines
1.6 KiB
Bash
Raw Normal View History

2019-09-30 15:29:28 +02:00
#!/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
2019-09-30 16:52:06 +02:00
DATA_FOLDER=$(readlink -f "$(dirname "$(readlink -f "${0}")")/../data");
if [ -z $(mount | grep $DATA_FOLDER) ]
then
echo "The data folder $DATA_FOLDER is locked. You need to unlock it!"
bash "$(dirname "$(readlink -f "${0}")")/unlock.sh" || exit 1;
fi
2019-09-30 23:51:06 +02:00
declare -a BACKUP_LIST=("$HOME/.ssh/" "$HOME/.gitconfig" "$HOME/.mozilla/firefox/" "$HOME/.atom/config.cson");
2019-09-30 15:29:28 +02:00
for system_item_path in "${BACKUP_LIST[@]}";
do
2019-09-30 16:36:34 +02:00
data_item_path="$DATA_FOLDER$system_item_path"
2019-09-30 15:29:28 +02:00
if [ "$1" = "reverse" ]
then
destination="$system_item_path"
source="$data_item_path"
2019-09-30 16:36:34 +02:00
echo "Export data from $source to $destination..."
2019-09-30 15:29:28 +02:00
else
source="$system_item_path"
destination="$data_item_path"
2019-09-30 16:36:34 +02:00
echo "Import data from $source to $destination..."
2019-09-30 15:29:28 +02:00
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"
2019-09-30 16:13:26 +02:00
if [ -f "$source" ]
then
echo "Copy data from $source to $destination..."
cp -vi "$source" "$destination"
else
if [ -d "$source" ]
then
echo "Copy data from directory $source to directory $destination_dir..."
cp -vir "$source" "$destination_dir"
else
echo "$source doesn't exist. Copying data is not possible."
fi
2019-09-30 16:13:26 +02:00
fi
2019-09-30 15:29:28 +02:00
done