-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathbuild.sh
executable file
·294 lines (265 loc) · 8.51 KB
/
build.sh
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
#!/usr/bin/env sh
set -e -u
cwd="$(realpath)"
export cwd
# Only run as superuser
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
kernrel="$(uname -r)"
case $kernrel in
'13.2-STABLE' | '14.0-STABLE' | '14.1-PRERELEASE' | '14.1-STABLE' | '15.0-CURRENT') ;;
*)
echo "FreeBSD or GhostBSD release is not supported."
exit 1
;;
esac
desktop_list=$(find packages -type f | grep base | cut -d '/' -f2 | tr -s '\n' ' ')
desktop_config_list=$(find desktop_config -type f)
help_function()
{
printf "Usage: %s -d desktop -r release type" "$0"
printf "\t-h for help"
printf "\t-d Desktop: %s" "${desktop_list}"
printf "\t-b Build type: unstable or release"
exit 1 # Exit script after printing help
}
# Set mate and release to be default
export desktop="mate"
export build_type="release"
while getopts "d:b:h" opt
do
case "$opt" in
'd') export desktop="$OPTARG" ;;
'b') export build_type="$OPTARG" ;;
'h') help_function ;;
'?') help_function ;;
*) help_function ;;
esac
done
if [ "${build_type}" = "release" ] ; then
PKGCONG="GhostBSD"
elif [ "${build_type}" = "unstable" ] ; then
PKGCONG="GhostBSD_Unstable"
else
printf "\t-b Build type: unstable or release"
exit 1
fi
# validate desktop packages
if [ ! -f "${cwd}/packages/${desktop}" ] ; then
echo "The packages/${desktop} file does not exist."
echo "Please create a package file named '${desktop}'and place it under packages/."
echo "Or use a valide desktop below:"
echo "$desktop_list"
echo "Usage: ./build.sh -d desktop"
exit 1
fi
# validate desktop
if [ ! -f "${cwd}/desktop_config/${desktop}.sh" ] ; then
echo "The desktop_config/${desktop}.sh file does not exist."
echo "Please create a config file named '${desktop}.sh' like these config:"
echo "$desktop_config_list"
exit 1
fi
if [ "${desktop}" != "mate" ] ; then
DESKTOP=$(echo "${desktop}" | tr '[:lower:]' '[:upper:]')
community="-${DESKTOP}"
else
community=""
fi
workdir="/usr/local"
livecd="${workdir}/ghostbsd-build"
base="${livecd}/base"
iso="${livecd}/iso"
software_packages="${livecd}/software_packages"
base_packages="${livecd}/base_packages"
release="${livecd}/release"
export release
cdroot="${livecd}/cdroot"
liveuser="ghostbsd"
export liveuser
time_stamp=""
release_stamp=""
label="GhostBSD"
workspace()
{
umount ${software_packages} >/dev/null 2>/dev/null || true
umount ${base_packages} >/dev/null 2>/dev/null || true
umount ${release}/dev >/dev/null 2>/dev/null || true
zpool destroy ghostbsd >/dev/null 2>/dev/null || true
umount ${release} >/dev/null 2>/dev/null || true
if [ -d "${cdroot}" ] ; then
chflags -R noschg ${cdroot}
rm -rf ${cdroot}
fi
mdconfig -d -u 0 >/dev/null 2>/dev/null || true
if [ -f "${livecd}/pool.img" ] ; then
rm ${livecd}/pool.img
fi
mkdir -p ${livecd} ${base} ${iso} ${software_packages} ${base_packages} ${release}
truncate -s 6g ${livecd}/pool.img
mdconfig -f ${livecd}/pool.img -u 0
zpool create ghostbsd /dev/md0
zfs set mountpoint=${release} ghostbsd
zfs set compression=zstd-9 ghostbsd
}
base()
{
base_list="$(cat "${cwd}/packages/base")"
mkdir -p ${release}/etc
cp /etc/resolv.conf ${release}/etc/resolv.conf
mkdir -p ${release}/var/cache/pkg
mount_nullfs ${base_packages} ${release}/var/cache/pkg
# shellcheck disable=SC2086
pkg-static -r ${release} -R "${cwd}/pkg/" install -y -r ${PKGCONG}_base $base_list
rm ${release}/etc/resolv.conf
umount ${release}/var/cache/pkg
touch ${release}/etc/fstab
mkdir ${release}/cdrom
}
set_ghostbsd_version()
{
version="-$(cat ${release}/etc/version)"
isopath="${iso}/${label}${version}${release_stamp}${time_stamp}${community}.iso"
}
packages_software()
{
if [ "${build_type}" = "unstable" ] ; then
cp pkg/GhostBSD_Unstable.conf ${release}/etc/pkg/GhostBSD.conf
fi
cp /etc/resolv.conf ${release}/etc/resolv.conf
mkdir -p ${release}/var/cache/pkg
mount_nullfs ${software_packages} ${release}/var/cache/pkg
mount -t devfs devfs ${release}/dev
pkg_list="$(cat "${cwd}/packages/${desktop}")"
# shellcheck disable=SC2086
pkg-static -c ${release} install -y $pkg_list
mkdir -p ${release}/proc
mkdir -p ${release}/compat/linux/proc
rm ${release}/etc/resolv.conf
umount ${release}/var/cache/pkg
}
fetch_x_drivers_packages()
{
if [ "${build_type}" = "release" ] ; then
pkg_url=$(pkg-static -R pkg/ -vv | grep '/stable' | cut -d '"' -f2)
else
pkg_url=$(pkg-static -R pkg/ -vv | grep '/unstable' | cut -d '"' -f2)
fi
mkdir ${release}/xdrivers
yes | pkg -R "${cwd}/pkg/" update
echo """$(pkg -R "${cwd}/pkg/" rquery -x -r ${PKGCONG} '%n %n-%v.pkg' 'nvidia-driver' | grep -v libva)""" > ${release}/xdrivers/drivers-list
pkg_list="""$(pkg -R "${cwd}/pkg/" rquery -x -r ${PKGCONG} '%n-%v.pkg' 'nvidia-driver' | grep -v libva)"""
for line in $pkg_list ; do
fetch -o ${release}/xdrivers "${pkg_url}/All/$line"
done
}
rc()
{
chroot ${release} touch /etc/rc.conf
chroot ${release} sysrc hostname='livecd'
chroot ${release} sysrc zfs_enable="YES"
chroot ${release} sysrc kld_list="linux linux64 cuse fusefs"
chroot ${release} sysrc linux_enable="YES"
chroot ${release} sysrc devfs_enable="YES"
chroot ${release} sysrc devfs_system_ruleset="devfsrules_common"
chroot ${release} sysrc moused_enable="YES"
chroot ${release} sysrc dbus_enable="YES"
chroot ${release} sysrc lightdm_enable="NO"
chroot ${release} sysrc webcamd_enable="YES"
chroot ${release} sysrc ipfw_enable="YES"
chroot ${release} sysrc firewall_enable="YES"
chroot ${release} sysrc cupsd_enable="YES"
chroot ${release} sysrc avahi_daemon_enable="YES"
chroot ${release} sysrc avahi_dnsconfd_enable="YES"
chroot ${release} sysrc ntpd_enable="YES"
chroot ${release} sysrc ntpd_sync_on_start="YES"
}
ghostbsd_config()
{
# echo "gop set 0" >> ${release}/boot/loader.rc.local
mkdir -p ${release}/usr/local/share/ghostbsd
echo "${desktop}" > ${release}/usr/local/share/ghostbsd/desktop
# bypass automount for live iso
mv ${release}/usr/local/etc/devd/automount_devd.conf ${release}/usr/local/etc/devd/automount_devd.conf.skip
mv ${release}/usr/local/etc/devd/automount_devd_localdisks.conf ${release}/usr/local/etc/devd/automount_devd_localdisks.conf.skip
# Mkdir for linux compat to ensure /etc/fstab can mount when booting LiveCD
chroot ${release} mkdir -p /compat/linux/dev/shm
# Add /boot/entropy file
chroot ${release} touch /boot/entropy
# default GhostBSD to local time instead of UTC
chroot ${release} touch /etc/wall_cmos_clock
}
desktop_config()
{
# run config for GhostBSD flavor
sh "${cwd}/desktop_config/${desktop}.sh"
}
uzip()
{
umount ${release}/dev
install -o root -g wheel -m 755 -d "${cdroot}"
mkdir "${cdroot}/data"
zfs snapshot ghostbsd@clean
zfs send -c -e ghostbsd@clean | dd of=/usr/local/ghostbsd-build/cdroot/data/system.img status=progress bs=1M
}
ramdisk()
{
ramdisk_root="${cdroot}/data/ramdisk"
mkdir -p "${ramdisk_root}"
cd "${release}"
tar -cf - rescue | tar -xf - -C "${ramdisk_root}"
cd "${cwd}"
install -o root -g wheel -m 755 "init.sh.in" "${ramdisk_root}/init.sh"
sed "s/@VOLUME@/GHOSTBSD/" "init.sh.in" > "${ramdisk_root}/init.sh"
mkdir "${ramdisk_root}/dev"
mkdir "${ramdisk_root}/etc"
touch "${ramdisk_root}/etc/fstab"
install -o root -g wheel -m 755 "rc.in" "${ramdisk_root}/etc/rc"
cp ${release}/etc/login.conf ${ramdisk_root}/etc/login.conf
makefs -b '10%' "${cdroot}/data/ramdisk.ufs" "${ramdisk_root}"
gzip "${cdroot}/data/ramdisk.ufs"
rm -rf "${ramdisk_root}"
}
boot()
{
cd "${release}"
tar -cf - boot | tar -xf - -C "${cdroot}"
cp COPYRIGHT ${cdroot}/COPYRIGHT
cd "${cwd}"
cp LICENSE ${cdroot}/LICENSE
cp -R boot/ ${cdroot}/boot/
mkdir ${cdroot}/etc
cd "${cwd}" && zpool export ghostbsd && while zpool status ghostbsd >/dev/null; do :; done 2>/dev/null
}
image()
{
cd script
sh mkisoimages.sh -b $label "$isopath" ${cdroot}
cd -
ls -lh "$isopath"
cd ${iso}
shafile=$(echo "${isopath}" | cut -d / -f6).sha256
torrent=$(echo "${isopath}" | cut -d / -f6).torrent
tracker1="http://tracker.openbittorrent.com:80/announce"
tracker2="udp://tracker.opentrackr.org:1337"
tracker3="udp://tracker.coppersurfer.tk:6969"
echo "Creating sha256 \"${iso}/${shafile}\""
sha256 "$(echo "${isopath}" | cut -d / -f6)" > "${iso}/${shafile}"
transmission-create -o "${iso}/${torrent}" -t ${tracker1} -t ${tracker2} -t ${tracker3} "${isopath}"
chmod 644 "${iso}/${torrent}"
cd -
}
workspace
base
set_ghostbsd_version
packages_software
fetch_x_drivers_packages
rc
desktop_config
ghostbsd_config
uzip
ramdisk
boot
image