tinyramfs/device-helper
illiliti e8858c1d34 device-helper: sleep conditionally
Call sleep in loop instead of hoping that sleep 2 is enough.
2021-05-10 11:24:59 +03:00

42 lines
921 B
Bash
Executable File

#!/bin/sh -f
#
# create /dev/disk/by-* and /dev/mapper/* symlinks
create_symlink()
{
dir="$1"; sym="$2"
sym="${sym%\"}"
sym="${sym#\"}"
sym="${dir}/${sym}"
mkdir -p "$dir"
ln -s "../../${dev_name}" "$sym"
}
[ -b "/dev/${dev_name=${DEVPATH##*/}}" ] || exit 1
exec > /dev/null 2>&1
read -r dm_name < "/sys/block/${dev_name}/dm/name" && {
mkdir -p /dev/mapper
ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}"
}
command -v blkid || exit 0
# prevent race condition
while ! blkid "/dev/${dev_name}"; do
if [ "$((count += 1))" = 30 ]; then
exit 1
else
sleep 1
fi
done
for line in $(blkid "/dev/${dev_name}"); do case "${line%%=*}" in
UUID) create_symlink /dev/disk/by-uuid "${line##*=}" ;;
LABEL) create_symlink /dev/disk/by-label "${line##*=}" ;;
PARTUUID) create_symlink /dev/disk/by-partuuid "${line##*=}" ;;
esac; done