-
Notifications
You must be signed in to change notification settings - Fork 7
/
entrypoint.sh
94 lines (77 loc) · 1.79 KB
/
entrypoint.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -e
# set timezone
rm /etc/localtime
ln -s /usr/share/zoneinfo/$LOCALTIME /etc/localtime
# set up config volume
mkdir -p /config/jottad
ln -sfn /config/jottad /root/.jottad
# start the service
export JOTTAD_SYSTEMD=0
/usr/bin/run_jottad &
# wait for service to fully start
sleep 5
# Exit on error no longer needed. Also, it would prevent detecting jotta-cli status
set +e
# Checking if jotta runs correctly
jotta-cli status >/dev/null 2>&1
R=$?
if [ $R -ne 0 ]; then
echo "Could not start jotta. Checking why."
# Assuming we are not logged in
if [[ "$(jotta-cli status 2>&1)" =~ "Not logged in" ]]; then
echo "First time login. Logging in."
# Login user
/usr/bin/expect -c "
set timeout 20
spawn jotta-cli login
expect \"accept license (yes/no): \" {send \"yes\n\"}
expect \"Personal login token: \" {send \"$JOTTA_TOKEN\n\"}
expect {
eof {
exit 1
}
\"Devicename*: \" {
send \"$JOTTA_DEVICE\n\"
expect eof
}
\"Do you want to re-use this device? (yes/no):\" {
send \"yes\n\"
expect eof
}
}
"
R=$?
if [ $R -ne 0 ]; then
echo "Login failed"
exit 1
fi
else
echo "ERROR: Not able to determine why Jotta cannot start:"
jotta-cli status
exit 1
fi
else
echo "Jotta started."
fi
echo "Adding backups"
for dir in /backup/* ; do if [ -d "${dir}" ]; then set +e && jotta-cli add /$dir && set -e; fi; done
# load ignore file
if [ -f /config/ignorefile ]; then
echo "loading ignore file"
jotta-cli ignores set /config/ignorefile
fi
# set scan interval
echo "Setting scan interval"
jotta-cli config set scaninterval $JOTTA_SCANINTERVAL
jotta-cli tail &
R=0
while [[ $R -eq 0 ]]
do
sleep 15
jotta-cli status >/dev/null 2>&1
R=$?
done
echo "Exiting:"
jotta-cli status
exit 1