diff options
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-x | ezjail-admin | 147 |
1 files changed, 79 insertions, 68 deletions
diff --git a/ezjail-admin b/ezjail-admin index ec375ba..34cbe49 100755 --- a/ezjail-admin +++ b/ezjail-admin | |||
@@ -37,8 +37,8 @@ ezjail_basesystem="base" | |||
37 | case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32"; ezjail_basesystem="${ezjail_basesystem} lib32";; esac | 37 | case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32"; ezjail_basesystem="${ezjail_basesystem} lib32";; esac |
38 | 38 | ||
39 | # Synopsis messages | 39 | # Synopsis messages |
40 | ezjail_usage_ezjailadmin="ezjail-admin v3.0b\nUsage: ${ezjail_admin} [archive|config|console|create|delete|install|list|restore|update] {params}" | 40 | ezjail_usage_ezjailadmin="${ezjail_admin} v3.0b\nUsage: ${ezjail_admin} [archive|config|console|create|delete|install|list|restore|update] {params}" |
41 | ezjail_usage_install="Usage: ${ezjail_admin} install [-mps] [-h host] [-r release]" | 41 | ezjail_usage_install="Usage: ${ezjail_admin} install [-mMpPsS] [-h host] [-r release]" |
42 | ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] [-a archive] jailname jailip" | 42 | ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli] [-C args] [-a archive] jailname jailip" |
43 | ezjail_usage_delete="Usage: ${ezjail_admin} delete [-w] jailname" | 43 | ezjail_usage_delete="Usage: ${ezjail_admin} delete [-w] jailname" |
44 | ezjail_usage_update="Usage: ${ezjail_admin} update [-s sourcetree] [-i] [-pP]" | 44 | ezjail_usage_update="Usage: ${ezjail_admin} update [-s sourcetree] [-i] [-pP]" |
@@ -132,12 +132,12 @@ start_stop_jail_by_script () { | |||
132 | elif [ -x "${ezjail_prefix}/etc/rc.d/ezjail.sh" ]; then | 132 | elif [ -x "${ezjail_prefix}/etc/rc.d/ezjail.sh" ]; then |
133 | (exec "${ezjail_prefix}/etc/rc.d/ezjail.sh" ${ezjail_action} ${ezjail_name}); | 133 | (exec "${ezjail_prefix}/etc/rc.d/ezjail.sh" ${ezjail_action} ${ezjail_name}); |
134 | else | 134 | else |
135 | exerr "Could not find ezjail's rc.d script in ${ezjail_prefix}/etc/rc.d/. You need to ${ezjail_action} ${ezjail_name} by hand." | 135 | exerr "Error: Could not find ezjail's rc.d script in ${ezjail_prefix}/etc/rc.d/.\n You need to ${ezjail_action} ${ezjail_name} by hand." |
136 | fi | 136 | fi |
137 | 137 | ||
138 | # Check for success of our operation | 138 | # Check for success of our operation |
139 | fetchjailinfo ${ezjail_name} | 139 | fetchjailinfo ${ezjail_name} |
140 | [ ${ezjail_success_check} "${ezjail_id}" ] || exerr "Error: Could not ${ezjail_action} ${ezjail_name}. You need to ${ezjail_action} it by hand." | 140 | [ ${ezjail_success_check} "${ezjail_id}" ] || exerr "Error: Could not ${ezjail_action} ${ezjail_name}.\n You need to ${ezjail_action} it by hand." |
141 | } | 141 | } |
142 | 142 | ||
143 | # fetch everything we need to know about an ezjail from config | 143 | # fetch everything we need to know about an ezjail from config |
@@ -196,13 +196,13 @@ fetchjailinfo () { | |||
196 | # fill the base jail - this function is used by install and update | 196 | # fill the base jail - this function is used by install and update |
197 | ezjail_splitworld() { | 197 | ezjail_splitworld() { |
198 | # Fill basejail from installed world | 198 | # Fill basejail from installed world |
199 | cd "${ezjail_jailfull}" || exerr "Cant access temporary Jail directory." | 199 | cd "${ezjail_jailfull}" || exerr "Error: Cant access temporary Jail directory." |
200 | 200 | ||
201 | # This mkdir is important, since cpio will create intermediate | 201 | # This mkdir is important, since cpio will create intermediate |
202 | # directories with permission 0700 which is bad | 202 | # directories with permission 0700 which is bad |
203 | mkdir -p "${ezjail_jailbase}/usr" | 203 | mkdir -p "${ezjail_jailbase}/usr" |
204 | for dir in ${ezjail_dirlist}; do | 204 | for dir in ${ezjail_dirlist}; do |
205 | find ${dir} | cpio -d -p -v "${ezjail_jailbase}" || exerr "Installation of ${dir} failed." | 205 | find ${dir} | cpio -d -p -v "${ezjail_jailbase}" || exerr "Error: Installation of ${dir} failed." |
206 | chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir} | 206 | chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir} |
207 | done | 207 | done |
208 | mkdir basejail | 208 | mkdir basejail |
@@ -245,7 +245,7 @@ ezjail_updateports () { | |||
245 | [ -d "${ezjail_jailbase}/usr/ports" ] && ezjail_portsnapaction="update" | 245 | [ -d "${ezjail_jailbase}/usr/ports" ] && ezjail_portsnapaction="update" |
246 | portsnap -p "${ezjail_jailbase}/usr/ports" ${ezjail_portsnapaction:-"extract"} | 246 | portsnap -p "${ezjail_jailbase}/usr/ports" ${ezjail_portsnapaction:-"extract"} |
247 | fi | 247 | fi |
248 | [ $? -eq 0 ] || exerr "Updating ports failed." | 248 | [ $? -eq 0 ] || exerr "Error: Updating ports failed." |
249 | } | 249 | } |
250 | 250 | ||
251 | # Try to fetch the list of releases the server provides | 251 | # Try to fetch the list of releases the server provides |
@@ -345,7 +345,7 @@ create) | |||
345 | [ "${ezjail_name}" -a "${ezjail_ip}" -a $# -eq 2 ] || exerr ${ezjail_usage_create} | 345 | [ "${ezjail_name}" -a "${ezjail_ip}" -a $# -eq 2 ] || exerr ${ezjail_usage_create} |
346 | 346 | ||
347 | # check for sanity of settings concerning the image feature | 347 | # check for sanity of settings concerning the image feature |
348 | [ -z "${ezjail_imagetype}" -o "${ezjail_exists}" -o "${ezjail_imagesize}" ] || exerr "Image jails need an image size." | 348 | [ -z "${ezjail_imagetype}" -o "${ezjail_exists}" -o "${ezjail_imagesize}" ] || exerr "Error: Image jails need an image size." |
349 | 349 | ||
350 | # check for a sane image type | 350 | # check for a sane image type |
351 | case ${ezjail_imagetype} in ""|simple|bde|eli) ;; *) exerr ${ezjail_usage_create};; esac | 351 | case ${ezjail_imagetype} in ""|simple|bde|eli) ;; *) exerr ${ezjail_usage_create};; esac |
@@ -360,10 +360,10 @@ create) | |||
360 | 360 | ||
361 | # check, whether ezjail has been set up correctly. existence of | 361 | # check, whether ezjail has been set up correctly. existence of |
362 | # ezjail_jailbase is our indicator | 362 | # ezjail_jailbase is our indicator |
363 | [ -d "${ezjail_jailbase}" ] || exerr "Error: base jail does not exist. Please run '${ezjail_admin} install' or '${ezjail_admin} update' first." | 363 | [ -d "${ezjail_jailbase}" ] || exerr "Error: base jail does not exist.\n Please run '${ezjail_admin} install' or '${ezjail_admin} update' first." |
364 | 364 | ||
365 | # relative paths don't make sense in rc.scripts | 365 | # relative paths don't make sense in rc.scripts |
366 | [ "${ezjail_jaildir%%[!/]*}" ] || exerr "Error: Need an absolute path in ezjail_jaildir, it currently is set to: ${ezjail_jaildir}." | 366 | [ "${ezjail_jaildir%%[!/]*}" ] || exerr "Error: Need an absolute path in ezjail_jaildir.\n It is currently set to: ${ezjail_jaildir}." |
367 | 367 | ||
368 | # jail names must not irritate file systems, excluding dots from this list | 368 | # jail names must not irritate file systems, excluding dots from this list |
369 | # was done intentionally to permit foo.com style directory names, however, | 369 | # was done intentionally to permit foo.com style directory names, however, |
@@ -377,11 +377,11 @@ create) | |||
377 | # This scenario really will only lead to real troubles in the 'fulljail' | 377 | # This scenario really will only lead to real troubles in the 'fulljail' |
378 | # case, but I should still explain this to the user and not claim that | 378 | # case, but I should still explain this to the user and not claim that |
379 | # "an ezjail would already exist" | 379 | # "an ezjail would already exist" |
380 | case ${ezjail_hostname} in basejail|newjail|fulljail|flavours|ezjailtemp) exerr "Error: ezjail needs the ${ezjail_hostname} directory for its own administrative purposes. Please rename the ezjail.";; esac | 380 | case ${ezjail_hostname} in basejail|newjail|fulljail|flavours|ezjailtemp) exerr "Error: Cannot name the jail ${ezjail_hostname}.\n ezjail needs the ${ezjail_hostname} directory for its own administrative purposes.\n Please rename the ezjail.";; esac |
381 | 381 | ||
382 | # jail names may lead to identical configs, eg. foo.bar.com == foo-bar.com | 382 | # jail names may lead to identical configs, eg. foo.bar.com == foo-bar.com |
383 | # so check, whether we might be running into problems | 383 | # so check, whether we might be running into problems |
384 | [ -e "${ezjail_config}" -o -e "${ezjail_config}.norun" ] && exerr "Error: an ezjail config already exists at ${ezjail_config}. Please rename the ezjail." | 384 | if [ -e "${ezjail_config}" -o -e "${ezjail_config}.norun" ] && exerr "Error: An ezjail config already exists at ${ezjail_config}.\n This can happen because ezjail converts non alphanumeric characters in jail names to '_'.\n Please rename the ezjail." |
385 | 385 | ||
386 | # if jail root specified on command line is not absolute, make it absolute | 386 | # if jail root specified on command line is not absolute, make it absolute |
387 | # inside our jail directory | 387 | # inside our jail directory |
@@ -391,22 +391,25 @@ create) | |||
391 | # install. Empty root dirs are considered okay, sometimes they are | 391 | # install. Empty root dirs are considered okay, sometimes they are |
392 | # mount points to be filled by ezjail. | 392 | # mount points to be filled by ezjail. |
393 | [ -d "${ezjail_rootdir}" ] && [ -z "`ls -I ${ezjail_rootdir}`" ] && ezjail_rootdirempty="YES" | 393 | [ -d "${ezjail_rootdir}" ] && [ -z "`ls -I ${ezjail_rootdir}`" ] && ezjail_rootdirempty="YES" |
394 | [ -e "${ezjail_rootdir}" -a -z "${ezjail_rootdirempty}" -a -z "${ezjail_exists}" ] && exerr "Error: the specified jail root ${ezjail_rootdir} already exists." | 394 | [ -e "${ezjail_rootdir}" -a -z "${ezjail_rootdirempty}" -a -z "${ezjail_exists}" ] && exerr "Error: A file or a non empty directory already exists at the specified jail root ${ezjail_rootdir}.\n Maybe you want to '${ezjail_admin} create -x' an existing jail?\n Please specify another jail root with the -r switch." |
395 | 395 | ||
396 | # if jail root specified on command line does not lie within our jail | 396 | # if jail root specified on command line does not lie within our jail |
397 | # directory, we need to create a softlink | 397 | # directory, we need to create a softlink |
398 | if [ "${ezjail_rootdir##${ezjail_jaildir}}" = "${ezjail_rootdir}" ]; then | 398 | if [ "${ezjail_rootdir##${ezjail_jaildir}}" = "${ezjail_rootdir}" ]; then |
399 | ezjail_softlink=${ezjail_jaildir}/`basename -- "${ezjail_rootdir}"` | 399 | ezjail_softlink=${ezjail_jaildir}/`basename -- "${ezjail_rootdir}"` |
400 | [ -e "${ezjail_softlink}" ] && exerr "Error: an ezjail already exists at ${ezjail_softlink}." | 400 | [ -e "${ezjail_softlink}" ] && exerr "Error: An ezjail already exists at ${ezjail_softlink}.\n Please specify another jail root with the -r switch." |
401 | fi | 401 | fi |
402 | 402 | ||
403 | # do some sanity checks on the selected flavour (if any) | 403 | # do some sanity checks on the selected flavour (if any) |
404 | [ "${ezjail_flavour}" -a ! -d "${ezjail_flavours}/${ezjail_flavour}" ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${ezjail_flavour} not found." | 404 | [ "${ezjail_flavour}" -a ! -d "${ezjail_flavours}/${ezjail_flavour}" ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${ezjail_flavour} not found.\n Refer to ${ezjail_admin}s man page for details on flavours." |
405 | 405 | ||
406 | # check for restore circumstances, normally this is invoked by the restore command | 406 | # check for restore circumstances, normally this is invoked by the restore command |
407 | [ "${ezjail_fromarchive}" -a "${ezjail_exists}" ] && exerr "Error: Cannot restore a jail that exists." | 407 | [ "${ezjail_fromarchive}" -a "${ezjail_exists}" ] && exerr "Error: You can not restore an archive over an existing jail.\n '${ezjail_admin} delete -w ${ezjail_name}' the old version first." |
408 | [ "${ezjail_fromarchive}" -a "${ezjail_flavour}" ] && exerr "Error: Cannot apply flavours to a restored jail." | 408 | [ "${ezjail_fromarchive}" -a "${ezjail_flavour}" ] && exerr "Error: Cannot apply flavours to a jail being restored." |
409 | [ "${ezjail_fromarchive}" -a "${ezjail_fromarchive}" != "-" -a ! -r "${ezjail_fromarchive}" ] && exerr "Error: Cannot restore from non existing archive: ${ezjail_fromarchive}." | 409 | [ "${ezjail_fromarchive}" -a "${ezjail_fromarchive}" != "-" -a ! -r "${ezjail_fromarchive}" ] && exerr "Error: No archive found at ${ezjail_fromarchive}." |
410 | |||
411 | # Ensure existence of our control directory | ||
412 | mkdir -p "${ezjail_jailcfgs}" || exerr "Error: ezjail can not create its control directory ${ezjail_jailcfgs}." | ||
410 | 413 | ||
411 | # | 414 | # |
412 | # All sanity checks that may lead to errors are hopefully passed here | 415 | # All sanity checks that may lead to errors are hopefully passed here |
@@ -415,7 +418,7 @@ create) | |||
415 | if [ "${ezjail_imagetype}" ]; then | 418 | if [ "${ezjail_imagetype}" ]; then |
416 | # Strip trailing slashes from jail root, those would confuse image path | 419 | # Strip trailing slashes from jail root, those would confuse image path |
417 | ezjail_image=${ezjail_rootdir%/}; while [ "${ezjail_image}" -a -z "${ezjail_image%%*/}" ]; do ezjail_image=${ezjail_image%/}; done | 420 | ezjail_image=${ezjail_rootdir%/}; while [ "${ezjail_image}" -a -z "${ezjail_image%%*/}" ]; do ezjail_image=${ezjail_image%/}; done |
418 | [ "${ezjail_image}" ] || exerr "Error: Could not determine image file name, something is wrong with the jail root: ${ezjail_rootdir}." | 421 | [ "${ezjail_image}" ] || exerr "Error: Could not determine image file name.\n Something is wrong with the jail root: ${ezjail_rootdir}." |
419 | 422 | ||
420 | # Location of our image file | 423 | # Location of our image file |
421 | ezjail_image="${ezjail_image}.img" | 424 | ezjail_image="${ezjail_image}.img" |
@@ -426,23 +429,23 @@ create) | |||
426 | 429 | ||
427 | # If NOT exist, create image | 430 | # If NOT exist, create image |
428 | if [ -z "${ezjail_exists}" ]; then | 431 | if [ -z "${ezjail_exists}" ]; then |
429 | [ -e "${ezjail_image}" ] && exerr "Error: a file exists at the location ${ezjail_image}, preventing our own image file to be created." | 432 | [ -e "${ezjail_image}" ] && exerr "Error: A file exists at ${ezjail_image}.\n Won't overwrite an existing image." |
430 | 433 | ||
431 | # Now create jail disc image | 434 | # Now create jail disc image |
432 | touch "${ezjail_image}" | 435 | touch "${ezjail_image}" |
433 | echo "Creating jail image ${ezjail_image}. This may take a while." | 436 | echo "Creating jail image ${ezjail_image}. This may take a while." |
434 | if [ "${ezjail_imageblockcount}" -gt 0 ]; then | 437 | if [ "${ezjail_imageblockcount}" -gt 0 ]; then |
435 | dd if="${ezjail_sourcedevice}" 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}." | 438 | dd if="${ezjail_sourcedevice}" of="${ezjail_image}" bs=1m count=${ezjail_imageblockcount} || exerr "Error: Could not (or not fully) create the image file.\n You might want to check (and possibly remove) the file ${ezjail_image}.\n The image size provided was ${ezjail_imagesize}." |
436 | fi | 439 | fi |
437 | if [ "${ezjail_imagerestbytes}" -gt 0 ]; then | 440 | if [ "${ezjail_imagerestbytes}" -gt 0 ]; then |
438 | ( dd if="${ezjail_sourcedevice}" 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}." | 441 | ( dd if="${ezjail_sourcedevice}" bs=${ezjail_imagerestbytes} count=1 >> "${ezjail_image}" ) || exerr "Error: Could not (or not fully) create the image file.\n You might want to check (and possibly remove) the file ${ezjail_image}.\n The image size provided was ${ezjail_imagesize}." |
439 | fi | 442 | fi |
440 | 443 | ||
441 | # Attach device | 444 | # Attach device |
442 | ezjail_imagedevice=`mdconfig -a -t vnode -f "${ezjail_image}"` | 445 | ezjail_imagedevice=`mdconfig -a -t vnode -f "${ezjail_image}"` |
443 | ezjail_devicelink="${ezjail_rootdir}.device" | 446 | ezjail_devicelink="${ezjail_rootdir}.device" |
444 | 447 | ||
445 | [ $? -eq 0 ] || detach_images || exerr "Error: Could not attach image device. (Command failed was 'mdconfig -a -t vnode -f ${ezjail_image}')" | 448 | [ $? -eq 0 ] || detach_images || exerr "Error: Could not attach image device.\n Command failed was 'mdconfig -a -t vnode -f ${ezjail_image}'." |
446 | fi | 449 | fi |
447 | 450 | ||
448 | case ${ezjail_imagetype} in | 451 | case ${ezjail_imagetype} in |
@@ -481,7 +484,10 @@ create) | |||
481 | mkdir -p "${ezjail_rootdir}" || detach_images || exerr "Error: Could not create jail root mount point ${ezjail_rootdir}." | 484 | mkdir -p "${ezjail_rootdir}" || detach_images || exerr "Error: Could not create jail root mount point ${ezjail_rootdir}." |
482 | mount "/dev/${ezjail_device}" "${ezjail_rootdir}" || detach_images || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_root}." | 485 | mount "/dev/${ezjail_device}" "${ezjail_rootdir}" || detach_images || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_root}." |
483 | else | 486 | else |
484 | [ -e "${ezjail_rootdir}" -a ! -d "${ezjail_rootdir}" ] && exerr "Error: Could not create mount point for your jail image. A file exists at its location. (For existing image jails, call this tool without the .img suffix when specifying jail root.)" | 487 | if [ -e "${ezjail_rootdir}" -a ! -d "${ezjail_rootdir}" ]; then |
488 | [ "${ezjail_rootdir%%*.img}" ] || exerr "Error: Could not create mount point for your jails image.\n A file exists at its location.\n Try '${ezjail_admin} create -x -r ${ezjail_rootdir%%.img} ${ezjail_name} ${ezjail_ip}' instead." | ||
489 | exerr "Error: Could not create mount point for your jails image.\n A file exists at its location." | ||
490 | fi | ||
485 | [ -d "${ezjail_rootdir}" ] || mkdir -p "${ezjail_rootdir}" | 491 | [ -d "${ezjail_rootdir}" ] || mkdir -p "${ezjail_rootdir}" |
486 | fi | 492 | fi |
487 | fi | 493 | fi |
@@ -510,7 +516,6 @@ create) | |||
510 | 516 | ||
511 | # now, where everything seems to have gone right, create control file in | 517 | # now, where everything seems to have gone right, create control file in |
512 | # ezjails config dir | 518 | # ezjails config dir |
513 | mkdir -p "${ezjail_jailcfgs}" || exerr "Error: can't create ezjails control directory (${ezjail_jailcfgs})." | ||
514 | ( | 519 | ( |
515 | if [ "${ezjail_fromarchive_config}" ]; then | 520 | if [ "${ezjail_fromarchive_config}" ]; then |
516 | grep -E ^\# ${ezjail_fromarchive_config}; echo | 521 | grep -E ^\# ${ezjail_fromarchive_config}; echo |
@@ -595,7 +600,7 @@ delete) | |||
595 | 600 | ||
596 | if [ "${ezjail_id}" ]; then | 601 | if [ "${ezjail_id}" ]; then |
597 | # if jail is still running, refuse to go any further | 602 | # if jail is still running, refuse to go any further |
598 | [ "${ezjail_forcestop}" ] || exerr "Error: Jail appears to be still running, stop it first (or use delete -f for force stop)." | 603 | [ "${ezjail_forcestop}" ] || exerr "Error: Jail appears to be still running.\n '${ezjail_admin} stop ${ezjail_name}' it first or use '${ezjail_admin} delete -f ${ezjail_name}' to force stop." |
599 | 604 | ||
600 | # This one will also exerr on failure | 605 | # This one will also exerr on failure |
601 | start_stop_jail_by_script stop | 606 | start_stop_jail_by_script stop |
@@ -603,13 +608,13 @@ delete) | |||
603 | 608 | ||
604 | if [ "${ezjail_attached}" ]; then | 609 | if [ "${ezjail_attached}" ]; then |
605 | # if jail is attached and detach is not forced, refuse to go any further | 610 | # if jail is attached and detach is not forced, refuse to go any further |
606 | [ "${ezjail_forcestop}" ] || exerr "Error: Jail image file ${ezjail_image} is attached as ${ezjail_device}. '${ezjail_admin} config -i detach' it first, or (or use delete -f for force detach)." | 611 | [ "${ezjail_forcestop}" ] || exerr "Error: Jail image file ${ezjail_image} is attached as ${ezjail_device}.\n '${ezjail_admin} config -i detach ${ezjail_name}' it first, or use '${ezjail_admin} delete -f ${ezjail_name}' to force detach." |
607 | 612 | ||
608 | detach_images keep | 613 | detach_images keep |
609 | 614 | ||
610 | # See, if it successfully detached | 615 | # See, if it successfully detached |
611 | fetchjailinfo ${ezjail_name} | 616 | fetchjailinfo ${ezjail_name} |
612 | [ "${ezjail_attached}" ] && exerr "Error: Could not detach ${ezjail_name}. You need to detach it by hand." | 617 | [ "${ezjail_attached}" ] && exerr "Error: Could not detach ${ezjail_name}.\n You need to detach it by hand." |
613 | fi | 618 | fi |
614 | 619 | ||
615 | # now we know everything we need to let the jail be gone. remove entry | 620 | # now we know everything we need to let the jail be gone. remove entry |
@@ -668,21 +673,21 @@ setup|update) | |||
668 | if [ "${ezjail_installaction}" = "none" ]; then | 673 | if [ "${ezjail_installaction}" = "none" ]; then |
669 | # check, whether ezjail has been setup correctly. existence of | 674 | # check, whether ezjail has been setup correctly. existence of |
670 | # ezjail_jailbase is our indicator | 675 | # ezjail_jailbase is our indicator |
671 | [ -d "${ezjail_jailbase}" ] || exerr "Error: base jail does not exist. You cannot fill base jails ports tree before creating it. Please run '${ezjail_admin} update' or '${ezjail_admin} install' first." | 676 | [ -d "${ezjail_jailbase}" ] || exerr "Error: base jail does not exist.\n You cannot fill base jails ports tree before creating it.\n Please run '${ezjail_admin} update' or '${ezjail_admin} install' first." |
672 | else | 677 | else |
673 | # Bump the user for some of the most common errors | 678 | # Bump the user for some of the most common errors |
674 | [ -d "${ezjail_sourcetree}" ] || exerr "Cannot find your copy of the FreeBSD source tree in ${ezjail_sourcetree}." | 679 | [ -d "${ezjail_sourcetree}" ] || exerr "Error: Cannot find your copy of the FreeBSD source tree in ${ezjail_sourcetree}.\n Consider using '${ezjail_admin} install' to create the base jail from an ftp server." |
675 | [ -e "${ezjail_sourcetree}/Makefile" ] || exerr "Your source tree in ${ezjail_sourcetree} seems to be incomplete (Makefile missing)." | 680 | [ -e "${ezjail_sourcetree}/Makefile" ] || exerr "Error: Your source tree in ${ezjail_sourcetree} seems to be incomplete (Makefile is missing)." |
676 | [ "`sysctl -n kern.securelevel`" -gt 0 ] && exerr "You're running in a secure level higher than 0. ezjail will not run correctly." | 681 | [ "`sysctl -n kern.securelevel`" -gt 0 ] && exerr "Error: You are running in a secure level higher than 0.\n ${ezjail_admin} will not update correctly.\n Please reboot into a lower secure level." |
677 | 682 | ||
678 | # Normally fulljail should be renamed by past ezjail-admin commands. | 683 | # Normally fulljail should be renamed by past ezjail-admin commands. |
679 | # However those may have failed | 684 | # However those may have failed |
680 | [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}" | 685 | [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}" |
681 | mkdir -p "${ezjail_jailfull}" || exerr "Cannot create temporary Jail directory." | 686 | mkdir -p "${ezjail_jailfull}" || exerr "Error: Cannot create temporary Jail directory." |
682 | 687 | ||
683 | # make and setup our world, then split basejail and newjail | 688 | # make and setup our world, then split basejail and newjail |
684 | cd "${ezjail_sourcetree}" && env DESTDIR="${ezjail_jailfull}" make ${ezjail_installaction} || exerr "make ${ezjail_installaction} failed." | 689 | cd "${ezjail_sourcetree}" && env DESTDIR="${ezjail_jailfull}" make ${ezjail_installaction} || exerr "Error: The command 'make ${ezjail_installaction}' failed.\n Refer to the error report(s) above." |
685 | cd "${ezjail_sourcetree}/etc" && env DESTDIR="${ezjail_jailfull}" make distribution || exerr "make distribution failed." | 690 | cd "${ezjail_sourcetree}/etc" && env DESTDIR="${ezjail_jailfull}" make distribution || exerr "Error: The command 'make distribution' failed.\n Refer to the error report(s) above." |
686 | ezjail_splitworld | 691 | ezjail_splitworld |
687 | 692 | ||
688 | fi # installaction="none" | 693 | fi # installaction="none" |
@@ -696,10 +701,13 @@ install) | |||
696 | # Clean variables, prevent polution | 701 | # Clean variables, prevent polution |
697 | unset ezjail_release ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir ezjail_ftpserverqueried | 702 | unset ezjail_release ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir ezjail_ftpserverqueried |
698 | 703 | ||
699 | shift; while getopts :mpsh:r: arg; do case ${arg} in | 704 | shift; while getopts :mMpPsSh:r: arg; do case ${arg} in |
700 | m) ezjail_installmanpages=" manpages";; | 705 | m) ezjail_installmanpages=" manpages";; |
706 | M) ezjail_installmanpages=" manpages"; unset ezjail_basesystem;; | ||
701 | s) ezjail_installsources=" src";; | 707 | s) ezjail_installsources=" src";; |
708 | S) ezjail_installsources=" src"; unset ezjail_basesystem;; | ||
702 | p) ezjail_installports="YES";; | 709 | p) ezjail_installports="YES";; |
710 | P) ezjail_installports="YES"; unset ezjail_basesystem;; | ||
703 | h) ezjail_ftphost=${OPTARG};; | 711 | h) ezjail_ftphost=${OPTARG};; |
704 | r) ezjail_release=${OPTARG};; | 712 | r) ezjail_release=${OPTARG};; |
705 | ?) exerr ${ezjail_usage_install};; | 713 | ?) exerr ${ezjail_usage_install};; |
@@ -713,7 +721,10 @@ install) | |||
713 | ezjail_dir=${ezjail_ftphost#file://} | 721 | ezjail_dir=${ezjail_ftphost#file://} |
714 | [ "${ezjail_dir%%[!/]*}" ] || ezjail_reldir=`pwd -P` | 722 | [ "${ezjail_dir%%[!/]*}" ] || ezjail_reldir=`pwd -P` |
715 | 723 | ||
716 | [ "`sysctl -n kern.securelevel`" -gt 0 ] && exerr "You're running in a secure level higher than 0. ezjail will not run correctly." | 724 | [ "`sysctl -n kern.securelevel`" -gt 0 ] && exerr "Error: You are running in a secure level higher than 0.\n ${ezjail_admin} will not install correctly.\n Please reboot into a lower secure level." |
725 | |||
726 | # Check for basejail when not installing base jail | ||
727 | [ "${ezjail_basesystem}" -o -d "${ezjail_jailbase}" ] || exerr "Error: The basejail does not exist.\n You cannot install distribution packages before creating ezjails environment.\n Please run '${ezjail_admin} update' or '${ezjail_admin} install' using lower case parameters first." | ||
717 | 728 | ||
718 | # ftp servers normally wont provide non-RELEASE-builds | 729 | # ftp servers normally wont provide non-RELEASE-builds |
719 | if [ -z "${ezjail_release}" -a "${ezjail_dir}" = "${ezjail_ftphost}" ]; then | 730 | if [ -z "${ezjail_release}" -a "${ezjail_dir}" = "${ezjail_ftphost}" ]; then |
@@ -731,7 +742,7 @@ install) | |||
731 | # Normally fulljail should be renamed by past ezjail-admin commands. | 742 | # Normally fulljail should be renamed by past ezjail-admin commands. |
732 | # However those may have failed | 743 | # However those may have failed |
733 | [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}" | 744 | [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}" |
734 | mkdir -p "${ezjail_jailfull}" || exerr "Cannot create temporary Jail directory." | 745 | mkdir -p "${ezjail_jailfull}" || exerr "Error: Cannot create temporary jail directory." |
735 | DESTDIR=${ezjail_jailfull} | 746 | DESTDIR=${ezjail_jailfull} |
736 | 747 | ||
737 | rm -rf "${ezjail_jailtemp}" | 748 | rm -rf "${ezjail_jailtemp}" |
@@ -740,13 +751,13 @@ install) | |||
740 | # The first case means, that a remote host has been specified. | 751 | # The first case means, that a remote host has been specified. |
741 | if [ "${ezjail_dir}" = "${ezjail_ftphost}" ]; then | 752 | if [ "${ezjail_dir}" = "${ezjail_ftphost}" ]; then |
742 | # Create and try to access temp dir | 753 | # Create and try to access temp dir |
743 | mkdir -p "${ezjail_jailtemp}" || exerr "Could not create temporary base jail directory ${ezjail_jailtemp}." | 754 | mkdir -p "${ezjail_jailtemp}" || exerr "Error: Could not create temporary base jail directory ${ezjail_jailtemp}." |
744 | cd "${ezjail_jailtemp}" || exerr "Could not cd to ${ezjail_jailtemp}." | 755 | cd "${ezjail_jailtemp}" || exerr "Error: Could not cd to ${ezjail_jailtemp}." |
745 | 756 | ||
746 | # Try all paths as stolen from sysinstall, break on success. | 757 | # Try all paths as stolen from sysinstall, break on success. |
747 | for ezjail_path in pub/FreeBSD/releases pub/FreeBSD/snapshot pub/FreeBSD releases snapshots NO; do | 758 | for ezjail_path in pub/FreeBSD/releases pub/FreeBSD/snapshot pub/FreeBSD releases snapshots NO; do |
748 | if [ "${ezjail_path}" = "NO" ]; then | 759 | if [ "${ezjail_path}" = "NO" ]; then |
749 | echo -e "\nCould not fetch ${pkg} from ${ezjail_ftphost}.\nMaybe your release (${ezjail_release}) is specified incorrectly or the host ${ezjail_ftphost} does not provide that release build.\nUse the -r option to specify an existing release or the -h option to specify an alternative ftp server." >&2 | 760 | echo -e "\nCould not fetch ${pkg} from ${ezjail_ftphost}.\n Maybe your release (${ezjail_release}) is specified incorrectly or the host ${ezjail_ftphost} does not provide that release build.\n Use the -r option to specify an existing release or the -h option to specify an alternative ftp server." >&2 |
750 | [ "${ezjail_ftpserverqueried}" ] || ezjail_queryftpserver | 761 | [ "${ezjail_ftpserverqueried}" ] || ezjail_queryftpserver |
751 | exit 1 | 762 | exit 1 |
752 | fi | 763 | fi |
@@ -759,19 +770,19 @@ install) | |||
759 | [ "${pkg}" = "base" ] && echo "Ignore the next question, ezjail answers it for you." | 770 | [ "${pkg}" = "base" ] && echo "Ignore the next question, ezjail answers it for you." |
760 | set -- all | 771 | set -- all |
761 | [ -f install.sh ] && yes | . install.sh | 772 | [ -f install.sh ] && yes | . install.sh |
762 | [ $? -eq 0 ] || exerr "Package install script for ${pkg} failed." | 773 | [ $? -eq 0 ] || exerr "Error: Package install script for ${pkg} failed." |
763 | 774 | ||
764 | rm -rf "${ezjail_jailtemp}" | 775 | rm -rf "${ezjail_jailtemp}" |
765 | else | 776 | else |
766 | cd "${ezjail_reldir}/${ezjail_dir}/${pkg}" || exerr "Could not cd to ${ezjail_dir}." | 777 | cd "${ezjail_reldir}/${ezjail_dir}/${pkg}" || exerr "Error: Could not cd to ${ezjail_dir}." |
767 | set -- all | 778 | set -- all |
768 | [ -f install.sh ] && yes | . install.sh | 779 | [ -f install.sh ] && yes | . install.sh |
769 | [ $? -eq 0 ] || exerr "Package install script for ${pkg} failed." | 780 | [ $? -eq 0 ] || exerr "Error: Package install script for ${pkg} failed." |
770 | fi | 781 | fi |
771 | done | 782 | done |
772 | 783 | ||
773 | # Split basejail and newjail | 784 | # Split basejail and newjail |
774 | ezjail_splitworld | 785 | [ "${ezjail_basesystem}" ] && ezjail_splitworld |
775 | 786 | ||
776 | # Fill ports, if requested | 787 | # Fill ports, if requested |
777 | [ "${ezjail_installports}" ] && ezjail_updateports | 788 | [ "${ezjail_installports}" ] && ezjail_updateports |
@@ -782,7 +793,7 @@ install) | |||
782 | [ -x "${ezjail_prefix}/etc/rc.d/ezjail" ] && exec "${ezjail_prefix}/etc/rc.d/ezjail" $@ | 793 | [ -x "${ezjail_prefix}/etc/rc.d/ezjail" ] && exec "${ezjail_prefix}/etc/rc.d/ezjail" $@ |
783 | [ -x "${ezjail_prefix}/etc/rc.d/ezjail.sh" ] && exec "${ezjail_prefix}/etc/rc.d/ezjail.sh" $@ | 794 | [ -x "${ezjail_prefix}/etc/rc.d/ezjail.sh" ] && exec "${ezjail_prefix}/etc/rc.d/ezjail.sh" $@ |
784 | 795 | ||
785 | exerr "Could not find ezjail's rc.d script in ${ezjail_prefix}/etc/rc.d/. You need to type it the long way." | 796 | exerr "Error: Could not find ezjail's rc.d script in ${ezjail_prefix}/etc/rc.d/.\n You need to type it the long way." |
786 | ;; | 797 | ;; |
787 | ######################## ezjail-admin CONSOLE ######################## | 798 | ######################## ezjail-admin CONSOLE ######################## |
788 | console) | 799 | console) |
@@ -808,7 +819,7 @@ console) | |||
808 | if [ -z "${ezjail_id}" ]; then | 819 | if [ -z "${ezjail_id}" ]; then |
809 | 820 | ||
810 | # If force start is requested, try that | 821 | # If force start is requested, try that |
811 | [ "$ezjail_forcestart}" ] || exerr "Error: Jail ${ezjail_name} appears not to be running, start it first (or use console -f for force start)." | 822 | [ "$ezjail_forcestart}" ] || exerr "Error: Jail ${ezjail_name} appears not to be running\n Start it first, or use '${ezjail_admin} console -f ${ezjail_name}' to force start." |
812 | 823 | ||
813 | # This one will also exerr on failure | 824 | # This one will also exerr on failure |
814 | start_stop_jail_by_script start | 825 | start_stop_jail_by_script start |
@@ -839,13 +850,13 @@ archive) | |||
839 | ezjail_archivedir=${ezjail_archivedir:-`pwd -P`} | 850 | ezjail_archivedir=${ezjail_archivedir:-`pwd -P`} |
840 | 851 | ||
841 | # Will not backup more than one jail per archive | 852 | # Will not backup more than one jail per archive |
842 | [ "${ezjail_archive}" -a "${ezjail_archivealljails}" ] && exerr "Error: Must not specify an archive location for multiple archives." | 853 | [ "${ezjail_archive}" -a "${ezjail_archivealljails}" ] && exerr "Error: Must not specify an archive location for multiple archives.\n Can not archive multiple jails into one archive." |
843 | 854 | ||
844 | # Will not backup more than one jail per archive | 855 | # Will not backup more than one jail per archive |
845 | [ $# -gt 1 -a "${ezjail_archive}" ] && exerr "Error: Must not specify an archive location for multiple archives." | 856 | [ $# -gt 1 -a "${ezjail_archive}" ] && exerr "Error: Must not specify an archive location for multiple archives.\n Can not archive multiple jails into one archive." |
846 | 857 | ||
847 | # Either all or only some. Decide. | 858 | # Either all or only some. Decide. |
848 | [ $# -gt 0 -a "${ezjail_archivealljails}" ] && exerr "Error: Must not specify an ezjail to backup with -A." | 859 | [ $# -gt 0 -a "${ezjail_archivealljails}" ] && exerr "Error: Must not specify an ezjail to backup with -A.\n Please use either '${ezjail_admin} archive -A' or '${ezjail_admin} archive $*'." |
849 | 860 | ||
850 | # Fetch list of all ezjails | 861 | # Fetch list of all ezjails |
851 | [ "${ezjail_archivealljails}" -a -d "${ezjail_prefix}/etc/ezjail/" ] && cd "${ezjail_prefix}/etc/ezjail/" && set - `ls | xargs rcorder` | 862 | [ "${ezjail_archivealljails}" -a -d "${ezjail_prefix}/etc/ezjail/" ] && cd "${ezjail_prefix}/etc/ezjail/" && set - `ls | xargs rcorder` |
@@ -861,7 +872,7 @@ archive) | |||
861 | 872 | ||
862 | # If jail is still running, refuse to go any further - unless forced | 873 | # If jail is still running, refuse to go any further - unless forced |
863 | if [ "${ezjail_id}" -a -z "${ezjail_force}" ]; then | 874 | if [ "${ezjail_id}" -a -z "${ezjail_force}" ]; then |
864 | echo "Warning: Jail ${ezjail_name} appears to be still running, stop it first or [-f]orce archiving." | 875 | echo "Warning: Jail ${ezjail_name} appears to be still running.\n Stop it first, or use '${ezjail_admin} -f ${ezjail_name}' to force archiving." |
865 | continue | 876 | continue |
866 | fi | 877 | fi |
867 | 878 | ||
@@ -869,11 +880,11 @@ archive) | |||
869 | if [ "${ezjail_imagetype}" -a -z "${ezjail_attached}" ]; then | 880 | if [ "${ezjail_imagetype}" -a -z "${ezjail_attached}" ]; then |
870 | if [ "${ezjail_attachblocking}" ]; then | 881 | if [ "${ezjail_attachblocking}" ]; then |
871 | echo "Warning: Jail ${ezjail_name} is an image jail and can not be attached automatically." | 882 | echo "Warning: Jail ${ezjail_name} is an image jail and can not be attached automatically." |
872 | echo " Use ezjail-admin config -i attach ${ezjail_name} to attach it first." | 883 | echo " Use '${ezjail_admin} config -i attach ${ezjail_name}' to attach it first." |
873 | continue | 884 | continue |
874 | fi | 885 | fi |
875 | mount_images | 886 | mount_images |
876 | ezjail_imagesize=-`stat -Lf %z ${ezjail_image}` | 887 | ezjail_imagesize=-`stat -Lf %z "${ezjail_image}"` |
877 | fi | 888 | fi |
878 | 889 | ||
879 | # This one goes into archive to identify jail by name and restore date | 890 | # This one goes into archive to identify jail by name and restore date |
@@ -905,7 +916,7 @@ archive) | |||
905 | 916 | ||
906 | [ -f "/etc/fstab.${ezjail_safename}" ] && ezjail_addfiles=/etc/fstab.${ezjail_safename} | 917 | [ -f "/etc/fstab.${ezjail_safename}" ] && ezjail_addfiles=/etc/fstab.${ezjail_safename} |
907 | 918 | ||
908 | cd "${ezjail_rootdir}" || exerr "Error: can't cd to ${ezjail_root}." | 919 | cd "${ezjail_rootdir}" || exerr "Error: Can't cd to ${ezjail_root}." |
909 | pax -wzXt -x ustar ${ezjail_archive_opt} \ | 920 | pax -wzXt -x ustar ${ezjail_archive_opt} \ |
910 | -s:"^[^\\.].*/${ezjail_safename}\$":prop.ezjail-${ezjail_archive_tag}: \ | 921 | -s:"^[^\\.].*/${ezjail_safename}\$":prop.ezjail-${ezjail_archive_tag}: \ |
911 | -s:"^[^\\.].*/${ezjail_safename}.norun\$":prop.ezjail-${ezjail_archive_tag}.norun: \ | 922 | -s:"^[^\\.].*/${ezjail_safename}.norun\$":prop.ezjail-${ezjail_archive_tag}.norun: \ |
@@ -919,10 +930,10 @@ archive) | |||
919 | [ "${ezjail_imagesize}" ] && detach_images keep | 930 | [ "${ezjail_imagesize}" ] && detach_images keep |
920 | 931 | ||
921 | # An error on a jail not running is bad | 932 | # An error on a jail not running is bad |
922 | [ ${ezjail_paxresult} -eq 0 -o "${ezjail_force}" ] || exerr "Error: Archiving jail failed. You might want to check ${ezjail_archive}." | 933 | [ ${ezjail_paxresult} -eq 0 -o "${ezjail_force}" ] || exerr "Error: Archiving jail failed.\n You might want to check and remove ${ezjail_archive}." |
923 | 934 | ||
924 | # When archiving a running jail, some errors might occur | 935 | # When archiving a running jail, some errors might occur |
925 | [ ${ezjail_paxresult} -eq 0 ] || echo "Warning: Archiving jail ${ezjail_name} was not completely successful. For a running jail this is not unusual. You might want to check ${ezjail_archive}." | 936 | [ ${ezjail_paxresult} -eq 0 ] || echo "Warning: Archiving jail ${ezjail_name} was not completely successful. For a running jail this is not unusual." |
926 | 937 | ||
927 | unset ezjail_archive ezjail_archive_opt ezjail_addfiles | 938 | unset ezjail_archive ezjail_archive_opt ezjail_addfiles |
928 | done | 939 | done |
@@ -947,7 +958,7 @@ restore) | |||
947 | unset ezjail_safename ezjail_imagedata ezjail_nameprop | 958 | unset ezjail_safename ezjail_imagedata ezjail_nameprop |
948 | 959 | ||
949 | # if archive location is absolute and doesn't exist, fail | 960 | # if archive location is absolute and doesn't exist, fail |
950 | [ "${ezjail_fromarchive%%[!/]*}" -a ! -f "${ezjail_fromarchive}" ] && exerr "Error: File for archive ${ezjail_fromarchive} not found." | 961 | [ "${ezjail_fromarchive%%[!/]*}" -a ! -f "${ezjail_fromarchive}" ] && exerr "Error: Archive ${ezjail_fromarchive} not found." |
951 | if [ -z "${ezjail_fromarchive%%[!/]*}" ]; then | 962 | if [ -z "${ezjail_fromarchive%%[!/]*}" ]; then |
952 | # Try archive location | 963 | # Try archive location |
953 | if [ -r "${ezjail_archivedir}/${ezjail_fromarchive}" ]; then | 964 | if [ -r "${ezjail_archivedir}/${ezjail_fromarchive}" ]; then |
@@ -969,8 +980,8 @@ restore) | |||
969 | # | 980 | # |
970 | # However, this does not protect against admins transporting | 981 | # However, this does not protect against admins transporting |
971 | # archives over insecure lines over the net. | 982 | # archives over insecure lines over the net. |
972 | [ `stat -f %u "${ezjail_fromarchive}"` -eq 0 ] || exerr "Error: Insecure ownership of archive ${ezjail_fromarchive}. Please check the file and chown it to root if you trust its source." | 983 | [ `stat -f %u "${ezjail_fromarchive}"` -eq 0 ] || exerr "Error: Insecure ownership of archive ${ezjail_fromarchive}.\n Please check the file and chown it to root if you trust its source." |
973 | [ $(( `stat -f %OLp "${ezjail_fromarchive}"` & 0022 )) -eq 0 ] || exerr "Error: Insecure permissions for archive ${ezjail_fromarchive}. Please check the file and fix permission (chmod og-w) if you trust its source." | 984 | [ $(( `stat -f %OLp "${ezjail_fromarchive}"` & 0022 )) -eq 0 ] || exerr "Error: Insecure permissions for archive ${ezjail_fromarchive}.\n Please check the file and fix permission (chmod og-w) if you trust its source." |
974 | 985 | ||
975 | ezjail_nameprop=`pax -zn -f ${ezjail_fromarchive} prop.ezjail-\*` | 986 | ezjail_nameprop=`pax -zn -f ${ezjail_fromarchive} prop.ezjail-\*` |
976 | [ $? -eq 0 -a "${ezjail_nameprop}" ] || exerr "Error: File ${ezjail_fromarchive} is not an ezjail archive." | 987 | [ $? -eq 0 -a "${ezjail_nameprop}" ] || exerr "Error: File ${ezjail_fromarchive} is not an ezjail archive." |
@@ -987,8 +998,8 @@ restore) | |||
987 | 998 | ||
988 | # Catch all errors that will likely create a broken backup | 999 | # Catch all errors that will likely create a broken backup |
989 | [ "${ezjail_safename}" -a "${ezjail_safename}" != "${ezjail_nameprop_safename}" ] && exerr "Error: Archive name ${ezjail_fromarchive} does not match archived jail ${ezjail_nameprop_safename}." | 1000 | [ "${ezjail_safename}" -a "${ezjail_safename}" != "${ezjail_nameprop_safename}" ] && exerr "Error: Archive name ${ezjail_fromarchive} does not match archived jail ${ezjail_nameprop_safename}." |
990 | [ "${ezjail_hsname}" != "${ezjail_nameprop_hsname}" -a -z "${ezjail_forcerestore}" ] && exerr "Error: Archive was created on host named ${ezjail_nameprop_hsname}. Consider using \"ezjail-admin create -a\" when migrating ezjails or -f to force restore." | 1001 | [ "${ezjail_hsname}" != "${ezjail_nameprop_hsname}" -a -z "${ezjail_forcerestore}" ] && exerr "Error: Archive was created on host named ${ezjail_nameprop_hsname}.\n Consider using '${ezjail_admin} create -a ${ezjail_fromarchive}' when migrating ezjails, or '${ezjail_admin} restore -f ${ezjail_fromarchive}' to force restore." |
991 | [ "${ezjail_hscpu}" != "${ezjail_nameprop_hscpu}" -a -z "${ezjail_forcerestore}" ] && exerr "Error: Archive was created on a different CPU. Can not restore. Consider using \"ezjail-admin create -a\" when migrating ezjails or -f to force restore." | 1002 | [ "${ezjail_hscpu}" != "${ezjail_nameprop_hscpu}" -a -z "${ezjail_forcerestore}" ] && exerr "Error: Archive was created on a different CPU. Can not restore.\n Consider using '${ezjail_admin} create -a ${ezjail_fromarchive}' when migrating ezjails, or '${ezjail_admin} restore -f ${ezjail_fromarchive}' to force restore." |
992 | 1003 | ||
993 | # Save config to tempfile and source it | 1004 | # Save config to tempfile and source it |
994 | ezjail_config=`mktemp /tmp/ezjail.prop.XXXXXXXX` | 1005 | ezjail_config=`mktemp /tmp/ezjail.prop.XXXXXXXX` |
@@ -997,10 +1008,10 @@ restore) | |||
997 | fetchjailinfo ${ezjail_safename} ${ezjail_config} | 1008 | fetchjailinfo ${ezjail_safename} ${ezjail_config} |
998 | 1009 | ||
999 | # Now all parameters are here, invoke ezjail-admin create | 1010 | # Now all parameters are here, invoke ezjail-admin create |
1000 | [ "${ezjail_rootdir}" -a "${ezjail_ip}" -a "${ezjail_hostname}" ] || exerr "Error: Archive does not contain a valid ezjail properties file." | 1011 | [ "${ezjail_rootdir}" -a "${ezjail_ip}" -a "${ezjail_hostname}" ] || exerr "Error: Archive does not contain a valid ezjail properties file.\n Some jails properties are missing." |
1001 | [ "${ezjail_imagetype}" ] && ezjail_imagedata="-c ${ezjail_imagetype} -C '${ezjail_attachparams}' -s ${ezjail_nameprop_imgagesize}" | 1012 | [ "${ezjail_imagetype}" ] && ezjail_imagedata="-c ${ezjail_imagetype} -C '${ezjail_attachparams}' -s ${ezjail_nameprop_imgagesize}" |
1002 | 1013 | ||
1003 | $0 create -a "${ezjail_fromarchive}" -A "${ezjail_config}" ${ezjail_imagedata} -r "${ezjail_rootdir}" "${ezjail_hostname}" "${ezjail_ip}" || exerr "Error: create failed." | 1014 | $0 create -a "${ezjail_fromarchive}" -A "${ezjail_config}" ${ezjail_imagedata} -r "${ezjail_rootdir}" "${ezjail_hostname}" "${ezjail_ip}" || exerr "Error: Create failed." |
1004 | rm -f "${ezjail_config}" | 1015 | rm -f "${ezjail_config}" |
1005 | 1016 | ||
1006 | done | 1017 | done |
@@ -1031,10 +1042,10 @@ config) | |||
1031 | # Do we want a new name for our jail? | 1042 | # Do we want a new name for our jail? |
1032 | if [ "${ezjail_new_name}" ]; then | 1043 | if [ "${ezjail_new_name}" ]; then |
1033 | # if jail is still running, refuse to go any further | 1044 | # if jail is still running, refuse to go any further |
1034 | [ "${ezjail_id}" ] && exerr "Error: Jail appears to be still running, stop it first." | 1045 | [ "${ezjail_id}" ] && exerr "Error: Jail appears to be still running.\n '${ezjail_admin} stop ${ezjail_name}' it first ." |
1035 | 1046 | ||
1036 | # Cannot rename an attached jail | 1047 | # Cannot rename an attached jail |
1037 | [ "${ezjail_attached}" ] && exerr "Error: Jail image file ${ezjail_image} is attached as ${ezjail_device}. '${ezjail_admin} config -i detach' it first." | 1048 | [ "${ezjail_attached}" ] && exerr "Error: Jail image file ${ezjail_image} is attached as ${ezjail_device}.\n '${ezjail_admin} config -i detach ${ezjail_name}' it first." |
1038 | 1049 | ||
1039 | # The new values for the jail | 1050 | # The new values for the jail |
1040 | ezjail_new_hostname=`echo -n ${ezjail_new_name} | tr '/~' '__'` | 1051 | ezjail_new_hostname=`echo -n ${ezjail_new_name} | tr '/~' '__'` |
@@ -1060,11 +1071,11 @@ config) | |||
1060 | # This scenario really will only lead to real troubles in the 'fulljail' | 1071 | # This scenario really will only lead to real troubles in the 'fulljail' |
1061 | # case, but I should still explain this to the user and not claim that | 1072 | # case, but I should still explain this to the user and not claim that |
1062 | # "an ezjail would already exist" | 1073 | # "an ezjail would already exist" |
1063 | case ${ezjail_new_hostname} in basejail|newjail|fulljail|flavours|ezjailtemp) exerr "Error: ezjail needs the ${ezjail_new_hostname} directory for its own administrative purposes. Please rename the ezjail.";; esac | 1074 | case ${ezjail_new_hostname} in basejail|newjail|fulljail|flavours|ezjailtemp) exerr "Error: ezjail needs the ${ezjail_new_hostname} directory for its own administrative purposes.\n Please chose another name.";; esac |
1064 | 1075 | ||
1065 | # jail names may lead to identical configs, eg. foo.bar.com == foo-bar.com | 1076 | # jail names may lead to identical configs, eg. foo.bar.com == foo-bar.com |
1066 | # so check, whether we might be running into problems | 1077 | # so check, whether we might be running into problems |
1067 | [ -e "${ezjail_new_config}" -o -e "${ezjail_new_config}.norun" ] && exerr "Error: an ezjail config already exists at ${ezjail_new_config}. Please rename the ezjail." | 1078 | [ -e "${ezjail_new_config}" -o -e "${ezjail_new_config}.norun" ] && exerr "Error: An ezjail config already exists at ${ezjail_new_config}.\n Please chose another name." |
1068 | 1079 | ||
1069 | # since we just used the old rootdir prefix and added the new hostname, | 1080 | # since we just used the old rootdir prefix and added the new hostname, |
1070 | # we might end up at an existing directory | 1081 | # we might end up at an existing directory |
@@ -1153,7 +1164,7 @@ config) | |||
1153 | ;; | 1164 | ;; |
1154 | detach) | 1165 | detach) |
1155 | # Check, if image really attached or running | 1166 | # Check, if image really attached or running |
1156 | [ "${ezjail_id}" ] && exerr "Error: Jail ${ezjail_name} still running. Can not detach." | 1167 | [ "${ezjail_id}" ] && exerr "Error: Jail ${ezjail_name} still running\n Can not detach.\n '${ezjail_admin} stop ${ezjail_name}' it first." |
1157 | [ "${ezjail_attached}" ] || exerr "Error: Jail image file ${ezjail_name} is not attached." | 1168 | [ "${ezjail_attached}" ] || exerr "Error: Jail image file ${ezjail_name} is not attached." |
1158 | 1169 | ||
1159 | # Unmount/detach everything | 1170 | # Unmount/detach everything |