aboutsummaryrefslogtreecommitdiff
blob: fb239b0916d6059fd71a3f58ce90ab2641da1da6 (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
#!/bin/bash

#
# THE MAIN CHROOT SCRIPT.
# ALL CONFIGURATIONS HAPPEN HERE OR ARE SOURCED FROM HERE
# PLEASE DO NOT MODIFY THIS FILE, BUT REFEREE AT CONFIGURATION SUBMENU
# IF YOU NEED TO ADD EXTRA FEATURES TO YOUR SYSTEM.
# 

if echo "${_flag_tty}" | grep -q 'sshd'; then
	LC_COLLATE="C"
	LC_ALL="en_US.UTF-8"
	LC_CTYPE="en_US.UTF-8"
fi

#trap ask_for_shell SIGINT

# ENVIROMENTAL ECHO FOR TESTING PHASE
echo "$@"

if echo "$@" | grep -q '_flag_verbose'; then
	set -x
fi

if echo "$@" | grep -q '_flag_chroot_silence'; then
	_chroot_silence='>/dev/null 2>&1'
else
	_chroot_silence=''
fi

# EXPORT IMPORTANT VARIABLES BEFORE GOING ON
source /etc/profile && export PS1="( 'Part C: Preparing to bootstrap' ) $PS1"
export CHDIR="/sinit.d"
export PATH=${PATH}:${CHDIR}
source "${CHDIR}/chinit.conf" \
&& source "${CHDIR}/cfunctions" && source "${CHDIR}/coptions"|| die "Failed"
[[ ! -e "${CHDIR}/emergeresume" ]] && echo "#####" >> "${CHDIR}/emergeresume" \
|| sed -i "/#####/d" "${CHDIR}/emergeresume"

# CHECK POSITIONAL PARAMETERS
inspector "$@"

# EXPORT ENFORCE SAVED ARGS
if [[ -e "${CHDIR}/array_args/enforce_args" ]]; then
	_enforce_args=()
	while read -r s; do
		_enforce_args+=("${s}")
	done < <(cat "${CHDIR}/array_args/enforce_args")
fi

# EXPORT LAWFUL SAVED ARGS
if [[ -e "${CHDIR}/array_args/lawful_args" ]]; then
	_lawful_args=()
	while read -r s; do
		_lawful_args+=("${s}")
	done < <(cat "${CHDIR}/array_args/lawful_args")
fi

# PART C BEGINS
_do_hs '\-gupdate' "before" "Part: Portage Update"
if _call_hook_points 'UPDATE' 'gupdate' 'Part: Portage Update' '_part_c' "$@"; then
	_monitor_chroot_flow "UPDATE"
else
	die "Part: Update Failed"
fi
_do_hs '\+gupdate' "after" "Part: Portage Update"

# PART PORTAGE, PROFILE AND FEATURES UPDATE
_do_hs '\-gportage' "before" "Part: Portage"
if _call_hook_points 'PORTAGE' 'gportage' 'Part: Portage' 'part_portage' "$@"; then
	_monitor_chroot_flow "PORTAGE"
else
	die "Part: Portage FAILED"
fi
_do_hs '\+gportage' "after" "Part: Portage"

# Part D Begins
_do_hs '\-grebuild' "before" "Part: System Rebuild"
_sreb() {
	echo -e "\e[35mPart D: Rebuilding system\e[0m"
	env-update > /dev/null 2>&1 && source /etc/profile && export PS1="( 'Part D: Rebuilding system' ) $PS1"
	export PATH=${PATH}:${CHDIR}
	build_the_world
	_monitor_chroot_flow "REBUILD"
}

if ! [[ "${_flag_auto}" ]]; then
	if echo "${_lawful_args[@]}" | grep -q 'grebuild'; then
		_e_report_back "Rebuild: Lawful entry detected, proceeding..."
	else
		if [[ "$(awk -F '=' '/REBUILD/{ print $2 }' <"${CHDIR}/chsinprog")" == 0 || -n "${_flag_force_new}" ]] || echo "${_enforce_args[@]}" | grep -q 'grebuild'; then
			if echo "${_enforce_args[@]}" | grep -q 'grebuild'; then
				_e_report_back "System Rebuild: Force entry detected, forcing..."
			fi
				_sreb
		fi
	fi
fi
_do_hs '\+grebuild' "after" "Part: System Rebuild"

# PART E BEGINS
_do_hs '\-gconfigure' "before" "Part: System Configuration"
if _call_hook_points 'CONFIGURE' 'gconfigure' 'Part: System Configuration' 'configure_system_f' "$@"; then
	_monitor_chroot_flow "CONFIGURE"
else
	die "Part: System Configuration FAILED"
fi
_do_hs '\+gconfigure' "after" "Part: System Configuration"

# PART F BEGINS
_do_hs '\-ginst' "before" "Part: Emerge requested packages"
if _call_hook_points 'INSTALL' 'ginst' 'Part: Emerge requested packages' 'emerge_requested' "$@"; then
	_monitor_chroot_flow "INSTALL"
else
	die "Part: Emerge Requested Packages FAILED"
fi
unset YN
_do_hs '\+ginst' "after" "Part: Emerge requested packages"

# PART G BEGINS
_do_hs '\-grun' "before" "Part: Runlevel Configurations"
if _call_hook_points 'RUNLEVEL' 'grun' 'Part: Runlevel Configurations' '_runlevel_configuration' "$@"; then
	_monitor_chroot_flow "RUNLEVEL"
else
	die "Part: Runlevel Configurations FAILED"
fi
unset YN
_do_hs '\+grun' "after" "Part: Runlevel Configurations"

# PART H BEGINS
_do_hs '\-gkernel' "before" "Part: Kernel build"
if [[ -n "${_flag_kernel}" ]] || [[ -n "${_flag_minimal}" ]]; then
	:
else
	if _call_hook_points 'KERNEL' 'gkernel' 'Part: Kernel build' '_kernel_build'; then
		_monitor_chroot_flow "KERNEL"
	else
		die "Part: Kernel build FAILED"
	fi
	unset YN
fi
_do_hs '\+gkernel' "after" "Part: Kernel build"

# PART I BEGINS
_do_hs '\-ginitrd' "before" "Part: Initramfs build"
if [[ -n "${_flag_kernel}" ]] || [[ -n "${_flag_minimal}" ]] || [[ -n "${_flag_initrd}" ]]; then
	:
else
	if _call_hook_points 'INITRAMFS' 'ginitrd' 'Part: Initramfs build' '_initramfs_builder'; then
		_monitor_chroot_flow "INITRAMFS"
	else
		die "Part: Initramfs build FAILED"
	fi
	unset YN
fi
_do_hs '\+ginitrd' "after" "Part: Initramfs build"

# PART DESELECT BEGINS
_do_hs '\-gdes' "before" "Part: Deselect packages"
if _call_hook_points 'DESP' 'gdes' 'Part: Deselect packages' '_des_c' "$@"; then
	_monitor_chroot_flow "DESP"
else
	die "Part: Deselect packages FAILED"
fi
unset YN
_do_hs '\+gdes' "after" "Part: Deselect packages"

# Creating user-data dir-tree
mkdir -p /user-data/persistent/{etc,var,logs,config.d,local,rmount}
mkdir -p /user-data/persistent/local/{data,home,root,mnt,media}
mkdir -p /user-data/tmpfs/{tmp,etc,run,opt,var}