summaryrefslogtreecommitdiff
path: root/www/squid30/pkg-install
blob: 19e4a434a409284745495f7fa1f9bb86d2682268 (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
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
#!/bin/sh
#
# $FreeBSD$
#

PATH=/bin:/usr/bin:/usr/sbin
pkgname=$1
squid_base=${PKG_PREFIX:-/usr/local}/squid
squid_confdir=${PKG_PREFIX:-/usr/local}/etc/squid
if [ -x /usr/sbin/nologin ]; then
	nologin=/usr/sbin/nologin
else
	nologin=/sbin/nologin
fi
squid_user=${squid_user:-squid}
squid_group=${squid_group:-squid}
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

	echo "===> Post-installation informations for ${pkgname}"
	echo ""
	echo "     o You can find the configuration files for this package"
	echo "       in the directory ${squid_confdir}."
	echo ""
	echo "     o A cache directory has been created in ${squid_base}/cache."
	echo "       Log files will be written to ${squid_base}/logs."
	echo ""
	echo "     o The default configuration will deny everyone access to the"
	echo "       proxy service. Edit the \"http_access\" directives in"
	echo "       ${squid_confdir}/squid.conf to suit your needs."
	echo ""
	echo "     o If you never ran squid on this system before, you need to"
	echo "       initialize the cache directory by running \"squid -z\""
	echo "       as 'root' or '${squid_user}' before starting squid."
	echo ""
	echo "     Please note that ${PKG_PREFIX}/etc/rc.d/squid.sh is now"
	echo "     an rcNG script by default. This means that squid will not"
	echo "     start automatically at boot time."
	echo ""
	echo "     To enable squid, set squid_enable=yes in either"
	echo "     /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/squid"
	echo "     See ${PKG_PREFIX}/etc/rc.d/squid.sh for more"
	echo "     configuration options."
	echo ""
	echo "     If you want the port to install an old style rc script, run"
	echo "     'make config' and deselect the option to install an"
	echo "     rcNG script."
	echo ""
	;;
*)
	exit 64
	;;
esac
exit 0