mirror of
https://codeberg.org/scip/jaildk.git
synced 2025-12-18 05:01:02 +01:00
switched half of the functions to getopt() work in progress!!!
This commit is contained in:
213
jaildk
213
jaildk
@@ -11,14 +11,14 @@ This is jaildk version $version, a jail management toolkit.
|
|||||||
Usage: $0 <command> <mode-args>
|
Usage: $0 <command> <mode-args>
|
||||||
|
|
||||||
${beg}Building Jails:${end}
|
${beg}Building Jails:${end}
|
||||||
base - build a new base
|
base -b <name> [-w] - build a new base
|
||||||
build - install a build chroot of a jail
|
build <jail> <mode> [-b <base>] [-v <version>] - install a build chroot of a jail
|
||||||
create - create a new jail from a template
|
create - create a new jail from a template
|
||||||
clone - clone an existing jail or jail version
|
clone -s <src> -d <dst> [-o <v>] [-n <v>] - clone an existing jail or jail version
|
||||||
fetch - fetch current port collection
|
fetch - fetch current port collection
|
||||||
|
|
||||||
${beg}Installing Jails:${end}
|
${beg}Installing Jails:${end}
|
||||||
install - install a jail (prepare mounts, devfs etc)
|
install <jail> <mode> [-r function] - install a jail (prepare mounts, devfs etc)
|
||||||
uninstall - uninstall a jail
|
uninstall - uninstall a jail
|
||||||
remove - remove a jail or a jail version
|
remove - remove a jail or a jail version
|
||||||
reinstall - stop, remove, install and start a jail
|
reinstall - stop, remove, install and start a jail
|
||||||
@@ -31,12 +31,12 @@ status - display a jail's status
|
|||||||
rc - execute an rc-script inside a jail
|
rc - execute an rc-script inside a jail
|
||||||
|
|
||||||
${beg}Managing Jails:${end}
|
${beg}Managing Jails:${end}
|
||||||
login - login into a jail (also available as separate command)
|
login <jail> - login into a jail (also available as separate command)
|
||||||
blogin - chroot into a build jail (dito)
|
blogin <jail> - chroot into a build jail (dito)
|
||||||
|
|
||||||
${beg}Transferring Jails:${end}
|
${beg}Transferring Jails:${end}
|
||||||
freeze - freeze (build an image of) a jail
|
freeze <jail> [-a -b -v <version>] - freeze (build an image of) a jail
|
||||||
thaw - thaw (install) an image of a jail somewhere else
|
thaw <image> - thaw (install) an image of a jail
|
||||||
|
|
||||||
Run the <command> without arguments to get usage help about the command.
|
Run the <command> without arguments to get usage help about the command.
|
||||||
|
|
||||||
@@ -101,28 +101,44 @@ die_if_not_exist() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usage_build() {
|
||||||
|
die "Usage: $0 build <jail name> <start|stop|status> [-b <base>] [-v <version>]"
|
||||||
|
}
|
||||||
|
|
||||||
jaildk_build() {
|
jaildk_build() {
|
||||||
jail=$1
|
jail=$1
|
||||||
mode=$2
|
mode=$2
|
||||||
base=$3
|
shift
|
||||||
version=$4
|
shift
|
||||||
|
|
||||||
|
base=''
|
||||||
|
version=''
|
||||||
|
|
||||||
load-jail-config $jail
|
while getopts "b:v:" arg; do
|
||||||
|
case $arg in
|
||||||
|
b) base=1;;
|
||||||
|
v) version=${OPTARG};;
|
||||||
|
*) usage_build;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
if test -z "$mode"; then
|
if test -z "$mode"; then
|
||||||
echo "Usage: $0 build <jail name> <start|stop|status> [<base>] [<version>]"
|
usage_build
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
die_if_not_exist $jail $version
|
||||||
|
|
||||||
|
load-jail-config $jail
|
||||||
|
|
||||||
if test -n "$buildbase"; then
|
if test -n "$buildbase"; then
|
||||||
base="$buildbase"
|
base="$buildbase"
|
||||||
elif test -z "$base"; then
|
elif test -z "$base"; then
|
||||||
# not configured, use default: latest
|
# nothing configured, use default: latest
|
||||||
base=`ls $j/base | tail -1`
|
base=`ls $j/base | tail -1`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install the jail to build/
|
# install the jail to build/
|
||||||
jaildk_install $jail all $mode rw $base $version
|
jaildk_install $jail $mode -r all -w -b $base -v $version
|
||||||
|
|
||||||
case $mode in
|
case $mode in
|
||||||
start)
|
start)
|
||||||
@@ -342,46 +358,55 @@ jaildk_rc_mount() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
jaildk_install_usage() {
|
usage_install() {
|
||||||
err "Usage: $0 install <jail> [[<rc.d-script>] <start|stop|restart|status>]"
|
die "Usage: $0 install <jail> [<mode>] [-r rc-function]
|
||||||
err "If <rc.d-script> is 'all' every script will be executed in rc-order."
|
Install <jail> according to its config. Options:
|
||||||
err "If <rc.d-script> is not specified, just execute all scripts with <start>."
|
<mode> Mode can either be start, stop or status. default: start
|
||||||
err "Available rc.d-scripts: $RCSCRIPTS_START"
|
-r <function> Only execute function with <mode> parameter. default: all.
|
||||||
exit 1
|
|
||||||
|
Available rc.d-scripts: $RCSCRIPTS_START"
|
||||||
}
|
}
|
||||||
|
|
||||||
jaildk_install() {
|
jaildk_install() {
|
||||||
jail=$1
|
jail=$1
|
||||||
rcd=$2
|
mode=$2
|
||||||
mode=$3
|
shift
|
||||||
|
shift
|
||||||
|
rcd=''
|
||||||
|
|
||||||
# used by jaildk_build() only
|
# options -b -w -v are undocumented, used by jaildk_build() only
|
||||||
rw=$4
|
rw=''
|
||||||
base=$5
|
base=''
|
||||||
version=$6
|
version=''
|
||||||
|
|
||||||
|
while getopts "r:wb:v:" arg; do
|
||||||
|
case $arg in
|
||||||
|
w) rw=1;;
|
||||||
|
b) base=${OPTARG};;
|
||||||
|
v) version=${OPTARG};;
|
||||||
|
r) rcd=${OPTARG};;
|
||||||
|
*) freeze_usage;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
if test -z "$jail"; then
|
if test -z "$jail"; then
|
||||||
jaildk_install_usage
|
usage_install
|
||||||
fi
|
|
||||||
|
|
||||||
if test -z "$rcd"; then
|
|
||||||
# default just install all
|
|
||||||
mode=start
|
|
||||||
rcd=all
|
|
||||||
else
|
|
||||||
case $rcd in
|
|
||||||
start|stop|restart|status)
|
|
||||||
# shift args
|
|
||||||
mode=$rcd
|
|
||||||
rcd=all
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "$mode"; then
|
if test -z "$mode"; then
|
||||||
jaildk_install_usage
|
mode=start
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -z "$rcd"; then
|
||||||
|
# default just install everything
|
||||||
|
rcd=all
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $mode in
|
||||||
|
start|stop|restart|status) :;;
|
||||||
|
*) usage_install;;
|
||||||
|
esac
|
||||||
|
|
||||||
die_if_not_exist $jail
|
die_if_not_exist $jail
|
||||||
|
|
||||||
if test "$rcd" = "all"; then
|
if test "$rcd" = "all"; then
|
||||||
@@ -413,7 +438,7 @@ jaildk_install() {
|
|||||||
jaildk_uninstall() {
|
jaildk_uninstall() {
|
||||||
# wrapper around _install
|
# wrapper around _install
|
||||||
jail=$1
|
jail=$1
|
||||||
rw=$2
|
rw=$2 # FIXME !!!!!!!!!! getopt !!!!!!!!!!
|
||||||
|
|
||||||
if test -z "$jail"; then
|
if test -z "$jail"; then
|
||||||
err "Usage: $0 uninstall <jail> [<remove build>]"
|
err "Usage: $0 uninstall <jail> [<remove build>]"
|
||||||
@@ -426,18 +451,33 @@ jaildk_uninstall() {
|
|||||||
die "Jail $jail($version) is still running, stop it before removing!"
|
die "Jail $jail($version) is still running, stop it before removing!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
jaildk_install $jail all stop $rw
|
jaildk_install $jail stop -r all -w
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
usage_base() {
|
||||||
|
die "Usage: $0 base -b <basename|basedir> [-w]
|
||||||
|
-b <name> <name> can be the name of a base (e.g. 12.2-RELEASE)
|
||||||
|
or a directory where it shall be created
|
||||||
|
-w Create a writable base, including compiler and other
|
||||||
|
build stuff. Use this if you want to use the ports
|
||||||
|
collection."
|
||||||
}
|
}
|
||||||
|
|
||||||
jaildk_base() {
|
jaildk_base() {
|
||||||
base=$1
|
base=""
|
||||||
rw=$2
|
rw=""
|
||||||
|
|
||||||
|
while getopts "b:w" arg; do
|
||||||
|
case $arg in
|
||||||
|
w) rw=1;;
|
||||||
|
b) base=${OPTARG};;
|
||||||
|
*) usage_base;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
if test -z "$base"; then
|
if test -z "$base"; then
|
||||||
err "Usage: $0 base <basename|basedir> [<rw>]"
|
usage_base
|
||||||
err "If the <rw> has been set, the base will not cleaned up"
|
|
||||||
err "and will contain compilers and other build stuff. Use"
|
|
||||||
err "this if you want to use the ports collection."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
removelist="tests
|
removelist="tests
|
||||||
@@ -565,21 +605,40 @@ clone() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usage_clone() {
|
||||||
|
die "Usage: $0 clone -s <jail> -d <jail> [-o <version>] [-n <version>]
|
||||||
|
-s <jail> Source jail to clone from
|
||||||
|
-d <jail> Destionation jail to create from source
|
||||||
|
-o <version> Old version
|
||||||
|
-n <version> New version
|
||||||
|
|
||||||
|
Hints:
|
||||||
|
- if no source version has been given, tha latest version will be used.
|
||||||
|
- if no new version has been given, source version will be used.
|
||||||
|
- if source and new jail are the same, both versions must be given
|
||||||
|
and a new version of the same jail will be created (update)"
|
||||||
|
}
|
||||||
|
|
||||||
jaildk_clone() {
|
jaildk_clone() {
|
||||||
src=$1
|
src=''
|
||||||
new=$2
|
new=''
|
||||||
srcversion=$3
|
srcversion=''
|
||||||
newversion=$4
|
newversion=''
|
||||||
update=""
|
update=''
|
||||||
|
|
||||||
|
while getopts "s:d:o:n:" arg; do
|
||||||
|
case $arg in
|
||||||
|
o) srcversion=${OPTARG};;
|
||||||
|
n) newversion=${OPTARG};;
|
||||||
|
s) src=${OPTARG};;
|
||||||
|
d) new=${OPTARG};;
|
||||||
|
*) usage_clone;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
if test -z "$new"; then
|
if test -z "$new"; then
|
||||||
echo "Usage: $0 clone <source jail> <new jail> [<source version> [<new version>]]"
|
usage_clone
|
||||||
echo "Hints:"
|
|
||||||
echo "- if no source version has been given, tha latest version will be used."
|
|
||||||
echo "- if no new version has been given, source version will be used."
|
|
||||||
echo "- if source and new jail are the same, both versions must be given"
|
|
||||||
echo " and a new version of the same jail will be created (update)"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$src" = "$new"; then
|
if test "$src" = "$new"; then
|
||||||
@@ -661,12 +720,16 @@ jaildk_clone() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usage_create() {
|
||||||
|
die "Usage: $0 create <jail>"
|
||||||
|
}
|
||||||
|
|
||||||
jaildk_create() {
|
jaildk_create() {
|
||||||
jail=$1
|
jail=$1
|
||||||
src=.template
|
src=.template
|
||||||
|
|
||||||
if test -z "$jail"; then
|
if test -z "$jail"; then
|
||||||
die "Usage: $0 create <jail>"
|
usage_create
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. $j/etc/$src/jail.conf
|
. $j/etc/$src/jail.conf
|
||||||
@@ -675,7 +738,7 @@ jaildk_create() {
|
|||||||
|
|
||||||
mkdir -p $j/etc/$jail
|
mkdir -p $j/etc/$jail
|
||||||
|
|
||||||
jaildk_clone $src $jail $srcversion $newversion
|
jaildk_clone -s $src -d $jail -o $srcversion -n $newversion
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
@@ -1063,7 +1126,7 @@ endif
|
|||||||
read yesno
|
read yesno
|
||||||
case $yesno in
|
case $yesno in
|
||||||
y|Y|yes|YES)
|
y|Y|yes|YES)
|
||||||
jaildk_base $j/base/$os
|
jaildk_base -b $j/base/$os
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -1092,7 +1155,7 @@ jaildk_fetch_ports() {
|
|||||||
ex rm -rf $j/ports/tmp/ports*
|
ex rm -rf $j/ports/tmp/ports*
|
||||||
}
|
}
|
||||||
|
|
||||||
freeze_usage() {
|
usage_freeze() {
|
||||||
echo "Usage: $0 freeze <jail> [options]
|
echo "Usage: $0 freeze <jail> [options]
|
||||||
Options:
|
Options:
|
||||||
-v <version> freeze <version> of <jail>
|
-v <version> freeze <version> of <jail>
|
||||||
@@ -1123,12 +1186,12 @@ jaildk_freeze() {
|
|||||||
a) ADDAPPL=1;;
|
a) ADDAPPL=1;;
|
||||||
b) ADDBASE=1;;
|
b) ADDBASE=1;;
|
||||||
v) VERSION=${OPTARG};;
|
v) VERSION=${OPTARG};;
|
||||||
*) freeze_usage;;
|
*) usage_freeze;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if test -z "$jail"; then
|
if test -z "$jail"; then
|
||||||
freeze_usage
|
usage_freeze
|
||||||
fi
|
fi
|
||||||
|
|
||||||
die_if_not_exist $jail "Jail to freeze" $VERSION
|
die_if_not_exist $jail "Jail to freeze" $VERSION
|
||||||
@@ -1231,9 +1294,12 @@ thaw_tarball() {
|
|||||||
ex rm -f $srcdir/$tarball
|
ex rm -f $srcdir/$tarball
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usage_thaw() {
|
||||||
|
die "Usage: $0 thaw <image>"
|
||||||
|
}
|
||||||
|
|
||||||
jaildk_thaw() {
|
jaildk_thaw() {
|
||||||
image=$1
|
image=$1
|
||||||
J=$2 # just for testing
|
|
||||||
|
|
||||||
if test -n "$J"; then
|
if test -n "$J"; then
|
||||||
j=$J
|
j=$J
|
||||||
@@ -1243,8 +1309,7 @@ jaildk_thaw() {
|
|||||||
version=$(echo $image | cut -d\- -f3 | cut -d\. -f1)
|
version=$(echo $image | cut -d\- -f3 | cut -d\. -f1)
|
||||||
|
|
||||||
if ! test -n "$version" -o -n "$jail"; then
|
if ! test -n "$version" -o -n "$jail"; then
|
||||||
err "Usage: $0 thaw <image>"
|
usage_thaw
|
||||||
die "Image filename pattern: <host>-<jail>-<version>.tgz"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -d $j/etc/$jail/etc-$version; then
|
if test -d $j/etc/$jail/etc-$version; then
|
||||||
|
|||||||
Reference in New Issue
Block a user