-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·235 lines (225 loc) · 6.15 KB
/
run.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
#!/bin/bash
#Laravel setup script for Debian-based distributions (this will change later!)
#Developed by PS-Professional
#
#
# ____ ____ ____ __ _ _
# | _ \/ ___| | _ \ _ __ ___ / _| ___ ___ ___(_) ___ _ __ __ _| |
# | |_) \___ \ _____| |_) | '__/ _ \| |_ / _ \/ __/ __| |/ _ \| '_ \ / _` | |
# | __/ ___) |_____| __/| | | (_) | _| __/\__ \__ \ | (_) | | | | (_| | |
# |_| |____/ |_| |_| \___/|_| \___||___/___/_|\___/|_| |_|\__,_|_|
#
#===================================================================================================
#Option for later release
#SYS_PKG=`cat /etc/os-release | grep 'ID_LIKE' | cut -f 2 -d '='`
#Functions
function help(){
echo -e "run.sh: Setup and run Laravel framework on Docker engine\n"
echo "Options:"
echo -e "N/A\t\t Run script in interactive mode"
echo -e "init\t\t Install Docker and setup Laravel image"
echo -e "start\t\t Start Laravel and MySQL containers"
echo -e "setup\t\t Setup Laravel and MySQL configurations"
echo -e "update\t\t Update Laravel image"
echo -e "restart\t\t Restart Laravel and MySQL containers"
echo -e "stop\t\t stop Laravel and MySQL containers"
}
function docker_install(){
#Install docker on your host
echo installing Docker\.\.\.
sleep 1
sudo apt update
sudo apt install -y\
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose
sleep 2
echo Installing done\!
}
function docker_update(){
#Update your system
echo Updating system\.\.\.
sleep 1
sudo apt update && sudo apt upgrade
sleep 2
echo Updating Done\!
}
function docker_init(){
#config files
echo Gitting files from GitHub and running configurations\.\.\.
sleep 1
#git clone git https://github.com/laravel/laravel.git --branch=6.X laravel
sudo docker pull composer
sudo docker build -t ps/php:1.0 .
echo 1.0 > .version
}
function ver_check(){
if [[ -f .version ]]
then
LV=`cat .version`
else
echo 1.0 > .version
LV=`cat .version`
fi
}
function update_image(){
echo Your last image version is: $LV
sleep 1
read -p 'Enter your new version tag: ' New
sed 's/'$LV'/'$New'/' Dcokerfile > tmp && cat tmp > Dockerfile && rm tmp
sudo docker build -t ps/php:$New .
echo $New > .version
sed 's/'$LV'/'$New'/' docker-compose.yml > tmp && cat tmp > docker-compose.yml && rm tmp
}
#Main funcion
function main(){
clear
echo Hello\! ; sleep 1
echo -e 'What you want me to do?\n1) Setup containers (init)\n2) Start containers (start)\n3) Setup container configurations (setup)\n4) Update image (update)\n5) Restart containers (restart)\n6) Stop containers (stop)\n7) Exit (exit)'
read -p '-> ' func
case $func in
init )
if [[ -f /usr/bin/docker ]]
then
echo Docker is already exsits in your system
sleep 1
State=1
while [[ $State = 1 ]]
do
read -p 'Do you want to check for system updates? ' update
if [[ $update = 'yes' ]] || [[ $update = 'y' ]]
then
docker_update
State=0
elif [[ $update = 'no' ]] || [[ $update = 'n' ]]
then
echo OK\!
sleep 1
State=0
else
echo I didn\'t understand\!
sleep 0.5
echo Please try again\!
sleep 0.5
fi
done
else
docker_install
fi
sleep 1
docker_init ;;
start )
sudo docker-compose up -d && \
sudo docker-compose exec --user=root App /etc/init.d/nginx start ;;
setup )
sudo docker-compose exec App php artisan key:generate && \
sudo docker-compose exec App php artisan config:cache && \
echo MySQL\'s Password is \: 'admin123' && \
sudo docker-compose exec DB bash && \
sudo docker-compose exec App php artisan migrate
read -p 'Would you like to test database connection? ' database
if [[ $database = 'yes' ]] || [[ $database = 'y' ]]
then
sudo docker-compose exec --user=root App php artisan tinker
elif [[ $database = 'no' ]] || [[ $database = 'n' ]]
then
echo OK\!
sleep 1
else
echo I didn\'t understand\!
sleep 0.5
echo Please try again\!
sleep 0.5
fi
echo Setting up contianers done\!
sleep 1;;
update )
update_image;;
restart )
sudo docker-compose restart;;
stop )
sudo docker-compose down;;
exit )
echo Goodbye\!;;
esac
}
# Main code
ver_check
if [[ -z $1 ]]
then
main
else
case $1 in
init )
if [[ -f /usr/bin/docker ]]
then
echo Docker is already exsits in your system
sleep 1
State=1
while [[ $State = 1 ]]
do
read -p 'Do you want to check for system updates? ' update
if [[ $update = 'yes' ]] || [[ $update = 'y' ]]
then
docker_update
State=0
elif [[ $update = 'no' ]] || [[ $update = 'n' ]]
then
echo OK\!
sleep 1
State=0
else
echo I didn\'t understand\!
sleep 0.5
echo Please try again\!
sleep 0.5
fi
done
else
docker_install
fi
sleep 1
docker_init ;;
start )
sudo docker-compose up -d && \
sudo docker-compose exec --user=root App /etc/init.d/nginx start ;;
Setup )
sudo docker-compose exec App php artisan key:generate && \
sudo docker-compose exec App php artisan config:cache && \
echo MySQL\'s Password is \: 'admin123' && \
sudo docker-compose exec DB bash && \
sudo docker-compose exec App php artisan migrate
read -p 'Would you like to test database connection? ' database
if [[ $database = 'yes' ]] || [[ $database = 'y' ]]
then
sudo docker-compose exec --user=root App php artisan tinker
elif [[ $database = 'no' ]] || [[ $database = 'n' ]]
then
echo OK\!
sleep 1
else
echo I didn\'t understand\!
sleep 0.5
echo Please try again\!
sleep 0.5
fi
echo Setting up contianers done\!
sleep 1;;
update )
update_image;;
restart )
sudo docker-compose restart;;
stop )
sudo docker-compose down;;
* )
help;;
esac
fi