This file is indexed.

/usr/share/bilibop/make_unpersistent_rules 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/sh
set -e

# /usr/share/bilibop/make_unpersistent_rules

# Remove some persistent udev rules files (cd & net) and replace them by links
# to unpersistent files (in /run/udev/rules.d); ...or restore them.
# This is made because these persistent rules files are cumulative, and so are
# not very adapted for an operating system on external hard disk or usb key.

### BEGIN ###

PATH="/sbin:/bin:/usr/bin"
PROG="${0##*/}"
SOPTS="ho:rsv"
LOPTS="help,only:,restore,status,verbose"

ETC_RULES_DIR="/etc/udev/rules.d"
RUN_RULES_DIR="/run/udev/rules.d"

if [ -f /etc/udev/udev.conf ]; then
	. /etc/udev/udev.conf
fi
udev_root="${udev_root:-/dev}"
udev_root="${udev_root%/}"

status=""
restore=""
verbose=""
only=""
TYPE=""
SKIP=""

short_usage() {
	cat <<EOF
Usage:
  ${PROG} -h|--help
  ${PROG} -s|--status
  ${PROG} [-v|--verbose] [-r|--restore] [-o|--only cd|net]
EOF
}

usage() {
	cat <<EOF
${PROG} replaces some persistent udev rules files by
links to unpersistent files (in ${RUN_RULES_DIR}).
This is done to avoid cumulative informations about optical drives
and network interfaces.

Usage: ${PROG} [OPTIONS]

OPTIONS:
  -h, --help
      Display this help and exit.

  -o TYPE, --only TYPE
      Apply actions only for the specified TYPE of rules (cd or net).

  -r, --restore
      Remove links to unpersistent rules files and restore persistent
      (static) udev rules files.

  -s, --status
      Display the status of each rules file and exit.

  -v, --verbose
      Be verbose.
EOF
}

execute() {
	if [ -n "${verbose}" ]; then
		echo "> ${@}"
	fi
	"${@}"
}


set +e
### Parse options ##############################################################
ARGS="$(getopt -o ${SOPTS} --long ${LOPTS} -n ${PROG} -- "${@}")"
if [ "${?}" != "0" ]; then
	short_usage >&2
	exit 1
else
	eval set -- "${ARGS}"
fi
################################################################################
set -e


while true; do
	case "${1}" in
		-h|--help)
			usage
			exit 0
			;;
		-o|--only)
			only="${2}"
			shift 2
			;;
		-r|--restore)
			restore="true"
			shift
			;;
		-s|--status)
			status="true"
			shift
			;;
		-v|--verbose)
			verbose="-v"
			shift
			;;
		--)
			shift
			break
			;;
		*)
			unknown_argument "${1}" >&2
			short_usage >&2
			exit 1
			;;
	esac
done

if [ "${status}" = "true" ]; then
	for rules in 70-persistent-cd.rules 70-persistent-net.rules; do
		printf "%s\t" "${rules}"
		if [ -h "${ETC_RULES_DIR}/${rules}" ]; then
			printf "%s " ":link: ->"
			readlink -f ${ETC_RULES_DIR}/${rules}
		elif [ -f "${ETC_RULES_DIR}/${rules}" ]; then
			printf "%s " ":file: =="
			ls ${ETC_RULES_DIR}/${rules}
		else
			printf "%s\n"   ":none: ()"
		fi
	done
	exit 0
fi

# Now, analyse the results.
case "${only}" in
	cd)
		TYPE="cd"
		SKIP="net"
		;;
	net)
		TYPE="net"
		SKIP="cd"
		;;
	"")
		TYPE="cd net"
		SKIP=""
		;;
	*)
		unknown_argument "${only}" >&2
		short_usage >&2
		exit 1
		;;
esac

make_regular() {
	persistent="${ETC_RULES_DIR}/70-persistent-${1}.rules"
	if [ -h "${persistent}" ]; then
		unpersistent="$(readlink -f ${persistent})"
		execute rm ${verbose} ${persistent}
		if [ -f "${unpersistent}" ]; then
			execute mv ${verbose} ${unpersistent} ${persistent}
		else
			execute touch ${persistent}
		fi

	elif [ ! -f "${persistent}" ]; then
		unpersistent="${RUN_RULES_DIR}/70-persistent-${1}.rules"
		if [ -f "${unpersistent}" ]; then
			execute mv ${verbose} ${unpersistent} ${persistent}
		else
			execute touch ${persistent}
		fi
	fi
}

make_symlink() {
	persistent="${ETC_RULES_DIR}/70-persistent-${1}.rules"
	unpersistent="${RUN_RULES_DIR}/70-persistent-${1}.rules"
	if [ -h "${persistent}" ]; then
		target="$(readlink -f ${persistent})"
		if	[ "${target}" = "${unpersistent}" ]; then
			[ -f "${target}" ] || execute touch ${target}
			# nothing else to do:
			continue
		else
			#[ -d "${RUN_RULES_DIR}" ] || execute mkdir -p ${RUN_RULES_DIR}
			[ -f "${target}" ] && execute mv ${verbose} ${target} ${unpersistent}
			execute rm ${verbose} ${persistent}
		fi

	elif [ -f "${persistent}" ]; then
		#[ -d "${RUN_RULES_DIR}" ] || execute mkdir -p ${RUN_RULES_DIR}
		execute mv ${verbose} ${persistent} ${unpersistent}
	fi

	#[ -e "${persistent}" ] && execute rm ${verbose} ${persistent}
	[ -e "${unpersistent}" ] || execute touch ${unpersistent}
	execute ln -s ${verbose} ${unpersistent} ${persistent}
}

# And run...
if [ "${restore}" = "true" ]; then
	for	i in ${TYPE}; do
		make_regular ${i}
	done
	for	i in ${SKIP}; do
		make_symlink ${i}
	done

else
	for	i in ${TYPE}; do
		make_symlink ${i}
	done
	for	i in ${SKIP}; do
		make_regular ${i}
	done
fi

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