-
Notifications
You must be signed in to change notification settings - Fork 1
/
initall.sh
91 lines (77 loc) · 2.43 KB
/
initall.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
#!/bin/bash
if ! python3 --version > /dev/null 2> /dev/null; then
echo "This script needs python to be able to run"
exit 1
fi
#The below should point to the folder where you want to place
#the database inside your project
#e.g. project=$PROJECT_FOLDER/src/main/assets/database
cat .env > /dev/null 2> /dev/null && project="$(sed 's/project=//' .env | sed 's/\"//g')" || project="/absolute/path/to/your/project/database"
execute_stm(){
if [[ $1 = "--help" || $1 = "-h" ]]; then
echo -e "\nDownload and initialise the database only for data from the STM."
echo -e "\nUse the --no-download flag to initialise the database if you already have the data from the STM.\n"
else
#to replace below if needed
path=.
cd $path/stm
rm stm_info.db
if [[ $1 = "--no-download" ]]; then
python3 setup_stm_db.py "no-download"
else
python3 setup_stm_db.py
fi
cp -i 'stm_info.db' "$project"
cd ..
fi
}
execute_exo(){
#to replace below if needed
#path=/project/folder
if [[ $1 = "--help" || $1 = "-h" ]]; then
echo -e "\nDownload and initialise the database only for data from Exo."
echo -e "\nUse the --no-download flag to initialise the database if you already have the data for Exo.\n"
else
path=.
cd $path/exo
rm exo_info.db
if [[ $1 = "--no-download" ]]; then
python3 setup_exo_db.py "no-download"
else
python3 setup_exo_db.py
fi
cp -i 'exo_info.db' "$project"
cd ..
fi
}
clean() {
# delete all subdirs inside exo dir
[ rm -r $(find ./exo -mindepth 1 -maxdepth 1 -type d) 2> /dev/null ] || echo "Exo files are already deleted"
#remove all text files in stm dir
[ rm ./stm/*.txt 2> /dev/null ] || echo "Stm files already deleted"
}
if [[ $# -eq 1 && ($1 = "--help" || $1 = "-h") ]]; then
echo "Script to initialise databases containing static data from transit agencies.
Usage: ./initall.sh [-h/--help] <agency-name | command> [<args>]
Giving no agency names or command will set up all the databases for all the available agencies
Available agency names:
exo
stm
Args:
--no-download Setup the database without redownloading the required files
Available commands:
clean -> deletes all the txt files in the subdir of this script
"
elif [[ $1 = "clean" && $# -eq 1 ]]; then
clean
elif [[ $1 = "stm" && $# -lt 3 ]]; then
execute_stm $2
elif [[ $1 = "exo" && $# -lt 3 ]]; then
execute_exo $2
elif [[ $# -eq 1 && ($1 = "--no-download") ]]; then
execute_stm $1
execute_exo $1
else
echo "Syntax Error!"
exit 1
fi