#!/bin/sh -eu

. install2-init-functions

##
# Purpose: find all removable devices.
# List stored at out file for future processing.
# List contains only devices, not partitions.
#

readonly OUT="/tmp/removable"
readonly UDEVADM="/sbin/udevadm"

if ! [ -x "$UDEVADM" ]; then
    fatal "Can't find $UDEVADM"
fi

#
# Ask udevadm for all removable block devices
#
"$UDEVADM" trigger --dry-run --verbose --subsystem-match=block --attr-match=removable=1 \
    | xargs --no-run-if-empty -n 1 \
    "$UDEVADM" info --export -a -p | sed -ne '/KERNEL==/s@^.*"\(.*\)"$@/dev/\1@p' > "$OUT"
