-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·37 lines (29 loc) · 985 Bytes
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
set -euo pipefail
# read variables
VARIABLES_FILE=$(dirname "$0")/variables
source $VARIABLES_FILE
# check if running as root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# check if restic is installed
if ! command -v restic &> /dev/null
then
echo "restic could not be found. Please install it first: https://restic.readthedocs.io/en/latest/020_installation.html"
exit
fi
mkdir -p $INSTALL_DIR
mkdir -p $BACKUP_DIR
cp -a ./* $INSTALL_DIR
chown -R root:root $INSTALL_DIR
# init restic repository if does not exsists
snapshots=$(restic -p $INSTALL_DIR/password -r sftp:$SFTP snapshots)
if [[ $snapshots == Fatal* ]]; then
echo "Initializing restic repository"
restic -p $INSTALL_DIR/password -r sftp:$SFTP init
fi
# add backup cron if not exists
crontab -l | grep 'restic-backuper.sh' || (crontab -l 2>/dev/null; echo "$BACKUP_CRONTAB $INSTALL_DIR/restic-backuper.sh >> $INSTALL_DIR/log") | crontab -
source ./change-data-folder.sh