summaryrefslogtreecommitdiff
path: root/buildbot
blob: d82729c8135f183e226735cb45f44ff88e002f6f (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
#!/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?!?)

lowerdir="kogaiondevelx64"
upperdir="upperdirx64"
overlaydir="overlaydirx64"
env_user="root"
env_targets="$@"
env_build_cmd="emerge -av "$env_targets""

envprepare () {
	# create the directories needed for squashfs + overlayfs mount
	mkdir "$lowerdir"
	mkdir "$upperdir"
	mkdir "$overlaydir"
}

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 - "$env_user" -c "$env_build_cmd"
}

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 "#            EXITING NOW 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 - "$env_user"
}

envcleanup () {
	# cleanup build environment
	rm -rf "$overlaydir"
	rm -rf "$upperdir"
	rm -rf "$lowerdir"
}

main () {
	envprepare
	envstart
	envbuild
	envchroot
	envstop
	envcleanup
}

main 
exit 0