aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-07-15 15:10:42 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2015-07-15 15:10:42 +0200
commit0cc00b53d8e918699413dbe1ddd1989bb4ddec4a (patch)
treee45ba2d1f2260b06f94434414ef532a8301d8d84
parent2a97a54f983f16aaea7d9ef77023d32ddcf8b6c7 (diff)
downloadalpine-conf-0cc00b53d8e918699413dbe1ddd1989bb4ddec4a.tar.bz2
alpine-conf-0cc00b53d8e918699413dbe1ddd1989bb4ddec4a.tar.xz
setup-bootable: warn and fix kernel name change
-rw-r--r--setup-bootable.in103
1 files changed, 94 insertions, 9 deletions
diff --git a/setup-bootable.in b/setup-bootable.in
index 116f776..35a5f73 100644
--- a/setup-bootable.in
+++ b/setup-bootable.in
@@ -84,10 +84,87 @@ find_disk_dev() {
return 1
}
+find_syslinux_cfg() {
+ # find where new syslinux.cfg is
+ for i in boot/syslinux/syslinux.cfg syslinux.cfg; do
+ if [ -e "$1"/$i ]; then
+ syslinux_cfg=$i
+ vecho "Found $syslinux_cfg"
+ break
+ fi
+ done
+}
+
+fix_syslinux_kernel() {
+ echo "Fixing $syslinux_cfg: kernel $1 -> $2"
+ sed -i -e "/^\s*[Kk][Ee][Rr][Nn][Ee][Ll]\s/s|$1|$2|" \
+ "$destdir/$syslinux_cfg"
+}
+
+fix_syslinux_initrd() {
+ echo "Fixing $syslinux_cfg: initrd $1 -> $2"
+ sed -i -e "/^\s*[Ii][Nn][Ii][Tt][Rr][Dd]\s/s|$1|$2|" \
+ -e "/^\s*[Aa][Pp][Pp][Ee][Nn][Dd]\s/s|initrd=$1|initrd=$2|" \
+ "$destdir/$syslinux_cfg"
+}
+
+check_syslinux() {
+ if [ -z "$syslinux_cfg" ]; then
+ find_syslinux_cfg "$destdir"
+ fi
+ if [ -z "$syslinux_cfg" ]; then
+ die "Could not find any syslinux.cfg. Aborting"
+ fi
+
+ # kernels
+ for i in $(awk 'tolower($1) == "kernel" {print $2}' "$destdir"/$syslinux_cfg); do
+ k="${destdir%/}/${i#/}"
+ f=${k##*/}
+
+ if [ -e "$k" ] && [ "${f#vmlinuz}" != "$f" ]; then
+ continue
+ fi
+
+ if [ -e "${k%/*}"/vmlinuz-$f ] && [ -n "$fix_syslinux_cfg" ]; then
+ fix_syslinux_kernel "$i" "${i%/*}"/vmlinuz-$f
+ elif ! [ -e "$k" ]; then
+ echo "Warning: $syslinux_cfg: kernel $k was not found"
+ echo " Run $0 -c -f "$destdir" to fix"
+ fi
+ done
+
+ #initramfs
+ initrds=$(awk 'tolower($1) == "initrd" {print $2}' \
+ "$destdir"/$syslinux_cfg)
+ for i in $(awk 'tolower($1) == "append" {print $0}' \
+ "$destdir"/$syslinux_cfg); do
+ case $i in
+ initrd=*) initrds=${i#initrd=};;
+ esac
+ done
+
+ for i in $initrds; do
+ if [ -e "$destdir"/$i ]; then
+ continue
+ fi
+ fname=${i##*/}
+ flavor=${fname%.gz}
+
+ new=${i%/*}/initramfs-$flavor
+ if [ -e "$destdir"/$new ] && [ -n "$fix_syslinux_cfg" ]; then
+ fix_syslinux_initrd "$i" "$new"
+ else
+ echo "Warning: initrd $i was not found. System will likely not boot"
+ echo " Run $0 -f -c "$destdir" to fix"
+ fi
+ done
+}
+
usage() {
cat <<__EOF__
$prog $version
usage: $prog [-fhUusv] SOURCE [DEST]
+ $prog -c DIR
Copy the contents of SOURCE to DEST and make DEST bootable.
@@ -97,19 +174,24 @@ or a device. If DEST is ommitted /media/usb will be used.
Options:
-f Force overwrite existing files. Will overwrite syslinux.cfg if upgrade.
-h Show this help.
+ -k fix kernel and initrd name in syslinux.cfg if needed.
-U Replace current alpine_dev in syslinux.cfg with UUID if UUID found.
-u Upgrade mode. Keep existing syslinux.cfg and don't run syslinux.
-s Force run syslinux, even if upgrade mode.
-v Verbose mode. Display whats going on.
+ -c Check syslinux.cfg in destination DIR. Use with -f to fix.
+
__EOF__
exit 1
}
-while getopts "fhUusv" opt; do
+while getopts "c:fhkUusv" opt; do
case "$opt" in
- f) force=1;;
+ c) check_syslinux="$OPTARG";;
+ f) force=1; fix_syslinux_cfg=1;;
h) usage;;
+ k) fix_syslinux_cfg=1;;
U) replace_alpine_dev=1;;
u) upgrade=1;;
s) syslinux=1;;
@@ -122,6 +204,11 @@ shift $(($OPTIND - 1))
src=${1}
dest=${2:-/media/usb}
+if [ -n "$check_syslinux" ]; then
+ destdir="$check_syslinux"
+ check_syslinux
+ exit 0
+fi
[ -z "$src" ] && usage
@@ -235,13 +322,8 @@ elif [ -n "$srcurl" ]; then
fi
# find where new syslinux.cfg is
-for i in boot/syslinux/syslinux.cfg syslinux.cfg; do
- if [ -e "$destdir"/.new/$i ]; then
- syslinux_cfg=$i
- vecho "Found $syslinux_cfg"
- break
- fi
-done
+find_syslinux_cfg "$destdir"/.new
+
# abort early in case unexpected trouble
if [ -z "$syslinux_cfg" ]; then
die "Could not find any syslinux.cfg on new iso?"
@@ -288,6 +370,9 @@ if [ -n "$replace_alpine_dev" -o -z "$upgrade" ] && [ -n "$UUID" ]; then
"$destdir"/$syslinux_cfg
fi
+# verify syslinux.cfg
+check_syslinux
+
# cleanup
[ -z "$keep_old" ] && rm -rf "$destdir"/.old "$destdir"/.new