Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3070 - (hide annotations) (download)
Fri Sep 1 09:31:56 2017 UTC (6 years, 9 months ago) by niro
File size: 13316 byte(s)
-fully reworked prepare_custom script and use netbootsystem as default basesystem and fully bootstrap the netboot image, instead of just duplicate it from the normal image. now the netboot image can be individually changed and managed
1 niro 2119 #!/bin/bash
2    
3 niro 2664 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 niro 3070 # prepare_custom_baseconfig $_OSROOT $_OSHOSTNAME $_OSHOSTDOMAIN
30     prepare_custom_baseconfig()
31 niro 2664 {
32 niro 3070 local _OSROOT="$1"
33     local _OSHOSTNAME="$2"
34     local _OSHOSTDOMAIN="$3"
35     if [[ -z ${_OSROOT} ]]
36 niro 3061 then
37 niro 3070 echo "no _OSROOT given"
38     return 1
39 niro 3061 fi
40 niro 3070 if [[ ! -d ${_OSROOT} ]]
41     then
42     echo "Root dir '${_OSROOT}' does not exist"
43     return 1
44     fi
45     if [[ -z ${_OSHOSTNAME} ]]
46     then
47     echo "no _OSHOSTNAME given"
48     return 1
49     fi
50     if [[ -z ${_OSHOSTDOMAIN} ]]
51     then
52     echo "no _OSHOSTDOMAIN given"
53     return 1
54     fi
55 niro 3061
56     # generate a new machine-id on first-boot
57 niro 3070 :> ${_OSROOT}/etc/machine-id
58 niro 3061
59     # fix localtime symlink
60 niro 3070 ln -snf ../usr/share/zoneinfo/Europe/Berlin ${_OSROOT}/etc/localtime
61 niro 3061
62     # activate timeserver via dhcp (NTP - option 42)
63 niro 3070 CDCHROOTDIR=${_OSROOT} custom_services add systemd-timesyncd.service
64 niro 3061
65     # empty root password
66 niro 3070 chroot ${_OSROOT} passwd -d root
67 niro 2664
68 niro 3061 # empty user password
69 niro 3070 chroot ${_OSROOT} passwd -d station
70 niro 3061
71 niro 3070 if [ -x ${_OSROOT}/usr/bin/mcorepasswd ] ||
72     [ -L ${_OSROOT}/usr/bin/mcorepasswd ]
73 niro 3061 then
74     # add mcored default user
75 niro 3070 ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${_OSROOT} /usr/bin/mcorepasswd mcore
76 niro 3061 fi
77    
78 niro 2664 # fix hostname and hosts file
79 niro 3070 echo "${_OSHOSTNAME}" > ${_OSROOT}/etc/hostname
80     echo "127.0.0.1 localhost ${_OSHOSTNAME}.${_OSHOSTDOMAIN} ${_OSHOSTNAME}" > ${_OSROOT}/etc/hosts
81     cat >> ${_OSROOT}/etc/hosts << EOF
82 niro 2664 ::1 ip6-localhost ip6-loopback
83     fe00::0 ip6-localnet
84     ff00::0 ip6-mcastprefix
85     ff02::1 ip6-allnodes
86     ff02::2 ip6-allrouters
87     ff02::3 ip6-allhosts
88     EOF
89 niro 3070 }
90 niro 2664
91 niro 3070 # prepare_custom_installertarball $_OSROOT $_TARBALLNAME $_TARBALLTARGET
92     prepare_custom_installertarball()
93     {
94     local _OSROOT="$1"
95     local _TARBALLNAME="$2"
96     local _TARBALLTARGET="$3"
97     if [[ -z ${_OSROOT} ]]
98     then
99     echo "no _OSROOT given"
100     return 1
101     fi
102     if [[ ! -d ${_OSROOT} ]]
103     then
104     echo "Root dir '${_OSROOT}' does not exist"
105     return 1
106     fi
107     if [[ -z ${_TARBALLNAME} ]]
108     then
109     echo "no _TARBALLNAME given"
110     return 1
111     fi
112     if [[ -z ${_TARBALLTARGET} ]]
113     then
114     echo "no _TARBALLTARGET given"
115     return 1
116     fi
117    
118 niro 2664 # create tarball
119 niro 3070 [[ -f ${_TARBALLTARGET}/${_TARBALLNAME}.tar.bz2 ]] && rm ${_TARBALLTARGET}/${_TARBALLNAME}.tar.bz2
120     ( cd ${_OSROOT}; tar cvjpf ${CDISOROOT}/${_TARBALLTARGET}/${_TARBALLNAME}.tar.bz2 ./ | tee ${LIVECDROOT}/${_TARBALLNAME}.log )
121 niro 2664
122     # create images.conf
123 niro 3070 echo "CDIMAGENAME=${_TARBALLNAME}.tar.bz2" > ${_TARBALLTARGET}/images.conf
124     echo "TOTALLINES=$(wc -l ${LIVECDROOT}/${_TARBALLNAME}.log | cut -d' ' -f1)" >> ${_TARBALLTARGET}/images.conf
125 niro 2664
126     # clean up
127 niro 3070 if [[ -z ${SKIP_REMOVE_INSTALLROOT} ]]
128 niro 2664 then
129 niro 3070 if [[ -d ${_OSROOT} ]]
130     then
131     rm -r ${_OSROOT}
132     fi
133     if [[ -f ${LIVECDROOT}/${_TARBALLNAME}.log ]]
134     then
135     rm ${LIVECDROOT}/${_TARBALLNAME}.log
136     fi
137 niro 2664 fi
138 niro 3070 }
139    
140     ##
141     # create the install tarball
142     ##
143     create_install_tarball()
144     {
145     install -d ${LIVECDROOT}/install-temp
146     install -d ${CDISOROOT}/system
147    
148     # use all settings from the global config, but the basesystem
149     # has to be the normal install basesystem not for livecds
150     mage-bootstrap \
151     --root ${LIVECDROOT}/install-temp \
152     --profile ${MAGE_PROFILE} \
153     --magerc ${MAGERC} \
154     --toolchain ${TOOLCHAIN} \
155     --update-tarball \
156     --basesystem basesystem || die "bootstrapping target system failed!"
157    
158     ## DEV SERVER ##
159     # NEW_MCORE_CONTROL_SERVER="alx-control-dev.dom-aka-nt.intern"
160     # CONFIG="${LIVECDROOT}/install-temp/etc/mcore/mcore.conf"
161     # updateconfig MCORE_CONTROL_SERVER
162     ###
163    
164     # fix missing symlink
165     if [ ! -L ${LIVECDROOT}/install-temp/usr/bin/X ]
166 niro 3065 then
167 niro 3070 ln -snf Xorg ${LIVECDROOT}/install-temp/usr/bin/X
168 niro 3065 fi
169 niro 3070
170     # os config
171     prepare_custom_baseconfig "${LIVECDROOT}/install-temp" "alx-${CDOSARCH}" "magellan-linux.de"
172    
173     # create tarball
174     prepare_custom_installertarball "${LIVECDROOT}/install-temp" "alx-${CDOSARCH}" "${CDISOROOT}/system"
175 niro 2664 }
176    
177     ##
178     # create the network image
179     ##
180     create_netboot_image()
181     {
182     install -d ${CDISOROOT}/netboot
183 niro 3070 install -d ${LIVECDROOT}/netboot-temp
184     install -d ${LIVECDROOT}/network-squashfs-temp
185 niro 2664
186 niro 3070 # use all settings from the global config, but use netbootsysten as basesystem
187     mage-bootstrap \
188     --root ${LIVECDROOT}/netboot-temp \
189     --profile ${MAGE_PROFILE} \
190     --magerc ${MAGERC} \
191     --toolchain ${TOOLCHAIN} \
192     --update-tarball \
193     --basesystem netbootsystem || die "bootstrapping target system failed!"
194 niro 2664
195 niro 3070 # os config
196     prepare_custom_baseconfig "${LIVECDROOT}/netboot-temp" "alx-${CDOSARCH}" "magellan-linux.de"
197    
198     # creating netboot image from here on
199     install -d ${LIVECDROOT}/network-squashfs-temp/{LiveOS,mnt} || die
200    
201 niro 3061 # fix fstab, use the livecd fstab without rootfs and swap
202 niro 3070 install -m 0644 $(get_profile fstab) ${LIVECDROOT}/netboot-temp/etc/fstab || die
203 niro 3061
204 niro 2664 # get the actual size of the chroot
205 niro 3070 size=$(du -s ${LIVECDROOT}/netboot-temp | sed 's:^\(.*\)[[:space:]].*:\1:')
206 niro 2664
207     # generate a ext3fs file for devicemapper
208 niro 3070 dd if=/dev/zero of=${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 20000 )) || die
209 niro 2664 # create a filesystem
210 niro 3070 mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img || die
211 niro 2664 # set mount_counts and check_intervals to 0
212 niro 3061 # set dir_index top, to speed up things with hashed b-trees
213 niro 2664 # allow acls too
214 niro 3070 tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img || die
215 niro 3061 # strip the journal
216 niro 3070 # tune2fs -O^has_journal ${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img || die
217 niro 3061 # fsck after journal removal
218 niro 3070 # fsck ${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img || die
219 niro 2664
220     # losetup the device
221     loopdev=$(losetup -f)
222     [[ -z ${loopdev} ]] && die "No unused loopdev found. Maybe you want 'modprobe loop'?"
223    
224     # mount the image
225 niro 3070 losetup ${loopdev} ${LIVECDROOT}/network-squashfs-temp/LiveOS/ext3fs.img || die
226     mount ${loopdev} ${LIVECDROOT}/network-squashfs-temp/mnt || die
227 niro 2664
228     # copy everything to the image file and preserve permissions
229 niro 3070 ( cd ${LIVECDROOT}/netboot-temp && tar cpf - . ) | ( cd ${LIVECDROOT}/network-squashfs-temp/mnt && tar xvpf - )
230 niro 2664 sleep 3
231    
232     # now umount everything and create the squashfs image
233 niro 3070 umount ${LIVECDROOT}/network-squashfs-temp/mnt || die
234 niro 2664 losetup -d ${loopdev} || die
235     # remove mount to not ending up in the squashfs image
236 niro 3070 if [[ -d ${LIVECDROOT}/network-squashfs-temp/mnt ]]
237 niro 2664 then
238 niro 3070 rm -r ${LIVECDROOT}/network-squashfs-temp/mnt || die
239 niro 2664 fi
240 niro 3070 mksquashfs ${LIVECDROOT}/network-squashfs-temp ${CDISOROOT}/netboot/squashfs.img || die
241 niro 2664
242 niro 2872 # copy kernel, bootloader and create initramfs to isoroot/netboot
243 niro 2664 install -d ${CDISOROOT}/netboot || die
244     # kernel
245     kimg="$(find ${CDCHROOTDIR}/boot -name kernel-\* -printf '%f\n')"
246     install ${CDCHROOTDIR}/boot/${kimg} ${CDISOROOT}/netboot/${CDKERNELNAME} || die
247     # initrd
248     install -d ${CDCHROOTDIR}/etc/dracut.conf.d || die
249 niro 2873 echo 'add_dracutmodules+=" livenet busybox "' > ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
250 niro 3061 echo 'omit_dracutmodules+=" mcored "' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
251     echo 'hostonly="no"' >> ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
252 niro 2664 # install dracut-dev package to have all modules
253 niro 2872 custom_packages install "dracut-dev curl curl-dev" || die
254 niro 2664 ## mlivecdbuild function
255     generate_initrd
256     mv ${CDISOROOT}/isolinux/initrd.gz ${CDISOROOT}/netboot/ || die
257 niro 3061 # fix initrd permissions
258     chmod 0644 ${CDISOROOT}/netboot/initrd.gz || die
259 niro 2664 if [ -e ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf ]
260     then
261     rm ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf
262     fi
263 niro 3061 # bootloader pxelinux
264     install -d ${CDISOROOT}/netboot/pxelinux/pxelinux.cfg
265     [ -f $(get_profile netboot/pxelinux.0) ] && install -m0644 $(get_profile netboot/pxelinux.0) ${CDISOROOT}/netboot/pxelinux/
266     [ -f $(get_profile netboot/pxelinux.cfg/pxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/pxelinux-default) ${CDISOROOT}/netboot/pxelinux/pxelinux.cfg
267     [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${CDISOROOT}/netboot/pxelinux/
268     [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${CDISOROOT}/netboot/pxelinux/
269     [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${CDISOROOT}/netboot/pxelinux/
270     [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${CDISOROOT}/netboot/pxelinux/
271     [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${CDISOROOT}/netboot/pxelinux/
272     [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${CDISOROOT}/netboot/pxelinux/
273     # bootloader lpxelinux
274     install -d ${CDISOROOT}/netboot/lpxelinux/pxelinux.cfg
275     [ -f $(get_profile netboot/lpxelinux.0) ] && install -m0644 $(get_profile netboot/lpxelinux.0) ${CDISOROOT}/netboot/lpxelinux/
276     [ -f $(get_profile netboot/ldlinux.c32) ] && install -m0644 $(get_profile netboot/ldlinux.c32) ${CDISOROOT}/netboot/lpxelinux/
277     [ -f $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/lpxelinux-default) ${CDISOROOT}/netboot/lpxelinux/pxelinux.cfg
278     [ -f $(get_profile netboot/pxelinux.cfg/boot.cat) ] && install -m0644 $(get_profile netboot/pxelinux.cfg/boot.cat) ${CDISOROOT}/netboot/lpxelinux/
279     [ -f $(get_profile boot.lss) ] && install -m0644 $(get_profile boot.lss) ${CDISOROOT}/netboot/lpxelinux/
280     [ -f $(get_profile boot.msg) ] && install -m0644 $(get_profile boot.msg) ${CDISOROOT}/netboot/lpxelinux/
281     [ -f $(get_profile debug.msg) ] && install -m0644 $(get_profile debug.msg) ${CDISOROOT}/netboot/lpxelinux/
282     [ -f $(get_profile help.msg) ] && install -m0644 $(get_profile help.msg) ${CDISOROOT}/netboot/lpxelinux/
283     [ -f $(get_profile index.msg) ] && install -m0644 $(get_profile index.msg) ${CDISOROOT}/netboot/lpxelinux/
284 niro 2664
285     # final cleanup
286 niro 3070 if [[ -z ${SKIP_REMOVE_INSTALLROOT} ]]
287 niro 2664 then
288 niro 3070 if [[ -d ${LIVECDROOT}/network-squasfs-temp ]]
289     then
290     rm -r ${LIVECDROOT}/network-squasfs-temp || die
291     fi
292     if [[ -d ${LIVECDROOT}/netboot-temp ]]
293     then
294     rm -r ${LIVECDROOT}/netboot-temp
295     fi
296 niro 2664 fi
297     }
298    
299 niro 3061 ##
300     # create the server tarball
301     ##
302     create_server_tarball()
303     {
304     install -d ${LIVECDROOT}/server-temp
305     install -d ${CDISOROOT}/server
306    
307     mage-bootstrap \
308     --root ${LIVECDROOT}/server-temp \
309     --profile ${MAGE_PROFILE} \
310     --magerc ${MAGERC} \
311     --toolchain ${TOOLCHAIN} \
312     --update-tarball \
313     --basesystem serversystem || die "bootstrapping target system failed!"
314    
315    
316     # enable getty1
317     install -d ${LIVECDROOT}/server-temp/etc/systemd/system/getty.target.wants
318     ln -snf /usr/lib/systemd/system/getty@.service ${LIVECDROOT}/server-temp/etc/systemd/system/getty.target.wants/getty@tty1.service
319    
320     # be more verbose
321     sed -i 's:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1"rd.info":' ${LIVECDROOT}/server-temp/etc/conf.d/grub
322    
323     # remove phpmyadmin configuration directory
324     if [ -d ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config ]
325     then
326     rm -r ${LIVECDROOT}/server-temp/usr/share/phpmyadmin/config
327     fi
328    
329 niro 3070 # os config
330     prepare_custom_baseconfig "${LIVECDROOT}/server-temp" "alx-svr-${CDOSARCH}" "magellan-linux.de"
331    
332 niro 3061 # fix certificate issues with mcored (common name of cert issuer) and >php-5.4
333     echo "127.0.0.1 mcored" >> ${LIVECDROOT}/server-temp/etc/hosts
334    
335     # create tarball
336 niro 3070 prepare_custom_installertarball "${LIVECDROOT}/server-temp" "alx-svr-${CDOSARCH}" "${CDISOROOT}/server"
337 niro 3061 }
338    
339 niro 2119 # set an empty root password
340     chroot ${CDCHROOTDIR} passwd -d root
341    
342     # install a custom boot-duration matching this livecd
343     install -d ${CDCHROOTDIR}/var/lib/plymouth || die
344     install -m 0644 $(get_profile boot-duration.livecd) ${CDCHROOTDIR}/var/lib/plymouth/boot-duration || die
345    
346 niro 2661 # setup de keymap and locales
347     if [ -f ${CDCHROOTDIR}/etc/vconsole.conf ]
348     then
349 niro 2663 cat > ${CDCHROOTDIR}/etc/vconsole.conf << EOF || die
350 niro 2661 KEYMAP=de
351     KEYMAP_TOGGLE=
352     FONT=lat9w-16
353     FONT_MAP=8859-1_to_uni
354     FONT_UNIMAP=
355     EOF
356     fi
357     if [ -f ${CDCHROOTDIR}/etc/locale.conf ]
358     then
359 niro 2662 sed -i "s:^\(LANG=\).*:\1\"de_DE.utf8\":" ${CDCHROOTDIR}/etc/locale.conf || die
360 niro 2661 fi
361    
362 niro 2119 # stop here if the user don't want to create the install tarball
363 niro 2664 [[ -n ${SKIP_CREATE_INSTALL_TARBALL} ]] || create_install_tarball
364 niro 2119
365 niro 3070 # stop here if the user don't want to create the netboot image
366     [[ -n ${SKIP_CREATE_NETBOOT_TARBALL} ]] || create_netboot_image
367    
368 niro 3061 # stop here if the user don't want to create the server tarball
369     [[ -n ${SKIP_CREATE_SERVER_TARBALL} ]] || create_server_tarball
370    
371 niro 2119 # install usb-install script
372     [ ! -d ${CDISOROOT}/usb-install ] && mkdir ${CDISOROOT}/usb-install
373     [ -f $(get_profile usb-install/usb-install.cmd) ] && cp $(get_profile usb-install)/usb-install.cmd ${CDISOROOT}/usb-install
374     [ -f $(get_profile usb-install/syslinux.exe) ] && cp $(get_profile usb-install)/syslinux.exe ${CDISOROOT}/usb-install
375     [ -f $(get_profile usb-install/syslinux.cfg) ] && cp $(get_profile usb-install)/syslinux.cfg ${CDISOROOT}/usb-install
376 niro 3061
377     # add installer-server script
378     cat > ${CDCHROOTDIR}/usr/bin/installer-server << EOF
379     #!/bin/bash
380     /usr/bin/installer --imageroot /run/initramfs/live/server
381     EOF
382     chmod 0755 ${CDCHROOTDIR}/usr/bin/installer-server