summaryrefslogtreecommitdiffstats
path: root/scripts/upd-bootimage
blob: e583cbc038ea6efa797e99df3fc1b765c037b212 (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
#!/bin/bash

if [ -z "$1" ]; then
    echo "$0: <image> <binary> [<initrdpath>]"
    exit 1
fi

if [ ! -f $1 ]; then
    echo "$1 doesn't exist"
    exit 1
fi

MNTPOINT=/tmp/updboottree.$$
INITRD=/tmp/updboottree.$$.initrd
LOOPMNT=/tmp/updboottree.$$.initrdmnt

rm -rf $MNTPOINT $LOOPMNT
mkdir $MNTPOINT $LOOPMNT
mount -t vfat -o loop $1 $MNTPOINT

gunzip < $MNTPOINT/initrd.img > $INITRD

mount -o loop $INITRD $LOOPMNT

FROM=$2
TO=$FROM
if [ $(echo $FROM | cut -d- -f1) = loader ]; then
    TO=loader
fi

if [ ! -x $LOOPMNT/sbin/$TO ]; then
    echo "$LOOPMNT/sbin/$TO doesn't exist"
else
    cp $FROM $FROM.foo
    strip $FROM.foo
    install $FROM.foo $LOOPMNT/sbin/$TO
    rm -f $FROM.foo
fi

umount $LOOPMNT
gzip -9 < $INITRD > $INITRD.new
cp $INITRD.new $MNTPOINT/initrd.img
if [ -f $MNTPOINT/efi/boot/initrd.img ]; then
    cp $INITRD.new $MNTPOINT/efi/boot/initrd.img
fi
umount $MNTPOINT

if [ -n "$3" -a -f "$3" ]; then
    echo "Replacing $3"
    cp -f $INITRD.new $3
fi

rm -rf $MNTPOINT $LOOPMNT $INITRD $INITRD.new