From 29bde9a8915fe432891aa4aa68b3e787c7dd4f05 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Wed, 9 Nov 2005 01:44:29 +0000 Subject: Comment field added to adduser line, install files and packages rudiments --- ezjail-config.sh | 59 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'ezjail-config.sh') diff --git a/ezjail-config.sh b/ezjail-config.sh index 0b9d083..a84407c 100644 --- a/ezjail-config.sh +++ b/ezjail-config.sh @@ -1,14 +1,16 @@ #!/bin/sh +# +# BEFORE: rcconf if [ -f /etc/ezjail.template ]; then . /etc/ezjail.template # we do need to install only once - # rm /etc/ezjail.template + # rm -f /etc/ezjail.template fi # set defaults -ezjail_template_root=${ezjail_template_root:-"/basejail/config/_JAILNAME_"} +ezjail_template_root=${ezjail_template_root:-"/basejail/config/default"} ezjail_template_files=${ezjail_template_files:-""} ezjail_template_users=${ezjail_template_users:-""} ezjail_template_packages=${ezjail_template_packages:-""} @@ -16,28 +18,49 @@ ezjail_template_packages=${ezjail_template_packages:-""} # try to create users for user in $ezjail_template_users; do TIFS=$IFS; IFS=:; set -- $user; IFS=$TIFS - if [ $# -eq 7 ]; then - name=$1; grouplist=$3; gidlist=$4 - [ $2 ] && uid="-u $2" || uid="" - [ $5 ] && pass=$5 || pass="*" - [ $6 ] && home=$6 - [ $7 ] && shell="-s $7" + if [ $# -eq 8 ]; then + gc=1; name=$1; grouplist=$3; gidlist=$4; home=$7 - [ x$6 = x${6#-} ] && mkhome="-r" || mkhome=""; home=${6#-} - [ $home ] && home="-h $home"; + [ $2 ] && uid="-u $2" || uid="" + [ $5 ] && comment="-c \"`echo $5 | tr _ ' '`\"" || comment="" + [ $6 ] && pass="$6" || pass="*" + [ $8 ] && shell="-s $8" || shell="" + [ "$home" = "${home#-}" ] && mkhome="-m" || mkhome="" + [ ${home#-} ] && home="-d ${home#-}" || home="" + + # ensure all groups if [ $grouplist ]; then - gc=1 - for $group in `echo $grouplist | tr "," " "`; do - gid=`echo $gidlist | cut -d , -f $gc`; [ $gid ] && gid="-n $gid" - echo pw groupadd -n $group $gid - gc=(($gc + 1)) + 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)) done - endif - if [ $name ]; then - echo pw useradd $name $uid $shell $home $grouplist fi + # create user + [ $grouplist ] && grouplist="-G $grouplist" + [ $name ] && echo "$pass" | pw useradd -n $name $uid $shell $mkhome $home $grouplist $comment -H 0 fi +done + +# try to install files +cd $ezjail_template_root +for file in $ezjail_template_files; do + TIFS=$IFS; IFS=:; set -- $file; IFS=$TIFS + 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 done + +# finally install packages +[ -d /basejail/config/pkg ] && cd /basejail/config/pkg +[ $ezjail_template_packages ] && pkg_add $ezjail_template_packages + +# Get rid off ourself +rm -f /etc/rc.d/ezjail-config.sh -- cgit v1.2.3