This file is indexed.

/bin/lsbilibop is in bilibop-rules 0.4.20.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh
set -e

# /bin/lsbilibop
# List BILIBOP tagged devices, display some udev properties about them,
# or trigger uevents to update their properties.

PATH="/sbin:/bin"
PROG="${0##*/}"
TAG_DIR="/run/udev/tags/BILIBOP"

info="false"
list="false"
trigger="false"
action=""

short_usage() {
	cat <<EOF
Usage:
  ${PROG} -h|-l
  ${PROG} [-a|-c|-i] [DEVICE [DEVICE [...]]]
EOF
}

usage() {
	cat <<EOF
${PROG}: list BILIBOP tagged devices, display or update some of their udev properties.

Usage:
  ${PROG} -h|-l
  ${PROG} [OPTION] [DEVICES]

Options:
  -a	Trigger uevents (action=add) for BILIBOP tagged devices.
  -c	Trigger uevents (action=change) for BILIBOP tagged devices.
  -h	Print this help on stdout and exit.
  -i    Display some udev properties of BILIBOP tagged devices.
  -l    Don't rely on BILIBOP tag to list bilibop devices.
EOF
}

bilibop_list() {
	. /lib/bilibop/common.sh
	get_udev_root
	BILIBOP_DISK="$(physical_hard_disk /)"
	for node in $(device_nodes); do
		if [ "$(physical_hard_disk ${udev_root}/${node})" = "${BILIBOP_DISK}" ]; then
			echo "${udev_root}/${node}"
		fi
	done
}

# Parse options. We use this order of priority -h > -l > -i > -a = -c:
# -h (help) overrides unconditionally all other options.
# -l (list) overrides unconditionally -i, -a and -c.
# -i (info) overrides unconditionally -a (add) and -c (change).
while getopts :achil opt; do
	case "${opt}" in
		h)
			usage
			exit 0
			;;
		a)
			trigger="true"
			action="add"
			;;
		c)
			trigger="true"
			action="change"
			;;
		i)
			info="true"
			;;
		l)
			list="true"
			;;
		'?')
			echo "${PROG}: unrecognized option '-${OPTARG}'." >&2
			short_usage >&2
			exit 1
			;;
	esac
done

if [ "${list}" = "true" ]; then
	bilibop_list
	exit $?
elif [ "${info}" = "true" ]; then
	trigger="false"
fi

shift $((OPTIND-1))
if [ "${1}" = "--" ]; then shift; fi

# At least, check if BILIBOP tagged devices exist, or exit with a useful
# message:
if [ ! -d "${TAG_DIR}" ]; then
	echo "${PROG}: ${TAG_DIR}: no such directory.\n" >&2
	if [ -f "/etc/udev/rules.d/66-bilibop.rules" ]; then
		cat >&2 <<EOF
You should modify /etc/udev/rules.d/66-bilibop.rules
or even remove it.
EOF
	else
		cat >&2 <<EOF
First, run /usr/share/bilibop/bilibop_rules_generator
and maybe modify /etc/udev/rules.d/66-bilibop.rules.
EOF
	fi
	cat >&2 <<EOF

	'udevadm info --query property --name <NODE>',
	'udevadm trigger --sysname-match <NODE>' and
	'udevadm test <DEVPATH>' can help you, if they
	are applied to the following device nodes:

EOF
	bilibop_list >&2
	echo >&2
	echo "But maybe your system is not running from a writable and removable media ?" >&2
	exit 8
fi

# Trigger uevents can only be done by root, but if it is tried by a
# unprivileged user, udevadm will silently do NOTHING without failure
# (i.e. with exit code = 0). So we place a poor checkpoint here.
if [ "${trigger}" = "true" ]; then
	if [ "${USER}" != "root" ]; then
		echo "${0##*/}: only root can use the '-a' or '-c' options." >&2
		exit 4
	fi
fi

# Get/set udev_root variable. It should be '/dev', but...
if [ -f /etc/udev/udev.conf ]; then
	. /etc/udev/udev.conf
fi
udev_root="${udev_root:-/dev}"

# Store device names given as arguments, if any:
for arg; do
	if [ -b "${arg}" ]; then
		arg="$(readlink -f ${arg})"
		DEVICE="${DEVICE:+${DEVICE} }${arg}"
	fi
done

# If ALL arguments are invalid, exit.
if [ -n "$*" -a -z "${DEVICE}" ]; then
	echo "${PROG}: bad argument(s) '$@'." >&2
	short_usage >&2
	exit 2
fi

# Trigger uevents for all BILIBOP tagged devices, and exit:
if [ -z "${DEVICE}" -a "${trigger}" = "true" ]; then
	udevadm trigger --tag-match="BILIBOP" --action="${action}"
	exit $?
fi

grep '[[:digit:]]' /proc/partitions |
while read major minor size node; do
	# Skip devices that are not tagged 'BILIBOP':
	[ ! -e "/run/udev/tags/BILIBOP/b${major}:${minor}" ] && continue

	# Filter by device names given as arguments:
	if [ -n "${DEVICE}" ]; then
		for device in ${DEVICE}; do
			[ "${device}" = "${udev_root}/${node}" ] && break
		done
		[ "${device}" = "${udev_root}/${node}" ] || continue
	fi

	if [ "${info}" = "true" ]; then
		echo "DEVNAME='${udev_root}/${node}'"
		udevadm info --query property --export --name ${node} |
		grep -E '^(BILIBOP_(DISK|(UNDERLYING_)?PARTITION)|DEVLINKS|UDISKS_(IGNORE|SYSTEM(_INTERNAL)?|(PRESENTATION_)?(ICON_)?NAME|PRESENTATION_HIDE|CAN_POWER_OFF)|ID_(FS_(UUID|LABEL|TYPE|USAGE)|DRIVE_DETACHABLE))='
		echo

	elif [ "${trigger}" = "true" ]; then
		udevadm trigger --sysname-match="${node}" --action="${action}"
	else
		echo "${udev_root}/${node}"
	fi
done

# vim: ts=4 sts=4 sw=4