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
|
#!/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 : add squashfs portage tree && overlays sync && build.git sync && profile setup
# Todo : auto push built packages to repos (maybe, really needed?!?)
export local sqfsroot="kogaiondevelx64.squashfs"
export local sqfsroothash="fb2afc5f3b387412a0954f242df54927"
export local rodir="rodir"
export local rwdir="rwdir"
export local overlaydir="overlaydir"
export local envuser="root"
export local envtargets="$@"
export local envbuildcmd="emerge -av "$envtargets""
envintegrity() {
# check if our squashfs chroot somehow got corrupted, abort if so
while : true ; do
if [[ "$(md5sum "$sqfsroot" | awk {'print $1'})" = "$sqfsroothash" ]]; then
break
else
exit 1
fi
done
}
envstart () {
# mount ro squashfs + add rw overlayfs layer to enable clean package building
mount -t squashfs "$sqfsroot" "$rodir"
mount -t overlayfs -o lowerdir="$rodir",upperdir="$rwdir" 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 "$rodir"
}
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 "$rodir" && ! -d "$rwdir" && ! -d "$overlaydir" ]]; then
for i in "$rodir" "$rwdir" "$overlaydir" ; do
mkdir "$i"
done
envstart
break
elif [[ -d "$overlaydir" && -f "$overlaydir/usr/bin/emerge" ]] ; then
envstop
for i in "$rodir" "$rwdir" "$overlaydir" ; do
rm -rf "$i"
done
continue
fi
done
}
main () {
envintegrity
envprepare
envbuild
envchroot
}
main
exit 0
|