aboutsummaryrefslogtreecommitdiff
path: root/bin/gse
blob: be300d9a07dc3639e7328acb11e65a676de36ba0 (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
#!/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.												      #
#																						      #
##																						     ##

# DEFINITION OF CWORKDIR AND IT'S SUBDIRECTORIES
export CWORKDIR="$(dirname ${PWD})"
export CCONFDIR="${CWORKDIR}/config.d"
export CDISTDIR="${CWORKDIR}/dist.d"
export CLOCALLG="${CWORKDIR}/local"
export CSYSROOT="${CWORKDIR}/sysroot"
export CREL="$(grep ^NAME /etc/*release | awk -F '=' '{ print $2 }')"

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

source "${CWORKDIR}/scripts/functions/sinit_functions" || { echo -e "\e[31mMissing scripts\e[0m" && exit 1; }
source "${CWORKDIR}/scripts/functions/catalyst_functions" || { echo -e "\e[31mMissing scripts\e[0m" && exit 1; }
source "${CWORKDIR}/etc/gentoo.conf" || { echo -e "\e[31mMissing gentoo.conf\e[0m" && exit 1; }

# 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
}

subterm_f() {
	echo -e "\e[33mCalling bash subshell\e[0m"
	sleep 0.5
	echo 'echo -e "\e[33mInside Subshell\e[0m"' >> /root/.bashrc
	echo 'echo -e "\e[33mExit to return back to parent\e[0m"' >> /root/.bashrc
	(clear; exec /bin/bash "${lppar[@]}";)
	sed -i "/Inside Subshell/d" "/root/.bashrc"
	sed -i "/Exit to return back to parent/d" "/root/.bashrc"
	echo -e "\e[33mYou are back to parent\e[0m"
}

# MENU FUNCTION
_call_menu() {
	echo "${@}"
	unset _PARENT
	unset _CHILD
	unset _STAY
	echo "$_PARENT"
	echo "$_CHILD"
	echo "$_STAY"
	while true; do
		clear; men_opt "$1"
		eval "$4" #"${@:5}"

		if [[ "${_PARENT}" ]]; then
			BACKTO="$2"
			break
		elif [[ "${_CHILD}" ]]; then
			BACKTO="${_CHILD}"
			break
		elif [[ "${_STAY}" ]]; then
			BACKTO="$3"
			break
		fi
	done
	unset SELCT
}

# MAIN LOOP FUNCTION
mainlp_f() {
BACKTO="$1"
while true; do
	case "${BACKTO:-Q}" in
		MM 		)
			# PULLS MAIN MENU FUNCTION
			_call_menu "1" "Q" "MM" "main_f" "${lppar[@]}";;
		DOC 	)
			# PULLS DOCUMENTATION MENU FUNCTION
			_call_menu "2" "MM" "DOC" "doc_f";;
		AB 		)
			# PULLS ABOUT MENU FUNCTION
			_call_menu "3" "MM" "DOC" "about_f";;
		PORT_M 	)
			# PULLS PORTAGE SUBMENU FUNCTION
			_call_menu "7" "SM" "PORT_M" "portage_men_f" "${lppar[@]}";;
		CATA_M 	)
			_call_menu "10" "SM" "CATA_M" "catalyst_f" "${lppar[@]}";;
		SM 		)
			# PULLS BUILD SYSTEM SUBMENU: THIS IS A SUBMENU OF BULDERS MENU
			_call_menu "6" "BSM" "SM" "bs_f" "${lppar[@]}";;
		BSM 	)
			# PULLS BUILDER MENU
			_call_menu "5" "MM" "BSM" "bs_menu_f" "${lppar[@]}";;
		CO_F 	)
			# PULLS CONFIGURATION SUBMENU: SUBMENU OF BUILDERS MENU
			_call_menu "8" "BSM" "CO_F" "config_f" "${lppar[@]}";;
		SELDEF 	)
			# PULLS SELECT DEFAULT SYSTEM SUBMENU: SUBMENU OF BUILDERS MENU
			_call_menu "9" "BSM" "SELDEF" "selectdef_f" "${lppar[@]}";;
		GSET 	)
			# PULL GSE TOOLS SUBMENU
			_call_menu "11" "MM" "GSET" "gse_t" "${lppar[@]}";;
		CONTR 	)
			_call_menu '' "MM" "CONTR" "controller_f" "${lppar[@]}";;
		Q 		)
			# EXIT
			sleep 1
			break;;
	esac
done
}

if echo "$@" | grep -q '\--conf'; then	
	if [[ "$#" != 1 ]]; then
		die "--conf argument has been detected"
	fi

	if [[ "$1" != *'='* || "${1#*=}" == '' ]]; then
		die "No target file was given"
	fi

	if [[ ! -e "${1#*=}" ]]; then
		die "No such file or directory"
	fi

	if [[ -d "${1#*=}" ]]; then
		die "Target is a directory, aborting"
	fi

	if _ct_conf; then
		_make_cimage
	else
		die "Exporting arguments from the configuration file has failed"
	fi
elif echo "$@" | grep -q '\--build-controller'; then
	if _controller_args "${@:2}"; then
		_make_cimage "${@:2}"
	else
		die "Given controller arguments could not be exported"
	fi
else
	if echo "$@" | grep -q '\--time-warp' && [[ "$#" != 1 ]]; then
		die "Error: Time Warp must be the only entry"
	fi

	if echo "$@" | grep -q '\--edit' && [[ "$#" != 2 ]]; then
		die "Error: Edit must be the only entry"
	fi

	lppar=()
	for i in "$@"; do
		lppar+=("$i")
	done

	if [[ -z "$@" ]] || echo "$@" | grep -q '\-mm'; then
		mainlp_f "MM" "${lppar[@]}" && unset BACKTO && exit 0
	else
		warp "$@"
	fi
fi