summaryrefslogtreecommitdiff
path: root/libvasile
blob: 69337828765c46c4a1e61b7fa5e4f9c3394f2b4d (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
# generic arch independent functions (used for both build && iso creation)

kernelconfig () {
	if [[ $(zgrep 'CONFIG_OVERLAYFS_FS=' /proc/config.gz) && $(zgrep "CONFIG_SQUASHFS=" /proc/config.gz) &&  $(zgrep "CONFIG_BLK_DEV_LOOP=" /proc/config.gz) ]] ; then
		# if you use 3.18 LTS or newer kernels, change CONFIG_OVERLAYFS_FS to CONFIG_OVERLAY_FS
		echo ""
		echo "Kernel configuration seems OK, moving on"
		echo ""
		sleep 1
	else
		echo ""
		echo "Vasile needs OVERLAYFS && SQUASHFS && LOOP DEVICES to work"
		echo "Please rebuild the kernel with those activated to use it"
		echo ""
		exit 1
	fi
}

checkroot () {
	if [[ "$(whoami)" != root ]] ; then
		echo ""
		echo "You're not root?...No cookies for you, go away !!!"
		echo ""
		exit 1
	fi
}

# generic x64 functions (used for both build && iso creation)

chrootchecksumx64 () {
	while : true ; do
		if [[ -f "$chrootx64" && -f "$chrootx64md5" ]] ; then
			echo "good, x64 squashed chroot && checksum file found ... verifying integrity"
			echo ""
			if [[ "$(md5sum -c "$chrootx64md5")" ]] ; then
				echo "good, x64 squashed chroot checksum passed ... starting engines"
				echo ""
				sleep 1
				break
			else
				echo "ooops, x64 squashed chroot checksum failed ... aborting"
				exit 1
			fi
		else
			echo "ooops, x64 squashed chroot or checksum file not found ... aborting"
			exit 1
		fi
	done
}

chrootchecksumx86 () {
	while : true ; do
		if [[ -f "$chrootx86" && -f "$chrootx86md5" ]] ; then
			echo "good, x86 squashed chroot && checksum file found ... verifying integrity"
			echo ""
			if [[ "$(md5sum -c "$chrootx86md5")" ]] ; then
				echo "good, x86 squashed chroot checksum found ... starting engines"
				echo ""
				sleep 1
				break
			else
				echo "ooops, x86 squashed chroot checksum failed ... aborting"
				exit 1
			fi
		else
			echo "ooops, x86 squashed chroot or checksum file not found ... aborting"
			exit 1
		fi
	done
}

# arch independent build functions

chrootstop () {
	umount -l "$overlaydir"/proc > /dev/null 2>&1
	umount -l "$overlaydir"/sys > /dev/null 2>&1
	umount -l "$overlaydir"/dev/pts > /dev/null 2>&1
	umount -l "$overlaydir"/dev/shm > /dev/null 2>&1
	umount -l "$overlaydir"/dev > /dev/null 2>&1
	umount -l "$overlaydir"/tmp > /dev/null 2>&1
	umount -l "$overlaydir"/usr/portage > /dev/null 2>&1
	umount -l "$overlaydir"/mnt > /dev/null 2>&1
	umount -l "$overlaydir" > /dev/null 2>&1
	umount -l "$rodir" > /dev/null 2>&1
}

# x64 specific build functions

chrootstartx64 () {
	mount -t squashfs "$chrootx64" "$rodir"
	if [[ "$(uname -r | cut -d . -f1,2)" = "3.14" ]] ; then
		mount -t overlayfs -o lowerdir="$rodir",upperdir="$rwdir" overlayfs "$overlaydir"
	else # kernel version equal or above 3.18
		mount -t overlay -o lowerdir="$rodir",upperdir="$rwdir",workdir="$workdir" overlay "$overlaydir"
	fi
	mount -o bind portage "$overlaydir"/usr/portage
	mount -o bind targets "$overlaydir"/mnt
	mount -t proc proc "$overlaydir"/proc
	mount -t sysfs sysfs "$overlaydir"/sys
	mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$overlaydir"/dev
	mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$overlaydir"/dev/pts
	mount -t tmpfs -o nosuid,nodev none "$overlaydir"/dev/shm
	mount -t tmpfs -o nosuid,nodev,noexec none  "$overlaydir"/tmp
}

chrootoverlaysx64 () {
	echo "injecting "$releasename" "$releasetarget" overlay into x64 environment"
	sleep 1
	chroot "$overlaydir" su - "$chrootuser" -c "$chrootmainoverlay"
}

chrootbuildsystemx64 () {
	echo "injecting "$releasename" x64 buildsystem && setting up portage"
	echo ""
	sleep 1
	for cmd in "$chrootbuildgit" "$chrootportageconfig" "$chrootmakeconfx64" "$chrootprofile" "$chrootenvupdate" ; do
		chroot "$overlaydir" su - "$chrootuser" -c "$cmd"
	done
}

chrootbuildx64 () {
	echo ""
	echo "x64 Environment is up && running ... building targets"
	sleep 1
	chroot "$overlaydir" su - "$chrootuser" -c "$chrootbuildtarget"
}

chrootx64 () {
	echo -e ""
	echo -e "#################################################################"
	echo -e "#       ENTERING CHROOT ENV FOR YOU TO PUSH BUILT PACKAGES      #"
	echo -e "#               OR TO FIX EVENTUAL BUILD ERRORS                 #"
	echo -e "#################################################################"
	echo -e "#            !!! WARNING !!! WARNING !!! WARNING !!!            #"
	echo -e "#################################################################"
	echo -e "#       NEXT RUN OF THIS SCRIPT WILL DESTROY ALL YOUR WORK      #"
	echo -e "#   DO NOT EXIT CHROOT UNTIL ALL PACKAGES ARE PUSHED TO REPOS   #"
	echo -e "#  OR, IN CASE OF BUILD FAILURES, UNTIL ALL FIXES ARE COMMITED  #"
	echo -e "#################################################################"
	echo -e "#            !!! WARNING !!! WARNING !!! WARNING !!!            #"
	echo -e "#################################################################"
	echo -e ""
	echo -e ""
	chroot "$overlaydir" su - "$chrootuser"
}

# x86 specific build functions

chrootstartx86 () {
	mount -t squashfs "$chrootx86" "$rodir"
	if [[ "$(uname -r | cut -d . -f1,2)" = "3.14" ]] ; then
		mount -t overlayfs -o lowerdir="$rodir",upperdir="$rwdir" overlayfs "$overlaydir"
	else # kernel version equal or above 3.18
		mount -t overlay -o lowerdir="$rodir",upperdir="$rwdir",workdir="$workdir" overlay "$overlaydir"
	fi
	mount -o bind portage "$overlaydir"/usr/portage
	mount -o bind targets "$overlaydir"/mnt
	mount -t proc proc "$overlaydir"/proc
	mount -t sysfs sysfs "$overlaydir"/sys
	mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$overlaydir"/dev
	mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$overlaydir"/dev/pts
	mount -t tmpfs -o nosuid,nodev none "$overlaydir"/dev/shm
	mount -t tmpfs -o nosuid,nodev,noexec none  "$overlaydir"/tmp
}

chrootoverlaysx86 () {
	echo "injecting "$releasename" "$releasetarget" overlay into x86 environment"
	sleep 1
	linux32 chroot "$overlaydir" su - "$chrootuser" -c "$chrootmainoverlay"
}

chrootbuildsystemx86 () {
	echo "injecting "$releasename" x86 buildsystem && setting up portage"
	echo ""
	sleep 1
	for cmd in "$chrootbuildgit" "$chrootportageconfig" "$chrootmakeconfx86" "$chrootprofile" "$chrootenvupdate" ; do
		linux32 chroot "$overlaydir" su - "$chrootuser" -c "$cmd"
	done
}

chrootbuildx86 () {
	echo ""
	echo "x86 environment is up && running ... building targets"
	sleep 1
	chroot "$overlaydir" su - "$chrootuser" -c "$chrootbuildtarget"
}

chrootx86 () {
	echo -e ""
	echo -e "#################################################################"
	echo -e "#       ENTERING CHROOT ENV FOR YOU TO PUSH BUILT PACKAGES      #"
	echo -e "#               OR TO FIX EVENTUAL BUILD ERRORS                 #"
	echo -e "#################################################################"
	echo -e "#            !!! WARNING !!! WARNING !!! WARNING !!!            #"
	echo -e "#################################################################"
	echo -e "#       NEXT RUN OF THIS SCRIPT WILL DESTROY ALL YOUR WORK      #"
	echo -e "#   DO NOT EXIT CHROOT UNTIL ALL PACKAGES ARE PUSHED TO REPOS   #"
	echo -e "#  OR, IN CASE OF BUILD FAILURES, UNTIL ALL FIXES ARE COMMITED  #"
	echo -e "#################################################################"
	echo -e "#            !!! WARNING !!! WARNING !!! WARNING !!!            #"
	echo -e "#################################################################"
	echo -e ""
	echo -e ""
	linux32 chroot "$overlaydir" su - "$chrootuser"
}

# x64 specific iso functions

isostartx64 () {
	mount -o bind packages "$isosyncdirx64"/usr/portage/packages
	mount -o bind targets "$isosyncdirx64"/mnt
	mount -t proc proc "$isosyncdirx64"/proc
	mount -t sysfs sysfs "$isosyncdirx64"/sys
	mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$isosyncdirx64"/dev
	mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$isosyncdirx64"/dev/pts
	mount -t tmpfs -o nosuid,nodev none "$isosyncdirx64"/dev/shm
	mount -t tmpfs -o nosuid,nodev,noexec none  "$isosyncdirx64"/tmp
}

isostopx64 () {
	umount -l "$isosyncdirx64"/proc > /dev/null 2>&1
	umount -l "$isosyncdirx64"/sys > /dev/null 2>&1
	umount -l "$isosyncdirx64"/dev/pts > /dev/null 2>&1
	umount -l "$isosyncdirx64"/dev/shm > /dev/null 2>&1
	umount -l "$isosyncdirx64"/dev > /dev/null 2>&1
	umount -l "$isosyncdirx64"/tmp > /dev/null 2>&1
	umount -l "$isosyncdirx64"/usr/portage/packages > /dev/null 2>&1
	umount -l "$isosyncdirx64"/mnt > /dev/null 2>&1
}

isooverlaysx64 () {
	echo "injecting "$releasename" "$releasetarget" overlay into x64 environment"
	sleep 1
	chroot "$isosyncdirx64" su - "$isouser" -c "$isomainoverlay"
}

isobuildsystemx64 () {
	echo "injecting "$releasename" x64 buildsystem && setting up portage"
	echo ""
	sleep 1
	for cmd in "$isobuildgit" "$isoportageconfig" "$isomakeconfx64" "$isoprofile" "$isoenvupdate" ; do
		chroot "$isosyncdirx64" su - "$isouser" -c "$cmd"
	done
}

isoramfsx64 () {
	chroot "$isosyncdirx64" su - "$isouser" -c "$isodracutcmd"
}

systemramfsx64 () {
	chroot "$isosyncdirx64" su - "$isouser" -c "$dracutcmdx64"
}

isoefiimgx64 () {
	chroot "$isosyncdirx64" su - "$isouser" -c "$isoeficmd"
}

isochrootx64 () {
	echo -e ""
	echo -e "DROPPING YOU TO A ROOT SHELL INTO ISO ENVIRONMENT"
	echo -e "INSTALL APPS & TARGETS & DES YOU WANT INSIDE ISO"
	echo -e "EXIT WHEN YOU'RE DONE AND I'LL CREATE THE IMAGE"
	echo -e ""
	chroot "$isosyncdirx64" su - "$isouser"
}

# x86 specific iso functions

isostartx86 () {
	mount -o bind packages "$isosyncdirx86"/usr/portage/packages
	mount -o bind targets "$isosyncdirx86"/mnt
	mount -t proc proc "$isosyncdirx86"/proc
	mount -t sysfs sysfs "$isosyncdirx86"/sys
	mount -t devtmpfs -o relatime,size=3055348k,nr_inodes=763837,mode=755 none "$isosyncdirx86"/dev
	mount -t devpts -o nosuid,noexec,relatime,gid=5,mode=620 none "$isosyncdirx86"/dev/pts
	mount -t tmpfs -o nosuid,nodev none "$isosyncdirx86"/dev/shm
	mount -t tmpfs -o nosuid,nodev,noexec none  "$isosyncdirx86"/tmp
}

isostopx86 () {
	umount -l "$isosyncdirx86"/proc > /dev/null 2>&1
	umount -l "$isosyncdirx86"/sys > /dev/null 2>&1
	umount -l "$isosyncdirx86"/dev/pts > /dev/null 2>&1
	umount -l "$isosyncdirx86"/dev/shm > /dev/null 2>&1
	umount -l "$isosyncdirx86"/dev > /dev/null 2>&1
	umount -l "$isosyncdirx86"/tmp > /dev/null 2>&1
	umount -l "$isosyncdirx86"/usr/portage/packages > /dev/null 2>&1
	umount -l "$isosyncdirx86"/mnt > /dev/null 2>&1
}

isooverlaysx86 () {
	echo "injecting "$releasename" "$releasetarget" overlay into x86 environment"
	sleep 1
	linux32 chroot "$isosyncdirx86" su - "$isouser" -c "$isomainoverlay"
}

isobuildsystemx86 () {
	echo "injecting "$releasename" x86 buildsystem && setting up portage"
	echo ""
	sleep 1
	for cmd in "$isobuildgit" "$isoportageconfig" "$isomakeconfx86" "$isoprofile" "$isoenvupdate" ; do
		linux32 chroot "$isosyncdirx86" su - "$isouser" -c "$cmd"
	done
}

isoramfsx86 () {
	linux32 chroot "$isosyncdirx86" su - "$isouser" -c "$isodracutcmd"
}

systemramfsx86 () {
	linux32 chroot "$isosyncdirx86" su - "$isouser" -c "dracutcmdx86"
}

isochrootx86 () {
	echo -e ""
	echo -e "DROPPING YOU TO A ROOT SHELL INTO ISO ENVIRONMENT"
	echo -e "INSTALL APPS & TARGETS & DES YOU WANT INSIDE ISO"
	echo -e "EXIT WHEN YOU'RE DONE AND I'LL CREATE THE IMAGE"
	echo -e ""
	linux32 chroot "$isosyncdirx86" su - "$isouser"
}