-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
executable file
·80 lines (75 loc) · 1.94 KB
/
setup.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
#!/bin/sh
########################################
# GLOBALS
STATUS_PREFIX=":>"
DBEX="db/tarchive.db.example"
DB="db/tarchive.db"
CFGEX="config/config.json.example"
CFG="config/config.json"
DBEX_EXISTS=true
DB_EXISTS=true
CFGEX_EXISTS=true
CFG_EXISTS=true
########################################
# CHECKS
if [ ! -f "$DBEX" ]; then
DBEX_EXISTS=false
fi
if [ ! -f "$DB" ]; then
DB_EXISTS=false
fi
if [ ! -f "$CFGEX" ]; then
CFGEX_EXISTS=false
fi
if [ ! -f "$CFG" ]; then
CFG_EXISTS=false
fi
########################################
# PROGRAM START WITH WELCOME PROMPT
printf "$DB $DB_EXISTS Starting Tarchivebot setup...\nChecking for files...\n"
printf "$STATUS_PREFIX\t'$DB':\t\t"
########################################
# CHECKS FOR DB FILE
if [ "$DB_EXISTS" = true ]; then
printf "OK\n"
else
printf "NOT FOUND\n"
if [ "$DBEX_EXISTS" = true ]; then
printf "$STATUS_PREFIX\t! Copy '$DBEX' to '$DB'? (Y/n) "
read answer
if echo "$answer" | grep -iq "^y"; then
cp -i $DBEX $DB
else
printf "$STATUS_PREFIX\t\tskipping...\n"
fi
else
printf ":>\t'$DBEX'\tNOT FOUND EITHER\n"
fi
fi
printf "$STATUS_PREFIX\t'config/config.json':\t\t"
########################################
# CHECKS FOR CONFIG FILE
if [ "$CFG_EXISTS" = true ]; then
printf "OK\n"
else
printf "NOT FOUND\n"
if [ "$CFGEX_EXISTS" = true ]; then
printf "$STATUS_PREFIX\t! Copy '$CFGEX' to '$CFG'? (Y/n) "
read answer
if echo "$answer" | grep -iq "^y"; then
cp -i $CFGEX $CFG
# PROMPT TO REPLACE DEFAULT TELEGRAM KEY
printf "$STATUS_PREFIX\t! Enter your Telegram Key (enter to skip): "
read answer_key
if [ -n "$answer_key" ]; then
sed -i -- "s/abcdefghi:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/$answer_key/g" $CFG
else
printf "$STATUS_PREFIX\t\tskipping Telegram key...\n"
fi
else
printf "$STATUS_PREFIX\t\tskipping...\n"
fi
else
printf ":>\t'$CFGEX'\tNOT FOUND EITHER\n"
fi
fi