ezjail/ezjail-config.sh

66 lines
1.7 KiB
Bash
Raw Normal View History

2005-11-08 15:11:51 +00:00
#!/bin/sh
#
# BEFORE: rcconf
2005-11-08 15:11:51 +00:00
set -o noglob
2005-12-18 16:47:21 +00:00
if [ -f /config/ezjail.flavour ]; then
. /config/ezjail.flavour
2005-11-08 15:11:51 +00:00
# we do need to install only once
2005-12-18 16:47:21 +00:00
rm -f /config/ezjail.flavour
2005-11-08 15:11:51 +00:00
fi
# set defaults
ezjail_flavour_files=${ezjail_flavour_files:-""}
ezjail_flavour_users=${ezjail_flavour_users:-""}
2005-11-08 15:11:51 +00:00
# try to create users
for user in $ezjail_flavour_users; do
2005-11-08 15:11:51 +00:00
TIFS=$IFS; IFS=:; set -- $user; IFS=$TIFS
if [ $# -eq 8 ]; then
gc=1; name=$1; grouplist=$3; gidlist=$4; home=$7
2005-11-08 15:11:51 +00:00
[ $2 ] && uid="-u $2" || uid=""
[ $5 ] && comment="-c$5" || comment=""
[ $6 ] && pass="$6" || pass="*"
[ $8 ] && shell="-s $8" || shell=""
2005-11-08 15:11:51 +00:00
[ "$home" = "${home#-}" ] && mkhome="-m" || mkhome=""
[ ${home#-} ] && home="-d ${home#-}" || home=""
# ensure all groups
2005-11-08 15:11:51 +00:00
if [ $grouplist ]; then
for group in `echo $grouplist | tr "," " "`; do
gid=`echo $gidlist | cut -d , -f $gc`; [ $gid ] && gid="-g $gid"
pw groupadd -n $group $gid
gc=$((1+$gc))
2005-11-08 15:11:51 +00:00
done
fi
# create user
[ $grouplist ] && grouplist="-G $grouplist"
[ $name ] && echo "$pass" | pw useradd -n $name $uid $shell $mkhome $home $grouplist "`echo $comment | tr = ' '`" -H 0
2005-11-08 15:11:51 +00:00
fi
done
# try to install files
2005-12-18 16:47:21 +00:00
cd /config
for file in $ezjail_flavour_files; do
TIFS=$IFS; IFS=:; set -- $file; IFS=$TIFS
set +o noglob
if [ $# -eq 3 -a "$3" ]; then
owner=$1; [ $2 ] && owner="$1:$2"
for file in ./$3; do
find ${file} | cpio -p -d /
chown -R $owner /$file
done
fi
set -o noglob
2005-11-08 15:11:51 +00:00
done
# finally install packages
2005-12-18 16:47:21 +00:00
set -o noglob
[ -d /config/pkg ] && cd /config/pkg && pkg_add *
# Get rid off ourself
rm -f /etc/rc.d/ezjail-config.sh