summaryrefslogtreecommitdiff
path: root/ezjail-config.sh
blob: 85d35e3f2b1431a3930ab20dfddb6f69f732a1a6 (plain)
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
#!/bin/sh
#
# BEFORE: rcconf

if [ -f /etc/ezjail.flavour ]; then
  . /etc/ezjail.flavour

  # we do need to install only once
  rm -f /etc/ezjail.flavour
fi

# set defaults
ezjail_flavour_root=${ezjail_flavour_root:-"/basejail/config/default"}
ezjail_flavour_files=${ezjail_flavour_files:-""}
ezjail_flavour_users=${ezjail_flavour_users:-""}
ezjail_flavour_packages=${ezjail_flavour_packages:-""}

# try to create users
for user in $ezjail_flavour_users; do
  TIFS=$IFS; IFS=:; set -- $user; IFS=$TIFS

  if [ $# -eq 8 ]; then
    gc=1; name=$1; grouplist=$3; gidlist=$4; home=$7

    [ $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
      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
    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_flavour_root
for file in $ezjail_flavour_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 -l -d /
      chown -R $owner $file
    done
  fi
done

# finally install packages
[ -d /basejail/config/pkg ] && cd /basejail/config/pkg
[ "${ezjail_flavour_packages}" ] && pkg_add ${ezjail_flavour_packages}

# Get rid off ourself
rm -f /etc/rc.d/ezjail-config.sh