aboutsummaryrefslogtreecommitdiff
path: root/sysutils/bsdstats/pkg-install
blob: ae1695356a9aa5eb1f604b11d5bdb9989d5cb15d (plain) (blame)
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
#!/bin/sh
# pkg-install : based off ${PORTSDIR}/mail/courier/files/pkg-install.in

# The default answer to each of the installation questions is "yes". You can
# override a question's default by setting its environment variable to "no".
#
# Environment Variable      | Question
# --------------------------+------------------------------------------------------------------
# BSDSTATS_MONTHLY_NOW      | Would you like to run it now?
# BSDSTATS_REBOOT_REPORTING | Would you like to enable reporting on bootup in /etc/rc.conf?

if [ -n "$PACKAGE_BUILDING" ]; then
	BSDSTATS_MONTHLY_NOW=${BSDSTATS_MONTHLY_NOW:=no}
	BSDSTATS_REBOOT_REPORTING=${BSDSTATS_REBOOT_REPORTING:=no}
else
	BSDSTATS_MONTHLY_NOW=${BSDSTATS_MONTHLY_NOW:=yes}
	BSDSTATS_REBOOT_REPORTING=${BSDSTATS_REBOOT_REPORTING:=yes}
fi

ask() {
	local question default answer

	question=$1
	default=$2
	if [ -z "$BATCH" -a -z "$PACKAGE_BUILDING" ]; then
		read -p "$question [$default]? " answer
	fi
	if [ -z "$answer" ]; then
		answer=$default
	fi
	echo $answer
}

yesno() {
	local question default answer

	question=$1
	default=$2
	while :; do
		answer=$(ask "$question" "$default")
		case "$answer" in
			[Yy]*) return 0;;
			[Nn]*) return 1;;
		esac
		echo "Please answer yes or no."
	done
}

if [ "$2" = "POST-INSTALL" ]; then
	log_file="${INSTALL_PREFIX}/var/log/bsdstats"
	need_to_ask=0
	if [ ! -e ${log_file} ]; then
		need_to_ask=1
	elif [ $(($(date +"%s")-$(stat -f %Sm -t %s ${log_file}))) -gt $((60*60*24*40)) ]; then
		need_to_ask=1
	fi
	if [ $need_to_ask = 1 ]; then
		if yesno "Would you like to run BSDstats now" $BSDSTATS_MONTHLY_NOW; then
			${INSTALL_PREFIX}${PKG_PREFIX}/etc/periodic/monthly/300.statistics -nodelay
		fi
	fi
	if [ ! -f "/etc/rc.conf" ] || [ -z $(grep bsdstats_enable /etc/rc.conf) ]; then
		echo
		echo "If you're installing BSDstats on a system that won't always be on, such as a"
		echo "desktop or a laptop, it is recommended that you enable it in /etc/rc.conf so"
		echo "that it will run on bootup. This will ensure that, even if your computer is"
		echo "off when \"monthly\" runs, your computer will be counted properly."
		echo
		if yesno "Would you like to enable reporting on bootup in /etc/rc.conf" $BSDSTATS_REBOOT_REPORTING; then
			echo "bsdstats_enable=\"YES\"" >> /etc/rc.conf
		fi
	fi
fi