Move usage functions into bkctld-help script

* Usage output is now auto-generated
This commit is contained in:
Victor LABORIE 2019-01-07 14:47:05 +01:00
parent d0165a9e3c
commit 0272c43751
20 changed files with 132 additions and 41 deletions

6
bkctld
View file

@ -21,10 +21,12 @@ subcommand="${1:-}"
jail="${2:-}"
option="${3:-}"
[ -x "${LIBDIR}/bkctld-${subcommand}" ] || usage
if [ ! -x "${LIBDIR}/bkctld-${subcommand}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
case "${subcommand}" in
"inc" | "rm" | "check" | "stats")
"inc" | "rm" | "check" | "stats" | "help")
"${LIBDIR}/bkctld-${subcommand}"
;;
"init")

View file

@ -1,4 +1,8 @@
#!/bin/sh
#
# Run check on jails (NRPE output)
# Usage: check
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Update firewall rules of <jailname> or all
# Usage: firewall <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
if [ -n "${FIREWALL_RULES}" ]; then
[ -f "${FIREWALL_RULES}" ] && sed -i "/#${jail}$/d" "${FIREWALL_RULES}"

21
lib/bkctld-help Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
#
# Print this help
# Usage: help
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
cat <<EOF
Usage: bkctld <subcommand> [options]
Subcommands:
EOF
for subcommand in ${LIBDIR}/bkctld-*; do
name=$(basename "${subcommand}"|cut -d'-' -f2)
desc=$(grep -E "^#" "${subcommand}"|sed -n '3p'|sed "s/^# //")
usage=$(grep -E "^# Usage: ${name}" "${subcommand}"|sed "s/^# Usage: ${name}//")
printf " %- 10s %- 30s %- 40s\n" "${name}" "${usage}" "${desc}"
done
printf "\n"

View file

@ -1,4 +1,8 @@
#!/bin/sh
#
# Make incremental inc of all jails
# Usage: inc
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Init jail <jailname>
# Usage: init <jailname>
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" && error "${jail} : trying to create existant jail"
sshd_config="${TPLDIR}/sshd_config"

View file

@ -1,10 +1,16 @@
#!/bin/sh
#
# Set or get allowed(s) ip(s) of <jailname>
# Usage: ip <jailname> [<ip>|all]
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
ip="${2:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : inexistant jail'"
if [ -z "${ip}" ]; then

View file

@ -1,10 +1,16 @@
#!/bin/sh
#
# Set or get ssh pubic key of <jailname>
# Usage: key <jailname> [<keyfile>]
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
keyfile="${2:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : inexistant jail'"
if [ -z "${keyfile}" ]; then

View file

@ -1,10 +1,16 @@
#!/bin/sh
#
# Set or get ssh port of <jailname>
# Usage: port <jailname> [<port>|auto]
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
port="${2:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : inexistant jail'"
if [ -z "${port}" ]; then

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Reload jail <jailname> or all
# Usage: reload <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to reload inexistant jail"
check_jail_on "${jail}" || exit 0

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Remove jail <jailname> or all
# Usage: remove <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to remove inexistant jail"
check_jail_on "${jail}" && . "${LIBDIR}/bkctld-stop" "${jail}"

View file

@ -1,11 +1,17 @@
#!/bin/sh
#
# Restart jail <jailname> or all
# Usage: restart <jailname>|all
#
set -eu
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to restart inexistant jail"
check_jail_on "${jail}" && "${LIBDIR}/bkctld-stop" "${jail}"
"${LIBDIR}/bkctld-start" "${jail}"

View file

@ -1,4 +1,8 @@
#!/bin/sh
#
# Remove old incremtal inc of all jails
# Usage: rm
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Start jail <jailname> or all
# Usage: start <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to start inexistant jail"
check_jail_on "${jail}" && exit 0

View file

@ -1,4 +1,8 @@
#!/bin/sh
#
# Make and display stats on jails (size, lastconn)
# Usage: stats
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Print status of <jailname> (default all jail)
# Usage: status [<jailname>]
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : inexistant jail ! Use '$0 status' for list all"
inc=$(get_inc "${jail}")

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Stop jail <jailname> or all
# Usage: stop <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to stop inexistant jail"
check_jail_on "${jail}" || exit 0

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Sync jail <jailname> or all to another node
# Usage: sync <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to sync inexistant jail"
[ -n "${NODE}" ] || error "Sync need config of \$NODE in /etc/default/bkctld !"

View file

@ -1,9 +1,15 @@
#!/bin/sh
#
# Update jail <jailname> or all
# Usage: update <jailname>|all
#
LIBDIR="$(dirname $0)" && . "${LIBDIR}/config"
jail="${1:-}"
[ -n "${jail}" ] || usage
if [ ! -n "${jail}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
check_jail "${jail}" || error "${jail} : trying to update inexistant jail"
check_jail_on "${jail}" && . "${LIBDIR}/bkctld-stop" "${jail}"

View file

@ -1,31 +1,5 @@
#!/bin/sh
usage() {
cat <<EOF
Usage: $0 <subcommand> [options]
Subcommands:
init <jailname> Init jail <jailname>
update <jailname>|all Update jail <jailname> or all
remove <jailname>|all Remove jail <jailname> or all
start <jailname>|all Start jail <jailname> or all
stop <jailname>|all Stop jail <jailname> or all
reload <jailname>|all Reload jail <jailname> or all
restart <jailname>|all Restart jail <jailname> or all
sync <jailname>|all Sync jail <jailname> or all to another node
firewall <jailname>|all Update firewall rules of <jailname> or all
status [<jailname>] Print status of <jailname> (default all jail)
key <jailname> [<keyfile>] Set or get ssh pubic key of <jailname>
port <jailname> [<port>|auto] Set or get ssh port of <jailname>
ip <jailname> [<ip>|all] Set or get allowed(s) ip(s) of <jailname>
inc Make incremental inc of all jails
rm Remove old incremtal inc of all jails
check Run check on jails (NRPE output)
stats Make and display stats on jails (size, lastconn)
EOF
exit 1
}
check_jail() {
jail="${1}"
[ -d "${JAILDIR}/${jail}" ] && return 0