File: preremove.in

package info (click to toggle)
nut 2.8.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,356 kB
  • sloc: ansic: 123,904; sh: 14,718; cpp: 12,558; makefile: 5,212; python: 1,114; perl: 855; xml: 47
file content (71 lines) | stat: -rwxr-xr-x 2,976 bytes parent folder | download | duplicates (4)
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
#!/bin/sh

# Preremove script for Network UPS Tools package

# Stop all nut services

NUT_DIR="@prefix@"
prefix="@prefix@" # expanded as part of some autoconf macros below

# TODO/FIXME : Should "/var/run" be a configure variable?
# Note that "/var/run" is transient tmpfs, so upgrade has to be done during same uptime.
ACTIVE_ENUMERATOR_FMRI_FILE="/var/run/nut-driver-enumerator-fmri.prev"

if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then
	# Unconfigure SMF services
	# First detect the first active (online, maintenance, etc.)
	# instance of nut-driver-enumerator so we can pass it to the
	# next lifetime in case of re-install of NUT and keep the
	# user's previously declared preference.
	ACTIVE_ENUMERATOR="`/usr/bin/svcs -H -o state,fmri '*/nut-driver-enumerator:*' | while read S F ; do [ "$S" != "disabled" ] && [ "$S" != "offline" ] && echo "$F" && break ; done`"
	if [ -n "$ACTIVE_ENUMERATOR" ]; then
		rm -f "${ACTIVE_ENUMERATOR_FMRI_FILE}"
		touch "${ACTIVE_ENUMERATOR_FMRI_FILE}"
		chmod 600 "${ACTIVE_ENUMERATOR_FMRI_FILE}"
		chown 0:0 "${ACTIVE_ENUMERATOR_FMRI_FILE}"
		echo "${ACTIVE_ENUMERATOR}" > "${ACTIVE_ENUMERATOR_FMRI_FILE}"
	fi
	# First tell the automagic to stop, so it does not interfere; diligently clean it out below
	/usr/sbin/svcadm disable nut-driver-enumerator:default || true
	/usr/sbin/svcadm disable nut-driver-enumerator:daemon || true
	for S in nut nut-monitor nut-server ; do
		echo "Stopping NUT service: $S..."
		/usr/sbin/svcadm clear "$S" 2>/dev/null
		/usr/sbin/svcadm disable -s "$S"
		echo "Removing NUT service: $S..."
		/usr/sbin/svccfg delete "$S" || \
		/usr/sbin/svccfg -s "$S" delete || \
		/usr/sbin/svccfg -s "$S" delete default
	done
	echo "Stopping NUT drivers, if any..."
	@SBINDIR@/upsdrvsvcctl stop
	@SBINDIR@/upsdrvctl -DDDDD stop
	sleep 5
	for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*'` `/usr/bin/svcs -H -o fmri '*/nut-driver-enumerator:*'` ; do
		echo "Stopping NUT service: $S..."
		/usr/sbin/svcadm clear "$S" 2>/dev/null
		/usr/sbin/svcadm disable -s "$S"
	done
	sleep 5
	for S in `/usr/bin/svcs -H -o fmri '*/nut-driver:*' | grep -wv default` `/usr/bin/svcs -H -o fmri '*/nut-driver-enumerator:*' | grep -wv default` ; do
		echo "Removing NUT service: $S..."
		# Note: S here is a full FMRI URL
		SB="`echo "$S" | sed 's,:[^:]*$,,'`"
		SI="`echo "$S" | sed 's,^.*:\([^:]*\)$,\1,'`"
		/usr/sbin/svcadm disable -s "$S"
		/usr/sbin/svccfg -s "$SB" delete -f "$SI" || \
		/usr/sbin/svccfg delete "$S"
	done
	for S in nut-driver-enumerator nut-driver ; do
		echo "Removing NUT service: $S..." && \
		/usr/sbin/svccfg delete "$S" || \
		/usr/sbin/svccfg -s "$S" delete || \
		/usr/sbin/svccfg -s "$S" delete default
	done
else
	[ -x /etc/init.d/nut ] && /etc/init.d/nut stop
fi

if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datarootdir@/augeas-lenses" ] ; then
	( cd "@datarootdir@/augeas-lenses" && find . -type f -exec rm -f "@auglensdir@"/'{}' \; )
fi