Created
January 23, 2019 22:25
-
-
Save chadcatlett/b1cda84fe6c14bbb8c328bd005b5b6be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: convert os_device | |
# Convert an OS device to the corresponding GRUB drive. | |
# This part is OS-specific. | |
convert () { | |
# First, check if the device file exists. | |
if test -e "$1"; then | |
: | |
else | |
echo "$1: Not found or not a block device." 1>&2 | |
exit 1 | |
fi | |
# Break the device name into the disk part and the partition part. | |
case "$host_os" in | |
linux*) | |
tmp_disk=`echo "$1" | grep -v '/mapper/control$' | | |
grep -v '/mapper/[[:alnum:]]\+-[[:alnum:]]\+$' | uniq | | |
sed -e 's%\([shv]d[a-z]\)[0-9]*$%\1%' \ | |
-e 's%\(d[0-9]*\)p[0-9]*$%\1%' \ | |
-e 's%\(fd[0-9]*\)$%\1%' \ | |
-e 's%/part[0-9]*$%/disc%' \ | |
-e 's%\(c[0-7]d[0-9]*\).*$%\1%' \ | |
-e 's%\(/mapper/[[:alpha:]]\+[[:digit:]]*\)p[[:digit:]]\+$%\1%' \ | |
-e 's%\(/mapper/isw_[[:alpha:]_]\+[[:alpha:]]\+[[:digit:]]\+\)p[[:digit:]]\+$%\1%' \ | |
-e 's%\(/mapper/[[:alpha:]]\+_[[:alpha:]]\+\)[[:digit:]]\+$%\1%' \ | |
-e 's%\(nvme[0-9]*n[0-9]*\)p[0-9]*$%\1%'` | |
tmp_part=`echo "$1" | grep -v '/mapper/control$' | | |
grep -v '/mapper/[[:alnum:]]\+-[[:alnum:]]\+$' | uniq | | |
sed -e 's%.*/[shv]d[a-z]\([0-9]*\)$%\1%' \ | |
-e 's%.*d[0-9]*p%%' \ | |
-e 's%.*/fd[0-9]*$%%' \ | |
-e 's%.*/floppy/[0-9]*$%%' \ | |
-e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \ | |
-e 's%.*c[0-7]d[0-9]*%%' \ | |
-e 's%.*/mapper/[[:alpha:]]\+[[:digit:]]*p\([[:digit:]]\+\)$%\1%' \ | |
-e 's%.*/mapper/isw_[[:alpha:]_]\+[[:alpha:]]\+[[:digit:]]\+p\([[:digit:]]\+\)$%\1%' \ | |
-e 's%.*/mapper/[[:alpha:]]\+_[[:alpha:]]\+\([[:digit:]]\+\)$%\1%' \ | |
-e 's%.*/nvme[0-9]*n[0-9]*p\([0-9]*\)%\1%' | | |
grep -v '.*/mapper/.*'` | |
<snip> | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment