Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3073 - (show annotations) (download)
Fri Sep 1 10:04:36 2017 UTC (6 years, 7 months ago) by niro
File size: 13288 byte(s)
-reorganized directory structure
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 # prepare_custom_baseconfig $_OSROOT $_OSHOSTNAME $_OSHOSTDOMAIN
30 prepare_custom_baseconfig()
31 {
32 local _OSROOT="$1"
33 local _OSHOSTNAME="$2"
34 local _OSHOSTDOMAIN="$3"
35 if [[ -z ${_OSROOT} ]]
36 then
37 echo "no _OSROOT given"
38 return 1
39 fi
40 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
56 # generate a new machine-id on first-boot
57 :> ${_OSROOT}/etc/machine-id
58
59 # fix localtime symlink
60 ln -snf ../usr/share/zoneinfo/Europe/Berlin ${_OSROOT}/etc/localtime
61
62 # activate timeserver via dhcp (NTP - option 42)
63 CDCHROOTDIR=${_OSROOT} custom_services add systemd-timesyncd.service
64
65 # empty root password
66 chroot ${_OSROOT} passwd -d root
67
68 # empty user password
69 chroot ${_OSROOT} passwd -d station
70
71 if [ -x ${_OSROOT}/usr/bin/mcorepasswd ] ||
72 [ -L ${_OSROOT}/usr/bin/mcorepasswd ]
73 then
74 # add mcored default user
75 ( echo "foobar"; sleep 0.1; echo "foobar" ) | chroot ${_OSROOT} /usr/bin/mcorepasswd mcore
76 fi
77
78 # fix hostname and hosts file
79 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 ::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 }
90
91 # 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 # create tarball
119 [[ -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
122 # create images.conf
123 echo "CDIMAGENAME=${_TARBALLNAME}.tar.bz2" > ${_TARBALLTARGET}/images.conf
124 echo "TOTALLINES=$(wc -l ${LIVECDROOT}/${_TARBALLNAME}.log | cut -d' ' -f1)" >> ${_TARBALLTARGET}/images.conf
125
126 # clean up
127 if [[ -z ${SKIP_REMOVE_INSTALLROOT} ]]
128 then
129 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 fi
138 }
139
140 ##
141 # create the install tarball
142 ##
143 create_install_tarball()
144 {
145 install -d ${LIVECDROOT}/install-chroot
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-chroot \
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-chroot/etc/mcore/mcore.conf"
161 # updateconfig MCORE_CONTROL_SERVER
162 ###
163
164 # fix missing symlink
165 if [ ! -L ${LIVECDROOT}/install-chroot/usr/bin/X ]
166 then
167 ln -snf Xorg ${LIVECDROOT}/install-chroot/usr/bin/X
168 fi
169
170 # os config
171 prepare_custom_baseconfig "${LIVECDROOT}/install-chroot" "alx-${CDOSARCH}" "magellan-linux.de"
172
173 # create tarball
174 prepare_custom_installertarball "${LIVECDROOT}/install-chroot" "alx-${CDOSARCH}" "${CDISOROOT}/system"
175 }
176
177 ##
178 # create the network image
179 ##
180 create_netboot_image()
181 {
182 install -d ${CDISOROOT}/netboot
183 install -d ${LIVECDROOT}/netboot-chroot
184 install -d ${LIVECDROOT}/netboot-squashfs
185
186 # use all settings from the global config, but use netbootsysten as basesystem
187 mage-bootstrap \
188 --root ${LIVECDROOT}/netboot-chroot \
189 --profile ${MAGE_PROFILE} \
190 --magerc ${MAGERC} \
191 --toolchain ${TOOLCHAIN} \
192 --update-tarball \
193 --basesystem netbootsystem || die "bootstrapping target system failed!"
194
195 # os config
196 prepare_custom_baseconfig "${LIVECDROOT}/netboot-chroot" "alx-${CDOSARCH}" "magellan-linux.de"
197
198 # creating netboot image from here on
199 install -d ${LIVECDROOT}/netboot-squashfs/{LiveOS,mnt} || die
200
201 # fix fstab, use the livecd fstab without rootfs and swap
202 install -m 0644 $(get_profile fstab) ${LIVECDROOT}/netboot-chroot/etc/fstab || die
203
204 # get the actual size of the chroot
205 size=$(du -s ${LIVECDROOT}/netboot-chroot | sed 's:^\(.*\)[[:space:]].*:\1:')
206
207 # generate a ext3fs file for devicemapper
208 dd if=/dev/zero of=${LIVECDROOT}/netboot-squashfs/LiveOS/ext3fs.img bs=1024 count=$(( ${size} + 20000 )) || die
209 # create a filesystem
210 mkfs.ext3 -L "_${CDID}_EXT3" -m 1 -b 1024 -F ${LIVECDROOT}/netboot-squashfs/LiveOS/ext3fs.img || die
211 # set mount_counts and check_intervals to 0
212 # set dir_index top, to speed up things with hashed b-trees
213 # allow acls too
214 tune2fs -c0 -i0 -Odir_index -ouser_xattr,acl ${LIVECDROOT}/netboot-squashfs/LiveOS/ext3fs.img || die
215 # strip the journal
216 # tune2fs -O^has_journal ${LIVECDROOT}/netboot-squashfs/LiveOS/ext3fs.img || die
217 # fsck after journal removal
218 # fsck ${LIVECDROOT}/netboot-squashfs/LiveOS/ext3fs.img || die
219
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 losetup ${loopdev} ${LIVECDROOT}/netboot-squashfs/LiveOS/ext3fs.img || die
226 mount ${loopdev} ${LIVECDROOT}/netboot-squashfs/mnt || die
227
228 # copy everything to the image file and preserve permissions
229 ( cd ${LIVECDROOT}/netboot-chroot && tar cpf - . ) | ( cd ${LIVECDROOT}/netboot-squashfs/mnt && tar xvpf - )
230 sleep 3
231
232 # now umount everything and create the squashfs image
233 umount ${LIVECDROOT}/netboot-squashfs/mnt || die
234 losetup -d ${loopdev} || die
235 # remove mount to not ending up in the squashfs image
236 if [[ -d ${LIVECDROOT}/netboot-squashfs/mnt ]]
237 then
238 rm -r ${LIVECDROOT}/netboot-squashfs/mnt || die
239 fi
240 mksquashfs ${LIVECDROOT}/netboot-squashfs ${CDISOROOT}/netboot/squashfs.img || die
241
242 # copy kernel, bootloader and create initramfs to isoroot/netboot
243 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 echo 'add_dracutmodules+=" livenet busybox "' > ${CDCHROOTDIR}/etc/dracut.conf.d/03-netboot.conf || die
250 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 # install dracut-dev package to have all modules
253 custom_packages install "dracut-dev curl curl-dev" || die
254 ## mlivecdbuild function
255 generate_initrd
256 mv ${CDISOROOT}/isolinux/initrd.gz ${CDISOROOT}/netboot/ || die
257 # fix initrd permissions
258 chmod 0644 ${CDISOROOT}/netboot/initrd.gz || die
259 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 # 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
285 # final cleanup
286 if [[ -z ${SKIP_REMOVE_INSTALLROOT} ]]
287 then
288 if [[ -d ${LIVECDROOT}/netboot-squashfs ]]
289 then
290 rm -r ${LIVECDROOT}/netboot-squashfs || die
291 fi
292 if [[ -d ${LIVECDROOT}/netboot-chroot ]]
293 then
294 rm -r ${LIVECDROOT}/netboot-chroot
295 fi
296 fi
297 }
298
299 ##
300 # create the server tarball
301 ##
302 create_server_tarball()
303 {
304 install -d ${LIVECDROOT}/server-chroot
305 install -d ${CDISOROOT}/server
306
307 mage-bootstrap \
308 --root ${LIVECDROOT}/server-chroot \
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-chroot/etc/systemd/system/getty.target.wants
318 ln -snf /usr/lib/systemd/system/getty@.service ${LIVECDROOT}/server-chroot/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-chroot/etc/conf.d/grub
322
323 # remove phpmyadmin configuration directory
324 if [ -d ${LIVECDROOT}/server-chroot/usr/share/phpmyadmin/config ]
325 then
326 rm -r ${LIVECDROOT}/server-chroot/usr/share/phpmyadmin/config
327 fi
328
329 # os config
330 prepare_custom_baseconfig "${LIVECDROOT}/server-chroot" "alx-svr-${CDOSARCH}" "magellan-linux.de"
331
332 # fix certificate issues with mcored (common name of cert issuer) and >php-5.4
333 echo "127.0.0.1 mcored" >> ${LIVECDROOT}/server-chroot/etc/hosts
334
335 # create tarball
336 prepare_custom_installertarball "${LIVECDROOT}/server-chroot" "alx-svr-${CDOSARCH}" "${CDISOROOT}/server"
337 }
338
339 # 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 # setup de keymap and locales
347 if [ -f ${CDCHROOTDIR}/etc/vconsole.conf ]
348 then
349 cat > ${CDCHROOTDIR}/etc/vconsole.conf << EOF || die
350 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 sed -i "s:^\(LANG=\).*:\1\"de_DE.utf8\":" ${CDCHROOTDIR}/etc/locale.conf || die
360 fi
361
362 # stop here if the user don't want to create the install tarball
363 [[ -n ${SKIP_CREATE_INSTALL_TARBALL} ]] || create_install_tarball
364
365 # stop here if the user don't want to create the netboot image
366 [[ -n ${SKIP_CREATE_NETBOOT_TARBALL} ]] || create_netboot_image
367
368 # stop here if the user don't want to create the server tarball
369 [[ -n ${SKIP_CREATE_SERVER_TARBALL} ]] || create_server_tarball
370
371 # 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
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