summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt32
-rw-r--r--Makefile1
-rw-r--r--VERSION.txt2
-rwxr-xr-xbin/container20
-rwxr-xr-xlib/container/auto19
-rwxr-xr-xlib/container/console19
-rwxr-xr-xlib/container/create19
-rwxr-xr-xlib/container/enter19
-rwxr-xr-xlib/container/limit19
-rwxr-xr-xlib/container/list282
-rwxr-xr-xlib/container/move (renamed from lib/container/rename)25
-rwxr-xr-xlib/container/remove19
-rwxr-xr-xlib/container/restart19
-rwxr-xr-xlib/container/start26
-rwxr-xr-xlib/container/status19
-rwxr-xr-xlib/container/stop19
-rwxr-xr-xlib/container/version19
-rw-r--r--share/bash-completion/container18
-rw-r--r--share/man/container-auto.1.txt2
-rw-r--r--share/man/container-console.1.txt2
-rw-r--r--share/man/container-create-curl.1.txt2
-rw-r--r--share/man/container-create-debconf.1.txt2
-rw-r--r--share/man/container-create-debootstrap.1.txt2
-rw-r--r--share/man/container-create.1.txt2
-rw-r--r--share/man/container-enter.1.txt2
-rw-r--r--share/man/container-limit.1.txt2
-rw-r--r--share/man/container-list.1.txt37
-rw-r--r--share/man/container-move.1.txt86
-rw-r--r--share/man/container-remove.1.txt2
-rw-r--r--share/man/container-restart.1.txt2
-rw-r--r--share/man/container-shell.1.txt2
-rw-r--r--share/man/container-start.1.txt2
-rw-r--r--share/man/container-status.1.txt2
-rw-r--r--share/man/container-stop.1.txt2
-rw-r--r--share/man/container-version.1.txt2
-rw-r--r--share/man/container.1.txt5
-rwxr-xr-xshare/scripts/curl19
-rwxr-xr-xshare/scripts/debconf19
-rwxr-xr-xshare/scripts/debootstrap19
39 files changed, 741 insertions, 70 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index aa0671d..0fd720b 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,35 @@
+2016-12-10 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+
+ * Releasing version 20161210.
+ * Backward incompatible changes:
+ - container list shows now only the first IPv4 address.
+ - container rename command has been renamed to move.
+ - container list full format has been renamed to cli.
+ - container list short format has been renamed to shell.
+
+ [ Daniel Baumann ]
+ * Adding container rename to mv symlink.
+ * Renaming container rename command to move for consistency.
+ * Tidying container move interactive question.
+ * Tidying container move comments.
+ * Adding container move manpage.
+ * Harmonizing markup of email addresses in manpages.
+ * Completing usage message in container list command.
+ * Renaming internal show function in container list command for consistency.
+ * Adding trailing line in full format for container list command.
+ * Sorting format code in container list command.
+ * Renaming full format in container list command to cli for consistency.
+ * Renaming short format in container list command to shell for consistency.
+ * Removing half-finished multi-address handling in container list command.
+ * Adding CSV export format to container list command.
+ * Adding JSON export format to container list command.
+ * Adding nwdiag export format to container list command.
+ * Adding YAML export format to container list command.
+ * Adding XML export format to container list command.
+ * Enabling pre and post hooks in container program.
+ * Enabling pre and post hooks in container commands.
+ * Enabling pre and post hooks in container create scripts.
+
2016-12-01 Daniel Baumann <daniel.baumann@open-infrastructure.net>
* Releasing version 20161201.
diff --git a/Makefile b/Makefile
index 891ea01..6c95f4a 100644
--- a/Makefile
+++ b/Makefile
@@ -104,6 +104,7 @@ install: build
ln -sf container-create-debconf.1 $(DESTDIR)/usr/share/man/man1/container-create-progress-linux.1
ln -sf list $(DESTDIR)/usr/lib/$(SOFTWARE)/container/ls
+ ln -sf move $(DESTDIR)/usr/lib/$(SOFTWARE)/container/mv
ln -sf remove $(DESTDIR)/usr/lib/$(SOFTWARE)/container/rm
ln -sf version $(DESTDIR)/usr/lib/$(SOFTWARE)/container/ver
diff --git a/VERSION.txt b/VERSION.txt
index 73f27d5..d407b1f 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1 +1 @@
-20161201
+20161210
diff --git a/bin/container b/bin/container
index 484a0e1..5b97d3e 100755
--- a/bin/container
+++ b/bin/container
@@ -21,6 +21,8 @@ set -e
SOFTWARE="container-tools"
PROGRAM="container"
+HOOKS="/etc/${SOFTWARE}/hooks"
+
# Parameter
PARAMETER="${1}"
@@ -43,6 +45,15 @@ fi
shift 1
OPTIONS="${@}"
+# Pre hooks
+for FILE in "${HOOKS}/pre-${PROGRAM}".* "${HOOKS}/${NAME}.pre-${PROGRAM}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Notification
if echo "${OPTIONS}" | grep -qs "\--no-notification"
then
@@ -76,3 +87,12 @@ fi
# Run
exec "/usr/lib/${SOFTWARE}/${PROGRAM}/${COMMAND}" "${OPTIONS}"
+
+# Post hooks
+for FILE in "${HOOKS}/post-${PROGRAM}".* "${HOOKS}/${NAME}.post-${PROGRAM}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/auto b/lib/container/auto
index eb23f87..969ce0a 100755
--- a/lib/container/auto
+++ b/lib/container/auto
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
Parameters ()
{
@@ -78,6 +79,15 @@ fi
HOST="$(hostname -f)"
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
for FILE in "${CONFIG}"/*.conf
do
@@ -88,3 +98,12 @@ do
cnt ${ACTION} -n ${CONTAINER} || true
fi
done
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/console b/lib/container/console
index ab3dfaf..fbf3c2d 100755
--- a/lib/container/console
+++ b/lib/container/console
@@ -20,6 +20,7 @@ set -e
COMMAND="$(basename ${0})"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -89,5 +90,23 @@ case "${STATE}" in
;;
esac
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
machinectl login ${NAME}
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/create b/lib/container/create
index cd3a455..1e855ef 100755
--- a/lib/container/create
+++ b/lib/container/create
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
SCRIPTS="/usr/share/container-tools/scripts"
@@ -141,6 +142,15 @@ fi
CNT_AUTO="${CNT_AUTO:-$(hostname -f)}"
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Creating bind mounts
if [ -n "${BIND}" ]
then
@@ -194,3 +204,12 @@ sed -e "s|@CNT_AUTO@|${CNT_AUTO}|g" \
# Run
"${SCRIPTS}/${SCRIPT}" $(echo "${@}" | sed -e 's| -- | |')
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/enter b/lib/container/enter
index 6023d92..4bcd5c6 100755
--- a/lib/container/enter
+++ b/lib/container/enter
@@ -20,6 +20,7 @@ set -e
COMMAND="$(basename ${0})"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -91,6 +92,15 @@ esac
LEADER="$(machinectl status ${NAME} | awk '/Leader: / { print $2 }')"
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
if [ -e "${MACHINES}/${NAME}/usr/bin/container-nsenter" ]
then
@@ -100,3 +110,12 @@ else
fi
nsenter --target ${LEADER} --mount --uts --ipc --net --pid --root --wd=/root ${OPTIONS}
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/limit b/lib/container/limit
index a9882c9..d2a193a 100755
--- a/lib/container/limit
+++ b/lib/container/limit
@@ -20,6 +20,7 @@ set -e
COMMAND="$(basename ${0})"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -182,5 +183,23 @@ then
Usage
fi
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
systemctl --runtime set-property ${NAME} ${BLOCK_IO_DEVICE_WEIGHT} ${BLOCK_IO_READ_BANDWITH} ${BLOCK_IO_WEIGHT} ${BLOCK_IO_WRITE_BANDWITH} ${CPU_QUOTA} ${CPU_SHARES} ${MEMORY_LIMIT} ${TASKS_MAX}
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/list b/lib/container/list
index 3c23c24..f9f46fb 100755
--- a/lib/container/list
+++ b/lib/container/list
@@ -21,11 +21,14 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
+VERSION="$(container version)"
+
Parameters ()
{
- GETOPT_LONGOPTIONS="all,format:,host:,other,started,stopped,"
+ GETOPT_LONGOPTIONS="all,csv-separator:,format:,host:,nwdiag-color:,nwdiag-label:,other,started,stopped,"
GETOPT_OPTIONS="a,f:,h:,o,s,t,"
PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
@@ -46,6 +49,11 @@ Parameters ()
shift 1
;;
+ --csv-separator)
+ CSV_SEPARATOR="${2}"
+ shift 2
+ ;;
+
-f|--format)
FORMAT="${2}"
shift 2
@@ -56,6 +64,16 @@ Parameters ()
shift 2
;;
+ --nwdiag-color)
+ NWDIAG_COLOR="${2}"
+ shift 2
+ ;;
+
+ --nwdiag-label)
+ NWDIAG_LABEL="${2}"
+ shift 2
+ ;;
+
-o|--other)
LIST="${LIST} other"
shift 1
@@ -86,19 +104,116 @@ Parameters ()
Usage ()
{
- echo "Usage: container ${COMMAND} -a|--all --format FORMAT -s|--started -t|--stopped" >&2
+ echo "Usage: container ${COMMAND} [-a|--all] [--csv-separator SEPARATOR] [--format FORMAT] [-h|--host HOSTNAME] [--nwdiag-color COLOR] [--nwdiag-label LABEL] [-o|--other] [-s|--started] [-t|--stopped]" >&2
exit 1
}
Parameters "${@}"
LIST="${LIST:-started stopped}"
-FORMAT="${FORMAT:-full}"
+FORMAT="${FORMAT:-cli}"
HOST="${HOST:-$(hostname -f)}"
+CSV_SEPARATOR="${CSV_SEPARATOR:-,}"
+
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
+List ()
+{
+ case "${FORMAT}" in
+ cli)
+ printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}"
+ ;;
+
+ csv)
+ echo "${HOST}${CSV_SEPARATOR}${CONTAINER}${CSV_SEPARATOR}${STATE}${CSV_SEPARATOR}${ADDRESS}"
+ ;;
+
+ json)
+
+cat << EOF
+ {
+ "name": "${CONTAINER}",
+ "status": "${STATE}",
+ "ipv4Address": "${ADDRESS}",
+ },
+EOF
+
+ ;;
+
+ nwdiag)
+ Nwdiag_width "${CONTAINER}"
+
+ case "${STATE}" in
+ started)
+ COLOR="#73d216"
+ ;;
+
+ stopped)
+ COLOR="#cc0000"
+ ;;
+
+ other)
+ COLOR="#d3d7cf"
+ ;;
+ esac
+
+ echo " ${CONTAINER} [address = \"${ADDRESS}\", color = \"${COLOR}\", shape = \"flowchart.terminator\", width = \"${WIDTH}\"];"
+ ;;
+
+ shell)
+ echo "${CONTAINER}"
+ ;;
+
+ yaml)
+
+cat << EOF
+ - name: ${CONTAINER}
+ ipv4_address: ${ADDRESS}
+EOF
+
+ ;;
+
+ xml)
+
+cat << EOF
+ <container>
+ <name>${CONTAINER}</name>
+ <ipv4Address>${ADDRESS}</ipv4Address>
+ </container>
+EOF
+
+ ;;
+ esac
+}
+
+Nwdiag_width ()
+{
+ NAME="${1}"
+
+ CHARACTERS="$(echo "${NAME}" | wc -c)"
+
+ if [ "${CHARACTERS}" -gt 13 ]
+ then
+ # default width is 128 fitting 13 characters
+ WIDTH="$(( ${CHARACTERS} - 13 ))"
+ WIDTH="$(( ${WIDTH} * 5 ))"
+ WIDTH="$(( ${WIDTH} + 128 ))"
+ else
+ WIDTH="128"
+ fi
+}
+
case "${FORMAT}" in
- full)
+ cli)
RED="$(tput setaf 1)$(tput bold)"
GREEN="$(tput setaf 2)$(tput bold)"
YELLOW="$(tput setaf 3)$(tput bold)"
@@ -113,36 +228,95 @@ EOF
;;
- short)
+ csv)
+
+cat << EOF
+# container-tools version ${VERSION}
+Host${CSV_SEPARATOR}Container${CSV_SEPARATOR}Status${CSV_SEPARATOR}IPv4-Address
+EOF
+
;;
-esac
-Show ()
+ json)
+
+cat << EOF
{
- case "${FORMAT}" in
- short)
- printf "${CONTAINER}\n"
- ;;
+ "container-tools": {
+ "version": "${VERSION}",
+ },
+ "host": {
+ "name": "${HOST}",
+ },
+ "container": [
+EOF
- full)
- FIRST_LINE="true"
-
- for ADDRESS in ${ADDRESSES}
- do
- case "${FIRST_LINE}" in
- true)
- FIRST_LINE="false"
- printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}"
- ;;
-
- *)
- printf "%-80s %-29s\n" "" "${ADDRESS}"
- ;;
- esac
- done
- ;;
- esac
-}
+ ;;
+
+ nwdiag)
+ NETWORK="$(echo ${HOST} | sed -e 's|\.|_|g')"
+
+cat << EOF
+# container-tools ${VERSION}
+nwdiag {
+ external_connector = none;
+ network ${NETWORK} {
+EOF
+
+ if [ -n "${NWDIAG_LABEL}" ]
+ then
+ echo " label = \"${NWDIAG_LABEL}\""
+ else
+ echo " label = \"\""
+ fi
+
+ NUMBER="$(${0} --format=short | wc -l)"
+
+ if [ -n "${NWDIAG_COLOR}" ]
+ then
+ COLOR="${NWDIAG_COLOR}"
+ else
+ COLOR="#3465a4"
+ fi
+
+ Nwdiag_width "${HOST}"
+
+cat << EOF
+ # host
+ ${HOST} [color = "${COLOR}", shape = "box", numbered = "${NUMBER}", width = "${WIDTH}"];
+ # container
+EOF
+
+ ;;
+
+ yaml)
+
+cat << EOF
+---
+container_tools:
+ version: ${VERSION}
+
+host:
+ name: ${HOST}
+
+container:
+EOF
+
+ ;;
+
+ xml)
+
+cat << EOF
+<container-tools>
+ <version>${VERSION}</version>
+</container-tools>
+<host>
+ <name>${HOST}</name>
+</host>
+<containers>
+EOF
+
+ ;;
+esac
CONTAINERS="$(cd "${MACHINES}" 2>/dev/null && find -maxdepth 1 -type d -and -not -name '.container-tools' -and -not -name 'container-tools' -and -not -name 'lost+found' -and -not -name '.snap' -and -not -name '.snapshot' -printf '%P\n' | sort)"
@@ -183,21 +357,21 @@ do
;;
esac
- ADDRESSES=""
+ ADDRESS=""
if ls "${MACHINES}/${CONTAINER}/etc/systemd/network"/*.network > /dev/null 2>&1
then
- ADDRESSES="$(awk -F= '/Address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/systemd/network/*.network)"
+ ADDRESS="$(awk -F= '/Address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/systemd/network/*.network | head -n1)"
elif [ -e "${MACHINES}/${CONTAINER}/etc/network/interfaces" ]
then
- ADDRESSES="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces)"
+ ADDRESS="$(awk '/address/ { print $2 }' ${MACHINES}/${CONTAINER}/etc/network/interfaces | head -n1)"
fi
- ADDRESSES="${ADDRESSES:-n/a}"
+ ADDRESS="${ADDRESS:-n/a}"
if echo ${LIST} | grep -qs all
then
- Show
+ List
fi
for ITEM in other started stopped
@@ -206,9 +380,45 @@ do
then
case "${STATE}" in
${ITEM})
- Show
+ List
;;
esac
fi
done
done
+
+case "${FORMAT}" in
+ cli)
+
+cat << EOF
+--------------------------------------------------------------------------------
+EOF
+
+ ;;
+
+ json)
+
+cat << EOF
+ ],
+}
+EOF
+
+ ;;
+
+ xml)
+
+cat << EOF
+</containers>
+EOF
+
+ ;;
+esac
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/rename b/lib/container/move
index 467d687..6e855e4 100755
--- a/lib/container/rename
+++ b/lib/container/move
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -110,7 +111,7 @@ case "${FORCE}" in
*)
if container list --other | grep -qs "^${OLD}$"
then
- echo -n "'${OLD}': rename remote container to '${NEW}' [y|N]? "
+ echo -n "'${OLD}': rename container to '${NEW}' [y|N]? "
read FORCE
FORCE="$(echo ${FORCE} | tr [A-Z] [a-z])"
@@ -127,11 +128,20 @@ case "${FORCE}" in
;;
esac
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
mv "${CONFIG}/${OLD}.conf" "${CONFIG}/${NEW}.conf"
mv "${MACHINES}/${OLD}" "${MACHINES}/${NEW}"
-# Renaming bind mounts
+# bind mounts
BIND="$(awk -F= '/^bind=/ { print $2 }' ${CONFIG}/${NAME}.conf)"
if [ -n "${BIND}" ]
@@ -158,5 +168,14 @@ then
done
fi
-# Updating configuration file
+# config
sed -i -e "s|${OLD}|${NEW}|g" "${CONFIG}/${NEW}.conf"
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/remove b/lib/container/remove
index 3670ca4..eec3b02 100755
--- a/lib/container/remove
+++ b/lib/container/remove
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -128,6 +129,15 @@ case "${VERBOSE}" in
;;
esac
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# data
if [ -e "${CONFIG}/${NAME}.conf" ]
then
@@ -150,3 +160,12 @@ fi
# Run
rm --preserve-root --one-file-system -rf ${RM_OPTIONS} "${MACHINES}/${NAME}"
rm -f ${RM_OPTIONS} "${CONFIG}/${NAME}.conf"
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/restart b/lib/container/restart
index 468b297..1c4c591 100755
--- a/lib/container/restart
+++ b/lib/container/restart
@@ -20,6 +20,7 @@ set -e
COMMAND="$(basename ${0})"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -77,5 +78,23 @@ then
exit 1
fi
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
machinectl reboot ${NAME}
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/start b/lib/container/start
index 20d738e..40ee195 100755
--- a/lib/container/start
+++ b/lib/container/start
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
START="false"
@@ -155,6 +156,22 @@ case "${HOST_ARCHITECTURE}" in
;;
esac
+case "${START}" in
+ start)
+ ;;
+
+ *)
+ # Pre hooks
+ for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+ do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+ done
+ ;;
+esac
+
# config
if [ -e "${CONFIG}/${NAME}.conf" ]
then
@@ -421,5 +438,14 @@ case "${START}" in
*)
# Run
${SETARCH} systemd-nspawn --keep-unit ${BIND} ${BOOT} ${CAPABILITY} ${DIRECTORY} ${DROP_CAPABILITY} ${MACHINE} ${NETWORK_VETH_EXTRA} ${LINK_JOURNAL} ${REGISTER}
+
+ # Post hooks
+ for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+ do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+ done
;;
esac
diff --git a/lib/container/status b/lib/container/status
index 65a7210..7429c78 100755
--- a/lib/container/status
+++ b/lib/container/status
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -78,5 +79,23 @@ then
exit 1
fi
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
systemctl status container@${NAME}.service --full
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/stop b/lib/container/stop
index 3327025..e91d0c6 100755
--- a/lib/container/stop
+++ b/lib/container/stop
@@ -21,6 +21,7 @@ set -e
COMMAND="$(basename ${0})"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
CLEAN="false"
@@ -90,6 +91,15 @@ then
exit 1
fi
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
STATE="$(machinectl show ${NAME} 2>&1 | awk -F= '/^State=/ { print $2 }')"
case "${CLEAN}" in
@@ -182,3 +192,12 @@ esac
# Run
machinectl ${MODE} ${NAME}
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/lib/container/version b/lib/container/version
index b57c17d..f72355e 100755
--- a/lib/container/version
+++ b/lib/container/version
@@ -18,6 +18,25 @@
set -e
+HOOKS="/etc/container-tools/hooks"
SHARE="/usr/share/container-tools"
+# Pre hooks
+for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
cat "${SHARE}/VERSION.txt"
+
+# Post hooks
+for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/share/bash-completion/container b/share/bash-completion/container
index e49311a..8d54ba4 100644
--- a/share/bash-completion/container
+++ b/share/bash-completion/container
@@ -47,7 +47,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -s -f short)
+ opts=$(container list -s -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -93,7 +93,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -s -f short)
+ opts=$(container list -s -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -113,7 +113,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -a -f short)
+ opts=$(container list -a -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -139,7 +139,7 @@ _container()
;;
-f|--format)
- opts="short full"
+ opts="cli csv json nwdiag shell yaml xml"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -159,7 +159,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -t -f short)
+ opts=$(container list -t -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -179,7 +179,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -s -f short)
+ opts=$(container list -s -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -199,7 +199,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -t -f short)
+ opts=$(container list -t -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -219,7 +219,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -t -f short)
+ opts=$(container list -t -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@@ -239,7 +239,7 @@ _container()
*)
case "${prev}" in
-n|--name)
- opts=$(container list -s -f short)
+ opts=$(container list -s -f shell)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
diff --git a/share/man/container-auto.1.txt b/share/man/container-auto.1.txt
index e3ece8a..0eb76d2 100644
--- a/share/man/container-auto.1.txt
+++ b/share/man/container-auto.1.txt
@@ -71,7 +71,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-console.1.txt b/share/man/container-console.1.txt
index 65f1621..7b25125 100644
--- a/share/man/container-console.1.txt
+++ b/share/man/container-console.1.txt
@@ -65,7 +65,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-create-curl.1.txt b/share/man/container-create-curl.1.txt
index 68fc0e2..e046b24 100644
--- a/share/man/container-create-curl.1.txt
+++ b/share/man/container-create-curl.1.txt
@@ -112,7 +112,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-create-debconf.1.txt b/share/man/container-create-debconf.1.txt
index 9e765f3..a51dfef 100644
--- a/share/man/container-create-debconf.1.txt
+++ b/share/man/container-create-debconf.1.txt
@@ -144,7 +144,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-create-debootstrap.1.txt b/share/man/container-create-debootstrap.1.txt
index 4c7bbcb..9de3f94 100644
--- a/share/man/container-create-debootstrap.1.txt
+++ b/share/man/container-create-debootstrap.1.txt
@@ -86,7 +86,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-create.1.txt b/share/man/container-create.1.txt
index fa6b713..0fd5187 100644
--- a/share/man/container-create.1.txt
+++ b/share/man/container-create.1.txt
@@ -102,7 +102,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-enter.1.txt b/share/man/container-enter.1.txt
index 6339e74..42a7211 100644
--- a/share/man/container-enter.1.txt
+++ b/share/man/container-enter.1.txt
@@ -65,7 +65,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-limit.1.txt b/share/man/container-limit.1.txt
index 7fedc5b..9fc9cba 100644
--- a/share/man/container-limit.1.txt
+++ b/share/man/container-limit.1.txt
@@ -98,7 +98,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-list.1.txt b/share/man/container-list.1.txt
index 5aa9f22..d964c4e 100644
--- a/share/man/container-list.1.txt
+++ b/share/man/container-list.1.txt
@@ -46,12 +46,21 @@ The following container options are available, defaults to *--started --stopped*
*-a, --all*::
List all available container (started, stopped, and other).
+*--csv-separator='SEPARATOR'*::
+ Specify custom CSV separator, defaults to ','.
+
*-f, --format='FORMAT'*::
- Use format to list container. Currently available formats are 'short' or 'full' (default).
+ Use format to list container. Currently available formats are 'cli' (default), 'csv', 'json', 'nwdiag', 'shell', 'yaml', or 'xml'.
*-h, --host='HOSTNAME'*::
List only container that are enabled for automatic start on the specified hostname. Defaults to list containers of the local system only. Using 'all' shows all container regardless of any automatic start configuration.
+*--nwdiag-color='COLOR'*::
+ Specify custom nwdiag color for the host box, defaults to '#3465a4'.
+
+*--nwdiag-label='LABEL'*::
+ Specify custom nwdiag label for the diagram, defaults to empty.
+
*-o, --other*::
List only container that are not enable for automatic start on the current system.
@@ -66,12 +75,30 @@ EXAMPLES
*List all started and stopped containers of the local system:*::
sudo container list
-*List all started and stopped containers of the local system as a machine-readable list:*::
- sudo container list -f short
-
*List all started and other containers:*::
sudo container list -s -o
+*Create a CSV export of all started and stopped containers:*::
+ sudo container list -f csv
+
+*Create a JSON export of all started and stopped containers:*::
+ sudo container list -f json
+
+*Create a nwdiag export of all started and stopped containers:*::
+ sudo container list -f nwdiag
+
+*Create a SVG image via nwdiag of all started and stopped containers:*::
+ sudo container list -f nwdiag | nwdiag -T svg -o cnt-list.svg -
+
+*Create a shell export of all started and stopped containers:*::
+ sudo container list -f shell
+
+*Create a YAML export of all started and stopped containers:*::
+ sudo container list -f yaml
+
+*Create a XML export of all started and stopped containers:*::
+ sudo container list -f xml
+
SEE ALSO
--------
@@ -87,7 +114,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-move.1.txt b/share/man/container-move.1.txt
new file mode 100644
index 0000000..43e04bc
--- /dev/null
+++ b/share/man/container-move.1.txt
@@ -0,0 +1,86 @@
+// container-tools - Manage systemd-nspawn containers
+// Copyright (C) 2014-2016 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+CONTAINER-REMOVE(1)
+===================
+:doctype: manpage
+:man manual: Open Infrastructure
+:man source: container-tools
+:man version: {revnumber}
+
+
+NAME
+----
+container-move - Rename a container
+
+
+SYNOPSIS
+--------
+*container move* ['OPTIONS']
+
+*container mv* ['OPTIONS']
+
+
+DESCRIPTION
+-----------
+The container move commands renames a container.
+
+
+OPTIONS
+-------
+The following container options are available:
+
+*-n, --new='NAME'*::
+ Specify new container name.
+
+*-f, --force*::
+ Do not prompt before moving.
+
+*-o, --old*::
+ Specify old container name.
+
+
+EXAMPLES
+--------
+*Rename example.net container to example.org:*::
+ sudo container move -n example.org -o example.net
+
+*Rename example.net container to example.org without prompt:*::
+ sudo container move -n example.org -o example.net -f
+
+
+SEE ALSO
+--------
+container-tools(7),
+container(1).
+
+
+HOMEPAGE
+--------
+More information about container-tools and the Open Infrastructure project can be found on the homepage at https://open-infrastructure.net.
+
+
+CONTACT
+-------
+Bug reports, feature requests, help, patches, support and everything else
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
+
+Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
+
+
+AUTHORS
+-------
+container-tools was written by Daniel Baumann <daniel.baumann@open-infrastructure.net>.
diff --git a/share/man/container-remove.1.txt b/share/man/container-remove.1.txt
index d5724bd..843fa5e 100644
--- a/share/man/container-remove.1.txt
+++ b/share/man/container-remove.1.txt
@@ -76,7 +76,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-restart.1.txt b/share/man/container-restart.1.txt
index 181c754..2aed923 100644
--- a/share/man/container-restart.1.txt
+++ b/share/man/container-restart.1.txt
@@ -65,7 +65,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-shell.1.txt b/share/man/container-shell.1.txt
index 1059d0e..38a8034 100644
--- a/share/man/container-shell.1.txt
+++ b/share/man/container-shell.1.txt
@@ -68,7 +68,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-start.1.txt b/share/man/container-start.1.txt
index a225a7c..64c4b3c 100644
--- a/share/man/container-start.1.txt
+++ b/share/man/container-start.1.txt
@@ -68,7 +68,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-status.1.txt b/share/man/container-status.1.txt
index db81d3b..8da969f 100644
--- a/share/man/container-status.1.txt
+++ b/share/man/container-status.1.txt
@@ -65,7 +65,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-stop.1.txt b/share/man/container-stop.1.txt
index 6113fd5..07426af 100644
--- a/share/man/container-stop.1.txt
+++ b/share/man/container-stop.1.txt
@@ -71,7 +71,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container-version.1.txt b/share/man/container-version.1.txt
index d4a8713..bb11d40 100644
--- a/share/man/container-version.1.txt
+++ b/share/man/container-version.1.txt
@@ -64,7 +64,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/man/container.1.txt b/share/man/container.1.txt
index 670efbe..f76bbda 100644
--- a/share/man/container.1.txt
+++ b/share/man/container.1.txt
@@ -64,6 +64,9 @@ The following container commands are available:
*remove*::
Remove a container, see container-remove(1).
+*move*::
+ Rename a container, see container-move(1).
+
*console*::
Attach console to a container, see container-console(1).
@@ -126,7 +129,7 @@ More information about container-tools and the Open Infrastructure project can b
CONTACT
-------
Bug reports, feature requests, help, patches, support and everything else
-are welcome on the Open Infrastructure Software Mailing List software@lists.open-infrastructure.net.
+are welcome on the Open Infrastructure Software Mailing List <software@lists.open-infrastructure.net>.
Debian specific bugs can also be reported in the Debian Bug Tracking System at https://bugs.debian.org.
diff --git a/share/scripts/curl b/share/scripts/curl
index 6b7d6a0..69badd9 100755
--- a/share/scripts/curl
+++ b/share/scripts/curl
@@ -20,6 +20,7 @@ set -e
SCRIPT="${0}"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
CACHE="/var/cache/container-tools/images"
@@ -132,6 +133,15 @@ PASSWORD="${PASSWORD:-$(dd if=/dev/urandom bs=12 count=1 2> /dev/null | base64)}
VERSION="$(container version)"
+# Pre hooks
+for FILE in "${HOOKS}/pre-${SCRIPT}".* "${HOOKS}/${NAME}.pre-${SCRIPT}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run
# FIXME: Show available image directories on server
@@ -227,3 +237,12 @@ case "${CLEAN}" in
rm -f "${CACHE}/${IMAGE}.sha512"
;;
esac
+
+# Post hooks
+for FILE in "${HOOKS}/post-${SCRIPT}".* "${HOOKS}/${NAME}.post-${SCRIPT}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/share/scripts/debconf b/share/scripts/debconf
index cde66cb..72e9c85 100755
--- a/share/scripts/debconf
+++ b/share/scripts/debconf
@@ -21,6 +21,7 @@ set -e
SCRIPT="${0}"
CONFIG="/etc/container-tools/config"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -964,6 +965,15 @@ Debconf
export NAME
+# Pre hooks
+for FILE in "${HOOKS}/pre-${SCRIPT}".* "${HOOKS}/${NAME}.pre-${SCRIPT}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
# Run debconf parts
for SCRIPT in /usr/share/container-tools/scripts/debconf.d/*
do
@@ -1077,3 +1087,12 @@ fi
# remove debconf temporary files
rm --preserve-root --one-file-system -rf "${DEBCONF_TMPDIR}"
rmdir --ignore-fail-on-non-empty /tmp/container-tools 2>&1 || true
+
+# Post hooks
+for FILE in "${HOOKS}/post-${SCRIPT}".* "${HOOKS}/${NAME}.post-${SCRIPT}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
diff --git a/share/scripts/debootstrap b/share/scripts/debootstrap
index 9c76ba0..2da573d 100755
--- a/share/scripts/debootstrap
+++ b/share/scripts/debootstrap
@@ -20,6 +20,7 @@ set -e
SCRIPT="${0}"
+HOOKS="/etc/container-tools/hooks"
MACHINES="/var/lib/machines"
Parameters ()
@@ -137,6 +138,15 @@ case "${MIRROR}" in
;;
esac
+# Pre hooks
+for FILE in "${HOOKS}/pre-${SCRIPT}".* "${HOOKS}/${NAME}.pre-${SCRIPT}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done
+
mkdir -p "${MACHINES}"
debootstrap --arch=${ARCHITECTURE} --include=${INCLUDE} ${DISTRIBUTION} ${MACHINES}/${NAME} ${MIRROR}
@@ -148,3 +158,12 @@ echo "${NAME}" > "${MACHINES}/${NAME}/etc/hostname"
# Setting root password
echo root:${PASSWORD} | chroot "${MACHINES}/${NAME}" chpasswd
echo "${NAME}: root password set to '${PASSWORD}'."
+
+# Post hooks
+for FILE in "${HOOKS}/post-${SCRIPT}".* "${HOOKS}/${NAME}.post-${SCRIPT}"
+do
+ if [ -x "${FILE}" ]
+ then
+ "${FILE}"
+ fi
+done