Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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