-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmymenu
executable file
·317 lines (298 loc) · 7.02 KB
/
mymenu
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
# if 'brew doctor' returns non-zero you fucked up
# if brew doctor >dev/null; then
# echo command went succesfully, no faults found!
# else
# echo Brew pkg's not installed properly!
# fi
# dpkg -V = verify
# Nu pacman nog...
# sudo pacman -Qkk | tee /tmp/tempfile | grep -v '0 altered files'
# We're only interested in files being changed.
##########################
# #
# Article I: Definitions #
# #
##########################
# Search for package manager and store in variable
if [[ -f /usr/bin/pacman ]] ; then
echo Pacman found!
pkgmgr="pacman"
pkgupd="pacman -Syy"
pkgupg="pacman -Suy"
pkgins="pacman -Sy "
###########################################
# #
# Start sorting different pacman distro's #
# #
###########################################
elif [[ -f /usr/bin/apt ]]; then
pkgmgr="apt"
pkgupd="apt update"
pkgupg="apt upgrade -y"
pkgins="apt install -y"
repodir="/etc/apt"
repolist="/etc/apt/sources.list"
custrepodir="/etc/apt/sources.list.d"
elif [[ -f /usr/bin/brew ]]; then
pkgmgr="brew"
pkgupd="brew update"
pkgupg="brew upgrade"
pkgins="brew install"
elif [[ -f /usr/bin/yum ]]; then
pkgmgr="yum"
pkgupd="yum update"
# pkgupg="yum upgrade" #Don't know if this is correct?
pkgins="yum install"
else
echo Package manager not found!
echo Some features of this program will not work.
echo
fi
##################################
# #
# Build a menu building function #
# #
##################################
function buildmenu () {
echo \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
N=0
for i in "$@"
do
N=$(expr $N + 1)
echo Option $N is: $i
done
echo \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
echo
echo Please select your choice:
}
##########################
# #
# Define our main menu. #
# #
##########################
function mainmenu () {
while true
do
# PS3="Please choose an option "
# Populate it with options, maybe we should write something to dynamically edit these options.
buildmenu "Network settings" "System settings" "Recovery settings" "User settings" Quit
read optMain
case $optMain in
1)
networkmenu ;;
2)
systemmenu ;;
3)
recoverymenu ;;
3)
usermenu ;;
4)
exit 0
esac
done
}
#########################
# #
# Define our submenu's. #
# #
#########################
function networkmenu () {
# Setup menu options for Network
while true
do
buildmenu IPtables "Add virtualhost" "Back to main menu"
read optNet
case $optNet in
1)
iptablesmenu ;;
2)
virthostmenu ;;
3)
mainmenu ;;
esac
done
}
function systemmenu () {
while true
do
# Setup menu options for System
buildmenu "View crontab" "Update system" "Reset/repair pacman" "Add executable as service" "Back to main menu"
read optSystem
case $optSystem in
1)
echo Who are you interested in viewing the cron?
read cronuser
bash modules/viewcron.sh -u $cronuser
;;
2)
echo Updating repositories....
$pkgupd
echo Starting full system upgrade....
$pkgupg
;;
3)
echo Checking internal package manager database...
;;
4)
echo Please enter the full path of the executable to be turned into a service.
read file
bash modules/makeservice.sh $file
;;
5)
mainmenu
;;
esac
done
}
function recoverymenu () {
while true
do
buildmenu "Reset/repair package repositories" "Check integrity of installed packages" "Back to main menu"
read optRecovery
case $optRecovery in
1)
repodir="/etc/apt"
custrepodir="/etc/apt/sources.list.d"
;;
2)
:
;;
3)
mainmenu
;;
esac
done
}
function usermenu () {
while true
do
buildmenu "view path" "View homefolder space" "Main menu"
read optUser
case $optUser in # Maak eerst een variabel aan voordat je hem probeert uit te lezen -_-
1)
echo Your current path is: $PATH ;;
2)
echo Your homefolder is $(du -hd 1 ~ | tail -n 1 | cut -f 1) big. ;;
3)
mainmenu ;;
esac
done
}
function iptablesmenu () {
while true
do
buildmenu "List IPtables chains" "Forward a port on the local system" "Main menu"
read optIptables
case $optIptables in
1)
echo The current IPtables chains are:
iptables -L | grep -i chains
;;
2)
echo Please provide external port nr:
read extport
echo External port set to $extport.
echo Please provide internal port nr:
read intport
echo Internal port set to $intport
# echo Please provide internal IP address to forward to:
# read destIP
# TODO: actually make it do something.
# iptables -A INPUT -p any :D :D :D
;;
3)
mainmenu
;;
esac
done
}
function virthostmenu () {
while true
do
buildmenu "Add virtualhost to Apache" "Add virtualhost to nginx" "Back to main menu"
read optVirthost
case $optVirthost in
1)
read "Enter desired FQDN hostname: " hostname
read -p "Enable localhost redirection [Y/N]?" optLocalhost
case $optLocalhost in
Y|y)
read -p "Port: " port
read -p "Obtain SSL cert using Certbot? [Y/N]" ssl
case $ssl in
Y|y)
modules/addvirthost -a -h $hostname -l $port -s
;;
N|n)
modules/addvirthost -a -h $hostname -l $port
;;
*)
echo Invalid option!
virthostmenu
;;
esac
;;
N|n)
read -p "Where are the files stored?" webdir
read -p "Obtain SSL cert using Certbot? [Y/N]" ssl
case $ssl in
Y|y)
modules/addvirthost -a -h $hostname -d $webdir -s
;;
N|n)
modules/addvirthost -a -h $hostname -d $webdir
;;
*)
echo Invalid option!
virthostmenu
;;
esac
esac
;;
2)
read "Enter desired FQDN hostname: " hostname
read -p "Enable localhost redirection [Y/N]?" optLocalhost
case $optLocalhost in
Y|y)
read -p "Port: " port
read -p "Obtain SSL cert using Certbot? [Y/N]" ssl
case $ssl in
Y|y)
modules/addvirthost -n -h $hostname -l $port -s
;;
N|n)
modules/addvirthost -n -h $hostname -l $port
;;
*)
echo Invalid option!
virthostmenu
;;
esac
;;
N|n)
read -p "Where are the files stored?" webdir
read -p "Obtain SSL cert using Certbot? [Y/N]" ssl
case $ssl in
Y|y)
modules/addvirthost -n -h $hostname -d $webdir -s
;;
N|n)
modules/addvirthost -n -h $hostname -d $webdir
;;
*)
echo Invalid option!
virthostmenu
;;
esac
esac
;;
3)
mainmenu
;;
esac
done
}
# We should find out which package manager the user is using.
# First let's start with apt because apt
mainmenu