diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2009-09-03 13:31:55 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2009-09-03 13:31:55 +0000 |
commit | b459037c11ef4385ba12574fd0e2c90be3d85f46 (patch) | |
tree | d1750c35777fbb6d79e0a6b6e6b26d0cc7af497b | |
parent | 0aa643409b6406f5da670359ed9fc9647b868758 (diff) | |
download | alpine-conf-b459037c11ef4385ba12574fd0e2c90be3d85f46.zip |
added missing setup-bootable-usb
-rw-r--r-- | setup-bootable-usb.in | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/setup-bootable-usb.in b/setup-bootable-usb.in new file mode 100644 index 0000000..32d40b2 --- /dev/null +++ b/setup-bootable-usb.in @@ -0,0 +1,52 @@ +#!/bin/sh + +cleanup() { + if [ "$install_syslinux" = "yes" ]; then + apk del -q syslinux + fi + if [ "$mount_dest" = "yes" ]; then + umount "$dest" + fi +} + +die() { + echo "$@" >&2 + cleanup + exit 1 +} + +apk info -q -e syslinux || install_syslinux=yes + + +if [ "$install_syslinux" = "yes" ]; then + apk add -q syslinux +fi + +src=${1:-/media/cdrom} + +[ -f "$src"/.alpine-release ] || die "$src/.alpine-release not found" + + +dest=${2:-/media/usb} + +if ! awk '{print $2}' /proc/mounts | grep -q "^$dest\$"; then + mount "$dest" || die "Failed to mount $dest" + mount_dest=yes +fi + +echo "Copying files..." +cp -r "$src"/* "$src"/.[a-z]* "$dest" || die "Failed to copy files" + +echo "Making usb bootable..." +dev=$(awk "\$2 == \"$dest\" {print \$1}" /proc/mounts) +parent=$(basename $(dirname /sys/block/*/$(basename $dev))) + +syslinux $dev + +if [ -b /dev/$parent ]; then + dd if=/usr/share/syslinux/mbr.bin of=/dev/$parent +else + echo "Warning: Could not find the parent device for $dev" +fi + +cleanup |