-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk_link.sh
executable file
·57 lines (52 loc) · 1.12 KB
/
disk_link.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/busybox ash
blkid_to_link()(
IFS='"'
unset SUBDIR
while read A B C D E F G H I J
do
IFS=
for ENT in "$A" "$B" "$C" "$D" "$E" "$F" "$G" "$H" "$I" "$J"
do
if [ -z "$SUBDIR" ]
then
case "$ENT" in
*PARTUUID=)
;;
*UUID=)
SUBDIR="by-uuid"
;;
*LABEL=)
SUBDIR="by-label"
;;
esac
else
# Try to sanitize the label.
ENT=$(echo "$ENT" | sed -e 's:/:\\x2f:g;s:\$:\\x24:g;s:\":\\x22:g' \
-e 's:\ :\\x20:g;s:\;:\\x3b:g;s:`:\\x60:g')
# ENT="${ENT/\//\\x2f}"
# ENT="${ENT/\$/\\x24}"
# ENT="${ENT/\"/\\x22}"
# ENT="${ENT/\ /\\x20}"
# ENT="${ENT/\`/\\x60}"
ln -sf "../../$MDEV" /dev/disk/"$SUBDIR"/"$ENT"
unset SUBDIR
fi
done
IFS='"'
done
)
if test "$ACTION" = "remove"
then
for L in /dev/disk/by-*/*
do [ -L "$L" -a ! -e "$L" ] && unlink "$L" || true
done
exit
fi
if test -b "/dev/$MDEV"
then
mkdir -p /dev/disk/by-uuid /dev/disk/by-label
blkid /dev/$MDEV | blkid_to_link
else
mkdir -p /dev/disk/by-uuid /dev/disk/by-label || exit
blkid | blkid_to_link
fi