diff --git a/README.md b/README.md index dbaf75c..b0e9c63 100644 --- a/README.md +++ b/README.md @@ -350,8 +350,9 @@ Next create a new base version: ``` jaildk base -b `uname -r` ``` +But of course you can update a jail with the current base as well. -Now you can create clone of your jail with a new version: +Now you can clone of your jail with a new version: ``` jaildk clone -s myjail -d myjail -o 20201106 -n 20210422 ``` @@ -368,9 +369,20 @@ pkg update ... ``` -The last step is to remove the current running jail, change the version in `etc/myjail.conf`, install and start the new version. +The last step is to remove the current running jail, change the +version in `etc/myjail.conf`, install and start the new version. This +can be easily done with the following command: +``` +jaildk reinstall myjail -b `uname -r` -v 20210422 +``` -If there's anything wrong you can always go back to the previous version using the above steps. +This command also creates a copy of the current jail.conf. + +If there's anything wrong you can always go back to the previous +version using the following command (using the previous base and version): +``` +jaildk reinstall myjail -b 12.2-RELEASE-p1 -v 20201106 +``` ## Advanced Features diff --git a/jaildk b/jaildk index 1b0691f..d6083fe 100755 --- a/jaildk +++ b/jaildk @@ -1,6 +1,6 @@ #!/bin/sh -version=1.12 +version=1.13 usage_jaildk() { beg=`tput -T ${TERM:-cons25} md` @@ -21,7 +21,8 @@ ${beg}Installing Jails:${end} install [-r function] - install a jail (prepare mounts, devfs etc) uninstall [-w] - uninstall a jail remove - remove a jail or a jail version -reinstall - stop, remove, install and start a jail +reinstall [-b ] [-v ] - stop, remove, install and start a jail, if + -b and/or -v is set, update the jail config ${beg}Maintaining Jails:${end} start - start a jail @@ -1219,13 +1220,26 @@ jaildk_login() { } usage_reinstall() { - fin "Usage: $0 reinstall -Stop, uninstall, install and start . + fin "Usage: $0 reinstall [-b ] [-v ] +Stop, uninstall, install and start . If and/or + is given, modify the jail config before reinstalling. " } jaildk_reinstall() { jail=$1 + shift + + NEWBASE='' + NEWVERSION='' + + while getopts "b:v:" arg; do + case $arg in + b) NEWBASE=${OPTARG};; + v) NEWVERSION=${OPTARG};; + *) usage_reinstall;; + esac + done if test -z "$jail"; then usage_reinstall @@ -1242,6 +1256,31 @@ jaildk_reinstall() { sleep 0.2 sync + if test -n "$NEWBASE" -o -n "$NEWVERSION"; then + load-jail-config $jail + ts=`date +%Y%m%d%H%M` + change='' + if test $NEWBASE != $base; then + base=$NEWBASE + change=1 + fi + + if test $NEWVERSION != $version; then + version=$NEWVERSION + change=1 + fi + + if test -n "$change"; then + bold "Saving current $jail config" + ex cp -p $j/etc/$jail/jail.conf $j/etc/$jail/jail.conf-$ts + + bold "Creating new $jail config" + cat $j/etc/$jail/jail.conf-$ts \ + | sed -e "s/^base=.*/base=$base/" -e "s/^version=.*/version=$version/" \ + > $j/etc/$jail/jail.conf + fi + fi + jaildk_install $jail start jaildk_jail start $jail