Skip to content

Commit a29d487

Browse files
rpardinijacobweinstock
authored andcommitted
hook-mdev: rename to persistent-storage.sh and shellfmt it (no real changes)
- simple rename & shellfmt; separate commit for easy future rebasing Signed-off-by: Ricardo Pardini <[email protected]>
1 parent 1e7c3a5 commit a29d487

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

images/hook-mdev/persistent-storage renamed to images/hook-mdev/persistent-storage.sh

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
symlink_action() {
44
case "$ACTION" in
5-
add) ln -sf "$1" "$2";;
6-
remove) rm -f "$2";;
5+
add) ln -sf "$1" "$2" ;;
6+
remove) rm -f "$2" ;;
77
esac
88
}
99

1010
sanitise_file() {
11-
sed -E -e 's/^\s+//' -e 's/\s+$//' -e 's/ /_/g' "$@" 2>/dev/null
11+
sed -E -e 's/^\s+//' -e 's/\s+$//' -e 's/ /_/g' "$@" 2> /dev/null
1212
}
1313

1414
sanitise_string() {
@@ -25,32 +25,31 @@ blkid_encode_string() {
2525

2626
# cdrom symlink
2727
case "$MDEV" in
28-
sr*|xvd*)
29-
caps="$(cat $SYSFS/block/$MDEV/capability 2>/dev/null)"
30-
if [ $(( 0x${caps:-0} & 8 )) -gt 0 ] || [ "$(cat $SYSFS/block/$MDEV/removable 2>/dev/null)" = "1" ]; then
28+
sr* | xvd*)
29+
caps="$(cat $SYSFS/block/$MDEV/capability 2> /dev/null)"
30+
if [ $((0x${caps:-0} & 8)) -gt 0 ] || [ "$(cat $SYSFS/block/$MDEV/removable 2> /dev/null)" = "1" ]; then
3131
symlink_action $MDEV cdrom
3232
fi
33+
;;
3334
esac
3435

35-
3636
# /dev/block symlinks
3737
mkdir -p block
3838
if [ -f "$SYSFS/class/block/$MDEV/dev" ]; then
3939
maj_min=$(sanitise_file "$SYSFS/class/block/$MDEV/dev")
4040
symlink_action ../$MDEV block/${maj_min}
4141
fi
4242

43-
4443
# by-id symlinks
4544
mkdir -p disk/by-id
4645

4746
if [ -f "$SYSFS/class/block/$MDEV/partition" ]; then
4847
# This is a partition of a device, find out its parent device
4948
_parent_dev="$(basename $(${SBINDIR:-/usr/bin}/readlink -f "$SYSFS/class/block/$MDEV/.."))"
5049

51-
partition=$(cat $SYSFS/class/block/$MDEV/partition 2>/dev/null)
50+
partition=$(cat $SYSFS/class/block/$MDEV/partition 2> /dev/null)
5251
case "$partition" in
53-
[0-9]*) partsuffix="-part$partition";;
52+
[0-9]*) partsuffix="-part$partition" ;;
5453
esac
5554
# Get name, model, serial, wwid from parent device of the partition
5655
_check_dev="$_parent_dev"
@@ -72,29 +71,29 @@ eval $(blkid /dev/$MDEV | cut -d: -f2-)
7271

7372
if [ -n "$wwid" ]; then
7473
case "$MDEV" in
75-
nvme*) symlink_action ../../$MDEV disk/by-id/nvme-${wwid}${partsuffix};;
74+
nvme*) symlink_action ../../$MDEV disk/by-id/nvme-${wwid}${partsuffix} ;;
7675
esac
7776
case "$wwid" in
78-
naa.*) symlink_action ../../$MDEV disk/by-id/wwn-0x${wwid#naa.}${partsuffix};;
77+
naa.*) symlink_action ../../$MDEV disk/by-id/wwn-0x${wwid#naa.}${partsuffix} ;;
7978
esac
8079
fi
8180

8281
if [ -n "$serial" ]; then
8382
if [ -n "$model" ]; then
8483
case "$MDEV" in
85-
nvme*) symlink_action ../../$MDEV disk/by-id/nvme-${model}_${serial}${partsuffix};;
86-
sd*) symlink_action ../../$MDEV disk/by-id/ata-${model}_${serial}${partsuffix};;
84+
nvme*) symlink_action ../../$MDEV disk/by-id/nvme-${model}_${serial}${partsuffix} ;;
85+
sd*) symlink_action ../../$MDEV disk/by-id/ata-${model}_${serial}${partsuffix} ;;
8786
esac
8887
fi
8988
if [ -n "$name" ]; then
9089
case "$MDEV" in
91-
mmcblk*) symlink_action ../../$MDEV disk/by-id/mmc-${name}_${serial}${partsuffix};;
90+
mmcblk*) symlink_action ../../$MDEV disk/by-id/mmc-${name}_${serial}${partsuffix} ;;
9291
esac
9392
fi
9493

9594
# virtio-blk
9695
case "$MDEV" in
97-
vd*) symlink_action ../../$MDEV disk/by-id/virtio-${serial}${partsuffix};;
96+
vd*) symlink_action ../../$MDEV disk/by-id/virtio-${serial}${partsuffix} ;;
9897
esac
9998
fi
10099

@@ -117,13 +116,13 @@ if [ -n "$UUID" ]; then
117116
fi
118117

119118
# nvme EBS storage symlinks
120-
if [ "${MDEV#nvme}" != "$MDEV" ] && [ "$model" = "Amazon_Elastic_Block_Store" ] && command -v nvme >/dev/null; then
119+
if [ "${MDEV#nvme}" != "$MDEV" ] && [ "$model" = "Amazon_Elastic_Block_Store" ] && command -v nvme > /dev/null; then
121120
n=30
122121
while [ $n -gt 0 ]; do
123-
ebs_alias=$(nvme id-ctrl -b /dev/$_check_dev \
124-
| dd bs=32 skip=96 count=1 2>/dev/null \
125-
| sed -nre '/^(\/dev\/)?(s|xv)d[a-z]{1,2} /p' \
126-
| tr -d ' ')
122+
ebs_alias=$(nvme id-ctrl -b /dev/$_check_dev |
123+
dd bs=32 skip=96 count=1 2> /dev/null |
124+
sed -nre '/^(\/dev\/)?(s|xv)d[a-z]{1,2} /p' |
125+
tr -d ' ')
127126
if [ -n "$ebs_alias" ]; then
128127
symlink_action "$MDEV" ${ebs_alias#/dev/}$partition
129128
break
@@ -145,4 +144,3 @@ if [ "${MDEV#sd}" != "$MDEV" ]; then
145144
;;
146145
esac
147146
fi
148-

0 commit comments

Comments
 (0)