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
# @author Kevin Veen-Birkenbach [aka. Frantz]
# @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
2019-10-01 08:50:17 +02:00
source " $( dirname " $( readlink -f " ${ 0 } " ) " ) /base.sh "
2019-10-01 12:30:27 +02:00
if [ -z " $( mount | grep " $DECRYPTED_PATH " ) " ]
2019-09-30 17:19:27 +02:00
then
2019-10-01 12:30:27 +02:00
echo " The decrypted folder $DECRYPTED_PATH is locked. You need to unlock it! "
bash " $SCRIPT_PATH /unlock.sh " || exit 1;
2019-09-30 17:19:27 +02:00
fi
2019-10-03 20:26:35 +02:00
declare -a BACKUP_LIST = ( " $HOME /.ssh/ " " $HOME /.gitconfig " " $HOME /.atom/config.cson " " $HOME /Documents/certificates/ " " $HOME /Documents/recovery_codes/ " " $HOME /Documents/passwords/ " " $HOME /.config/dconf/user " ) ;
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-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:"
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 " )
2019-09-30 15:29:28 +02:00
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 " ]
2019-09-30 17:19:27 +02:00
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