-
Notifications
You must be signed in to change notification settings - Fork 5
/
getsysl
44 lines (34 loc) · 817 Bytes
/
getsysl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#get syslinux 'hd? ?' from device name (e.g. /dev/sda1) example
#use getsysl <device>
SYSL_ID=""
get_sysl_hd() #$1 - device name
{
#get basename and check name
T_DN=`basename $1|grep '^[sh]d[a-z][1-9]*$'`
if [ -z "$T_DN" ]; then
return 1
fi
#get letter #3
T_3LET=`expr substr $T_DN 3 1`
#get letter number in alphabet
S_CODE=`printf '%d' \'$T_3LET`
A_CODE=`printf '%d' \'a`
SYSL_ID="hd"`expr $S_CODE - $A_CODE`
#get volume number
T_VOLNUM=`echo "$T_DN" | sed 's/^[a-z]*//'`
if [ -z "$T_VOLNUM" ]; then
T_VOLNUM=0
fi
SYSL_ID="$SYSL_ID $T_VOLNUM"
}
if [ -z "$1" ]; then
echo "Use "`basename $0` "<device>"
exit
fi
get_sysl_hd "$1"
if [ $? -ne 0 ];then
echo "Bad device name!"
else
echo "$1: $SYSL_ID"
fi