summaryrefslogtreecommitdiff
path: root/tst
blob: a7da2d89d6201da7b6d9a27c4d5f557dd17a10ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#! /bin/sh


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function switch_disk {
  disk=$1
  tmp=tmp

  if [ -z "$disk" -o ! -f "$tmp/syslinux.img_$disk" ] ; then
    echo "usage:"
    echo "  tst -d disk_number"
    exit 1
  fi

  dd if="$tmp/syslinux.img_$disk" of="$tmp/syslinux.img" conv=notrunc status=noxfer
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function tst_isolinux {
  bin="test/syslinux.rpm"
  src="test/$1"
  dst="$tmp/$1"
  img="$tmp/$1.iso"
  vm_src=test/vm
  vm_tmp=tmp/$1.vm
  isolx=$bin/usr/share/syslinux/isolinux.bin

  rm -rf $dst $vm_tmp
  rm -f $img

  isodir32=boot/i386/loader
  isodir64=boot/x86_64/loader
  mkdir -p $dst/$isodir32 $dst/$isodir64
  cp $isolx $dst/$isodir32/isolinux.bin
  cp $isolx $dst/$isodir64/isolinux.bin
  test/syslinux.rpm/usr/bin/isolinux-config --base=$isodir32 $dst/$isodir32/isolinux.bin
  test/syslinux.rpm/usr/bin/isolinux-config --base=$isodir64 $dst/$isodir64/isolinux.bin

  cp -a $src/* $dst/$isodir32
  rm -f $dst/$isodir32/{linux,initrd}64
  cp -a $logo $dst/$isodir32/bootlogo
  bin/unpack_bootlogo $dst/$isodir32

  cp -a $src/* $dst/$isodir64
  [ -f $dst/$isodir64/linux64 ] && mv $dst/$isodir64/linux64 $dst/$isodir64/linux
  [ -f $dst/$isodir64/initrd64 ] && mv $dst/$isodir64/initrd64 $dst/$isodir64/initrd
  cp -a $logo $dst/$isodir64/bootlogo
  bin/unpack_bootlogo $dst/$isodir64

  test/2hl --link --quiet $dst

  echo "$dst/$isodir32/isolinux.bin 1" >$tmp/cd_sort
  echo "$dst/$isodir64/isolinux.bin 1" >>$tmp/cd_sort

  rm -f `find $dst/boot -name \*~`

  # rm -r $dst/boot/x86_64

  mkisofs -o $img -J -r -sort $tmp/cd_sort \
    -b $isodir32/isolinux.bin -c $isodir32/boot.catalog \
    -publisher "Tester" \
    -no-emul-boot -boot-load-size 4 -boot-info-table $dst

  tagmedia --check --md5 $img

  rm -f $tmp/cd_sort

  if [ "$program" = vmware ] ; then
    # vmware
    cp -a $vm_src $vm_tmp
    perl -pi -e "s/^\s*#\s*(floppy0.startConnected)/\$1/" $vm_tmp/gfxboot.vmx
    perl -pi -e "s:<isoimage>:`pwd`/$img:g" $vm_tmp/gfxboot.vmx
    vmplayer $vm_tmp/gfxboot.vmx
  elif [ "$program" = qemu ] ; then
    # qemu
    $qemu -cdrom $img -serial pty
  elif [ "$program" = bd ] ; then
    # bochs debug wrapper
    bd $img
  elif [ "$program" = bochs ] ; then
    # bochs
    bochs -q 'boot: cdrom' "ata0-master: type=cdrom, path=$img, status=inserted" 'log: /dev/null' 'parport1: enabled=0'
  else
    echo -e "\n***  Error: $program not supported  ***\n"
  fi
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function tst_lilo {
  bin="test/lilo.rpm"
  src="test/$1"
  dst="$tmp/$1"
  img="$tmp/$1.img"
  vm_src=test/vm
  vm_tmp=tmp/$1.vm

  rm -rf $dst $vm_tmp
  rm -f $img

  mkdir -p $dst/boot
  cp -a $src/* $dst/boot
  cp -a $logo $dst/boot/message

  for i in /boot/vmlinuz /boot/initrd ; do
    [ -f $i ] && cp --parents $i $dst
  done

  test/hdimg $img

  sw 0 mount -oloop=/dev/loop7,offset=32256 $img /mnt
  sw 0 cp -r $dst/* /mnt
  sw 0 losetup /dev/loop6 $img
  sw 0 $bin/sbin/lilo -w -C /mnt/boot/lilo.conf -m /mnt/boot/map
  sw 0 losetup -d /dev/loop6
  sw 0 umount /mnt

  if [ "$program" = vmware ] ; then
    # vmware
    cp -a $vm_src $vm_tmp
    perl -pi -e "s/^\s*#\s*(ide1:0.startConnected)/\$1/" $vm_tmp/gfxboot.vmx
    perl -pi -e "s:<floppyimage>:`pwd`/$img:g" $vm_tmp/gfxboot.vmx
    vmware -qx $vm_tmp/gfxboot.vmx
  elif [ "$program" = qemu ] ; then
    # qemu
    $qemu -boot c -hda $img
  elif [ "$program" = bd ] ; then
    # bochs debug wrapper
    bd $img
  elif [ "$program" = bochs ] ; then
    # bochs
    bochs -q 'boot: a' "floppya: image=$img, status=inserted" 'log: /dev/null' 'ata0-master: type=disk, path=/dev/null' 'parport1: enabled=0'
  else
    echo -e "\n***  Error: $program not supported  ***\n"
  fi
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function tst_grub {
  bin="test/grub.rpm"
  src="test/$1"
  dst="$tmp/$1"
  img="$tmp/$1.img"
  vm_src=test/vm
  vm_tmp=tmp/$1.vm

  rm -rf $dst $vm_tmp
  rm -f $img

  mkdir -p $dst/boot
  cp -a $src/* $dst/boot
  cp $bin/usr/lib/grub/{fat_stage1_5,stage1,stage2} $dst/boot/grub
  cp -a $logo $dst/boot/message
  for i in /boot/vmlinuz /boot/initrd ; do
    [ -f $i ] && cp --parents $i $dst
  done

  sh -c "echo '(hd0) $img' >$dst/boot/grub/device.map"

  test/hdimg $img

  sw 0 mount -oloop,offset=32256 "$img" /mnt
  sw 0 cp -r $dst/* /mnt
  sw 0 umount /mnt

  echo "setup --prefix=/boot/grub (hd0,0) (hd0,0)" | \
  $bin/usr/sbin/grub --batch --config-file=$dst/boot/grub/menu.lst --device-map=$dst/boot/grub/device.map
  echo

  if [ "$program" = vmware ] ; then
    # vmware
    #cp -a $vm_src $vm_tmp
    #perl -pi -e "s/^\s*#\s*(ide1:0.startConnected)/\$1/" $vm_tmp/gfxboot.vmx
    #perl -pi -e "s:<floppyimage>:`pwd`/$img:g" $vm_tmp/gfxboot.vmx
    #vmplayer $vm_tmp/gfxboot.vmx
    vm --vm vmplayer --disk $img
  elif [ "$program" = qemu ] ; then
    # qemu
    $qemu -boot c -hda $img
  elif [ "$program" = bd ] ; then
    # bochs debug wrapper
    bd $img
  elif [ "$program" = bochs ] ; then
    # bochs
    bochs -q 'boot: a' "floppya: image=$img, status=inserted" 'log: /dev/null' 'ata0-master: type=disk, path=/dev/null' 'parport1: enabled=0'
  else
    echo -e "\n***  Error: $program not supported  \n"
  fi
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function tst_syslinux {
  bin="test/syslinux.rpm"
  src="test/$1"
  dst="$tmp/$1"
  img="$tmp/$1.img"
  vm_src=test/vm
  vm_tmp=tmp/$1.vm
  syslx=$bin/usr/bin/syslinux-nomtools

  rm -rf $dst $vm_tmp
  rm -f $img*

  mkdir -p $dst
  cp -a $src/* $dst
  cp -a $logo $dst/bootlogo

  rm -f $dst/*~
  bin/unpack_bootlogo $dst

  sw 0 test/mkbootdisk --syslinux=$syslx --out=${img}_ $dst

  sw 0 chown --reference=tmp $img*

  cp $dst.img_01 $img

  if [ "$program" = vmware ] ; then
    # vmware
    cp -a $vm_src $vm_tmp
    perl -pi -e "s/^\s*#\s*(ide1:0.startConnected)/\$1/" $vm_tmp/gfxboot.vmx
    perl -pi -e "s:<floppyimage>:`pwd`/$img:g" $vm_tmp/gfxboot.vmx
    vmware -qx $vm_tmp/gfxboot.vmx
  elif [ "$program" = qemu ] ; then
    # qemu
    $qemu -boot a -fda $img
  elif [ "$program" = bd ] ; then
    # bochs debug wrapper
    bd $img
  elif [ "$program" = bochs ] ; then
    # bochs
    bochs -q 'boot: a' "floppya: image=$img, status=inserted" 'log: /dev/null' 'ata0-master: type=disk, path=/dev/null' 'parport1: enabled=0'
  else
    echo -e "\n***  Error: $program not supported  ***\n"
  fi
}



# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function usage {
  echo "usage: tst [-b] [-d floppy_nr] [-i] [-l language] [-p program] [-s test_src_dir] [-t theme] what"
  exit 1
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

qemu=qemu

while getopts bd:hil:p:s:t:x opt ; do
  case $opt in
    \:|\?|h) usage
      ;;

    b) logo=boot
      ;;

    d) disk=$OPTARG
      ;;

    i) logo=install
      ;;

    l) lang="DEFAULT_LANG=$OPTARG"
      ;;

    p) program=$OPTARG
      ;;

    s) src=$OPTARG
      ;;

    t) theme=$OPTARG
      ;;

    x) qemu=qemu-system-x86_64
      ;;
  esac
done
shift $(($OPTIND - 1))

if [ "$disk" ] ; then
  switch_disk $disk
  exit
fi

theme=${theme:-openSUSE}

program=${program:-qemu}

what=$1
what=${what:-cdrom}

[ "$what" = cdrom ] && what=isolinux
[ "$what" = cd ] && what=isolinux
[ "$what" = floppy ] && what=syslinux

if [ ! "$logo" ] ; then
  logo=boot
  [ "$what" = syslinux -o "$what" = isolinux ] && logo=install
fi

[ "$logo" = "boot" ] && logo="themes/$theme/message"
[ "$logo" = "install" ] && logo="themes/$theme/bootlogo"

[ "$BOOTLOGO" ] && logo=$BOOTLOGO

[ -x gfxboot-compile ] || {
  echo "error: gfxboot-compile missing. Try make."
  exit 2
}

if [ ! "$what" ] ; then
  echo "What is "\""$what"\""?"
  usage
fi

# make BINDIR=../../ -C themes/$theme prep
make -C themes/$theme $lang || exit

[ -f "$logo" ] || logo="themes/$theme/bootlogo"

if [ ! -f "$logo" ] ; then
  echo "no such file: $logo"
  usage
fi

tmp=tmp
mkdir -p "$tmp" || exit

if [ -z "$src" ] ; then
  src=$what
  [ $what = isolinux ] && src=syslinux
fi

if [ ! -d test/$src ] ; then
  echo "no such directory: $src"
  usage
fi

if [ "`type -t tst_$what`" = function ] ; then
  tst_$what $src
else
  echo "What is "\""$what"\""?"
  usage
fi