-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.sh
246 lines (225 loc) · 5.83 KB
/
launch.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
clear
user=""
path="/path/to/parent/directory"
#Database config
dbdsn=""
dbuser=""
dbpassword=""
#don't touch
CL='\033[1;32m'
CR='\033[0;31m'
CLA='\033[1;33m'
CG='\033[1;34m'
NC='\033[0m'
######
# Cmd functions
# help
# List of available commands
help () {
printf "Available commands:\n"
printf "${CLA}clear: ${CL}Clean the terminal\n"
printf "${CLA}help: ${CL}List of available commands\n"
printf "${CLA}install: ${CL}Install and set up the PhoenixMachina repositories\n"
printf "${CLA}update: ${CL}Check update of Julia and PhoenixMachina repositories\n"
printf "${CLA}start: ${CL}Start PhoenixMachina\n"
printf "${CLA}test: ${CL}Run test file of the repository\n"
printf "${CLA}quit: ${CL}Close the terminal${NC}\n"
}
# install
# Install and set up the PhoenixMachina repositories
install () {
if [[ ! -d "PhoenixMachina" ]]; then
printf "${CG} Cloning PhoenixMachina repository${NC}\n"
git clone https://github.com/PhoenixMachina/PhoenixMachina.git PhoenixMachina
else
printf "${CL}PhoenixMachina already exists${NC}\n"
fi
if [[ ! -d "Tlaloc" ]]; then
printf "${CG} Cloning Tlaloc repository${NC}\n"
git clone https://github.com/PhoenixMachina/Tlaloc.git Tlaloc
else
printf "${CL}Tlaloc already exists${NC}\n"
fi
if [[ ! -d "ConfParser" ]]; then
printf "${CG} Cloning ConfParser repository${NC}\n"
git clone https://github.com/PhoenixMachina/ConfParser.jl.git ConfParser
else
printf "${CL}ConfParser already exists${NC}\n"
fi
if [[ ! -d "Yodel" ]]; then
printf "${CG} Cloning Yodel repository${NC}\n"
git clone https://github.com/PhoenixMachina/Yodel.git Yodel
else
printf "${CL}Yodel already exists${NC}\n"
fi
if [[ ! -d "SapphireORM" ]]; then
printf "${CG} Cloning SapphireORM repository${NC}\n"
git clone https://github.com/PhoenixMachina/SapphireORM.git SapphireORM
else
printf "${CL}SapphireORM already exists${NC}\n"
fi
if [[ ! -d "launcher-linux" ]]; then
printf "${CG} Cloning launcher-linux repository${NC}\n"
git clone https://github.com/PhoenixMachina/launcher-linux.git launcher-linux
else
printf "${CL}launcher-linux already exists${NC}\n"
fi
cd PhoenixMachina
printf "${CG} Install packages for PhoenixMachina${NC}\n"
julia install.jl
cd ..
sudo chown -R $user *
sudo chown -R $user */
sudo chown -R $user */*
sudo chown -R $user */*/
sudo chown -R $user */*/*
printf "${CG} Configuring config.jl${NC}\n"
if [[ -f "PhoenixMachina/config.jl" ]]; then
rm PhoenixMachina/config.jl
fi
echo "#REQUIRED
#Home URLS
HOME_CONTROLLER = \"homeController.jl\"
HOME_URL = \"$path/PhoenixMachina/\"
DB_DSN = \"$dbdsn\"
DB_USER = \"$dbuser\"
DB_PASSWORD = \"$dbpassword\"
#OPTIONAL
Logging.configure(output=open(\"$path/PhoenixMachina/logfile.log\", \"a\"))" >> PhoenixMachina/config.jl
printf "${CG} Configuring tlaloc.ini${NC}\n"
if [[ -f "PhoenixMachina/include/tlaloc.ini" ]]; then
rm PhoenixMachina/include/tlaloc.ini
fi
echo "viewPath=$path/PhoenixMachina/views/
templatePath=$path/PhoenixMachina/templates/
resourcePath=$path/PhoenixMachina/resources/" >> $path/PhoenixMachina/include/tlaloc.ini
printf "${CG} Configuring test_conf.ini in Tlaloc${NC}\n"
if [[ -f "Tlaloc/test/test_conf.ini" ]]; then
rm Tlaloc/test/test_conf.ini
fi
echo "viewPath=thisIsTheViewPath
templatePath=thisIsTheTemplatePath
resourcePath=$path/Tlaloc/test/thisIsTheResource" >> $path/Tlaloc/test/test_conf.ini
}
# update
# Check update of Julia and PhoenixMachina repositories
update () {
printf "${CG} Check update for julia package ${NC}\n"
sudo apt-get install julia
printf "${CG} Updating julia packages ${NC}\n"
julia -e "Pkg.update()"
if [[ -d "PhoenixMachina/" ]]; then
cd PhoenixMachina
printf "${CG} Pull PhoenixMachina repository from Github to local ${NC}\n"
git pull
cd ..
else
printf "${CR}PhoenixMachina wasn't found ${NC}\n"
fi
if [[ -d "SapphireORM/" ]]; then
cd SapphireORM
printf "${CG} Pull SapphireORM repository ${NC}\n"
git pull
cd ..
else
printf "${CR}SapphireORM wasn't found ${NC}\n"
fi
if [[ -d "Tlaloc/" ]]; then
cd Tlaloc
printf "${CG} Pull Tlaloc repository ${NC}\n"
git pull
cd ..
else
printf "${CR}Tlaloc wasn't found ${NC}\n"
fi
if [[ -d "Yodel/" ]]; then
cd Yodel
printf "${CG} Pull Yodel repository${NC}\n"
git pull
cd ..
else
printf "${CR}Yodel wasn't found ${NC}\n"
fi
if [[ -d "ConfParser/" ]]; then
cd ConfParser
printf "${CG} Pull ConfParser repository${NC}\n"
git pull
cd ..
else
printf "${CR}ConfParser wasn't found ${NC}\n"
fi
cd launcher-linux
printf "${CG} Pull launcher-linux repository${NC}\n"
git pull
cd ..
}
# start
# Start PhoenixMachina
start () {
if [[ -d "PhoenixMachina/" ]]; then
cd launcher-linux/logs
printf "${CG} Starting PhoenixMachina ${NC}\n"
julia ../../PhoenixMachina/start_server.jl 2>&1 | tee logs$(date +"%F%T")
cd ../..
else
printf "${CR}PhoenixMachina wasn't found${NC}\n"
fi
}
# test
# Run test file of the repository
testc () {
folder=${cmd:4}
julia $folder/test/runtests.jl
}
######
# Terminal
# Unknown command
default () {
printf "${CL}Unknown command. Type ${CLA}help ${CL}to check commands\n${NC}"
}
# First Message
intro () {
printf "${CL}PhoenixMachina launcher for Linux\n"
printf "type ${CLA}help ${CL}to check commands${CL}\n${NC}"
}
#Startup
intro
cd $path
while [ true ]
do
# Input
printf "[$USER:$path] "
read cmd
# Check if cmd is a valid command, if yes, execute it.
case $cmd in
help)
help
;;
update)
update
;;
start)
start
;;
install)
install
;;
clear)
clear
intro
;;
quit)
clear
exit 1
;;
*)
if [[ ${cmd:0:4} = "test" ]]
then
testc
else
default
fi
;;
esac
done