# shellcheck shell=sh
# shellcheck disable=SC2034

# ferreus_orbit Plugins for qemu based VM

fo_get_sorted_name(){
  if [ -n "$ID_BUS" ] && [ "$ID_BUS" = "scsi" ]; then
    card=$(echo "$DEVPATH" | cut -d/ -f5)
    target=$(echo "$DEVPATH" | cut -d/ -f8| cut -d: -f3)
    if [ "$card" = "virtio0" ] || [ "$card" = "virtio1" ] ; then
      disk=sd$(fo_get_dev_letter "${target}")
      logger -t "udev" "Adding symlink $disk for device $card-$target"
      if [ "$USE_FO_NAME" -lt 1 ]; then
        echo "$disk"
        exit 0
      else
        box=$(echo "${card}" | awk -F "virtio" '{print $2}')
        echo "Box${box}-Disk${target}"
        exit 0
      fi
    else
      logger -t "udev" "Device $DEVPATH detected but not supported"; exit 1
    fi
  else
    logger -t "udev" "Device $DEVPATH detected but not supported"; exit 1
  fi
}

fo_get_did(){
  fo_get_id "$1"
}

fo_get_id(){
  if [ -n "$ID_BUS" ] && [ "$ID_BUS" = "scsi" ]; then
    id=$(echo "$DEVPATH" | cut -d/ -f8| cut -d: -f3)
  fi
  echo "$id"
}

FO_DISPOSITION="Disposition unavailable"
