summaryrefslogtreecommitdiff
path: root/buildbot
blob: dd0351f7e5a69a38e6d26969d77594743cee16c5 (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
#!/usr/bin/env bash
# 
# Script to build Kogaion Linux packages in a clean squashfs + overlayfs chroot
# Using predefined targets : kernel.target, libs.target, x11.target, sound.target, artwork.target etc
# Targets are passed as arguments, and will remain private...for now (not all of them are stable yet)
# Author	: V3n3RiX @ RogentOS
# Deps		: squashfs + overlayfs kernel support
# Todo		: squashfs checksum verification
#			: add squashfs portage tree	
#			: sync build.git
#			: sync overlays
#			: setup profiles
#			: auto push built packages to repos (maybe, really needed?!?)

export local lowerdir="kogaiondevelx64"
export local upperdir="upperdirx64"
export local overlaydir="overlaydirx64"
export local envuser="root"
export local envtargets="$@"
export local envbuildcmd="emerge -av "$envtargets""


envstart () {
	# mount ro squashfs + add rw overlayfs layer to enable clean package building
	mount -t squashfs "$lowerdir".squashfs "$lowerdir"
	mount -t overlayfs -o lowerdir="$lowerdir",upperdir="$upperdir" overlayfs "$overlaydir"
	mount -o bind /proc "$overlaydir"/proc
	mount -o bind /sys "$overlaydir"/sys
	mount -o bind /dev "$overlaydir"/dev
	mount -o bind /dev/pts "$overlaydir"/dev/pts
	mount -o bind /dev/shm "$overlaydir"/dev/shm
	mount -o bind /tmp "$overlaydir"/tmp
}

envstop () {
	# umount squashfs + overlayfs chroot
	umount -l "$overlaydir"/proc
	umount -l "$overlaydir"/sys
	umount -l "$overlaydir"/dev/pts
	umount -l "$overlaydir"/dev/shm
	umount -l "$overlaydir"/dev
	umount -l "$overlaydir"/tmp
	umount -l "$overlaydir"
	umount -l "$lowerdir"
}

envbuild () {
	# build packages in squashfs + overlayfs chroot
	chroot "$overlaydir" su - "$envuser" -c "$envbuildcmd"
}

envchroot() {
	# enter squashfs + overlayfs chroot to push packages, or debug build errors
	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 - "$envuser"
}

envprepare () {
	# first let's check our environment for sanity
	# if safe, trigger start && break the loop to build packages
	# else trigger stop && cleanup && check again
	while : true ; do
		if [[ ! -d "$lowerdir" && ! -d "$upperdir" && ! -d "$overlaydir" ]]; then
			for i in "$lowerdir" "$upperdir" "$overlaydir" ; do
				mkdir "$i"
			done
			envstart
			break
		elif [[ -d "$overlaydir" && -f "$overlaydir/usr/bin/emerge" ]] ; then
			envstop
			for i in "$lowerdir" "$upperdir" "$overlaydir" ; do
				rm -rf "$i"
			done
			continue
		fi
	done
}

main () {
	envprepare
	envbuild
	envchroot
}

main 
exit 0