forked from ghostbsd/ghostbsd-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
285 lines (257 loc) · 9.09 KB
/
functions.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
#!/usr/bin/env sh
cwd="`realpath | sed 's|/scripts||g'`"
liveuser=ghostbsd
systems=$1
desktop=$2
workdir="/usr/local"
livecd="${workdir}/ghostbsd-build/${systems}"
base="${livecd}/base"
software_packages="${livecd}/software_packages"
base_packages="${livecd}/base_packages"
release="${livecd}/release"
cdroot="${livecd}/cdroot"
version="19.03"
# version=""
# releasestamp=""
releasestamp="-RC2"
# timestamp=`date "+-%Y-%m-%d-%H-%M"`
timestamp=""
label="GhostBSD"
union_dirs=${union_dirs:-"boot cdrom dev etc libexec media mnt root tmp usr/home usr/local/etc usr/local/share/mate-panel var"}
kernrel="`uname -r`"
# Only run as superuser
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Only run with 13.0-CURRENT.
case $kernrel in
'13.0-CURRENT')
echo "Using correct kernel release" 1>&2
;;
*)
echo "Using wrong kernel release. Use TrueOS 18.12 or GhostBSD 19 to build iso."
exit 1
;;
esac
display_usage()
{
echo "You must specify a systems at minimum!"
echo "Possible choices are:"
ls ${cwd}/systems
echo "Usage: ./build.sh trueos"
exit 1
}
validate_systems()
{
if [ ! -d "${cwd}/systems/${systems}" ] ; then
display_usage
fi
}
validate_desktop()
{
if [ ! -f "${cwd}/systems/${systems}/packages/${desktop}" ] ; then
echo "Invalid choice specified"
echo "Possible choices are:"
ls ${cwd}/systems/${systems}/packages
echo "Usage: ./build.sh trueos mate"
exit 1
fi
}
# We must choose a systems at minimum
if [ -z "${systems}" ] ; then
echo "You must specify a systems!"
echo "Possible choices are:"
ls ${cwd}/systems
echo "Usage: ./build.sh trueos"
exit 1
else
validate_systems
fi
# Validate package selection if chosen
if [ -z "${desktop}" ] ; then
desktop=mate
else
validate_desktop
fi
if [ "${desktop}" == "xfce" ] ; then
community="-XFCE"
else
community=""
fi
isopath="${livecd}/${label}${version}${releasestamp}${timestamp}${community}.iso"
workspace()
{
umount ${release}/var/cache/pkg >/dev/null 2>/dev/null
if [ -d "${livecd}" ] ;then
chflags -R noschg ${release} ${cdroot} >/dev/null 2>/dev/null
rm -rf ${release} ${cdroot} >/dev/null 2>/dev/null
fi
mkdir -p ${livecd} ${base} ${software_packages} ${base_packages} ${release} >/dev/null 2>/dev/null
}
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
pkg-static -R ${cwd}/systems/trueos/repos/usr/local/etc/pkg/repos/ -C GhostBSD search -q GhostBSD | grep "GhostBSD-" | grep -v -E "(-doc|-debug)" | xargs pkg-static -r ${release} -R ${cwd}/systems/trueos/repos/usr/local/etc/pkg/repos/ -C GhostBSD install -y -g
rm ${release}/etc/resolv.conf
umount ${release}/var/cache/pkg
touch ${release}/etc/fstab
mkdir ${release}/cdrom
}
packages_software()
{
cp -R ${cwd}/systems/trueos/repos/ ${release}
cp /etc/resolv.conf ${release}/etc/resolv.conf
mkdir -p ${release}/var/cache/pkg
mount_nullfs ${software_packages} ${release}/var/cache/pkg
case $desktop in
mate)
cat ${cwd}/systems/${systems}/packages/mate | xargs pkg-static -c ${release} install -y ;;
xfce)
cat ${cwd}/systems/${systems}/packages/xfce | xargs pkg-static -c ${release} install -y ;;
esac
rm ${release}/etc/resolv.conf
umount ${release}/var/cache/pkg
cp -R ${cwd}/systems/trueos/repos/ ${release}
}
rc()
{
chroot ${release} sysrc -f /etc/rc.conf root_rw_mount="NO"
chroot ${release} sysrc -f /etc/rc.conf hostname='livecd'
chroot ${release} sysrc -f /etc/rc.conf sendmail_enable="NONE"
chroot ${release} sysrc -f /etc/rc.conf sendmail_submit_enable="NO"
chroot ${release} sysrc -f /etc/rc.conf sendmail_outbound_enable="NO"
chroot ${release} sysrc -f /etc/rc.conf sendmail_msp_queue_enable="NO"
# DEVFS rules
chroot ${release} sysrc -f /etc/rc.conf devfs_system_ruleset="devfsrules_common"
# Load the following kernel modules
# chroot ${release} sysrc -f /etc/rc.conf kld_list="linux linux64 /boot/modules/i915kms.ko /boot/modules/radeonkms.ko amdgpu"
# chroot ${release} sysrc -f /etc/rc.conf kld_list="geom_mirror"
# remove kldload_nvidia on rc.conf
( echo 'g/kldload_nvidia="nvidia-modeset nvidia"/d' ; echo 'wq' ) | ex -s ${release}/etc/rc.conf
chroot ${release} rc-update add devfs default
chroot ${release} rc-update add moused default
chroot ${release} rc-update add dbus default
chroot ${release} rc-update add hald default
chroot ${release} rc-update add webcamd default
chroot ${release} rc-update delete vboxguest default
chroot ${release} rc-update delete vboxservice default
chroot ${release} rc-update add cupsd default
chroot ${release} rc-update add avahi-daemon default
chroot ${release} rc-update add avahi-dnsconfd default
chroot ${release} rc-update add ntpd default
chroot ${release} sysrc -f /etc/rc.conf ntpd_sync_on_start="YES"
}
user()
{
chroot ${release} pw useradd ${liveuser} \
-c "GhostBSD Live User" -d "/usr/home/${liveuser}" \
-g wheel -G operator -m -s /usr/local/bin/fish -k /usr/share/skel -w none
}
extra_config()
{
. ${cwd}/systems/trueos/extra/common-live-setting.sh
. ${cwd}/systems/trueos/extra/common-base-setting.sh
. ${cwd}/systems/trueos/extra/setuser.sh
. ${cwd}/systems/trueos/extra/dm.sh
. ${cwd}/systems/trueos/extra/finalize.sh
. ${cwd}/systems/trueos/extra/autologin.sh
. ${cwd}/systems/trueos/extra/gitpkg.sh
set_live_system
git_pc_sysinstall
## git_gbi is for development testing and gbi should be
## remove from the package list to avoid conflict
git_gbi
setup_liveuser
setup_base
lightdm_setup
# setup_xinit
setup_autologin
final_setup
echo "gop set 0" >> ${release}/boot/loader.rc.local
# To fix lightdm crashing to be remove on the new base update.
sed -i '' -e 's/memorylocked=128M/memorylocked=256M/' ${release}/etc/login.conf
chroot ${release} cap_mkdb /etc/login.conf
}
xorg()
{
if [ -n "${desktop}" ] ; then
install -o root -g wheel -m 755 "${cwd}/xorg/bin/xconfig" "${release}/usr/local/bin/"
install -o root -g wheel -m 755 "${cwd}/xorg/rc.d/xconfig" "${release}/usr/local/etc/rc.d/"
if [ -f "${release}/sbin/openrc-run" ] ; then
install -o root -g wheel -m 755 "${cwd}/xorg/init.d/xconfig" "${release}/usr/local/etc/init.d/"
fi
if [ ! -d "${release}/usr/local/etc/X11/cardDetect/" ] ; then
mkdir -p ${release}/usr/local/etc/X11/cardDetect
fi
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.vesa" "${release}/usr/local/etc/X11/cardDetect/"
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.scfb" "${release}/usr/local/etc/X11/cardDetect/"
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.virtualbox" "${release}/usr/local/etc/X11/cardDetect/"
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.vmware" "${release}/usr/local/etc/X11/cardDetect/"
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.nvidia" "${release}/usr/local/etc/X11/cardDetect/"
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.intel" "${release}/usr/local/etc/X11/cardDetect/"
install -o root -g wheel -m 755 "${cwd}/xorg/cardDetect/XF86Config.modesetting" "${release}/usr/local/etc/X11/cardDetect/"
fi
}
uzip()
{
install -o root -g wheel -m 755 -d "${cdroot}"
mkdir "${cdroot}/data"
makefs "${cdroot}/data/system.ufs" "${release}"
mkuzip -o "${cdroot}/data/system.uzip" "${cdroot}/data/system.ufs"
rm -f "${cdroot}/data/system.ufs"
}
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"
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}"
}
mfs()
{
for dir in ${union_dirs}; do
echo ${dir} >> ${cdroot}/data/uniondirs
cd ${release} && tar -cpzf ${cdroot}/data/mfs.tgz ${union_dirs}
done
}
boot()
{
cd "${release}"
tar -cf - --exclude boot/kernel boot | tar -xf - -C "${cdroot}"
for kfile in kernel geom_uzip.ko nullfs.ko tmpfs.ko geom_mirror.ko crypto.ko geom_eli.ko aesni.ko; do
tar -cf - boot/kernel/${kfile} | tar -xf - -C "${cdroot}"
done
cd "${cwd}"
cp -R boot/ ${cdroot}/boot/
mkdir ${cdroot}/etc
}
image()
{
sh mkisoimages.sh -b $label $isopath ${cdroot}
ls -lh $isopath
cd ${livecd}
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 \"${livecd}/${shafile}\""
sha256 `echo ${isopath} | cut -d / -f6` > ${livecd}/${shafile}
transmission-create -o ${livecd}/${torrent} -t ${tracker1} -t ${tracker3} -t ${tracker3} ${isopath}
chmod 644 ${livecd}/${torrent}
cd -
}