summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin125
1 files changed, 56 insertions, 69 deletions
diff --git a/ezjail-admin b/ezjail-admin
index bbabd98..5cd25ea 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -34,7 +34,7 @@ ezjail_dirlist="bin boot lib libexec rescue sbin usr/bin usr/games usr/include u
34# 34#
35 35
36# define our bail out shortcut 36# define our bail out shortcut
37exerr () { echo -e "$*"; exit 1; } 37exerr () { echo -e "$*" >&2 ; exit 1; }
38 38
39# define detach strategy for image jails 39# define detach strategy for image jails
40detach_images () { 40detach_images () {
@@ -132,35 +132,30 @@ ezjail_updateports () {
132# 132#
133 133
134# check for command 134# check for command
135[ "$1" ] || exerr "Usage: `basename -- $0` [config|create|delete|install|list|update] {params}" 135[ $# -gt 0 ] || exerr "Usage: `basename -- $0` [config|create|delete|install|list|update] {params}"
136 136
137case "$1" in 137case "$1" in
138######################## ezjail-admin CREATE ######################## 138######################## ezjail-admin CREATE ########################
139create) 139create)
140 shift
141 args=`getopt f:r:s:xic:C: $*` || exerr "Usage: `basename -- $0` create [-xi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip"
142
143 # Clean variables, prevent polution 140 # Clean variables, prevent polution
144 unset ezjail_rootdir ezjail_flavour ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_device ezjail_config 141 unset ezjail_rootdir ezjail_flavour ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_device ezjail_config
145 ezjail_fillme="YES" 142 ezjail_fillme="YES"
146 143
147 set -- ${args} 144 shift; while getopts :f:r:s:xic:C: arg; do case ${arg} in
148 for arg do 145 x) ezjail_fillme="NO";;
149 case ${arg} in 146 r) ezjail_rootdir="${OPTARG}";;
150 -x) ezjail_fillme="NO"; shift;; 147 f) ezjail_flavour="${OPTARG}";;
151 -r) ezjail_rootdir="$2"; shift 2;; 148 c) ezjail_imagetype="${OPTARG}";;
152 -f) ezjail_flavour="$2"; shift 2;; 149 C) ezjail_imageparams="${OPTARG}";;
153 -c) ezjail_imagetype=$2; shift 2;; 150 i) ezjail_imagetype=${ezjail_imagetype:-"simple"};;
154 -C) ezjail_imageparams=$2; shift 2;; 151 s) ezjail_imagesize="${OPTARG}";;
155 -i) ezjail_imagetype=${ezjail_imagetype:-"simple"}; shift;; 152 ?) exerr "Usage: `basename -- $0` create [-xi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip";;
156 -s) ezjail_imagesize="$2"; shift 2;; 153 esac; done; shift $(( ${OPTIND} - 1 ))
157 --) shift; break;; 154
158 esac
159 done
160 ezjail_name=$1; ezjail_ip=$2 155 ezjail_name=$1; ezjail_ip=$2
161 156
162 # we need at least a name and an ip for new jail 157 # we need at least a name and an ip for new jail
163 [ "${ezjail_name}" -a "${ezjail_ip}" -a $# = 2 ] || exerr "Usage: `basename -- $0` create [-xi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip" 158 [ "${ezjail_name}" -a "${ezjail_ip}" -a $# -eq 2 ] || exerr "Usage: `basename -- $0` create [-xi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip"
164 159
165 # check for sanity of settings concerning the image feature 160 # check for sanity of settings concerning the image feature
166 [ "${ezjail_imagetype}" -a "${ezjail_fillme}" = "YES" -a ! "${ezjail_imagesize}" ] && exerr "Image jails need an image size." 161 [ "${ezjail_imagetype}" -a "${ezjail_fillme}" = "YES" -a ! "${ezjail_imagesize}" ] && exerr "Image jails need an image size."
@@ -168,6 +163,15 @@ create)
168 # check for a sane image type 163 # check for a sane image type
169 case ${ezjail_imagetype} in ""|simple|bde|eli) ;; *) exerr "Usage: `basename -- $0` create [-xi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip";; esac 164 case ${ezjail_imagetype} in ""|simple|bde|eli) ;; *) exerr "Usage: `basename -- $0` create [-xi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] jailname jailip";; esac
170 165
166 # check for a sane image size and split it up in blocks
167 if [ "${ezjail_imagesize}" ]; then
168 _val=`echo "${ezjail_imagesize}"|tr A-Z a-z|sed -Ees:g:km:g -es:m:kk:g -es:k:*2b:g -es:b:*128w:g -es:w:*4\ :g -e"s:(^|[^0-9])0x:\1\0X:g" -ey:x:*:`
169 _val=`echo $(( ${_val} ))`
170 [ $? -eq 0 ] || exerr "Error: The image size you specified is somehow incomprehensible."
171 ezjail_imageblockcount=$(( ${_val} / 1048576 ))
172 ezjail_imagerestbyte=$(( ${_val} % 1048576 ))
173 fi
174
171 # check, whether ezjail-update has been called. existence of 175 # check, whether ezjail-update has been called. existence of
172 # ezjail_jailbase is our indicator 176 # ezjail_jailbase is our indicator
173 [ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first." 177 [ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first."
@@ -229,7 +233,8 @@ create)
229 233
230 # Now create jail disc image 234 # Now create jail disc image
231 touch "${ezjail_image}" 235 touch "${ezjail_image}"
232 dd if=/dev/random of="${ezjail_image}" bs="${ezjail_imagesize}" count=1 || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${ezjail_image}. The image size provided was ${ezjail_imagesize}." 236 dd if=/dev/random of="${ezjail_image}" bs=1m count=${ezjail_imageblockcount} || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${ezjail_image}. The image size provided was ${ezjail_imagesize}."
237 ( dd if=/dev/random bs=${ezjail_imagerestbytes} count=1 >> "${ezjail_image}" ) || exerr "Error: Could not (or not fully) create the image file. You might want to check (and possibly remove) the file ${ezjail_image}. The image size provided was ${ezjail_imagesize}."
233 238
234 # And attach device 239 # And attach device
235 ezjail_imagedevice=`mdconfig -a -t vnode -f ${ezjail_image}` 240 ezjail_imagedevice=`mdconfig -a -t vnode -f ${ezjail_image}`
@@ -334,22 +339,16 @@ create)
334 ;; 339 ;;
335######################## ezjail-admin DELETE ######################## 340######################## ezjail-admin DELETE ########################
336delete) 341delete)
337 shift
338 args=`getopt w $*` || exerr "Usage: `basename -- $0` delete [-w] jailname"
339
340 # Clean variables, prevent polution 342 # Clean variables, prevent polution
341 unset ezjail_wipeme 343 unset ezjail_wipeme
342 344
343 set -- ${args} 345 shift; while getopts :w arg; do case ${arg} in
344 for arg do 346 w) ezjail_wipeme="YES";;
345 case ${arg} in 347 ?) exerr "Usage: `basename -- $0` delete [-w] jailname";;
346 -w) ezjail_wipeme="YES"; shift;; 348 esac; done; shift $(( $OPTIND - 1 ))
347 --) shift; break;;
348 esac
349 done
350 349
351 # we need name of jail to vanish 350 # we need name of jail to vanish
352 [ $# = 1 ] || exerr "Usage: `basename -- $0` delete [-w] jailname" 351 [ $# -eq 1 ] || exerr "Usage: `basename -- $0` delete [-w] jailname"
353 352
354 # Get all info we have on that jail 353 # Get all info we have on that jail
355 fetchjailinfo $1 354 fetchjailinfo $1
@@ -376,6 +375,8 @@ delete)
376 ;; 375 ;;
377######################## ezjail-admin LIST ######################## 376######################## ezjail-admin LIST ########################
378list) 377list)
378 [ $# -eq 0 ] || exerr "Usage: `basename -- $0` list"
379
379 ezjail_list=`find -X ${ezjail_prefix}/etc/ezjail/ 2> /dev/null | xargs rcorder | xargs basename -a` 380 ezjail_list=`find -X ${ezjail_prefix}/etc/ezjail/ 2> /dev/null | xargs rcorder | xargs basename -a`
380 381
381 printf "%-3s %-5s %-15s %-28s %s\\n" STA JID IP Hostname "Root Directory" 382 printf "%-3s %-5s %-15s %-28s %s\\n" STA JID IP Hostname "Root Directory"
@@ -392,23 +393,19 @@ list)
392 ;; 393 ;;
393######################## ezjail-admin UPDATE ######################## 394######################## ezjail-admin UPDATE ########################
394setup|update) 395setup|update)
395 shift
396 args=`getopt ipPs: $*` || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
397
398 # Clean variables, prevent polution 396 # Clean variables, prevent polution
399 unset ezjail_provideports 397 unset ezjail_provideports
400 ezjail_installaction="world" 398 ezjail_installaction="world"
401 399
402 set -- ${args} 400 shift; while getopts :ipPs: arg; do case ${arg} in
403 for arg do 401 i) ezjail_installaction="installworld";;
404 case ${arg} in 402 s) ezjail_sourcetree="${OPTARG}";;
405 -i) ezjail_installaction="installworld"; shift;; 403 p) ezjail_provideports="YES";;
406 -s) ezjail_sourcetree="$2"; shift 2;; 404 P) ezjail_provideports="YES"; ezjail_installaction="none";;
407 -p) ezjail_provideports="YES"; shift;; 405 ?) exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]";;
408 -P) ezjail_provideports="YES"; ezjail_installaction="none"; shift;; 406 esac; done; shift $(( ${OPTIND} - 1 ))
409 --) shift; break;; 407
410 esac 408 [ $# -eq 0 ] || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
411 done
412 409
413 if [ "${ezjail_installaction}" = "none" ]; then 410 if [ "${ezjail_installaction}" = "none" ]; then
414 # check, whether ezjail-update has been called. existence of 411 # check, whether ezjail-update has been called. existence of
@@ -437,23 +434,19 @@ setup|update)
437 ;; 434 ;;
438######################## ezjail-admin INSTALL ######################## 435######################## ezjail-admin INSTALL ########################
439install) 436install)
440 shift
441 args=`getopt mpsh:r: $*` || exerr "Usage: `basename -- $0` install [-mps] [-h host] [-r release]"
442
443 # Clean variables, prevent polution 437 # Clean variables, prevent polution
444 unset ezjail_release ezjail_ftphost ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir 438 unset ezjail_release ezjail_ftphost ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir
445 439
446 set -- ${args} 440 shift; while getopts :mpsh:r: arg; do case ${arg} in
447 for arg do 441 m) ezjail_installmanpages=" manpages";;
448 case ${arg} in 442 s) ezjail_installsources=" src";;
449 -m) ezjail_installmanpages=" manpages"; shift;; 443 p) ezjail_installports="YES";;
450 -s) ezjail_installsources=" src"; shift;; 444 h) ezjail_ftphost="${OPTARG}";;
451 -p) ezjail_installports="YES"; shift;; 445 r) ezjail_release="${OPTARG}";;
452 -h) ezjail_ftphost="$2"; shift 2;; 446 ?) exerr "Usage: `basename -- $0` install [-mps] [-h host] [-r release]";;
453 -r) ezjail_release="$2"; shift 2;; 447 esac; done; shift $(( ${OPTIND} - 1 ))
454 --) shift; break;; 448
455 esac 449 [ $# -eq 0 ] || exerr "Usage: `basename -- $0` install [-mps] [-h host] [-r release]";;
456 done
457 450
458 ezjail_installarch=`uname -p` 451 ezjail_installarch=`uname -p`
459 ezjail_ftphost=${ezjail_ftphost:-"ftp.freebsd.org"} 452 ezjail_ftphost=${ezjail_ftphost:-"ftp.freebsd.org"}
@@ -518,21 +511,15 @@ install)
518 ;; 511 ;;
519######################## ezjail-admin CONFIG ######################## 512######################## ezjail-admin CONFIG ########################
520config) 513config)
521 shift
522 args=`getopt -r: $*` || exerr "Usage: `basename -- $0` config [-r run|norun] jailname"
523
524 # Clean variables, prevent polution 514 # Clean variables, prevent polution
525 unset ezjail_setrunnable 515 unset ezjail_setrunnable
526 516
527 set -- ${args} 517 shift; while getopts :r: arg; do case ${arg} in
528 for arg do 518 r) ezjail_setrunnable=${OPTARG};;
529 case ${arg} in 519 ?) exerr "Usage: `basename -- $0` config [-r run|norun] jailname";;
530 -r) ezjail_setrunnable=$2; shift 2;; 520 esac; done; shift $(( ${OPTIND} - 1 ))
531 --) shift; break;;
532 esac
533 done
534 521
535 [ $# = 1 ] || exerr "Usage: `basename -- $0` config [-r run|norun] jailname" 522 [ $# -eq 1 ] || exerr "Usage: `basename -- $0` config [-r run|norun] jailname"
536 523
537 # Jail name mandatory 524 # Jail name mandatory
538 fetchjailinfo $1 525 fetchjailinfo $1