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