Add memtest support.
[syslinux-debian/hramrach.git] / debian / local / extlinux-install
blobfef8d78856acee365ba1485c361fe773c60750e5
1 #!/bin/sh
3 ## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
4 ##
5 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
6 ## This is free software, and you are welcome to redistribute it
7 ## under certain conditions; see COPYING for details.
10 set -e
12 _DEVICE="${1}"
14 # Exit if user has not specified a device to install
15 if [ -z "${_DEVICE}" ]
16 then
17 echo "E: Usage: ${0} DEVICE"
18 exit 1
19 else
20 shift
23 _DIRECTORY="/boot/extlinux"
25 # Exit if user is unprivileged
26 if [ "$(id -u)" -ne 0 ]
27 then
28 echo "E: need root privileges"
29 exit 1
32 # Exit if user has specified a non-existing device
33 if [ ! -e "${_DEVICE}" ]
34 then
35 echo "E: cannot access \"${_DEVICE}\": No such device"
36 exit 1
39 # Exit if user has specified an invalid device
40 if [ ! -b "${_DEVICE}" ]
41 then
42 echo "E: cannot access \"${_DEVICE}\": No valid device"
43 exit 1
46 # Checking extlinux directory
47 echo -n "P: Checking for EXTLINUX directory..."
49 # Creating extlinux directory
50 if [ ! -e "${_DIRECTORY}" ]
51 then
52 echo " not found."
54 echo -n "P: Creating EXTLINUX directory..."
55 mkdir -p "${_DIRECTORY}"
56 echo " done: ${_DIRECTORY}"
57 else
58 echo " found."
61 _MBR="$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${_DEVICE})"
63 case "${_MBR}" in
64 gpt)
65 _MBR="gptmbr"
69 _MBR="mbr"
71 esac
73 # Searching syslinux MBR
74 if [ ! -e /usr/lib/EXTLINUX/${_MBR}.bin ]
75 then
76 echo "E: /usr/lib/EXTLINUX/${_MBR}.bin: No such file"
77 exit 1
80 # Saving old MBR
81 echo -n "P: Saving old ${_MBR}..."
82 dd if="${_DEVICE}" of=/boot/${_MBR}-$(basename "${_DEVICE}").old bs=440 count=1 conv=notrunc 2> /dev/null
83 echo " done: /boot/${_MBR}-$(basename "${_DEVICE}").old"
85 # Writing syslinux MBR
86 echo -n "P: Writing new ${_MBR}..."
87 dd if=/usr/lib/EXTLINUX/${_MBR}.bin of="${_DEVICE}" bs=440 count=1 conv=notrunc 2> /dev/null
88 echo " done: ${_DEVICE}"
90 # Writing extlinux loader
91 echo "P: Installing EXTLINUX..."
92 extlinux --install "${_DIRECTORY}" ${@}