-
Notifications
You must be signed in to change notification settings - Fork 5
/
installdb.sh
executable file
·58 lines (52 loc) · 1.28 KB
/
installdb.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
#!/bin/sh
set -e
DIR=$(cd "$(dirname "$0")" && pwd)
DBFILE="$DIR/asr.db"
BOATID=$1
print_result() {
if $1; then
printf 'Success\n'
else
printf 'Failed\n'
fi
}
if [ -f "$DBFILE" ]; then
rm -v "$DBFILE"
fi
case "$BOATID" in
ASPire)
printf 'Creating database for ASPire in %s\n' "$DBFILE"
if sqlite3 "$DBFILE" <"$DIR/createtablesASPire.sql"; then
print_result true
else
print_result false
fi
;;
Janet)
printf 'Creating database for Janet in %s\n' "$DBFILE"
if sqlite3 "$DBFILE" <"$DIR/createtablesJanet.sql"; then
print_result true
else
print_result false
fi
;;
*)
printf "ERROR: No arguments to create the DataBase!\\n"
printf "Please insert 'ASPire' or 'Janet' as arguments to create the DB.\\n"
exit 1
;;
esac
printf "Server connection HTTPsync configuration\\n"
printf "Example server adresses are https://sailingrobots.ax/aspire/sync/"
printf " or http://localhost/sync/\\n"
printf 'Enter server address (URL): '
read -r SRVADDR
printf 'Enter boat password: '
read -r BOATPWD
printf 'Storing configuration into %s\n' "$DBFILE"
if sqlite3 "$DBFILE" "INSERT INTO config_httpsync(id, loop_time, remove_logs, push_only_latest_logs, boat_id, boat_pwd, srv_addr) VALUES('1', '0.5', '0', '0', '$BOATID', '$BOATPWD', '$SRVADDR')"
then
print_result true
else
print_result false
fi