summaryrefslogtreecommitdiff
path: root/ezjail-admin
blob: 19725d28961bcad8d1ced0e2ce2820ccc1c101db (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
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
#!/bin/sh

# ugly: this variable is set during port install time
ezjail_prefix=EZJAIL_PREFIX

if [ "0" != "`id -u`" ]; then
  echo "Retry as root"; exit 1;
fi

if [ -f ${ezjail_prefix}/etc/ezjail.conf ]; then
  . ${ezjail_prefix}/etc/ezjail.conf;
fi

# set defaults
ezjail_jaildir=${ezjail_jaildir:-"/usr/jails"}
ezjail_jailtemplate=${ezjail_jailtemplate:-"$ezjail_jaildir/newjail"}
ezjail_jailbase=${ezjail_jailbase:-"$ezjail_jaildir/basejail"}
ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}

ezjail_mount_enable=${ezjail_mount_enable:-"YES"}
ezjail_devfs_enable=${ezjail_devfs_enable:-"YES"}
ezjail_devfs_ruleset=${ezjail_devfs_ruleset:-"devfsrules_jail"}
ezjail_procfs_enable=${ezjail_procfs_enable:-"YES"}
ezjail_fdescfs_enable=${ezjail_fdescfs_enable:-"YES"}

# check for command
if [ -z "$1" ];
  then echo "Usage: `basename $0` [create|delete|list|update] {params}"; exit;
fi

case "$1" in
create)
  shift
  args=`getopt xr: $*`
  if [ $? != 0 ]; then
    echo 'Usage: ezjail create [-r jailroot] [-x] jailname jailip'; exit 1;
  fi

  newjail_root=
  newjail_fill="YES"

  for arg in args; do
    case $arg in
      -x) newjail_fill="NO"; shift;;
      -r) newjail_root="$2"; shift 2;;
      --) shift; break;;
    esac
  done;
  newjail_name=$1;  newjail_ip=$2;  shift 2;

  if [ -z "$newjail_name" -o -z "$newjail_ip" -o $# != 0 ]; then
    echo 'Usage: ezjail create [-r jailroot] [-x] jailname jailip'; exit 1;
  fi

  echo running CREATE $newjail_name $newjail_ip $newjail_fill

  exit

  mkdir ${newjail_root} && cd ${ezjail_jailtemplate} \
        && find * | cpio -p -v ${newjail_root}
  ;;
delete)

  ;;
list)

  ;;
update)

  if [ ! -d ${ezjail_sourcetree} ]; then
    echo "Cannot find your copy of the FreeBSD source tree in $ezjail_sourcetree."; exit 1;
  fi

  cd ${ezjail_sourcetree}
  rm -r ${ezjail_jailfull}; mkdir -p ${ezjail_jailfull}
  make world DESTDIR=${ezjail_jailfull}
  make distribution DESTDIR=${ezjail_jailfull}

  cd ${ezjail_jailfull}
  mkdir -p ${ezjail_jailbase}
  for a in bin sbin usr/bin usr/include usr/lib usr/libexec usr/sbin usr/src usr/share; do
    find ${a} | cpio -d -p -v ${ezjail_jailbase};
    chflags -R noschg ${a}; rm -r ${a}; ln -s /basejail/${a} ${a}
  done
  mkdir basejail

  if [ -d ${ezjail_jailtemplate} ]; then
    mv ${ezjail_jailtemplate} ${ezjail_jailtemplate}_old
  fi
  mv ${ezjail_jailfull} ${ezjail_jailtemplate}

  ;;
*)
  echo "Usage: `basename $0` [create|delete|list|update] {params}"; exit;
  ;;
esac