File: postinstall.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 (131 lines) | stat: -rwxr-xr-x 5,029 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

# Postinstall script for Network UPS Tools package

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"

# make sure the nut user exists and has correct memberships
res="`getent group @RUN_AS_GROUP@`" || res=""
if [ -z "$res" ]; then
	/usr/sbin/groupadd "@RUN_AS_GROUP@"
fi
res="`getent passwd @RUN_AS_USER@`" || res=""
if [ -z "$res" ]; then
	/usr/sbin/useradd -c "Network UPS Tools" -g "@RUN_AS_GROUP@" -G root -d "@STATEPATH@" -s /bin/false @RUN_AS_USER@
fi

res="`groups "@RUN_AS_GROUP@" | grep -w "@RUN_AS_USER@"`" || res=""
if [ -z "$res" ]; then
	/usr/sbin/usermod -g "@RUN_AS_GROUP@" -G root "@RUN_AS_USER@"
fi

# make sure that conffiles are secured and have the correct ownerships
if [ -d "@CONFPATH@" ] ; then
	chown "root:@RUN_AS_GROUP@" "@CONFPATH@"
fi
for file in nut.conf ups.conf upsd.conf upsmon.conf upsd.users upssched.conf nut-driver-enumerator.conf; do
	if [ -f "@CONFPATH@/$file" ] ; then
		chown "root:@RUN_AS_GROUP@" "@CONFPATH@/$file"
		chmod 640 "@CONFPATH@/$file"
	fi
done

# make sure that /var/run exists (for privileged processes)
if [ ! -d "@PIDPATH@" ] ; then
	mkdir -p "@PIDPATH@"
fi

# make sure that /var/run/nut exists and has the correct ownerships
if [ ! -d "@ALTPIDPATH@" ] ; then
	mkdir -p "@ALTPIDPATH@"
fi
if [ -d "@ALTPIDPATH@" ] ; then
	chown "root:@RUN_AS_GROUP@" "@ALTPIDPATH@"
	chmod 770 "@ALTPIDPATH@"
fi

# make sure that /var/state/ups exists and has the correct ownerships
if [ ! -d "@STATEPATH@" ] ; then
	mkdir -p "@STATEPATH@"
fi
if [ -d "@STATEPATH@" ] ; then
	chown "root:@RUN_AS_GROUP@" "@STATEPATH@"
	chmod 770 "@STATEPATH@"
fi

if [ -n "@auglensdir@" ] && [ -d "@auglensdir@" ] && [ -d "@datarootdir@/augeas-lenses" ] ; then
	( cd "@datarootdir@/augeas-lenses" && cp -prf ./ "@auglensdir@"/ )
fi

if test -x /usr/sbin/svcadm && test -x /usr/sbin/svccfg && test -x /usr/bin/svcs ; then
	echo "Register SMF services..."
	for S in nut-driver-enumerator nut-driver nut-server nut-monitor nut ; do
		echo "Importing NUT service manifest: $S..."
		/usr/sbin/svccfg import "@datarootdir@/solaris-smf/manifest/$S.xml"
	done
	# Enable services if the system already has a configuration (e.g. upgrade)
	if test -s "@CONFPATH@/ups.conf" ; then
		echo "Stopping NUT drivers, if any (in case of upgrade)..."
		@SBINDIR@/upsdrvsvcctl stop
		@SBINDIR@/upsdrvctl -DDDDD stop
		sleep 5
		echo "(Re-)register NUT drivers (if any)..."
		REPORT_RESTART_42=no AUTO_START=no "@NUT_LIBEXECDIR@/nut-driver-enumerator.sh" --reconfigure
		sleep 2
		echo "Enable NUT drivers (if any)..."
		# Note: we now provide two services, a daemon that keeps checking
		# the config for changes and a default one that should be refreshed
		# manually to reconfigure nut-driver instances - and is "cheaper".
		# This may still fail if the daemon instance is somehow enabled (admin)
		PREV_ACTIVE_ENUMERATOR=""
		if test -s "${ACTIVE_ENUMERATOR_FMRI_FILE}" ; then
			PREV_ACTIVE_ENUMERATOR="`head -1 "${ACTIVE_ENUMERATOR_FMRI_FILE}"`"
		fi
		[ x"nut-driver-enumerator:default" = x"${PREV_ACTIVE_ENUMERATOR}" ] && PREV_ACTIVE_ENUMERATOR=""
		for ACTIVE_ENUMERATOR in ${PREV_ACTIVE_ENUMERATOR} nut-driver-enumerator:default ; do
			/usr/sbin/svcadm enable -s ${ACTIVE_ENUMERATOR} || \
			{ /usr/sbin/svcadm clear ${ACTIVE_ENUMERATOR} 2>/dev/null ; \
			  /usr/sbin/svcadm enable -s ${ACTIVE_ENUMERATOR} ; } && break || true
		done
		@SBINDIR@/upsdrvsvcctl start
	else
		echo "NOT ENABLING nut-driver-enumerator at this time : missing or empty @CONFPATH@/ups.conf" >&2
	fi
	if test -s "@CONFPATH@/ups.conf" && test -e "@CONFPATH@/upsd.conf" && test -e "@CONFPATH@/upsd.users" ; then
		# Note on the mix of "-s" and "-e" in tests above:
		# it is a valid use-case for an admin to have just touched an
		# empty upsd.conf and so use default settings for the daemon
		echo "Enable NUT upsd data server..."
		/usr/sbin/svcadm enable -s nut-server
	else
		echo "NOT ENABLING nut-server at this time : missing at least one of : @CONFPATH@/ups.conf @CONFPATH@/upsd.conf @CONFPATH@/upsd.users" >&2
	fi
	if test -s "@CONFPATH@/upsmon.conf" ; then
		echo "Enable NUT upsmon client..."
		/usr/sbin/svcadm enable -s nut-monitor
	else
		echo "NOT ENABLING nut-monitor at this time : missing or empty @CONFPATH@/upsmon.conf" >&2
	fi
	echo "Enable NUT umbrella service..."
	/usr/sbin/svcadm enable -s nut
else
	echo "Put init script in /etc/init.d..."
	cp -pf "@NUT_DATADIR@/solaris-init/nut" /etc/init.d
	chown root:bin /etc/init.d/nut
	chmod 744 /etc/init.d/nut

	ln -s ../init.d/nut /etc/rc3.d/S90nut > /dev/null 2>&1
	ln -s ../init.d/nut /etc/rc3.d/K10nut > /dev/null 2>&1

	# Start nut services

	#echo "Starting nut services"
	#$NUT_DIR/sbin/upsdrvctl start #> /dev/null 2>&1
	#$NUT_DIR/sbin/upsd #> /dev/null 2>&1
	#$NUT_DIR/sbin/upsmon #> /dev/null 2>&1
fi