Magellan Linux

Contents of /trunk/mlivecdbuild/profiles/alx-0_7_branch/prepare_custom

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3061 - (show annotations) (download)
Thu Aug 31 12:27:43 2017 UTC (6 years, 8 months ago) by niro
File size: 15539 byte(s)
-added server install image and installer start wrapper, install both pxelinux and lpxelinux bootloaders for netboot, fix issues with systemd dracut modules and mcored, fix spelling typos, add more space to the netboot ext3 image, do not remove the journal from the ext3 image, use a rootless fstab for netboot, do not updated any config files, user station already exist afer pkg installation, set an empty password for user station, set an mcored password, configure Xorg, systemd, and systemd-timesync, fix locales and zoneinfo
1 #!/bin/bash
2
3 updateconfig()
4 {
5 local variables="$@"
6 local value
7 local i
8
9 if [[ -z ${CONFIG} ]]
10 then
11 echo "You must define \$CONFIG varibale first!"
12 return 1
13 fi
14
15 for i in ${variables}
16 do
17 value="$(eval echo \${NEW_${i}})"
18 if [[ ! -z $(grep "^${i}=" ${CONFIG}) ]]
19 then
20 echo "fixing ${i} -> ${value}"
21 sed -i "s|^\(${i}=\).*|\1\"${value}\"|" ${CONFIG}
22 else
23 echo "adding ${i}=${value}"
24 echo "${i}=\"${value}\"" >> ${CONFIG}
25 fi
26 done
27 }
28
29 ##
30 # create the install tarball
31 ##
32 create_install_tarball()
33 {
34 install -d ${LIVECDROOT}/install-temp
35 install -d ${CDISOROOT}/system
36
37 # use all settings from the global config, but the basesystem
38 # has to be the normal install basesystem not for livecds
39 mage-bootstrap \
40 --root ${LIVECDROOT}/install-temp \
41 --profile ${MAGE_PROFILE} \
42 --magerc ${MAGERC} \
43 --toolchain ${TOOLCHAIN} \
44 --update-tarball \
45 --basesystem basesystem || die "bootstrapping target system failed!"
46
47 # # HACK: add all mesa-gallium modules but intel modules
48 # local i
49 # for i in nouveau r300 r600 radeonsi swrast
50 # do
51 # CDCHROOTDIR=${LIVECDROOT}/install-temp custom_packages install "mesa-gallium-${i}" || die
52 # done
53 #
54 # # HACK: add mesa-gallium-i915
55 # CDCHROOTDIR=${LIVECDROOT}/install-temp custom_packages install "mesa-gallium-i915" || die
56 #
57 # # HACK: add all mesa-dri modules
58 # local i
59 # for i in i915 i965 nouveau r200 radeon swrast
60 # do
61 # CDCHROOTDIR=${LIVECDROOT}/install-temp custom_packages install "mesa-dri-${i}" || die
62 # done
63 # # but disable i915_dri atm, which breaks
64 # if [[ -L ${LIVECDROOT}/install-temp/usr/lib/dri/i915_dri.so ]]
65 # then
66 # rm ${LIVECDROOT}/install-temp/usr/lib/dri/i915_dri.so
67 # fi
68
69 ## DEV SERVER ##
70 # NEW_MCORE_CONTROL_SERVER="alx-control-dev.dom-aka-nt.intern"
71 # CONFIG="${LIVECDROOT}/install-temp/etc/mcore/mcore.conf"
72 # updateconfig MCORE_CONTROL_SERVER
73 ###
74
75 # fix missing symlink
76 if [ ! -L ${LIVECDROOT}/install-temp/usr/bin/X ]
77 then
78 ln -snf Xorg ${LIVECDROOT}/install-temp/usr/bin/X
79 fi
80
81 # generate a new machine-id on first-boot
82 :> ${LIVECDROOT}/install-temp/etc/machine-id
83
84 # fix localtime symlink
85 ln -snf ../usr/share/zoneinfo/Europe/Berlin ${LIVECDROOT}/install-temp/etc/localtime
86
87 # activate timeserver via dhcp (NTP - option 42)
88 CDCHROOTDIR=${LIVECDROOT}/install-temp custom_services add systemd-timesyncd.service
89
90 # empty root password
91 chroot ${LIVECDROOT}/install-temp passwd -d root
92
93 # add user station with empty password
94 # chroot ${LIVECDROOT}/install-temp adduser -G users -h /home/station -s /bin/bash -D station
95
96 # empty user password
97 chroot ${LIVECDROOT}/install-temp passwd -d station
98
99 # install xinitrc
100 # echo 'exec startfluxbox' > ${LIVECDROOT}/install-temp/home/station/.xinitrc
101
102 if [ -x ${LIVECDROOT}/install-temp/usr/bin/mcorepasswd ] ||
103 [ -L ${LIVECDROOT}/install-temp/usr/bin/mcorepasswd ]
104 then
105 # add mcored default user
106 ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${LIVECDROOT}/install-temp /usr/bin/mcorepasswd mcore
107 fi
108
109 # fix hostname and hosts file
110 echo "alx-i486" > ${LIVECDROOT}/install-temp/etc/hostname
111 echo "127.0.0.1 localhost alx-i486.magellan-linux.de alx-i486" > ${LIVECDROOT}/install-temp/etc/hosts
112 cat >> ${LIVECDROOT}/install-temp/etc/hosts << EOF
113 ::1 ip6-localhost ip6-loopback
114 fe00::0 ip6-localnet
115 ff00::0 ip6-mcastprefix
116 ff02::1 ip6-allnodes
117 ff02::2 ip6-allrouters
118 ff02::3 ip6-allhosts
119 EOF
120
121 # # create a default network interface config file
122 # cat > ${LIVECDROOT}/install-temp/etc/conf.d/net.eth0 << EOF
123 #ONBOOT="yes"
124 #NETWORKING="dhcp"
125 #EOF
126
127 # fix mage.rc and config.rc
128 # NEW_SQL_USER="alx_install"
129 # NEW_SQL_PASS="@lx"
130 # NEW_SQL_HOST="128.20.41.110"
131 # NEW_SQL_DB="alx_web"
132 # NEW_SMB_UPDATE_HOST="//${NEW_SQL_HOST}/magetmp"
133 # NEW_SMB_UPDATE_USER="${NEW_SQL_USER}"
134 # NEW_SMB_UPDATE_PASS="${NEW_SQL_PASS}"
135 # NEW_MAGE_MIRRORS="http://${NEW_SQL_HOST}/magellan/alx-070"
136 # NEW_MAGE_RSYNC="rsync://${NEW_SQL_HOST}/mage-alx-070"
137 # NEW_RSYNC="${NEW_MAGE_RSYNC}"
138 # NEW_SMAGE2RSYNC="rsync://${NEW_SQL_HOST}/smage-alx-070"
139 # NEW_MIRRORS="${NEW_MAGE_MIRRORS}"
140 # NEW_MAGE_UNINSTALL_TIMEOUT="0"
141 # CONFIG="${LIVECDROOT}/install-temp/etc/mage.rc"
142 # updateconfig RSYNC SMAGE2RSYNC MIRRORS MAGE_UNINSTALL_TIMEOUT
143 # CONFIG="${LIVECDROOT}/install-temp/etc/alxconfig-ng/config.rc"
144 # updateconfig SQL_USER SQL_PASS SQL_HOST SQL_DB SMB_UPDATE_HOST SMB_UPDATE_USER SMB_UPDATE_PASS MAGE_MIRRORS MAGE_RSYNC
145
146 # create tarball
147 [[ -f ${CDISOROOT}/system/alx-i486.tar.bz2 ]] && rm ${CDISOROOT}/system/alx-i486.tar.bz2
148 ( cd ${LIVECDROOT}/install-temp; tar cvjpf ${CDISOROOT}/system/alx-i486.tar.bz2 ./ | tee log)
149
150 # create images.conf
151 echo "CDIMAGENAME=alx-i486.tar.bz2" > ${CDISOROOT}/system/images.conf
152 echo "TOTALLINES=$(wc -l ${LIVECDROOT}/install-temp/log | cut -d' ' -f1)" >> ${CDISOROOT}/system/images.conf
153
154 create_netboot_image
155
156 # clean up
157 if [[ -d ${LIVECDROOT}/install-temp ]]
158 then
159 rm -rf ${LIVECDROOT}/install-temp
160 fi
161 }
162
163 ##
164 # create the network image
165 ##
166 create_netboot_image()
167 {
168 install -d ${CDISOROOT}/netboot
169 install -d ${LIVECDROOT}/network-temp
170
171 install -d ${LIVECDROOT}/network-temp/{LiveOS,mnt} || die
172
173 # fix fstab, use the livecd fstab without rootfs and swap
174 install -m 0644 $(get_profile fstab) ${LIVECDROOT}/install-temp/etc/fstab || die
175
176 # get the actual size of the chroot
177 size=$(du -s ${LIVECDROOT}/install-temp | sed 's:^\(.*\)[[:space:]].*:\1:')
178
179 # generate a ext3fs file for devicemapper
180 dd if=/dev/zero of=${LIVECDROOT}/network-temp/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 20000 )) || die
181 # create a filesystem
182 mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die
183 # set mount_counts and check_intervals to 0
184 # set dir_index top, to speed up things with hashed b-trees
185 # allow acls too
186 tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die
187 # strip the journal
188 # tune2fs -O^has_journal ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die
189 # fsck after journal removal
190 # fsck ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die
191
192 # losetup the device
193 loopdev=$(losetup -f)
194 [[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?"
195
196 # mount the image
197 losetup ${loopdev} ${LIVECDROOT}/network-temp/LiveOS/ext3fs.img || die
198 mount ${loopdev} ${LIVECDROOT}/network-temp/mnt || die
199
200 # copy everything to the image file and preserve permissions
201 ( cd ${LIVECDROOT}/install-temp && tar cpf - . ) | ( cd ${LIVECDROOT}/network-temp/mnt && tar xvpf - )
202 sleep 3
203
204 # now umount everything and create the squashfs image
205 umount ${LIVECDROOT}/network-temp/mnt || die
206 losetup -d ${loopdev} || die
207 # remove mount to not ending up in the squashfs image
208 if [[ -d ${LIVECDROOT}/network-temp/mnt ]]
209 then
210 rm -r ${LIVECDROOT}/network-temp/mnt || die
211 fi
212 mksquashfs ${LIVECDROOT}/network-temp ${CDISOROOT}/netboot/squashfs.img || die
213
214 # copy kernel, bootloader and create initramfs to isoroot/netboot
215 install -d ${CDISOROOT}/netboot || die
216 # kernel
217 kimg="$(find ${CDCHROOTDIR}/boot -name kernel-\* -printf '%f\n')"
218 install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/netboot/${CDKERNELNAME} || die
219 # initrd
220 install -d ${CDCHROOTDIR}/etc/dracut.conf.d || die
221 echo 'add_dracutmodules+=" livenet busybox "' > ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
222 #echo 'omit_dracutmodules+=" systemd plymouth mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
223 # use plymouth to get all kms modules, but boot with nosplash as default to fix some Xorg issues
224 #echo 'omit_dracutmodules+=" systemd mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
225 echo 'omit_dracutmodules+=" mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
226 echo 'hostonly="no"' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
227 # install dracut-dev package to have all modules
228 custom_packages install "dracut-dev curl curl-dev" || die
229 ## mlivecdbuild function
230 generate_initrd
231 mv ${CDISOROOT}/isolinux/initrd.gz ${CDISOROOT}/netboot/ || die
232 # fix initrd permissions
233 chmod 0644 ${CDISOROOT}/netboot/initrd.gz || die
234 # custom_packages uninstall "dracut-dev curl curl-dev" || die
235 if [ -e ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf ]
236 then
237 rm ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf
238 fi
239 # bootloader pxelinux
240 install -d ${CDISOROOT}/netboot/pxelinux/pxelinux.cfg
241 [ -f $(get_profile netboot/pxelinux.0) ] && install -m0644 $(get_profile netboot/pxelinux.0) ${CDISOROOT}/netboot/pxelinux/
242 [ -f $(get_profile netboot/pxelinux.cfg/pxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/pxelinux-default) ${CDISOROOT}/netboot/pxelinux/pxelinux.cfg
243 [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${CDISOROOT}/netboot/pxelinux/
244 [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${CDISOROOT}/netboot/pxelinux/
245 [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${CDISOROOT}/netboot/pxelinux/
246 [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${CDISOROOT}/netboot/pxelinux/
247 [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${CDISOROOT}/netboot/pxelinux/
248 [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${CDISOROOT}/netboot/pxelinux/
249 # bootloader lpxelinux
250 install -d ${CDISOROOT}/netboot/lpxelinux/pxelinux.cfg
251 [ -f $(get_profile netboot/lpxelinux.0) ] && install -m0644 $(get_profile netboot/lpxelinux.0) ${CDISOROOT}/netboot/lpxelinux/
252 [ -f $(get_profile netboot/ldlinux.c32) ] && install -m0644 $(get_profile netboot/ldlinux.c32) ${CDISOROOT}/netboot/lpxelinux/
253 [ -f $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ${CDISOROOT}/netboot/lpxelinux/pxelinux.cfg
254 [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${CDISOROOT}/netboot/lpxelinux/
255 [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${CDISOROOT}/netboot/lpxelinux/
256 [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${CDISOROOT}/netboot/lpxelinux/
257 [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${CDISOROOT}/netboot/lpxelinux/
258 [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${CDISOROOT}/netboot/lpxelinux/
259 [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${CDISOROOT}/netboot/lpxelinux/
260
261 # final cleanup
262 if [[ -d ${LIVECDROOT}/network-temp ]]
263 then
264 rm -r ${LIVECDROOT}/network-temp || die
265 fi
266 }
267
268 ##
269 # create the server tarball
270 ##
271 create_server_tarball()
272 {
273 install -d ${LIVECDROOT}/server-temp
274 install -d ${CDISOROOT}/server
275
276 mage-bootstrap \
277 --root ${LIVECDROOT}/server-temp \
278 --profile ${MAGE_PROFILE} \
279 --magerc ${MAGERC} \
280 --toolchain ${TOOLCHAIN} \
281 --update-tarball \
282 --basesystem serversystem || die "bootstrapping target system failed!"
283
284 # generate a new machine-id on first-boot
285 :> ${LIVECDROOT}/server-temp/etc/machine-id
286
287 # enable getty1
288 install -d ${LIVECDROOT}/server-temp/etc/systemd/system/getty.target.wants
289 ln -snf /usr/lib/systemd/system/getty@.service ${LIVECDROOT}/server-temp/etc/systemd/system/getty.target.wants/getty@tty1.service
290
291 # be more verbose
292 sed -i 's:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1"rd.info":' ${LIVECDROOT}/server-temp/etc/conf.d/grub
293
294 # fix localtime symlink
295 ln -snf ../usr/share/zoneinfo/Europe/Berlin ${LIVECDROOT}/server-temp/etc/localtime
296
297 # activate timeserver via dhcp (NTP - option 42)
298 CDCHROOTDIR=${LIVECDROOT}/server-temp custom_services add systemd-timesyncd.service
299
300 # empty root password
301 chroot ${LIVECDROOT}/server-temp passwd -d root
302
303 # empty user password
304 chroot ${LIVECDROOT}/server-temp passwd -d station
305
306 if [ -x ${LIVECDROOT}/server-temp/usr/bin/mcorepasswd ] ||
307 [ -L ${LIVECDROOT}/server-temp/usr/bin/mcorepasswd ]
308 then
309 # add mcored default user
310 ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${LIVECDROOT}/server-temp /usr/bin/mcorepasswd mcore
311 fi
312
313 # remove phpmyadmin configuration directory
314 if [ -d ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config ]
315 then
316 rm -r ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config
317 fi
318
319 # fix hostname and hosts file
320 echo "alx-svr-i486" > ${LIVECDROOT}/server-temp/etc/hostname
321 echo "127.0.0.1 localhost alx-svr-i486.magellan-linux.de alx-svr-i486" > ${LIVECDROOT}/server-temp/etc/hosts
322 # fix certificate issues with mcored (common name of cert issuer) and >php-5.4
323 echo "127.0.0.1 mcored" >> ${LIVECDROOT}/server-temp/etc/hosts
324 cat >> ${LIVECDROOT}/server-temp/etc/hosts << EOF
325 ::1 ip6-localhost ip6-loopback
326 fe00::0 ip6-localnet
327 ff00::0 ip6-mcastprefix
328 ff02::1 ip6-allnodes
329 ff02::2 ip6-allrouters
330 ff02::3 ip6-allhosts
331 EOF
332
333 # create tarball
334 [[ -f ${CDISOROOT}/server/alx-svr-i486.tar.bz2 ]] && rm ${CDISOROOT}/server/alx-svr-i486.tar.bz2
335 ( cd ${LIVECDROOT}/server-temp; tar cvjpf ${CDISOROOT}/server/alx-svr-i486.tar.bz2 ./ | tee log)
336
337 # create images.conf
338 echo "CDIMAGENAME=alx-svr-i486.tar.bz2" > ${CDISOROOT}/server/images.conf
339 echo "TOTALLINES=$(wc -l ${LIVECDROOT}/server-temp/log | cut -d' ' -f1)" >> ${CDISOROOT}/server/images.conf
340
341 # clean up
342 if [[ -d ${LIVECDROOT}/server-temp ]]
343 then
344 rm -rf ${LIVECDROOT}/server-temp
345 fi
346 }
347
348 # set an empty root password
349 chroot ${CDCHROOTDIR} passwd -d root
350
351 # install a custom boot-duration matching this livecd
352 install -d ${CDCHROOTDIR}/var/lib/plymouth || die
353 install -m 0644 $(get_profile boot-duration.livecd) ${CDCHROOTDIR}/var/lib/plymouth/boot-duration || die
354
355 # install mnt-cdrom mount service, should be provided by alxinstall-ng
356 #install -m 0644 $(get_profile mnt-cdrom.mount) ${CDCHROOTDIR}/usr/lib/systemd/system/mnt-cdrom.mount || die
357 #ln -snf ../mnt-cdrom.mount ${CDCHROOTDIR}/usr/lib/systemd/system/local-fs.target.wants/mnt-cdrom.mount || die
358
359 # disable splash X11 vt change and set splash to be always verbose
360 #if [[ -f ${CDCHROOTDIR}/etc/splash/splash.conf ]]
361 #then
362 # sed -i -e 's:^\(SPLASH_X11_TTY=.*\):#\1:' \
363 # -e 's:^\(SPLASH_MODE=\).*:\1\"verbose\":' \
364 # ${CDCHROOTDIR}/etc/splash/splash.conf
365 #fi
366
367 # setup de keymap and locales
368 if [ -f ${CDCHROOTDIR}/etc/vconsole.conf ]
369 then
370 cat > ${CDCHROOTDIR}/etc/vconsole.conf << EOF || die
371 KEYMAP=de
372 KEYMAP_TOGGLE=
373 FONT=lat9w-16
374 FONT_MAP=8859-1_to_uni
375 FONT_UNIMAP=
376 EOF
377 fi
378 if [ -f ${CDCHROOTDIR}/etc/locale.conf ]
379 then
380 sed -i "s:^\(LANG=\).*:\1\"de_DE.utf8\":" ${CDCHROOTDIR}/etc/locale.conf || die
381 fi
382
383 # stop here if the user don't want to create the install tarball
384 [[ -n ${SKIP_CREATE_INSTALL_TARBALL} ]] || create_install_tarball
385
386 # stop here if the user don't want to create the server tarball
387 [[ -n ${SKIP_CREATE_SERVER_TARBALL} ]] || create_server_tarball
388
389 # install usb-install script
390 [ ! -d ${CDISOROOT}/usb-install ] && mkdir ${CDISOROOT}/usb-install
391 [ -f $(get_profile usb-install/usb-install.cmd) ] && cp $(get_profile usb-install)/usb-install.cmd ${CDISOROOT}/usb-install
392 [ -f $(get_profile usb-install/syslinux.exe) ] && cp $(get_profile usb-install)/syslinux.exe ${CDISOROOT}/usb-install
393 [ -f $(get_profile usb-install/syslinux.cfg) ] && cp $(get_profile usb-install)/syslinux.cfg ${CDISOROOT}/usb-install
394
395 # add installer-server script
396 cat > ${CDCHROOTDIR}/usr/bin/installer-server << EOF
397 #!/bin/bash
398 /usr/bin/installer --imageroot /run/initramfs/live/server
399 EOF
400 chmod 0755 ${CDCHROOTDIR}/usr/bin/installer-server