summaryrefslogtreecommitdiffstats
path: root/main/compat-pvgrub
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2013-11-18 18:44:05 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2013-11-18 18:46:33 +0000
commit81bf2a318304a903261a644cb4df24023c9d27f4 (patch)
tree3545b0ebd8f617c3b96ffd211a7b2fef44d16290 /main/compat-pvgrub
parent1d74a452d83a0ebe676a82dbcaae91a9141c4de3 (diff)
downloadaports-81bf2a318304a903261a644cb4df24023c9d27f4.tar.bz2
aports-81bf2a318304a903261a644cb4df24023c9d27f4.tar.xz
main/compat-pvgrub: new aport
This builds a grub configuration automatically, similar to update-extlinux (derived from that code). It assumes a typical Xen deployment, with the filesystem being flat, and on (hd0). fix #2356
Diffstat (limited to 'main/compat-pvgrub')
-rw-r--r--main/compat-pvgrub/APKBUILD33
-rw-r--r--main/compat-pvgrub/compat-pvgrub.trigger3
-rwxr-xr-xmain/compat-pvgrub/update-pvgrub117
3 files changed, 153 insertions, 0 deletions
diff --git a/main/compat-pvgrub/APKBUILD b/main/compat-pvgrub/APKBUILD
new file mode 100644
index 000000000..61e3741e1
--- /dev/null
+++ b/main/compat-pvgrub/APKBUILD
@@ -0,0 +1,33 @@
+# Contributor: William Pitcock <nenolod@dereferenced.org>
+# Maintainer: William Pitcock <nenolod@dereferenced.org>
+pkgname=compat-pvgrub
+pkgver=1
+pkgrel=0
+pkgdesc="compatibility support for PV-GRUB 1.x"
+url="http://www.alpinelinux.org/"
+arch="noarch"
+license="ISC"
+depends=""
+depends_dev=""
+makedepends="$depends_dev"
+triggers="compat-pvgrub.trigger=/boot"
+install=""
+subpackages=""
+source="update-pvgrub"
+
+_builddir="$srcdir"
+
+package() {
+ cd "$_builddir"
+
+ mkdir -p "$pkgdir"/boot/grub "$pkgdir"/sbin
+ touch "$pkgdir"/boot/grub/.keep-compat-pvgrub
+
+ sed "/^version=/s/=.*/=$pkgver-r$pkgrel/" "$srcdir"/update-pvgrub \
+ > "$pkgdir"/sbin/update-pvgrub
+ chmod 755 "$pkgdir"/sbin/update-pvgrub
+}
+
+md5sums="19cc71a4929ebf83df27af57b167cd8e update-pvgrub"
+sha256sums="ede72f8a3f7091d8e03f15720c1bab0e7da3f6c5bea70811690c84269d50b824 update-pvgrub"
+sha512sums="6b41f5d7280527164ebfa631c04240f6c05854cb31fb839a1e7e5375c5bdc5a608e7e20228dc83d31534c21558c8157a437fb537b6c194f2d220b59a0438c017 update-pvgrub"
diff --git a/main/compat-pvgrub/compat-pvgrub.trigger b/main/compat-pvgrub/compat-pvgrub.trigger
new file mode 100644
index 000000000..541aed7c6
--- /dev/null
+++ b/main/compat-pvgrub/compat-pvgrub.trigger
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+update-pvgrub
diff --git a/main/compat-pvgrub/update-pvgrub b/main/compat-pvgrub/update-pvgrub
new file mode 100755
index 000000000..56594a337
--- /dev/null
+++ b/main/compat-pvgrub/update-pvgrub
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+version=
+default=0
+timeout=5
+verbose=0
+
+conf=/boot/grub/menu.lst
+myconf=/etc/update-extlinux.conf
+
+# read in extlinux settings
+if [ -f "$myconf" ]; then
+ . $myconf
+fi
+
+everbose() {
+ if [ "$verbose" = "0" ]; then
+ return
+ fi
+
+ echo $*
+}
+
+ewarn() {
+ echo "WARNING:" $@ >&2
+}
+
+eerror() {
+ echo "ERROR:" $@ >&2
+ return 1
+}
+
+everbose "Updating extlinux configuration."
+
+if [ "x$root" = "x" ]; then
+ ewarn "Root device is not specified in $myconf."
+ blkid_export=$(blkid -o export /dev/root)
+ if [ -n "$blkid_export" ]; then
+ export $blkid_export
+ fi
+ if [ -z "$UUID" ]; then
+ # try parse /proc/mount for mounted /
+ dev=$(awk '$2 == "/" {dev=$1} END {print dev}' /proc/mounts)
+ if [ -n "$dev" ]; then
+ blkid_export=$(blkid -o export $dev)
+ if [ -n "$blkid_export" ]; then
+ export "$blkid_export"
+ fi
+ fi
+ fi
+ if [ -z "$UUID" ]; then
+ if [ -z "$dev" ]; then
+ eerror "Failed to detect root device"
+ exit 1
+ else
+ root=$dev
+ fi
+ else
+ root=UUID=$UUID
+ fi
+ everbose "Root device is: $root"
+fi
+
+menu_hidden=
+
+umask 0022
+rm -f $conf.new
+echo "# Generated by update-pvgrub $version" > $conf.new
+echo "default 0" >> $conf.new
+if [ "$hidden" = "1" ]; then
+ echo "hiddenmenu" >> $conf.new
+fi
+echo "timeout $rtimeout" >> $conf.new
+
+lst=0
+
+for kernel in $(find /boot -name "vmlinuz-*" -type f); do
+ tag=$(basename $kernel | cut -b9-)
+ everbose "Found kernel: $kernel"
+ label=$(grep -w -l $tag /usr/share/kernel/*/kernel.release | cut -d/ -f5)
+ if [ -z "$label" ]; then
+ label=$lst
+ fi
+ echo "title Linux $tag" >> $conf.new
+ echo "root (hd0)" >> $conf.new
+ echo "kernel /boot/$(basename $kernel) root=$root modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts" >> $conf.new
+ if [ -f "/boot/initramfs-$tag" ]; then
+ everbose "Found initramfs: /boot/initramfs-$tag"
+ echo "initrd /boot/initramfs-$tag" >> $conf.new
+ fi
+ echo "" >> $conf.new
+ lst=$(($lst + 1))
+done
+
+if [ -n "$password" ]; then
+ echo "password --md5 $password" >> $conf.new
+ echo "" >> $conf.new
+ chmod o-r $conf.new
+fi
+
+everbose "$lst entries found."
+
+if cmp -s $conf.new $conf; then
+ everbose "Configuration unchanged."
+ rm $conf.new
+fi
+
+if [ "$overwrite" != "1" ]; then
+ exit 0
+elif [ -f "$conf.new" ]; then
+ # keep a backup just in case
+ if [ -f "$conf" ]; then
+ mv $conf $conf.old
+ fi
+
+ mv $conf.new $conf
+fi