aboutsummaryrefslogtreecommitdiff
path: root/bin/gse
blob: 28fe34bb1c5402b4b0f5dedc5aba501e56e1a774 (plain)
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#!/bin/bash

##																						     ##
#																						      #
# Gentoo Stateless Environment project													      #
#																						      #
# Everything inside this directory has been created during Gentoo-soc 2017 and is distributed #
# under General Public License version 2.												      #
#																						      #
##																						     ##

LC_COLLATE=C


# DEFINITION OF WORKDIR AND IT'S SUBDIRECTORIES
export WORKDIR="$(dirname ${PWD})"
export CONFDIR="${WORKDIR}/config.d"
export DISTDIR="${WORKDIR}/dist.d"
export LOCALLG="${WORKDIR}/local"

# PATH DEFINITION FOR THE SCRIPTS WHICH WILL AID THE PROCESS
export PATH=${PATH}:${WORKDIR}/scripts/functions

STAT_VAR=''

set -o

# CHECK IF BASH IS THE DEFAULT {CURRENT} SHELL, ISSUE A WARNING OTHERIWSE
shl_f() {
	SHL=$SHELL
	ISITBASH=$(echo "${SHL}" |  awk -F "bin/" '{ print $2}')
	if [[ ${ISITBASH} != "bash" ]]; then
		echo "Seems like you are not using bash"
		echo "Keep in mind that all scripts from this project are written for bash interpretation"
		while true; do
			read -p "Do you want to continue?: " S
			case ${S} in
				[Yy][eE][sS]|[yY]) clear; break;;
				[Nn][oO]|[nN]) echo "Exiting..."; exit;;
				* ) echo  "Select Y/N";;
			esac
		done
	fi
}

# ROOT CHECK FUNCTION, IS NEEDED FOR THE CATALYST AND CHROOT PROCESS
amiroot() {
	if [[ "$1" != "0" ]]
	then
		echo "This operation requires root privileges"
		echo "Returning back..."
		sleep 2
		BACKTO="MM"
	fi
}

# MAIN MENU FUNCTION
main_f() {
	while true; do
		clear; men_opt 1
		read -p "Please select an option: " SELCT
		case ${SELCT:-6} in
			I|i|1|-I|-i|-1)
				# CALL BUILDER SUBMENU
				bs_menu_f; break;;
			II|ii|2|-II|-ii|-2)
				# CALL CONTROLLER SUBMENU
				con_f; break;;
	 		III|iii|3|-III|-iii|-3)
				# CALL DOCUMENTATION SUBMENU
				doc_f; break;;
			IV|iv|4|-IV|-iv|-4)
				# CALL ABOUT SUBMENU
				about_f; break;;
			V|v|5|-V|-v|-5[Qq][uU][iI][tT]|[Ee][Xx][Ii][tT]|[qQ])
 				echo -e "\e[32mExiting\e[39m..."; BACKTO="Q";;
 			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="MM" 
  				clear; break;;
			* ) clear; men_opt 1;;
		esac
	done
}

# BUILDER SUBMENU
bs_menu_f() {
	clear; men_opt 5
	while true; do
		read -p "Select an option: " SELCT
		case ${SELCT:-4} in
			I|i|1|-I|-i|-1)
				# CALL BUILD SYSTEM SUBMENU
				clear; bs_f
				break;;
			II|ii|2|-II|-ii|-2)
				# CALL CONFIGURATION SUBMENU
				clear; config_f
				break;;
			III|iii|3|-III|-iii|-3)
				# CALL SELECT DEFAULT SYSTEM SUBMENU
				clear; selectdef_f
				break;;
			IV|iv|4|-IV|-iv|-4)
				# TBU: WILL INCLUDE A STAGE4 TARBALL CREATION
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="BSM";
				break;;
			V|v|5)
				clear; BACKTO="MM"; break;;
			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="BSM";
  				clear; break;;
			* ) clear; men_opt 5;;
		esac
	done
}

# BUILD SYSTEM SUBMENU
bs_f() {
clear; men_opt 6
	while true; do
		read -p "Select an option: " SELCT
		case ${SELCT:-3} in
			I|i|1|-I|-i|-1)
				# CALL PORTAGE SUBMENU
				portage_men_f
				break;;
			II|ii|2|-II|-ii|-2)
				# CALL CATALYST SUBMENU
				catalyst_f
				break;;
			III|iii|3|-III|-iii|-3)
				# START LOCAL BUILD
				clear; source "${WORKDIR}/scripts/sinit" "no_seed" "localrb"
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="SM";
				break;;
			IV|iv|4|-IV|-iv|-4)
				# START PRE PRECOMPILED
				clear; source "${WORKDIR}/scripts/sinit" "seed" "precomp"
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="SM";
				break;;
			V|v|5|-V|-v|-5)
				clear; BACKTO="BSM"; break;;
			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="SM";
  				clear; break;;
			* ) clear; men_opt 6;;
		esac
	done
}

# PORTAGE SUBMENU
portage_men_f() {
	clear; men_opt 7
	while true; do
		read -p "Select an option: " SELCT
		case ${SELCT:-5} in
			I|i|1|-I|-i|-1)
				# MAKE MAKE.CONF: AUTOMATIC OR GUIDED CONFIGURATION
				makeconf_ed &&{ clear; echo -e "[\e[32m*\e[0m] Configurations was successful!"
				echo "Presh any key to return"; } || { cho -e "[\e[31m*\e[0m] Something went wrong"; }
				read -r 1>&-; BACKTO="PORT_M"; break;;
			II|ii|2|-II|-ii|-2)
				# MANUAL EDIT OF MAKE.CONF
				cp "${CONFDIR}/system/portage/makeconf.backup" "${CONFDIR}/system/portage/make.conf"
				vim "${CONFDIR}/system/portage/make.conf"
				clear; echo "Presh any key to return"
				read -r 1>&-; BACKTO="PORT_M"; break;;
			III|iii|3|-III|-iii|-3)
				# PREVIW OF MAKE.CONF: WILL BE REMOVED AS AN OPTION
				less "${CONFDIR}/system/portage/make.conf"
				clear; echo "Presh any key to return"
				read -r 1>&-; BACKTO="PORT_M"; break;;
			IV|iv|4|-IV|-iv|-4)
				# MANUAL EDIT OF USEFLAGS
				vim "${CONFDIR}/system/portage/package.use/sysbuild"
				clear; echo "Presh any key to return"
				read -r 1>&-; BACKTO="PORT_M"; break;;
			V|v|5|-V|-v|-5)
				# PREVIEW OF USEFLAGS: WILL BE REMOVED AS AN OPTION
				less "${CONFDIR}/system/portage/package.use/sysbuild"
				clear; echo "Presh any key to return"
				read -r 1>&-; BACKTO="PORT_M"; break;;
			VI|vi|6|-VI|-vi|-6)
				# REGENERATES MAKE.CONF TO DEFAULT
				cp "${CONFDIR}/system/portage/package.use/sysbuild.backup" "${CONFDIR}/system/portage/package.use/sysbuild"
				clear; echo "Presh any key to return"
				read -r 1>&-; BACKTO="PORT_M"; break;;
			VII|vii|7|-VII|-vii|-7)
				BACKTO="SM"; break;;
			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="PORT_M";
  				clear; break;;
			* ) clear; men_opt 7;;
		esac
	done
}

catalyst_f() {
	clear; men_opt 10
	while true; do
		read -p "Select an option: " SELCT
		case ${SELCT:-6} in
			I|i|1|-I|-i|-1)
				# CONFIGURE CATALYST.CONF
				vim "${CONFDIR}/system/catalyst/catalyst.conf"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CATA_M"; break;;
			II|ii|2|-II|-ii|-2)
				# CONFIGURE CATALYSTRC
				vim "${CONFDIR}/system/catalyst/catalystrc"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CATA_M"; break;;
			III|iii|3|-III|-iii|-3)
				# CONFIGURE STAGE1.SPEC
				vim "${CONFDIR}/system/catalyst/stage1.spec"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CATA_M"; break;;
			IV|iv|4|-IV|-iv|-4)
				# CONFIGURE STAGE2.SPEC
				vim "${CONFDIR}/system/catalyst/stage2.spec"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CATA_M"; break;;
			V|v|5|-V|-v|-5)
				# CONFIGURE STAGE3.SPEC
				vim "${CONFDIR}/system/catalyst/stage3.spec"
				clear; echo "Presh any key to return"
				read -r 1>&-; BACKTO="CATA_M"; break;;
			VI|vi|6|-VI|-vi|-6)
				# START MAIN BUILDER PROCESS
				clear; source "${WORKDIR}/scripts/sinit" "seed" "catalyst" "s1" "s2" "s3"
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="CATA_M";
				break;;
			VII|vii|7)
				BACKTO="SM"; break;;
			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="PORT_M";
  				clear; break;;
			* ) clear; men_opt 7;;
		esac
	done
}
# CONFIGURATION SUBMENU
config_f() {
	clear; men_opt 8
	while true; do
		read -p "Select an option: " SELCT
		case ${SELCT:-3} in
			I|i|1|-I|-i|-1)
				# GUIDED FSTAB EDITOR
				drv_interface
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			II|ii|2|-II|-ii|-2)
				# MANUAL FSTAB EDIT
				vim "${CONFDIR}/system/fstab"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			III|iii|3|-III|-iii|-3)
				# DEVICES FOR BOOT, SYSTEM, USERDATA: RELATED ONLY WITH THE HOSTS
				vim "${CONFDIR}/system/devname.info"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			IV|iv|4|-IV|-iv|-4)
				# HOSTNAME
				vim "${CONFDIR}/system/hostname"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			V|v|5|-V|-v|-5)
				# NETWORKING
				vim "${CONFDIR}/system/net"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			VI|vi|6|-VI|-vi|-6)
				# LOCALES
				vim "${CONFDIR}/system/locale.gen"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			VII|vii|7)
				# CONSOLEFONTS
				vim "${CONFDIR}/system/consolefont"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			VIII|viii|8)
				# SSHD CONFIGURATION FILE
				vim "${CONFDIR}/system/sshd"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			IX|ix|9)
				# SSH PUBLIC KEY: WILL BE INCLUDED ON THE HOSTS
				vim "${CONFDIR}/system/ssh.pub"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			X|x|10)
				# SETS SYMLINKS, BIND MOUNTS, TMPFS AND OVERLAYS
				vim "${CONFDIR}/system/system_links"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			XI|xi|11)
				# SETS CUSTOM USER SCRIPTS ON BOOTUP
				vim "${CONFDIR}/system/custom_scripts"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			XII|xii|12)
				# LIST FOR CUSTOM PACKAGES TO BE INSTALLED DURING THE PROCESS
				vim "${CONFDIR}/system/custom_pacl"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			XIII|xiii|13)
				# KERNEL COMAND LINE
				vim "${CONFDIR}/system/kernel-cmdl"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			XIV|xiv|14)
				# UPDATES RUNLEVEL ENTRIES
				vim "${CONFDIR}/system/runlevels"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			XV|xv|15)
				# INJECT CUSTOM FILES
				vim "${CONFDIR}/system/inject_files"
				clear; echo -e "[\e[32m*\e[0m] Presh any key to return"
				read -r 1>&-; BACKTO="CO_F"; break;;
			XVI|xvi|16)
				BACKTO="BSM"; break;;
			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="CO_F";
  				clear; break;;
			* ) clear; men_opt 8;;
		esac
	done
}

# SELECT DEFAULT SYSTEM MENU
selectdef_f() {
	#show list of local builds
	#add imput for setting default
		#will change the dist system-arch-version to system-arch-version-default
		#same for kernel-arch-version
	clear; men_opt 9
	while true; do
		read -p "Select an option: " SELCT
		case ${SELCT:-3} in
			I|i|1|-I|-i|-1)
				clear; echo "Documentations submenu option a)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="SELDEF"; break;;
			II|ii|2|-II|-ii|-2)
				clear; echo "Documentations submenu option b)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="SELDEF"; break;;
			III|iii|3|-III|-iii|-3)
				clear; BACKTO="BSM"; break;;
			[tT])
				clear; /bin/bash
				echo "Presh any key to return"
				read -r 1>&-;BACKTO="SELDEF";
  				clear; break;;
			* ) clear; men_opt 9;;
		esac
	done
}

# THE CONTROLLER MENU
con_f() {
	clear; amiroot "$UID"; echo "You selected: build the controller image"; echo
	source cinit.sh
	BACKTO="MM"
}

# DOCUMENTATIONS MENU
doc_f(){
	clear; echo "	      Documentations. Please enjoy yourself!"; echo
	men_opt 2
	while true; do
		read -p "Choose a document you wish to read: " SELCT
		case ${SELCT:-5} in
			I|i|1|-I|-i|-1)
				clear; echo "Documentations submenu option a)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="DOC"; break;;
			II|ii|2|-II|-ii|-2)
				clear; echo "Documentations submenu option b)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="DOC"; break;;
			III|iii|3|-III|-iii|-3)
				clear; echo "Documentations submenu option c)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="DOC"; break;;
			IV|iv|4|-IV|-iv|-4)
				clear; echo "Documentations submenu option d)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="DOC"; break;;
			V|v|5|-V|-v|-5)
				clear; echo "Documentations submenu option e)"
				BACKTO="MM"; break;;
			* ) clear; men_opt 2;;
		esac
	done
}

# ABOUT MENU
about_f() {
	clear; echo "		     Welcome to About Menu"; echo
	men_opt 3
	while true; do
		read -p "Choose a journey: " SELCT
		case ${SELCT:-4} in
			I|i|1|-I|-i|-1)
				clear; echo "About submenu option a)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="AB"; break;;
			II|ii|2|-II|-ii|-2)
				clear; echo "About submenu option b)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="AB"; break;;
			III|iii|3|-III|-iii|-3)
				clear; echo "About submenu option c)"
				echo "Presh any key to return"
				read -r 1>&-; BACKTO="AB"; break;;
			IV|iv|4|-IV|-iv|-4)
				clear; echo "About submenu option d)"
				BACKTO="MM"; break;;
			* ) clear; men_opt 3;;
		esac
	done
}

# MAIN LOOP FUNCTION
mainlp_f() {
BACKTO="MM"
while true; do
	case "${BACKTO:-MM}" in
		MM)
			# PULLS MAIN MENU FUNCTION
			main_f;;
		DOC)
			# PULLS DOCUMENTATION MENU FUNCTION
			doc_f;;
		AB)
			# PULLS ABOUT MENU FUNCTION
			about_f;;
		PORT_M)
			# PULLS PORTAGE SUBMENU FUNCTION
			portage_men_f;;
		CATA_M)
			catalyst_f;;
		SM)
			# PULLS BUILD SYSTEM SUBMENU: THIS IS A SUBMENU OF BULDERS MENU
			bs_f;;
		BSM)
			# PULLS BUILDER MENU
			bs_menu_f;;
		CO_F)
			# PULLS CONFIGURATION SUBMENU: SUBMENU OF BUILDERS MENU
			config_f;;
		SELDEF)
			# PULLS SELECT DEFAULT SYSTEM SUBMENU: SUBMENU OF BUILDERS MENU
			selectdef_f;;
		Q)
			exit 0;;
	esac
done
}

# STARTS MAIN LOOP FUNCTION
mainlp_f; unset BACKTO; exit 0