various fixes
[automated-distro-installer] / fai / config / distro-install-common / devbyid
1 #!/bin/bash
2
3 # input eg: /dev/sda1 or /dev/sda
4 # output: /dev/disk/by-id/model+serial, or if no link exists, the same as input
5
6 short_dev=$1
7 if [[ ! -e $short_dev ]]; then
8 echo "devbyid: error: argument=$short_dev does not exist"
9 exit 1
10 fi
11
12 # devices are identified by model+serial num
13 # and for ssd/hdd: wwn, and for nvme: eui.
14 # model+serial gives me more info, so use that.
15 shopt -s extglob
16 for id in /dev/disk/by-id/!(nvme-eui*|wwn*); do
17 [[ -e $id ]] || break # if we matched nothing
18 if [[ $(readlink -f $id) == "$short_dev" ]]; then
19 printf '%s\n' "$id"
20 exit
21 fi
22 done
23 # a vm may not have a by-id link.
24 printf '%s\n' "$short_dev"