+ed
[nethome.git] / src / OOo-LiveCD.sh
1 #! /bin/bash
2 # $Id$
3
4 set -ex
5 SIZE=2021654528
6 BASE=OOo-LiveCD
7 BIN=$BASE.bin
8 ISO64=$BASE-x86_64.iso
9 ISO32=$BASE-i686.iso
10 ISO=$BASE.iso
11 KS=$BASE.ks
12 SELF=$BASE.sh
13 # $PWD: rpm: arguments to --root (-r) must begin with a /
14 MNT=$PWD/$BASE.mnt
15 # Cheat livecd-iso-to-disk getdisk():
16 LOOPDEV=/dev/loop-$BASE.dev
17 LOOPDEVMK="mknod $LOOPDEV b 7 0"
18 LOOPDEV1=/dev/loop-$BASE.dev1
19 LOOPDEV1MK="mknod $LOOPDEV1 b 7 1"
20
21 set -o pipefail
22 renice +19 -p $$
23 ionice -c3 -p $$
24 test "`uname -m`" = "x86_64"
25 test ! -e $BIN
26 test ! -e $ISO
27 test ! -e $LOOPDEV
28 test ! -e $LOOPDEV1
29 test ! -e $MNT
30 test -e $SELF
31
32 if [ ! -e $ISO64 ];then
33   test -e "$KS"
34   livecd-creator --config=$KS --fslabel=$BASE --cache=/var/cache/live
35   test -e $ISO
36   mv -f $ISO $ISO64
37 fi
38 if [ ! -e $ISO32 ];then
39   test -e "$KS"
40   setarch i686 livecd-creator --config=$KS --fslabel=$BASE --cache=/var/cache/live
41   test -e $ISO
42   mv -f $ISO $ISO32
43 fi
44
45 $LOOPDEVMK
46 test "`losetup $LOOPDEV 2>&1|tee /proc/self/fd/2`" = "loop: can't get info on device $LOOPDEV: No such device or address"
47 $LOOPDEV1MK
48 test "`losetup $LOOPDEV1 2>&1|tee /proc/self/fd/2`" = "loop: can't get info on device $LOOPDEV1: No such device or address"
49
50 dd if=/dev/zero of=$BIN bs=1 seek=$[SIZE-1] count=1
51 losetup $LOOPDEV $BIN
52 losetup -o $[34*512] $LOOPDEV1 $LOOPDEV
53 # --overlay-size-mb 100 --home-size-mb 100
54 echo | livecd-iso-to-disk --unencrypted-home --livedir $BASE-i686 --format --reset-mbr $ISO32 $LOOPDEV
55 mkdir $MNT
56 mount $LOOPDEV1 $MNT
57 UUID1="$(sed <$MNT/syslinux/syslinux.cfg -n 's/^.* root=live:UUID=\([0-9A-Z]*-[0-9A-Z]*\) .*$/\1/p'|uniq)"
58 test -n "$UUID1"
59 mv $MNT/syslinux/initrd0.img $MNT/syslinux/initrd1.img
60 mv $MNT/syslinux/vmlinuz0 $MNT/syslinux/vmlinuz1
61 umount $MNT
62 rmdir $MNT
63 livecd-iso-to-disk --unencrypted-home --livedir $BASE-x86_64 $ISO64 $LOOPDEV1
64 mkdir $MNT
65 mount $LOOPDEV1 $MNT
66 UUID0="$(sed <$MNT/syslinux/syslinux.cfg -n 's/^.* root=live:UUID=\([0-9A-Z]*-[0-9A-Z]*\) .*$/\1/p'|uniq)"
67 test -n "$UUID0"
68 cp -p /usr/share/syslinux/ifcpu64.c32 $MNT/syslinux/
69 cat >$MNT/syslinux/syslinux.cfg <<EOH
70
71 default vesamenu.c32
72 timeout 100
73
74 menu background splash.jpg
75 menu title Welcome to $BASE!
76 menu color border 0 #ffffffff #00000000
77 menu color sel 7 #ffffffff #ff000000
78 menu color title 0 #ffffffff #00000000
79 menu color tabmsg 0 #ffffffff #00000000
80 menu color unsel 0 #ffffffff #00000000
81 menu color hotsel 0 #ff000000 #ffffffff
82 menu color hotkey 7 #ffffffff #ff000000
83 menu color timeout_msg 0 #ffffffff #00000000
84 menu color timeout 0 #ffffffff #00000000
85 menu color cmdline 0 #ffffffff #00000000
86 menu hidden
87 menu hiddenrow 5
88 label detect
89   menu label Autoselect x86_64 / i686 Boot
90   kernel ifcpu64.c32
91   append linux0 -- linux1
92 menu default
93 label linux0
94   menu label Boot x86_64
95   kernel vmlinuz0
96   append initrd=initrd0.img root=live:UUID=$UUID0 rootfstype=vfat ro liveimg live_dir=$BASE-x86_64 quiet  rhgb rd_NO_LUKS rd_NO_MD noiswmd 
97 label check0
98   menu label Verify and Boot x86_64
99   kernel vmlinuz0
100   append initrd=initrd0.img root=live:UUID=$UUID0 rootfstype=vfat ro liveimg live_dir=$BASE-x86_64 quiet  rhgb check
101 label linux1
102   menu label Boot i686
103   kernel vmlinuz1
104   append initrd=initrd1.img root=live:UUID=$UUID1 rootfstype=vfat ro liveimg live_dir=$BASE-i686 quiet  rhgb rd_NO_LUKS rd_NO_MD noiswmd 
105 label check1
106   menu label Verify and Boot i686
107   kernel vmlinuz1
108   append initrd=initrd1.img root=live:UUID=$UUID1 rootfstype=vfat ro liveimg live_dir=$BASE-i686 quiet  rhgb check
109 label memtest
110   menu label Memory Test
111   kernel memtest
112 label local
113   menu label Boot from local drive
114   localboot 0xffff
115 EOH
116 cp -p $SELF $MNT/
117 if [ -e "$KS" ];then
118   cp -p $KS $MNT/
119 fi
120 umount $MNT
121
122 mkdir $MNT/{a,b,c}
123 mount    -o loop $LOOPDEV1 $MNT/a
124 mount -r -o loop $MNT/a/$BASE-x86_64/squashfs.img $MNT/b
125 mount -r -o loop $MNT/b/LiveOS/ext3fs.img $MNT/c
126 rpm -r $MNT/c -qa|sort >$MNT/a/$BASE-x86_64/rpm-qa
127 umount $MNT/{c,b}
128 mount -r -o loop $MNT/a/$BASE-i686/squashfs.img $MNT/b
129 mount -r -o loop $MNT/b/LiveOS/ext3fs.img $MNT/c
130 rpm -r $MNT/c -qa|sort >$MNT/a/$BASE-i686/rpm-qa
131 umount $MNT/{c,b}
132 diff -u <(sed 's/\.x86_64$//' <$MNT/a/$BASE-x86_64/rpm-qa) <(sed 's/\.i686$//' <$MNT/a/$BASE-i686/rpm-qa) || :
133 umount $MNT/a
134 rmdir $MNT/{c,b,a}
135
136 rmdir $MNT
137 losetup -d $LOOPDEV1
138 rm -f $LOOPDEV1
139 losetup -d $LOOPDEV
140 rm -f $LOOPDEV
141 # livecd-iso-to-disk resetMBR does not work due to /dev/loop*.
142 dd bs=1 if=/usr/share/syslinux/mbr.bin of=$BIN conv=notrunc
143 echo OK