summaryrefslogtreecommitdiff
path: root/www/squid31/files/pkg-install.in
blob: 5fc09b22e0e32cdcebe3f2d64d9e6029b58236d7 (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
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
#!/bin/sh
#
# $FreeBSD$
#

PATH=/bin:/usr/bin:/usr/sbin
pkgname=$1
squid_base="${PKG_PREFIX:-%%PREFIX%%}/squid"
squid_confdir="${PKG_PREFIX:-%%PREFIX%%}/etc/squid"
if [ -x /usr/sbin/nologin ]; then
	nologin=/usr/sbin/nologin
else
	nologin=/sbin/nologin
fi
squid_user="%%SQUID_UID%%"
squid_group="%%SQUID_GID%%"
squid_gid=100
squid_uid=100
# Try to catch the case where the $squid_user might have been created with an
# id greater than or equal 3128. The valid exception is "nobody".
nobody_uid=65534
nobody_gid=65534
squid_oldgid=3128
squid_olduid=3128
unset wrong_id
case $2 in
PRE-INSTALL)
	echo "===> Pre-installation configuration for ${pkgname}"
	if ! pw groupshow ${squid_group} -q >/dev/null ; then
		echo "There is no group '${squid_group}' on this system, so I will try to create it:"
		if ! pw groupadd ${squid_group} -g ${squid_gid} -q ; then
			echo "Failed to create group \"${squid_group}\"!" >&2
			echo "Please create it manually." >&2
			exit 1
		else
			echo "Group '${squid_group}' created successfully:"
		fi
	else
		echo "I will use the existing group '${squid_group}':"
		current_gid=`pw groupshow ${squid_group}|cut -f 3 -d :`
		if [ ${current_gid} -ge ${squid_oldgid} \
		    -a ${current_gid} -ne ${nobody_gid} ]; then
			wrong_id=1
		fi	
	fi
	pw groupshow ${squid_group}

	if ! pw usershow ${squid_user} -q >/dev/null ; then
		echo "There is no account '${squid_user}' on this system, so I will try to create it:"
		if ! pw useradd -q -n ${squid_user} \
		    -u ${squid_uid} -g ${squid_group} \
	  	    -c "Squid caching-proxy pseudo user" \
		    -d "${squid_base}" -s "${nologin}" \
		    -h - ; then
			echo "Failed to create user '${squid_user}'!" >&2
			echo "Please create it manually." >&2
			exit 1
		else
			echo "User '${squid_user}' created successfully:"
		fi
	else
		echo "I will use the existing user '${squid_user}':"
		current_uid=`id -u ${squid_user}`
		if [ ${current_uid} -ge ${squid_olduid} \
		    -a ${current_uid} -ne ${nobody_uid} ];
		then
			wrong_id=1
		fi
	fi
	pw usershow ${squid_user}
	if [ "${wrong_id}" ]; then
		echo ""
		echo " * NOTICE *"
		echo ""
		echo "The Squid pseudo-user's uid and/or gid have been found"
		echo "to be greater than or equal 3128."
		echo ""
		echo "This is not a problem as such, but violates the FreeBSD"
		echo "ports' principle that a ports must not claim a uid greater"
		echo "than 999."
		echo ""
		echo "Since version 2.5.4_11, the Squid user is thus created"
		echo "with an id of ${squid_uid}:${squid_gid} while earlier versions of this"
		echo "port used the first unused uid/gid greater than or"
		echo "equal 3128."
		echo ""
		echo "If you want to change the existing Squid user's id, run"
		echo "'make changeuser' after the installation has completed."
		echo "If you installed this port via a package, issue the"
		echo "following commands as root:"
		echo ""
		echo "pw userdel -u ${current_uid}"
		echo "pw groupadd -n ${squid_group} -g ${squid_gid}"
		echo "pw useradd -n ${squid_user} -u ${squid_uid} \\"
		echo "    -c \"Squid caching-proxy pseudo user\" \\"
		echo "    -g ${squid_group} -d ${squid_base} -s /sbin/nologin \\"
		echo "    -h -"
		echo "find -H ${PKG_PREFIX} -user ${current_uid} -exec chown ${squid_user} {} \\;"
		echo "find -H ${PKG_PREFIX} -group ${current_gid} -exec chgrp ${squid_group} {} \\;"
		echo ""
		echo "In case you have installed third party software for Squid"
		echo "like squidGuard, you should additionally run:"
		echo "find -H /var -user ${current_uid} -exec chown ${squid_user} {} \\;"
		echo "find -H /var -group ${current_gid} -exec chgrp ${squid_group} {} \\;"
		echo ""
		if [ -z "${PACKAGE_BUILDING}" -a -z "${BATCH}" ]; then
			sleep 30
		fi
	fi
	for dir in cache logs; do
	if [ ! -d ${squid_base}/${dir} ]; then
		echo "Creating ${squid_base}/${dir}..."
		install -d -o ${squid_user} -g ${squid_group} \
		    -m 0750 ${squid_base}/${dir}
	fi
	done
	if [ ! -d ${squid_confdir} ]; then
		echo "Creating ${squid_confdir}..."
		install -d -o root -g ${squid_group} \
		    -m 0750 ${squid_confdir}
	fi
	;;
POST-INSTALL)
	for file in cachemgr.conf mime.conf squid.conf; do
		if [ ! -f ${squid_confdir}/${file} \
		    -a -f ${squid_confdir}/${file}.default ]; then
			echo "Creating ${file} from default..."
			install -c -o root -g ${squid_group} -m 0640 \
		    	    ${squid_confdir}/${file}.default \
			    ${squid_confdir}/${file}
		fi
	done
	;;
*)
	exit 64
	;;
esac
exit 0