mirror of
https://codeberg.org/scip/jaildk.git
synced 2025-12-16 12:11:05 +01:00
Change -m params, bump version to 2.0.0, fix completion, reorg repo
This commit is contained in:
17
Makefile
17
Makefile
@@ -1,5 +1,14 @@
|
||||
JAILDIR=/jail
|
||||
|
||||
all:
|
||||
bash bin/bash-completor -c completions.sh
|
||||
echo "JAILDIR=/jail" > jaildk-completion.bash
|
||||
cat _jaildk-completion.bash >> jaildk-completion.bash
|
||||
rm -f _jaildk-completion.bash
|
||||
bash bin/bash-completor -c src/completions.sh
|
||||
grep -B10 COMPLETIONCODE src/jaildk.sh | grep -v COMPLETIONCODE > jaildk
|
||||
cat src/_jaildk-completion.bash >> jaildk
|
||||
grep -A 10000 COMPLETIONCODE src/jaildk.sh | grep -v COMPLETIONCODE >> jaildk
|
||||
rm -f src/_jaildk-completion.bash
|
||||
|
||||
install:
|
||||
sh jaildk setup $JAILDIR
|
||||
|
||||
clean:
|
||||
rm -f jaildk
|
||||
|
||||
77
README.md
77
README.md
@@ -1,4 +1,4 @@
|
||||
## jaildk - a FreeBSD jail development kit
|
||||
## jaildk - a FreeBSD jail development kit v2.0.0
|
||||
|
||||
This is the README for the FreeBSD jail utility `jaildk`. It can be
|
||||
used to build, update, manage and run jails in a versioned environment.
|
||||
@@ -112,53 +112,72 @@ handy wrappers to make live easier.
|
||||
|
||||
For an overview of the provided commands, here's the usage screen:
|
||||
```
|
||||
Usage: /usr/local/bin/jaildk <command> <mode-args>
|
||||
Usage: ./jaildk <command> <command-args>
|
||||
|
||||
Building Jails:
|
||||
base -b <name> [-w] - build a new base
|
||||
build <jail> <mode> [-b <base>] [-v <version>] - install a build chroot of a jail
|
||||
create - create a new jail from a template
|
||||
clone -s <src> -d <dst> [-o <v>] [-n <v>] - clone an existing jail or jail version
|
||||
fetch - fetch current port collection
|
||||
base -b <name> [-w] - build a new base
|
||||
build <jail> -m <mode> [-b <base>] [-v <version>] - install a build chroot of a jail
|
||||
create - create a new jail from a template
|
||||
clone -s <src> -d <dst> [-o <v>] [-n <v>] - clone an existing jail or jail version
|
||||
fetchports [-v <version>] - fetch current port collection
|
||||
|
||||
Installing Jails:
|
||||
install <jail> <mode> [-r function] - install a jail (prepare mounts, devfs etc)
|
||||
uninstall <jail> [-w] - uninstall a jail
|
||||
remove <jail> - remove a jail or a jail version
|
||||
reinstall <jail> - stop, remove, install and start a jail
|
||||
(Un)installing Jails:
|
||||
install <jail> -m <mode> [-r function] - install a jail (prepare mounts, devfs etc)
|
||||
uninstall <jail> [-w] - uninstall a jail
|
||||
remove <jail> - remove a jail or a jail version
|
||||
reinstall <jail> [-b <base>] [-v <version>] - stop, remove, install and start a jail, if
|
||||
-b and/or -v is set, update the jail config
|
||||
prune [-b | -a | -j <jail> - display unused directories
|
||||
|
||||
Maintaining Jails:
|
||||
start <jail> - start a jail
|
||||
stop <jail> - stop a jail
|
||||
restart <jail> - restart a jail
|
||||
status [<jail>] - display a jail's status
|
||||
rc <jail> <mode> [-r <rc.d script>] - execute an rc-script inside a jail
|
||||
start <jail> - start a jail
|
||||
stop <jail> - stop a jail
|
||||
restart <jail> - restart a jail
|
||||
status [<jail>] [-v] - display status of jails or <jail>
|
||||
rc <jail> -m <mode> [-r <rc.d script>] - execute an rc-script inside a jail
|
||||
ipfw <jail> -m <mode> - add or remove ipfw rules
|
||||
|
||||
Managing Jails:
|
||||
login <jail> [<user>] - login into a jail
|
||||
blogin <jail> - chroot into a build jail
|
||||
login <jail> [<user>] - login into a jail
|
||||
blogin <jail> - chroot into a build jail
|
||||
|
||||
Transferring Jails:
|
||||
freeze <jail> [-a -b -v <version>] - freeze (build an image of) a jail
|
||||
thaw <image> - thaw (install) an image of a jail
|
||||
freeze <jail> [-a -b -v <version>] - freeze (build an image of) a jail
|
||||
thaw <image> - thaw (install) an image of a jail
|
||||
|
||||
Getting help:
|
||||
help <command> - request help on <command>
|
||||
Getting help and internals:
|
||||
completion - print completion code. to use execute in a bash:
|
||||
source <(jaildk completion)
|
||||
help <command> - request help on <command>
|
||||
version - print program version
|
||||
update [-f] - update jaildk from git repository
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
Download the file `jaildk` or clone this repository to your FreeBSD server and execute the following command:
|
||||
Clone this repository to your FreeBSD server and execute the following command:
|
||||
```
|
||||
./jaildk setup <directory>
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
This will create the directory structure required for the tool itself,
|
||||
create a template jail and build a base directory.
|
||||
create a template jail and build a base directory. The default base
|
||||
directory is `/jail`. You can modify this by issuing:
|
||||
```
|
||||
make install JAILDIR=/another/dir
|
||||
```
|
||||
|
||||
Be aware, that the `jaildk` script itself will only be installed to
|
||||
`$JAILDIR/bin/jaildk`. Either put this directory into your `$PATH`
|
||||
variable or create a symlink to the script in some bin dir.
|
||||
|
||||
## Bash Completion
|
||||
|
||||
If you want to use `jaildk` with bash completion, source the script `jaildk-completion.bash`.
|
||||
If you want to use `jaildk` with bash completion, put this line into your `.bashrc`:
|
||||
```
|
||||
source <(jaildk completion)
|
||||
```
|
||||
|
||||
## Basic usage
|
||||
|
||||
@@ -325,7 +344,7 @@ mount - mount -t nullfs -o rw /jail/home/myjail/root-20201106 /jail/run/myjail/r
|
||||
Jail myjail start:
|
||||
Starting jails: myjail.
|
||||
|
||||
# jaildk startus myjail
|
||||
# jaildk status myjail
|
||||
Jail scipown status:
|
||||
JID IP Address Hostname Path
|
||||
myjail 172.16.1.1 myjail /jail/run/myjail
|
||||
@@ -363,7 +382,7 @@ jaildk clone -s myjail -d myjail -o 20201106 -n 20210422
|
||||
|
||||
Mount the build chroot for the new version:
|
||||
```
|
||||
jaildk build myjail start -b `uname -r` -v 20210422
|
||||
jaildk build myjail -m start -b `uname -r` -v 20210422
|
||||
```
|
||||
|
||||
And finally chroot into the new jail and update it:
|
||||
|
||||
@@ -1,397 +0,0 @@
|
||||
JAILDIR=/jail
|
||||
# This file is generated by [bash-completor](https://github.com/adoyle-h/bash-completor/tree/v0.1.0). Do not modify it manually.
|
||||
#
|
||||
# [Usage]
|
||||
# Put "source _jaildk-completion.bash" in your bashrc.
|
||||
#
|
||||
# If you want to debug the completion.
|
||||
# Search '# Uncomment this line for debug' line in this file.
|
||||
#
|
||||
# [Update Script]
|
||||
# bash-completor -c completions.sh
|
||||
|
||||
# shellcheck disable=2207
|
||||
# editorconfig-checker-disable
|
||||
|
||||
_jaildk_comp_cmd_opts=( )
|
||||
|
||||
|
||||
_jaildk_comp_subcmd_opts_base=( -b -w )
|
||||
|
||||
_jaildk_comp_subcmd_opts_build=( -b -v -m )
|
||||
|
||||
_jaildk_comp_subcmd_opts_clone=( -s -d -o -n )
|
||||
|
||||
_jaildk_comp_subcmd_opts_fetchports=( -v )
|
||||
|
||||
_jaildk_comp_subcmd_opts_freeze=( -a -b -v )
|
||||
|
||||
_jaildk_comp_subcmd_opts_install=( -m -r )
|
||||
|
||||
_jaildk_comp_subcmd_opts_ipfw=( -m )
|
||||
|
||||
_jaildk_comp_subcmd_opts_prune=( -b -a -j )
|
||||
|
||||
_jaildk_comp_subcmd_opts_rc=( -m -r )
|
||||
|
||||
_jaildk_comp_subcmd_opts_reinstall=( -b -v )
|
||||
|
||||
_jaildk_comp_subcmd_opts_status=( -v )
|
||||
|
||||
_jaildk_comp_subcmd_opts_uninstall=( -w )
|
||||
|
||||
_jaildk_comp_subcmd_opts_update=( -f )
|
||||
|
||||
declare -A _jaildk_comp_word_to_varname=()
|
||||
_jaildk_comp_util_get_varname ()
|
||||
{
|
||||
local name=${1:-};
|
||||
local encoded=${_jaildk_comp_word_to_varname[$name]:-};
|
||||
if [[ -z ${encoded} ]]; then
|
||||
encoded=${name//[^a-zA-Z_]/_};
|
||||
fi;
|
||||
echo "${encoded}"
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_base ()
|
||||
{
|
||||
local bases=$(ls $JAILDIR/base);
|
||||
COMPREPLY=($(compgen -W "${bases[*]}" -- "$cur"))
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_dirs ()
|
||||
{
|
||||
local IFS=$'\n';
|
||||
compopt -o nospace -o filenames;
|
||||
COMPREPLY=($(compgen -A directory -- "$cur"))
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_files ()
|
||||
{
|
||||
local IFS=$'\n';
|
||||
compopt -o nospace -o filenames;
|
||||
COMPREPLY=($(compgen -A file -- "$cur"))
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_files_in_pattern ()
|
||||
{
|
||||
compopt -o nospace -o filenames;
|
||||
local path;
|
||||
while read -r path; do
|
||||
if [[ $path =~ $1 ]] || [[ -d $path ]]; then
|
||||
COMPREPLY+=("$path");
|
||||
fi;
|
||||
done < <(compgen -A file -- "$cur")
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_jail ()
|
||||
{
|
||||
local jails=$(ls $JAILDIR/etc);
|
||||
COMPREPLY=($(compgen -W "${jails[*]}" -- "$cur"))
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_list ()
|
||||
{
|
||||
local IFS=', ';
|
||||
local array_list="" array_name;
|
||||
for array_name in $@;
|
||||
do
|
||||
array_list="$array_list \${${array_name}[*]}";
|
||||
done;
|
||||
array_list="${array_list[*]:1}";
|
||||
IFS=$'\n'' ';
|
||||
eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )"
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_version ()
|
||||
{
|
||||
local versions=$(ls -d $JAILDIR/etc/*/etc-*|cut -d- -f2 | sort -u);
|
||||
COMPREPLY=($(compgen -W "${versions[*]}" -- "$cur"))
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_words ()
|
||||
{
|
||||
local IFS=$'\n';
|
||||
COMPREPLY=($(IFS=', ' compgen -W "$*" -- "${cur#=}"))
|
||||
}
|
||||
|
||||
_jaildk_comp_reply_set() {
|
||||
local IFS=', '
|
||||
local array_list="" array_name
|
||||
# shellcheck disable=2068
|
||||
for array_name in $@; do
|
||||
array_list="$array_list \${_jaildk_comp_var_${array_name}[*]}"
|
||||
done
|
||||
array_list="${array_list[*]:1}"
|
||||
|
||||
IFS=$'\n'' '
|
||||
eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )"
|
||||
}
|
||||
|
||||
_jaildk_comp_subcmds=( base build create clone fetchports install uninstall remove reinstall prune start stop restart status rc ipfw login blogin freeze thaw help version update )
|
||||
|
||||
_jaildk_completions_base() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_base
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_build() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_build
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-b) _jaildk_comp_reply_base ;;
|
||||
-v) _jaildk_comp_reply_version ;;
|
||||
-m) _jaildk_comp_reply_words 'start,stop,status,restart' ;;
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_clone() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_clone
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-s) _jaildk_comp_reply_jail ;;
|
||||
-d) _jaildk_comp_reply_jail ;;
|
||||
-o) _jaildk_comp_reply_version ;;
|
||||
-n) _jaildk_comp_reply_version ;;
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_fetchports() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_fetchports
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-v) _jaildk_comp_reply_version ;;
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_install() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_install
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-m) _jaildk_comp_reply_words 'start,stop,status,restart' ;;
|
||||
-r) _jaildk_comp_reply_words 'mount,ports,mtree,pf' ;;
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_uninstall() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_uninstall
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_reinstall() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_reinstall
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-b) _jaildk_comp_reply_base ;;
|
||||
-v) _jaildk_comp_reply_version ;;
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_prune() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_prune
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-j) _jaildk_comp_reply_jail ;;
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_status() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_status
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_rc() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_rc
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-m) _jaildk_comp_reply_words 'start,stop,status,restart' ;;
|
||||
-r) _jaildk_comp_reply_words 'mount,ports,mtree,pf' ;;
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_ipfw() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_ipfw
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-m) _jaildk_comp_reply_words 'start,stop,status,restart' ;;
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_freeze() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_freeze
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
-v) _jaildk_comp_reply_version ;;
|
||||
*) _jaildk_comp_reply_jail ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_jail
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions_update() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts_update
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions__fallback() {
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmd_opts__fallback
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_files
|
||||
fi
|
||||
}
|
||||
|
||||
_jaildk_completions() {
|
||||
COMPREPLY=()
|
||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
# Uncomment this line for debug
|
||||
# echo "[COMP_CWORD:$COMP_CWORD][cur:$cur][prev:$prev][WORD_COUNT:${#COMP_WORDS[*]}][COMP_WORDS:${COMP_WORDS[*]}]" >> bash-debug.log
|
||||
|
||||
if (( COMP_CWORD > 1 )); then
|
||||
# Enter the subcmd completion
|
||||
local subcmd_varname
|
||||
subcmd_varname="$(_jaildk_comp_util_get_varname "${COMP_WORDS[1]}")"
|
||||
if type "_jaildk_completions_$subcmd_varname" &>/dev/null; then
|
||||
"_jaildk_completions_$subcmd_varname"
|
||||
else
|
||||
# If subcmd completion function not defined, use the fallback
|
||||
"_jaildk_completions__fallback"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Enter the cmd completion
|
||||
if [[ ${cur:0:1} == [-+] ]]; then
|
||||
# rely options of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_cmd_opts
|
||||
elif [[ ${prev:0:1} == [-+] ]]; then
|
||||
case "${prev}" in
|
||||
# rely the value of command option
|
||||
*) _jaildk_comp_reply_files ;;
|
||||
esac
|
||||
else
|
||||
# rely the argument of command
|
||||
_jaildk_comp_reply_list _jaildk_comp_subcmds
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _jaildk_completions -o bashdefault jaildk
|
||||
# vi: sw=2 ts=2
|
||||
@@ -21,27 +21,24 @@ reply_version() {
|
||||
COMPREPLY=( $(compgen -W "${versions[*]}" -- "$cur") )
|
||||
}
|
||||
|
||||
rcscripts='mount,ports,mtree,pf'
|
||||
functions='mount,ports,mtree,pf'
|
||||
modes='start,stop,status,restart'
|
||||
|
||||
### sub cmd base
|
||||
subcmd_opts_base=(-b -w)
|
||||
|
||||
### sub cmd build
|
||||
# FIXME: -m
|
||||
subcmd_opts_build=(-b:@base -v:@version -m:$modes)
|
||||
subcmd_args_build=@jail
|
||||
|
||||
### sub cmd clone
|
||||
# FIXME: how to fetch version from already selected jail
|
||||
subcmd_opts_clone=(-s:@jail -d:@jail -o:@version -n:@version)
|
||||
|
||||
### sub cmd fetchports
|
||||
subcmd_opts_fetchports=(-v:@version)
|
||||
|
||||
### sub cmd install
|
||||
# FIXME: -m
|
||||
subcmd_opts_install=(-m:$modes -r:$rcscripts)
|
||||
subcmd_opts_install=(-m:$modes -r:$functions)
|
||||
subcmd_args_install=@jail
|
||||
|
||||
### sub cmd uninstall
|
||||
@@ -72,7 +69,8 @@ subcmd_opts_status=(-v)
|
||||
subcmd_args_status=@jail
|
||||
|
||||
### sub cmd rc
|
||||
subcmd_opts_rc=(-m:$modes -r:$rcscripts)
|
||||
subcmd_opts_rc=(-m:$modes -r)
|
||||
subcmd_args_rc=@jail
|
||||
|
||||
### sub cmd ipfw
|
||||
subcmd_opts_ipfw=(-m:$modes)
|
||||
@@ -1,6 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
version=1.28
|
||||
version=2.0.0
|
||||
|
||||
# this will be completed during build. Don't touch it, just execute
|
||||
# make and use the resulting script!
|
||||
JAILDK_COMPLETION=$(
|
||||
cat<<'EOF'
|
||||
# will be modified during installation (jaildk setup)
|
||||
JAILDIR=/jail
|
||||
|
||||
COMPLETIONCODE
|
||||
EOF
|
||||
)
|
||||
|
||||
usage_jaildk() {
|
||||
beg=`tput -T ${TERM:-cons25} md`
|
||||
@@ -8,43 +19,45 @@ usage_jaildk() {
|
||||
usage=$(cat <<EOF
|
||||
This is jaildk version $version, a jail management toolkit.
|
||||
|
||||
Usage: $0 <command> <mode-args>
|
||||
Usage: $0 <command> <command-args>
|
||||
|
||||
${beg}Building Jails:${end}
|
||||
base -b <name> [-w] - build a new base
|
||||
build <jail> <mode> [-b <base>] [-v <version>] - install a build chroot of a jail
|
||||
create - create a new jail from a template
|
||||
clone -s <src> -d <dst> [-o <v>] [-n <v>] - clone an existing jail or jail version
|
||||
fetchports [-v <version>] - fetch current port collection
|
||||
base -b <name> [-w] - build a new base
|
||||
build <jail> -m <mode> [-b <base>] [-v <version>] - install a build chroot of a jail
|
||||
create - create a new jail from a template
|
||||
clone -s <src> -d <dst> [-o <v>] [-n <v>] - clone an existing jail or jail version
|
||||
fetchports [-v <version>] - fetch current port collection
|
||||
|
||||
${beg}(Un)installing Jails:${end}
|
||||
install <jail> <mode> [-r function] - install a jail (prepare mounts, devfs etc)
|
||||
uninstall <jail> [-w] - uninstall a jail
|
||||
remove <jail> - remove a jail or a jail version
|
||||
reinstall <jail> [-b <base>] [-v <version>] - stop, remove, install and start a jail, if
|
||||
-b and/or -v is set, update the jail config
|
||||
prune [-b | -a | -j <jail> - display unused directories
|
||||
install <jail> -m <mode> [-r function] - install a jail (prepare mounts, devfs etc)
|
||||
uninstall <jail> [-w] - uninstall a jail
|
||||
remove <jail> - remove a jail or a jail version
|
||||
reinstall <jail> [-b <base>] [-v <version>] - stop, remove, install and start a jail, if
|
||||
-b and/or -v is set, update the jail config
|
||||
prune [-b | -a | -j <jail> - display unused directories
|
||||
|
||||
${beg}Maintaining Jails:${end}
|
||||
start <jail> - start a jail
|
||||
stop <jail> - stop a jail
|
||||
restart <jail> - restart a jail
|
||||
status [<jail>] [-v] - display status of jails or <jail>
|
||||
rc <jail> <mode> [-r <rc.d script>] - execute an rc-script inside a jail
|
||||
ipfw <jail> <mode> - add or remove ipfw rules
|
||||
start <jail> - start a jail
|
||||
stop <jail> - stop a jail
|
||||
restart <jail> - restart a jail
|
||||
status [<jail>] [-v] - display status of jails or <jail>
|
||||
rc <jail> -m <mode> [-r <rc.d script>] - execute an rc-script inside a jail
|
||||
ipfw <jail> -m <mode> - add or remove ipfw rules
|
||||
|
||||
${beg}Managing Jails:${end}
|
||||
login <jail> [<user>] - login into a jail
|
||||
blogin <jail> - chroot into a build jail
|
||||
login <jail> [<user>] - login into a jail
|
||||
blogin <jail> - chroot into a build jail
|
||||
|
||||
${beg}Transferring Jails:${end}
|
||||
freeze <jail> [-a -b -v <version>] - freeze (build an image of) a jail
|
||||
thaw <image> - thaw (install) an image of a jail
|
||||
freeze <jail> [-a -b -v <version>] - freeze (build an image of) a jail
|
||||
thaw <image> - thaw (install) an image of a jail
|
||||
|
||||
${beg}Getting help and internals:${end}
|
||||
help <command> - request help on <command>
|
||||
version - print program version
|
||||
update [-f] - update jaildk from git repository
|
||||
completion - print completion code. to use execute in a bash:
|
||||
source <(jaildk completion)
|
||||
help <command> - request help on <command>
|
||||
version - print program version
|
||||
update [-f] - update jaildk from git repository
|
||||
|
||||
EOF
|
||||
)
|
||||
@@ -184,28 +197,29 @@ parse_jail_conf() {
|
||||
|
||||
|
||||
usage_build() {
|
||||
fin "Usage: $0 build <jail> [<start|stop|status>] [-b <base>] [-v <version>]
|
||||
fin "Usage: $0 build <jail> [-m <start|stop|status>] [-b <base>] [-v <version>]
|
||||
Mount <jail> to $j/build read-writable for maintenance. Options:
|
||||
-b <base> Use specified <base>. default: use configured base.
|
||||
-v <version> Mount <version> of <jail>.
|
||||
<mode> One of start, stop or status. default: start."
|
||||
-m <mode> One of start, stop or status. default: start."
|
||||
}
|
||||
|
||||
jaildk_build() {
|
||||
local jail mode BASE VERSION base version
|
||||
|
||||
jail=$1
|
||||
mode=$2
|
||||
mode=start
|
||||
shift
|
||||
shift
|
||||
|
||||
BASE=''
|
||||
VERSION=''
|
||||
|
||||
while getopts "b:v:" arg; do
|
||||
while getopts "b:v:m:" arg; do
|
||||
case $arg in
|
||||
b) BASE=${OPTARG};;
|
||||
v) VERSION=${OPTARG};;
|
||||
m) mode=${OPTARG};;
|
||||
*) usage_build;;
|
||||
esac
|
||||
done
|
||||
@@ -214,10 +228,6 @@ jaildk_build() {
|
||||
usage_build
|
||||
fi
|
||||
|
||||
if test -z "$mode"; then
|
||||
mode=start
|
||||
fi
|
||||
|
||||
die_if_not_exist $jail $VERSION
|
||||
|
||||
load-jail-config $jail
|
||||
@@ -240,7 +250,7 @@ jaildk_build() {
|
||||
fi
|
||||
|
||||
# install the jail to build/
|
||||
jaildk_install $jail $mode -r all -w -b $base -v $version
|
||||
jaildk_install $jail -m $mode -r all -w -b $base -v $version
|
||||
|
||||
case $mode in
|
||||
start)
|
||||
@@ -667,9 +677,9 @@ rc_mount() {
|
||||
|
||||
|
||||
usage_install() {
|
||||
fin "Usage: $0 install <jail> [<mode>] [-r rc-function]
|
||||
fin "Usage: $0 install <jail> [-m <mode>] [-r rc-function]
|
||||
Install <jail> according to its config. Options:
|
||||
<mode> Mode can either be start, stop or status. default: start
|
||||
-m <mode> Mode can either be start, stop or status. default: start
|
||||
-r <function> Only execute function with <mode> parameter. default: all.
|
||||
|
||||
Available rc.d-scripts: $RCSCRIPTS_START"
|
||||
@@ -679,8 +689,7 @@ jaildk_install() {
|
||||
local jail mode rcd rw base version rcscripts type
|
||||
|
||||
jail=$1
|
||||
mode=$2
|
||||
shift
|
||||
mode=start
|
||||
shift
|
||||
rcd=''
|
||||
|
||||
@@ -689,12 +698,13 @@ jaildk_install() {
|
||||
base=''
|
||||
version=''
|
||||
|
||||
while getopts "r:b:v:w" arg; do
|
||||
while getopts "r:b:v:wm:" arg; do
|
||||
case $arg in
|
||||
w) rw=1;;
|
||||
b) base=${OPTARG};;
|
||||
v) version=${OPTARG};;
|
||||
r) rcd=${OPTARG};;
|
||||
m) mode=${OPTARG};;
|
||||
*) usage_install;;
|
||||
esac
|
||||
done
|
||||
@@ -703,10 +713,6 @@ jaildk_install() {
|
||||
usage_install
|
||||
fi
|
||||
|
||||
if test -z "$mode"; then
|
||||
mode=start
|
||||
fi
|
||||
|
||||
if test -z "$rcd"; then
|
||||
# default just install everything
|
||||
rcd=all
|
||||
@@ -808,10 +814,10 @@ jaildk_uninstall() {
|
||||
fi
|
||||
|
||||
if test -n "$all"; then
|
||||
jaildk_install $jail stop -r all
|
||||
jaildk_install $jail stop -r all -b $base -v $version -w
|
||||
jaildk_install $jail -m stop -r all
|
||||
jaildk_install $jail -m stop -r all -b $base -v $version -w
|
||||
else
|
||||
jaildk_install $jail stop -r all -b $base -v $version $rw
|
||||
jaildk_install $jail -m stop -r all -b $base -v $version $rw
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1329,7 +1335,7 @@ jaildk_jail() {
|
||||
) | column -t
|
||||
|
||||
if test -n "$jail"; then
|
||||
jaildk_rc $jail status
|
||||
jaildk_rc $jail -m status
|
||||
fi
|
||||
elif test -z "$jail"; then
|
||||
usage_$mode
|
||||
@@ -1345,14 +1351,19 @@ jaildk_jail() {
|
||||
}
|
||||
|
||||
get_rc_scripts() {
|
||||
local jail jaipath files rcvar
|
||||
local jail jailpath files rcvar name
|
||||
jail="$1"
|
||||
jailpath=`get_jail_path $jail`
|
||||
|
||||
files=$(ls $j/run/$jailpath/usr/local/etc/rc.d/* $j/run/$jailpath/etc/rc.d/* 2>/dev/null)
|
||||
|
||||
rcorder $files 2>/dev/null | while read SCRIPT; do
|
||||
# we need to fetch the rcvar variable. sometimes these scripts
|
||||
# use ${name}_enable, so we also fetch the $name variable and
|
||||
# interpolate $rcvar accordingly
|
||||
rcvar=`egrep "^rcvar=" $SCRIPT | cut -d= -f2 | sed 's/"//g' | tail -1`
|
||||
name=`egrep "^name=" $SCRIPT | cut -d= -f2 | sed 's/"//g' | tail -1`
|
||||
rcvar=$(eval echo "$rcvar")
|
||||
if egrep -iq "^${rcvar}=.*yes" $j/run/$jailpath/usr/local/etc/rc.conf; then
|
||||
echo $SCRIPT | sed "s|$j/run/$jailpath||"
|
||||
fi
|
||||
@@ -1360,7 +1371,7 @@ get_rc_scripts() {
|
||||
}
|
||||
|
||||
usage_rc() {
|
||||
fin "Usage: $0 rc <jail> [<mode>] [-r <rc.d script]
|
||||
fin "Usage: $0 rc <jail> [-m <mode>] [-r <rc.d script]
|
||||
Execute an rc.d script inside <jail> with parameter <mode>. Options:
|
||||
-r <rc.d script> Execute <rc.d script>. default: execute all enabled scripts."
|
||||
}
|
||||
@@ -1369,15 +1380,14 @@ jaildk_rc() {
|
||||
local jail mode rcd jailpath ok script jid
|
||||
|
||||
jail=$1
|
||||
mode=$2
|
||||
shift
|
||||
shift
|
||||
|
||||
rcd=''
|
||||
|
||||
while getopts "r:" arg; do
|
||||
while getopts "r:m:" arg; do
|
||||
case $arg in
|
||||
r) rcd=${OPTARG};;
|
||||
m) mode=${OPTARG};;
|
||||
*) usage_rc;;
|
||||
esac
|
||||
done
|
||||
@@ -1597,7 +1607,7 @@ jaildk_reinstall() {
|
||||
fi
|
||||
fi
|
||||
|
||||
jaildk_install $jail start
|
||||
jaildk_install -m $jail start
|
||||
jaildk_jail start $jail
|
||||
|
||||
sleep 0.2
|
||||
@@ -1605,6 +1615,11 @@ jaildk_reinstall() {
|
||||
jaildk_jail status $jail
|
||||
}
|
||||
|
||||
_install_jaildk() {
|
||||
realj=`cd $j; pwd`
|
||||
sed "s|^JAILDIR=.*|JAILDIR=$realj|" $0 > $j/bin/jaildk
|
||||
ex chmod 755 $j/bin/jaildk
|
||||
}
|
||||
|
||||
jaildk_setup() {
|
||||
local j version subdir
|
||||
@@ -1615,6 +1630,12 @@ jaildk_setup() {
|
||||
fin "Usage: $0 setup <base dir for jail environment>"
|
||||
fi
|
||||
|
||||
if test -e "$j/bin/jaildk"; then
|
||||
bold "$j/bin/jaildk aleady exists, updating..."
|
||||
_install_jaildk $j
|
||||
return
|
||||
fi
|
||||
|
||||
bold "preparing directories"
|
||||
ex mkdir -p $j
|
||||
for subdir in etc bin appl base data home log run ports; do
|
||||
@@ -1674,9 +1695,7 @@ run
|
||||
tmp' > $j/etc/.template/mtree.conf
|
||||
|
||||
bold "installing jaildk"
|
||||
realj=`cd $j; pwd`
|
||||
sed "s|^JAILDIR=.*|JAILDIR=$realj|" $0 > $j/bin/jaildk
|
||||
ex chmod 755 $j/bin/jaildk
|
||||
_install_jaildk $j
|
||||
|
||||
bold "configuring root shell template"
|
||||
echo "# root shell inside jail
|
||||
@@ -1764,6 +1783,7 @@ jaildk_update() {
|
||||
if test -n "$gitversion"; then
|
||||
if test 1 -eq $(echo "$gitversion > $version" | bc) -o -n "$force"; then
|
||||
echo "Updating jaildk from $version to version $gitversion..."
|
||||
ex make -C $j/git/jaildk
|
||||
ex install -o root -g wheel $j/git/jaildk/jaildk $j/bin/jaildk || die "Failed to update self!"
|
||||
else
|
||||
die "jaildk git version unchanged, aborting"
|
||||
@@ -2035,7 +2055,7 @@ jaildk_thaw() {
|
||||
}
|
||||
|
||||
usage_ipfw() {
|
||||
echo "Usage: $0 ipfw <jail> <mode>
|
||||
echo "Usage: $0 ipfw <jail> -m <mode>
|
||||
[Un]install ipfw rules. <mode> can be start or stop.
|
||||
The jail needs to have a ipfw.conf file, containing
|
||||
ipfw rules. You can use variables like \$ip and \$ip6
|
||||
@@ -2047,7 +2067,13 @@ jaildk_ipfw() {
|
||||
local jail mode
|
||||
|
||||
jail=$1
|
||||
mode=$2
|
||||
|
||||
while getopts "m:" arg; do
|
||||
case $arg in
|
||||
m) mode=${OPTARG};;
|
||||
*) usage_ipfw;;
|
||||
esac
|
||||
done
|
||||
|
||||
if test -z "$mode"; then
|
||||
usage_ipfw
|
||||
@@ -2387,7 +2413,7 @@ jaildk_bootstrap() {
|
||||
|
||||
# mount build
|
||||
if test -n "$PORTS"; then
|
||||
jaildk_build $jail start -b $BASE -v $VERSION
|
||||
jaildk_build $jail -m start -b $BASE -v $VERSION
|
||||
|
||||
echo "Installing ports"
|
||||
for port in `echo "$PORTS" | sed 's/,/ /g'`; do
|
||||
@@ -2396,7 +2422,7 @@ jaildk_bootstrap() {
|
||||
fi
|
||||
|
||||
# install
|
||||
jaildk_install $jail start
|
||||
jaildk_install $jail -m start
|
||||
|
||||
# run
|
||||
RUN=''
|
||||
@@ -2471,6 +2497,12 @@ case $runner in
|
||||
# eventually calls sudo
|
||||
jaildk_login $*
|
||||
;;
|
||||
completion)
|
||||
echo "$JAILDK_COMPLETION"
|
||||
;;
|
||||
_get_rc_scripts)
|
||||
get_rc_scripts $*
|
||||
;;
|
||||
*)
|
||||
# every other management command, if it exists
|
||||
if type "jaildk_$runner" 2>&1 > /dev/null; then
|
||||
@@ -2481,3 +2513,5 @@ case $runner in
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user