freebsd-ports/net/freeradius2/files/pkg-install.in
Pav Lucistnik a08a59ba48 - Allow the installation to proceed with read-only workdir
PR:		ports/138355
Submitted by:	Dan Lukes <dan@obluda.cz>
Approved by:	David Wood <david@wood2.org.uk> (maintainer)
Feature safe:	yes
2009-09-18 11:18:09 +00:00

180 lines
4.4 KiB
Bash

#!/bin/sh
# $FreeBSD$
PATH=/usr/sbin:/usr/bin:/bin ; export PATH
radius_user="%%USER%%"
radius_uid="%%UID%%"
radius_gecos="%%GECOS%%"
radius_home="%%HOME%%"
radius_shell="%%SHELL%%"
radius_group="%%GROUP%%"
radius_gid="%%GID%%"
radius_raddb_work="%%RADDB_WORK%%"
radius_raddb="%%RADDB%%"
radius_logdir="%%LOGDIR%%"
radius_libdir="%%LIBDIR%%"
radius_run_as_user="%%RUN_AS_USER%%"
create_group() {
local user uid group gid gecos home shell
user=$1
uid=$2
group=$3
gid=$4
gecos=$5
home=$6
shell=$7
if pw group show -n $group >/dev/null 2>&1 ; then
echo "===> Using existing group $group"
else
if pw groupadd -n $group -g $gid ; then
echo "===> Created group $group"
else
cat <<-EOERRORMSG
*** Failed to create group $group.
Please add user $user and group $group
manually with the following commands:
pw groupadd -n $group -g $gid
pw useradd -n $user -u $uid -g $group -c "$gecos" \\
-d $home -s $shell -h -
and retry installing this package.
EOERRORMSG
exit 1
fi
fi
}
create_user() {
local user uid group gid gecos home shell
user=$1
uid=$2
group=$3
gid=$4
gecos=$5
home=$6
shell=$7
if pw user show -n $user >/dev/null 2>&1 ; then
echo "===> Using existing user $user"
else
if pw useradd -n $user -u $uid -g $group -c "$gecos" \
-d $home -s $shell -h - ; then
echo "===> Created user $user"
else
cat <<-EOERRORMSG
*** Failed to create user $user.
Please add user $user manually with the following command:
pw useradd -n $user -u $uid -g $group -c "$gecos" \\
-d $home -s $shell -h -
and retry installing this package.
EOERRORMSG
exit 1
fi
fi
}
if [ ${radius_run_as_user} != "yes" ]; then exit 0; fi
case $2 in
PRE-INSTALL)
# Create the radius user and group if they do not already exist
create_group $radius_user $radius_uid $radius_group $radius_gid \
"$radius_gecos" $radius_home $radius_shell
create_user $radius_user $radius_uid $radius_group $radius_gid \
"$radius_gecos" $radius_home $radius_shell
# Fix the user and group in raddb/radiusd.conf
echo "===> Setting user and group in radiusd.conf"
for file in ${radius_raddb_work}/radiusd.conf ${radius_raddb}/radiusd.conf; do
if [ -w ${file} ]; then
if ! sed -Ee "s/^[[:space:]#]*(user[[:space:]]*=[[:space:]]*).*$/\1${radius_user}/" \
-e "s/^[[:space:]#]*(group[[:space:]]*=[[:space:]]*).*$/\1${radius_group}/" \
-i .orig ${file}; then
echo "Failed to patch ${file}."
exit 1
fi
if [ -f ${file}.orig ]; then
if ! rm ${file}.orig; then
echo "Failed to delete backup file ${file}.orig."
exit 1
fi
fi
fi
done
;;
POST-INSTALL)
# Change ownership of directories
for dir in $radius_raddb $radius_logdir/radacct \
/var/run/radiusd ; do
if [ -d $dir ] || [ -L $dir ]; then
echo "===> Adjusting ownership of directory ${dir}"
if ! chown -HR $radius_user:$radius_group $dir; then
echo "Failed to adjust ownership of ${dir}."
exit 1
fi
fi
done
for file in $radius_logdir/radius.log $radius_logdir/radutmp \
$radius_logdir/radwtmp; do
if [ -f $file ]; then
echo "===> Adjusting ownership of ${file}"
if ! chown $radius_user:$radius_group $file; then
echo "Failed to adjust ownership of ${file}."
exit 1
fi
fi
done
# Update the libdir line in radiusd.conf
echo "===> Updating libdir in ${radius_raddb}/radiusd.conf"
if ! sed -i.update-libdir-original -Ee $( \
echo -n 's:^(libdir[[:space:]=]+)(.*[[:space:]:]+)?' ; \
echo -n $( echo ${radius_libdir} | \
sed -Ee 's:^(.*)-[[:digit:].]+$:\1:' ) ; \
echo -n '(-[[:digit:].]+)?([[:space:]:]+.*)?$' ; \
echo -n ':\1\2'${radius_libdir}'\4:' \
) ${radius_raddb}/radiusd.conf; then
echo "Failed to update libdir in ${radius_raddb}/radius.conf"
exit 1
fi
if [ -f ${radius_raddb}/radiusd.conf.update-libdir-original ]; then
if ! rm ${radius_raddb}/radiusd.conf.update-libdir-original; then
echo -n 'Failed to delete backup file '
echo "${radius_raddb}/radiusd.conf.update-libdir-original."
exit 1
fi
fi
;;
esac
# Emacs variables
# Local Variables:
# mode: sh
# sh-basic-offset: 4
# sh-indent-comment: nil
# End: