Advertisement
tolikpunkoff

get syslinux hd from device name

Jun 15th, 2019
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #get syslinux 'hd? ?' from device name (e.g. /dev/sda1) example
  4. #use getsysl <device>
  5.  
  6. SYSL_ID=""
  7.  
  8. get_sysl_hd() #$1 - device name
  9. {
  10.     #get basename and check name
  11.     T_DN=`basename $1|grep '^[sh]d[a-z][1-9]*$'`
  12.     if [ -z "$T_DN" ]; then
  13.         return 1
  14.     fi
  15.    
  16.     #get letter #3
  17.     T_3LET=`expr substr $T_DN 3 1`
  18.    
  19.     #get letter number in alphabet
  20.     S_CODE=`printf '%d' \'$T_3LET`
  21.     A_CODE=`printf '%d' \'a`
  22.     SYSL_ID="hd"`expr $S_CODE - $A_CODE`
  23.    
  24.     #get volume number
  25.     T_VOLNUM=`echo "$T_DN" | sed 's/^[a-z]*//'`
  26.     if [ -z "$T_VOLNUM" ]; then
  27.         T_VOLNUM=0
  28.     fi
  29.    
  30.     SYSL_ID="$SYSL_ID $T_VOLNUM"
  31. }
  32.  
  33. if [ -z "$1" ]; then
  34.     echo "Use "`basename $0` "<device>"
  35.     exit
  36. fi
  37.  
  38. get_sysl_hd "$1"
  39.  
  40. if [ $? -ne 0 ];then
  41.     echo "Bad device name!"
  42. else
  43.     echo "$1: $SYSL_ID"
  44. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement