aboutsummaryrefslogtreecommitdiff
blob: fcc02c08ec3312daea39ece1518f8898080cfd4c (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
#!/usr/bin/env python3.6

def _call_main():
	# Essential libraries
	import os, sys
	from os import system, getcwd
	from sys import argv, exit

	# Export current working category
	CWORKDIR = getcwd()

	if CWORKDIR in '/usr/bin' and os.path.isfile('/usr/lib64/gse/gse'):
		# If the project has been installed to root
		#prnt("system") # Exists only: for testing
		CWORKDIR = '/usr/lib64/gse'
		CGSE = CWORKDIR + '/gse.py'
		CCONFDIR = CWORKDIR + '/config.d'
		CDISTDIR = '/var/tmp/gse/dist.d'
		CLOCALLG = CWORKDIR + '/local'
		CLOGLG = '/var/log/gse'
		CSYSROOT = '/home/gse'
		CLOCALLIB = '/var/lib/gse'
		CFUNCTIONS = CWORKDIR + 'scripts/pyfunctions'

	elif os.path.isdir(os.path.dirname(CWORKDIR)+'/.git'):
		# If the project has been git cloned or simply copied to a location
		CWORKDIR = os.path.dirname(CWORKDIR)
		#print(CWORKDIR) # Exists only: for testing
		CFUNCTIONS = CWORKDIR+'/scripts/pyfunctions'
		CCONFDIR = CWORKDIR+'/config.d'
		CDISTDIR = CWORKDIR+'/dist.d'
		CLOCALLG = CWORKDIR+'/local'
		CLOGLG = CWORKDIR+'/var/log'
		CSYSROOT = CWORKDIR+'/sysroot'
		CLOCALLIB = CWORKDIR+'/var/lib'


	# Append new python path at CWORKDIR + /scripts/pyfunctions
	sys.path.append(CFUNCTIONS)


	# Simplle die function
	from gseout import die

	# Import yellow, green, blue and purple color reports
	from gseout import e_report, g_report, b_report, p_report

	# Cmdline argument's function
	def gse_args():
		if 'system' in argv[1:2]:
			sequence = "system"
		elif 'controller' in argv[1:2]:
			sequence = "controller"
		elif '-h' in argv[1:2] or '--help' in argv[1:2]:
			sequence = "target"
		else:
			sequence = "err"

		# Check if base and controller are issues at the same time. If yes, exit with error
		if sequence in 'system' or sequence in 'controller':
			if any('system' in item1 for item1 in argv[1:]) and any ("controller" in item2 for item2 in argv[1:]):
				die("Error: System and Controller arguments can not be issued at the same time. " +
					"Only one operating at a given time can be supported.")

		if sequence == "system":
			# Export arguments for system sequence
			from arg_opt import _export_args

			b_report("System sequence enabled")
			args = _export_args(sequence)

			del _export_args

			from arg_opt import _check_args
			_check_args(args)

			del _check_args


		elif sequence == 'controller':
			# Export arguments for controller sequence
			from arg_opt import _export_args

			b_report("Controller sequence enabled")
			args = _export_args(sequence)

			del _export_args

			from arg_opt import _ct_check_args
			_ct_check_args(args)

			del _ct_check_args

		elif sequence == 'target':
			from arg_opt import _export_args

			args = _export_args(sequence)
		elif sequence == "err":	
			e_report("You must specify exactly one of: 'system' or 'controller' targets as the first argument")
			e_report("See gse -h or gse 5 for more info and gse 1 for options manpage")
			die('')


		return args, sequence


	# Import the returned arguments
	args, sequence = gse_args()

	del gse_args

	# Import dist check function
	from preliminary import _is_gentoo

	# Check the output. In case of a fail, issue warning and abort
	if _is_gentoo() == 0:
		pass
	else:
		if args.dev == 0:
			e_report("Dev is enabled: Ignoring dist check fail")
		else:
			e_report("The building process has been developed for Gentoo Linux.")
			e_report("If you have a compatible system and you wish to run your scripts AT YOUR OWN RISK, ")
			e_report("then edit " + CWORKDIR + "/bin/gse.py, and remove the die entry from if _is_gentoo statement.")
			die("Aborting")

	# Clear check function
	del _is_gentoo

	# Import super user check function
	from preliminary import _is_su

	# Pass if super user, issue warning if not and abort
	if _is_su() == 0:
		e_report("Super user privileges found. Proceeding.")
	else:
		if args.dev == True:
			e_report("Dev is enabled: Ignoring su fail")
		else:
			die("No super user privileges found. Can not continue.")


	del _is_su

	# If args.mm, initiate text menu
	if args.mm:
		from preliminary import _call_menu
		_ex_stat = _call_menu(CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR)
		
		del _call_menu

	# if args.gmm, initiate gui menu
	if args.gmm:
		from gportal import _gmm
		_ex_stat = _gmm()

		del _gmm

	return _ex_stat

# Main function
if __name__ == "__main__":
	_ex_stat = _call_main()
	
	if _ex_stat == 0:
		print("Success")
		exit(0)
	else:
		print("Fail")
		exit(1)