update-kernel.in 2.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/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

17 18 19 20 21 22 23 24 25

DESTDIR=$1
MNTDIR=

if [ -z "$DESTDIR" ]; then
    while read MOUNT; do
	set -- $MOUNT
	[ $2 = /.modloop ] || continue
	DESTDIR=$(dirname $(losetup $1 | cut -d " " -f 3))
26
	MNTDIR=$(dirname "$DESTDIR")
27 28 29 30 31 32 33
	break
    done < /proc/mounts

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

remount() {
37
    mount $1 -o remount "$MNTDIR"
38 39 40 41 42 43 44 45 46 47 48
}


ignore_sigs() {
    trap "" $SIGNALS
}

clean_up() {
    set +e
    ignore_sigs

49
    apk del -q $VIRTUAL
50
    rm -fr "$TMPDIR"
51 52 53 54 55
}

trap clean_up EXIT $SIGNALS


56
apk add -qU -t $VIRTUAL mkinitfs squashfs-tools
57 58 59 60

. /etc/mkinitfs/mkinitfs.conf

FLAVOR=$(uname -r | cut -d - -f 3-)
61 62 63 64 65 66
KVER_FLAVOR=-$FLAVOR
if [ -z "$FLAVOR" ]; then
    FLAVOR=vanilla
    KVER_FLAVOR=
fi

67 68 69
TMPDIR=$(mktemp -dt $SCRIPT.XXXXXX)
ROOT=$TMPDIR/root

70
_apk() {
71 72 73
    local cmd=$1
    shift
    apk $cmd -p "$ROOT" --keys-dir /etc/apk/keys \
74 75 76
	--repositories-file /etc/apk/repositories $*
}

77 78 79 80 81 82 83 84 85 86 87 88 89 90
add_pkgs() {
    _apk add -q --no-scripts $*
}

extra_pkgs() {
    local res=$(_apk search -x $1)
    if [ "$res" ]; then
	add_pkgs $*
    fi
}

add_pkgs -U --initdb alpine-base linux-$FLAVOR linux-firmware
extra_pkgs dahdi-linux-$FLAVOR dahdi-linux
extra_pkgs xtables-addons-$FLAVOR
91

92

93 94
KVER=$(ls "$ROOT/lib/modules")
depmod -b "$ROOT" $KVER
95 96 97 98 99 100


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

101 102 103 104
mkdir "$MODLOOP" "$STAGING"
cp -a "$ROOT/lib/modules" "$MODLOOP"
cp -a "$ROOT/lib/firmware" "$MODLOOP/modules"
mksquashfs "$MODLOOP" "$STAGING/$MODIMG" -comp xz
105

106
mkinitfs -q -F "$features squashfs" -b "$ROOT" -o "$STAGING/$FLAVOR.gz" $KVER
107
cp "$ROOT/boot/vmlinuz$KVER_FLAVOR" "$STAGING/$FLAVOR"
108 109


110 111 112 113 114
if [ "$MNTDIR" ]; then
    ignore_sigs
    remount -w
    rm -f "$DESTDIR/$MODIMG"
fi
115

116
mv "$STAGING"/* "$DESTDIR"
117

118 119 120 121 122
if [ "$MNTDIR" ]; then
    set +e
    sync
    remount -r
fi
123 124

exit 0