Commit 8c64e9de authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

update-kernel: do not require superuser rights

parent 89306b4e
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
SCRIPT=update-kernel SCRIPT=update-kernel
VIRTUAL=.tmp-$SCRIPT VIRTUAL=.tmp-$SCRIPT
SUPERUSER=
[ $(id -u) -eq 0 ] && SUPERUSER=Y
BUILDDIR= BUILDDIR=
FLAVOR= FLAVOR=
MNTDIR= MNTDIR=
...@@ -80,6 +83,9 @@ if [ -z "$DESTDIR" ]; then ...@@ -80,6 +83,9 @@ if [ -z "$DESTDIR" ]; then
[ "$FLAVOR" ] && \ [ "$FLAVOR" ] && \
usage 1 "Cannot specify flavor when updating the current kernel" usage 1 "Cannot specify flavor when updating the current kernel"
[ "$SUPERUSER" ] || \
usage 1 "Specify destination directory or run as superuser"
while read MOUNT; do while read MOUNT; do
set -- $MOUNT set -- $MOUNT
[ $2 = /.modloop ] || continue [ $2 = /.modloop ] || continue
...@@ -107,14 +113,16 @@ clean_up() { ...@@ -107,14 +113,16 @@ clean_up() {
set +e set +e
ignore_sigs ignore_sigs
apk del -q $VIRTUAL [ "$SUPERUSER" ] && apk del -q $VIRTUAL
rm -fr $TMPDIR rm -fr $TMPDIR
} }
trap clean_up EXIT $SIGNALS trap clean_up EXIT $SIGNALS
apk add -qU -t $VIRTUAL mkinitfs squashfs-tools if [ "$SUPERUSER" ]; then
apk add -qU -t $VIRTUAL mkinitfs squashfs-tools
fi
if [ -z "$features" ]; then if [ -z "$features" ]; then
. /etc/mkinitfs/mkinitfs.conf . /etc/mkinitfs/mkinitfs.conf
...@@ -128,11 +136,28 @@ fi ...@@ -128,11 +136,28 @@ fi
TMPDIR=$(mktemp -d /tmp/$SCRIPT.XXXXXX) TMPDIR=$(mktemp -d /tmp/$SCRIPT.XXXXXX)
ROOT=$TMPDIR/root ROOT=$TMPDIR/root
BOOT=$ROOT/boot BOOT=$ROOT/boot
WRAPPER=eval
_exec() {
$WRAPPER "$1"
}
_apk() { _apk() {
local cmd=$1 local cmd=$1
shift shift
apk $cmd -p $ROOT --keys-dir /etc/apk/keys \
local wrapper=
if [ -z "$SUPERUSER" ]; then
local opt=
local fake_env=$TMPDIR/fake-env
if [ -f $fake_env ]; then
opt="-i $fake_env"
WRAPPER="fakeroot $opt --"
fi
wrapper="fakeroot $opt -s $fake_env --"
fi
$wrapper apk $cmd -p $ROOT --keys-dir /etc/apk/keys \
--repositories-file /etc/apk/repositories $* --repositories-file /etc/apk/repositories $*
} }
...@@ -174,10 +199,10 @@ MODIMG=$FLAVOR.modloop.squashfs ...@@ -174,10 +199,10 @@ MODIMG=$FLAVOR.modloop.squashfs
mkdir $MODLOOP $STAGING mkdir $MODLOOP $STAGING
cp -a $ROOT/lib/modules $MODLOOP cp -a $ROOT/lib/modules $MODLOOP
cp -a $ROOT/lib/firmware $MODLOOP/modules cp -a $ROOT/lib/firmware $MODLOOP/modules
mksquashfs $MODLOOP $STAGING/$MODIMG -comp xz _exec "mksquashfs $MODLOOP $STAGING/$MODIMG -comp xz"
mkinitfs -q -b $ROOT -F "$features base squashfs" -o "$STAGING/$FLAVOR.gz" \ _exec "mkinitfs -q -b $ROOT -F '$features base squashfs' \
"$KVER" -o '$STAGING/$FLAVOR.gz' '$KVER'"
cp "$BOOT/vmlinuz$KVER_FLAVOR" "$STAGING/$FLAVOR" cp "$BOOT/vmlinuz$KVER_FLAVOR" "$STAGING/$FLAVOR"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment