update-kernel.in 1.68 KB
Newer Older
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
#!/bin/sh -e

# update-kernel
#
# Kernel and firmware update script for Alpine installations set up
# with setup-bootable
#
# Copyright (c) 2014 Timo Teräs
# Copyright (c) 2014 Kaarle Ritvanen


TMPDIR=
SIGNALS="HUP INT TERM"
SCRIPT=update-kernel
VIRTUAL=.tmp-$SCRIPT

while read MOUNT; do
    set -- $MOUNT
    [ $2 = /.modloop ] || continue
    DESTDIR=$(dirname $(losetup $1 | cut -d " " -f 3))
    MNTDIR=$(dirname $DESTDIR)
    break
done < /proc/mounts

if [ -z "$MNTDIR" ]; then
    echo "Module loopback device not mounted" >&2
    exit 1
fi

remount() {
    mount $1 -o remount $MNTDIR
}


ignore_sigs() {
    trap "" $SIGNALS
}

clean_up() {
    set +e
    ignore_sigs

43
    apk del -q $VIRTUAL
44 45 46 47 48 49
    rm -fr $TMPDIR
}

trap clean_up EXIT $SIGNALS


50
apk add -qU -t $VIRTUAL mkinitfs squashfs-tools
51 52 53 54 55 56 57 58

. /etc/mkinitfs/mkinitfs.conf

ARCH=$(apk --print-arch)
FLAVOR=$(uname -r | cut -d - -f 3-)
TMPDIR=$(mktemp -dt $SCRIPT.XXXXXX)
ROOT=$TMPDIR/root

59 60 61 62 63 64 65 66 67
_apk() {
    apk add -q -p $ROOT --no-scripts --arch $ARCH --keys-dir /etc/apk/keys \
	--repositories-file /etc/apk/repositories $*
}

_apk -U --initdb alpine-base linux-$FLAVOR linux-firmware
_apk dahdi-linux dahdi-linux-$FLAVOR || :
_apk xtables-addons-$FLAVOR || :

68 69 70 71 72 73 74 75 76 77 78 79 80 81

KVER=$(ls $ROOT/lib/modules)
depmod -b $ROOT $KVER


STAGING=$TMPDIR/boot
MODLOOP=$TMPDIR/modloop
MODIMG=$FLAVOR.modloop.squashfs

mkdir $MODLOOP $STAGING
cp -a $ROOT/lib/modules $MODLOOP
cp -a $ROOT/lib/firmware $MODLOOP/modules
mksquashfs $MODLOOP $STAGING/$MODIMG -comp xz

82
mkinitfs -q -F "$features squashfs" -b $ROOT -o $STAGING/$FLAVOR.gz $KVER
83 84 85 86 87 88 89 90 91 92 93 94 95 96
cp $ROOT/boot/vmlinuz-$FLAVOR $STAGING/$FLAVOR


ignore_sigs
remount -w

rm -f $DESTDIR/$MODIMG
mv $STAGING/* $DESTDIR

set +e
sync
remount -r

exit 0