summaryrefslogtreecommitdiff
path: root/buildbot
blob: 53929d67ae31c1b5bf3e6fec143ca60615418da1 (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
#!/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
# Dependencies : squashfs + overlayfs kernel support


# env mount variables
export local rodir="rodir"
export local rwdir="rwdir"
export local overlaydir="overlaydir"

# env user variable
export local envkogaionuser="root"

# env target variable (can be a single package, multiple packages, or a target file passed as parameter)
export local envkogaiontarget="$@"
export local envkogaionbuildtarget="emerge -av "$envkogaiontarget""

# env buildsystem variables
export local envkogaionportageconfig="ln -sf /opt/build/conf/intel/portage /etc/portage"
export local envkogaionbuildgit="cd /opt && git clone https://github.com/Rogentos/build.git"
export local envkogaionoverlay="layman -f -a kogaion -o https://raw.github.com/Rogentos/kogaion/master/overlay.xml"
export local envkogaiondesktopoverlay="layman -f -a kogaion-desktop -o https://raw.github.com/Rogentos/kogaion-desktop/master/overlay.xml"


envkogaionsquashfsintegrity () {
	# our bare metal buildserver is x86_64 but we want to build 32bit packages as well
	# run this script with linux32 to fool it we run i686 and to build 32bit packages
	while : true ; do
		if [[ "$(uname -m)" = "x86_64" ]] ; then
			export local sqfsroot="kogaiondevelx64.squashfs"
			export local sqfsrootmd5file=""$sqfsroot".md5"
			export local sqfsrootmd5="$(cat "$sqfsrootmd5file" | awk {'print $1'})"
			if [[ -f "$sqfsroot" && -f "$sqfsrootmd5file" ]] ; then
				echo "Good, x86_64 squashed chroot && checksum file FOUND ... verifying integrity"
				echo ""
				if [[ "$(md5sum "$sqfsroot" | awk {'print $1'})" = "$sqfsrootmd5" ]] ; then
					echo "Good, x86_64 squashed chroot checksum PASSED ... starting environment"
					echo ""
					sleep 1
					break
				else
					echo "Ooops, x86_64 squashed chroot checksum FAILED ... aborting"
					exit 1
				fi
			else
				echo "Ooops, x86_64 squashed chroot or checksum file NOT FOUND ... aborting"
				exit 1
			fi
		elif [[ "$(uname -m)" = "i686" ]] ; then
			export local sqfsroot="kogaiondevelx86.squashfs"
			export local sqfsrootmd5file=""$sqfsroot".md5"
			export local sqfsrootmd5="$(cat "$sqfsrootmd5file" | awk {'print $1'})"
			if [[ -f "$sqfsroot" && -f "$sqfsrootmd5file" ]] ; then
				echo "Good, i686 squashed chroot && checksum FOUND ... verifying integrity"
				echo ""
				if [[ "$(md5sum "$sqfsroot" | awk {'print $1'})" = "$sqfsrootmd5" ]] ; then
					echo "Good, i686 squashed chroot checksum PASSED ... starting environment"
					echo ""
					sleep 1
					break
				else
					echo "Ooops, i686 squashed chroot checksum FAILED ... aborting"
				fi
			else
				echo "Ooops, i686 squashed chroot of checksum file NOT FOUND ... aborting"
				exit 1
			fi
		fi
	done
}

envkogaionstart () {
	# mount ro squashfs chroot + 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
}

envkogaionstop () {
	# 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"
}

envkogaionbuild () {
	# build packages in squashfs + overlayfs chroot
	if [[ "$(uname -m)" = "x86_64" ]] ; then
		echo ""
		echo "Environment is UP && RUNNING ... building targets"
		sleep 1
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionbuildtarget"
	elif [[ "$(uname -m)" = "i686" ]] ; then
		echo ""
		echo "Environment is UP && RUNNING ... building targets"
		sleep 1
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionbuildtarget"
	fi
}

envkogaionchroot() {
	# 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 ""
	if [[ "$(uname -m)" = "x86_64" ]] ; then
		chroot "$overlaydir" su - "$envkogaionuser"
	elif [[ "$(uname -m)" = "i686"  ]] ; then
		linux32 chroot "$overlaydir" su - "$envkogaionuser"
	fi
}

envkogaionbuildsystem() {
	# since squashed chroot is barebones, we need to set it up
	# add our overlays && set up our buildsystem
	if [[ "$(uname -m)" = "x86_64" ]] ; then
		export local envkogaionmakeconf="ln -sf /opt/build/conf/intel/portage/make.conf.amd64 /etc/portage/make.conf"
		export local envkogaionprofile="eselect profile set 1"
		echo "Adding Kogaion Linux Main Overlay"
		sleep 1
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionoverlay"
		echo "Adding Kogaion Linux Desktop Overlay"
		sleep 1
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaiondesktopoverlay"
		echo "Adding Kogaion Linux X86_64 Buildsystem && Setting up Portage && Setting up make.conf"
		echo ""
		sleep 1
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionbuildgit"
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionportageconfig"
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionmakeconf"
		chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionprofile"
	elif [[ "$(uname -m)" = "i686" ]] ; then
		export local envkogaionmakeconf="ln -sf /opt/build/conf/intel/portage/make.conf.x86 /etc/portage/make.conf"
		export local envkogaionprofile="eselect profile set 1"
		echo "Adding Kogaion Linux Main Overlay"
		sleep 1
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionoverlay"
		echo "Adding Kogaion Linux Desktop Overlay"
		sleep 1
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaiondesktopoverlay"
		echo "Adding Kogaion Linux i686 Buildsystem && Setting up Portage && Setting up make.conf"
		echo ""
		sleep 1
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionbuildgit"
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionportageconfig"
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionmakeconf"
		linux32 chroot "$overlaydir" su - "$envkogaionuser" -c "$envkogaionprofile"
	fi

}

envkogaionprepare () {
	# 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
			envkogaionstart
			break
		elif [[ -d "$rodir" && -d "$rwdir" && -d "$overlaydir" ]] ; then
			envkogaionstop
			for i in "$rodir" "$rwdir" "$overlaydir" ; do
				rm -rf "$i"
			done
			continue
		fi
	done
}

main () {
	envkogaionsquashfsintegrity
	envkogaionprepare
	envkogaionbuildsystem
	envkogaionbuild
	envkogaionchroot
}

main 
exit 0