-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemptool
executable file
·215 lines (185 loc) · 6.3 KB
/
lemptool
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
#! /bin/bash
source lemptool_scripts
#-------------------Utility help-----------------------------------------#
show_help() {
echo ""
echo "Usage:"
echo ""
echo "lemptool [--option1 --option2 -y ...] [--param1=value1_2 value2_2 --param2=value2_1 ...]"
echo ""
echo "Option arguments are value less, instead with param arguments you can pass"
echo "string values after the (=) sing."
echo ""
echo "Arguments:"
echo ""
echo " -i, --install Proceed to setup repo and install:"
echo " nginx + php + mariadb + extra-laravel-development"
echo " deb packages. "
echo ""
echo " -y You can pass this option to skip all the confirmation"
echo " messages, is valid for all th below commands/options"
echo " -pki= --package-install= Installs os packages."
echo " Usage example: "
echo " $ ./lemptool -pki=htop nodejs git"
echo ""
echo " -ng --nginx-install Installs Nginx server."
echo ""
echo " -mdb --mariadb-install Installs Mariadb version 10.6."
echo ""
echo " --mariadb-user-db-create Creates a new Mariadb user and a new db with the same"
echo " name as user, also grant all rights to that user on"
echo " the newly created database."
echo " It needs a user and a password as parameters."
echo " Usage example:"
echo " $ ./lemptool --mariadb-user-db-create=user password host"
echo ""
echo " --mariadb-superuser-create Creates a new Mariadb superuser. and gran all rights"
echo " Usage example:"
echo " $ ./lemptool --mariadb-superuser-create=user password host"
echo ""
echo " -p= --php-install= Installs a php version on system together with "
echo " dependencies for laravel development,it also"
echo " installs composer."
echo " When used the php version must be passed"
echo " as param value."
echo " Usage example:"
echo " $ ./lemptool -p=8.0"
echo ""
echo " -fpm= --php-fpm-create= Creates a new php fpm pool, using a template,"
echo " it need a valid os user name as a param value."
echo " Usage example: "
echo " $ ./lemptool -fpm=myusername"
echo ""
echo " --fpm-ng-server-create Creates a new (laravel in mind), nginx server unit"
echo " together with a existing valid fpm pool, a domain"
echo " and local public files path to serve as params."
echo " Usage example:"
echo ' $ ./lemptool --fpm-ng-server-create="fpm-name" "domain" "/public/path"'
echo ""
echo " -lemp It takes a OS user create a folder at /var/www/ with the name of "
echo " that user, it solflink it from user home folder and create and"
echo " runs --fpm-ng-server-create and --mariadb-user-db-create"
echo " Usage example:"
echo ' $ ./lemptool lemp="username" "domain" "dbpassword"'
echo ""
echo " --phpmyadmin-install Installs phpmyadmin from official source."
echo " It does so using fpm, so it create a php-fpm with"
echo " a os 'phpmyadmin' user, also it create an nginx server "
echo ""
return 0
}
#-------------------Arguments Handling-----------------------------------------#
clear_state() {
CURRENT_SCRIPT=""
SCRIPT_ARGUMENTS=""
}
run_current_script(){
# echo "script to run"
# echo "$CURRENT_SCRIPT"
# echo "arguments"
# echo "$SCRIPT_ARGUMENTS"
show_confirmations=1
for i in $SCRIPT_ARGUMENTS; do
if [ $i == "-y" ];then
show_confirmations=0
fi
done
str="$SCRIPT_ARGUMENTS"
oldstr=" -y"
newstr=" "
_y_replaced=$(echo $str | sed "s/$oldstr/$newstr/g")
str="$_y_replaced"
oldstr="-y "
y__replaced=$(echo $str | sed "s/$oldstr/$newstr/g")
SCRIPT_ARGUMENTS_NO_Y=$y__replaced
if ! $CURRENT_SCRIPT $SCRIPT_ARGUMENTS_NO_Y ; then
echo "Error running script $CURRENT_SCRIPT"
echo ""
show_help
fi
}
add_argument(){
SCRIPT_ARGUMENTS="$SCRIPT_ARGUMENTS $1"
}
add_script() {
if [ -n "$CURRENT_SCRIPT" ]; then
run_current_script
SCRIPT_ARGUMENTS=""
fi
CURRENT_SCRIPT="$1"
}
if [ -z "$*" ]; then
echo "No arguments, you must pass at least one option or param"
show_help
fi
clear_state
for i in "$@"; do
case $i in
-help | --help)
clear_state
show_help
exit $?
shift # past argument=value
;;
-i* | --install*)
show_confirmations=0
install_mariadb
install_nginx
install_php 8.1
shift # past arg
;;
-pki=* | --package-install=*)
add_script "packages_installer"
add_argument "${i#*=}"
shift # past arg
;;
-ng* | --nginx-install*)
add_script "install_nginx"
add_argument "${i#*=}"
shift # past arg
;;
-mdb* | --mariadb-install*)
add_script "install_mariadb"
#add_argument "${i#*=}"
shift # past arg
;;
--mariadb-user-db-create=*)
add_script "add_mdb_user_with_db"
add_argument "${i#*=}"
shift # past arg
;;
--mariadb-superuser-create=*)
add_script "add_mdb_superuser"
add_argument "${i#*=}"
shift # past arg
;;
-p=* | --php-install=*)
add_script "install_php"
add_argument "${i#*=}"
shift # past arg
;;
-fpm=* | --fpm-create=*)
add_script "fpm_create"
add_argument "${i#*=}"
shift # past arg
;;
--fpm-ng-server-create=*)
add_script "fpm_ng_server_create"
add_argument "${i#*=}"
shift # past arg
;;
-lemp=*)
add_script "lemp_create"
add_argument "${i#*=}"
shift # past arg
;;
--phpmyadmin-install*)
install_phpmyadmin
shift # past arg
;;
*)
add_argument "${i#*}"
;;
esac
done
run_current_script