Better help message composition and formating

This commit is contained in:
Jérémy Lecour 2020-10-11 14:51:39 +02:00
parent 2ad1032f9d
commit 05c3715c6a
26 changed files with 48 additions and 43 deletions

View File

@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Better help message composition and formating
### Deprecated
### Removed
@ -58,7 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* bkctld-update: start jail after upgrade if it was started before
* bkctld: don't replace SSH host keys when creating/updating a jail
* Split check into check-jails and check-setup
* bkctld-check-jails checks if jails
* bkctld-check-jails checks if jails
* bkctld-check-setup checks if the partition is mounted and writable, if firewall is configured and if all jails are in their expected state
* create new ssh keys for new jails instead of copying those from the host

6
bkctld
View File

@ -36,6 +36,10 @@ fi
# Parse options
# based on https://gist.github.com/deshion/10d3cb5f88a21671e17a
if [ "$#" = "0" ]; then
show_help
exit 1
fi
while :; do
case $1 in
-h|-\?|--help)
@ -81,7 +85,7 @@ case "${subcommand}" in
show_help
exit 1
else
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
fi
;;
"key" | "port" | "ip")

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Run check on all expected incs of all jails
# Description: Run check on all expected incs of all jails
# Usage: check-incs all
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Run check on jails (NRPE output)
# Description: Run check on jails (NRPE output)
# Usage: check-jails
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Run check on the last inc of all jails
# Description: Run check on the last inc of all jails
# Usage: check-incs last
#

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Run check on jails (NRPE output)
# Usage: check-setup
# Description: Run check on jails (NRPE output)
# Usage: check setup
#
# shellcheck source=./includes

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Update firewall rules of <jailname> or all
# Usage: firewall <jailname>|all
# Description: Update firewall rules
# Usage: firewall [<jailname>|all]
#
# shellcheck source=./includes

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Make incremental inc of all jails
# Description: Make dated copies (incs) of jails
# Usage: inc
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Init jail <jailname>
# Description: Initialize a new jail
# Usage: init <jailname>
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Set or get allowed(s) ip(s) of <jailname>
# Description: Set or get allowed(s) ip(s)
# Usage: ip <jailname> [<ip>|all]
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Check if a jail is on or not
# Description: Check if a SSH server is on (exit 0) or not (exit 100)
# Usage: is-on <jailname>
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Set or get ssh pubic key of <jailname>
# Description: Set or get ssh pubic key
# Usage: key <jailname> [<keyfile>]
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# List jails
# Description: List jails
# Usage: list
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Set or get ssh port of <jailname>
# Description: Set or get SSH port
# Usage: port <jailname> [<port>|auto]
#

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Reload jail <jailname> or all
# Usage: reload <jailname>|all
# Description: Reload SSH server
# Usage: reload [<jailname>|all]
#
# shellcheck source=./includes

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Remove jail <jailname> or all
# Description: Remove jail and all dated copies (incs)
# Usage: remove <jailname>|all
#

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Restart jail <jailname> or all
# Usage: restart <jailname>|all
# Description: Restart SSH server
# Usage: restart [<jailname>|all]
#
set -eu

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Remove old incremtal inc of all jails
# Description: Remove old dated copies (incs) according to policy
# Usage: rm
#
@ -102,7 +102,7 @@ for jail_name in ${jails_list}; do
# If no incs policy is found, we don't remove incs
if [ -n "${incs_policy_file}" ]; then
# shellcheck disable=SC2046
incs_to_delete=$(incs_to_delete "${jail_name}" "${incs_policy_file}")
incs_total=$(echo ${incs_to_delete} | wc -w)
incs_count=0

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Start jail <jailname> or all
# Description: Start SSH Server
# Usage: start <jailname>|all
#

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Make and display stats on jails (size, lastconn)
# Description: Display stats on jails (size, last connection…)
# Usage: stats
#

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Print status of <jailname> (default all jail)
# Usage: status [<jailname>]
# Description: Display status of SSH server
# Usage: status [<jailname>|all]
#
# shellcheck source=./includes

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Stop jail <jailname> or all
# Usage: stop <jailname>|all
# Description: Stop SSH server
# Usage: stop [<jailname>|all]
#
# shellcheck source=./includes
@ -21,7 +21,7 @@ pid=$(cat "${jail_path}/${SSHD_PID}")
pkill --parent "${pid}"
if kill "${pid}"; then
if kill "${pid}"; then
notice "Stop jail \`${jail_name}' : OK [${pid}]"
umount --lazy --recursive "${jail_path}/dev"

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Sync jail <jailname> or all to another node
# Usage: sync <jailname>|all
# Description: Sync jail configuration and state on other node(s)
# Usage: sync [<jailname>|all]
#
# shellcheck source=./includes

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Update jail <jailname> or all
# Usage: update <jailname>|all
# Description: Update binaries and libraries
# Usage: update [<jailname>|all]
#
# shellcheck source=./includes

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Upgrade chroot components for jail <jailname> or all
# Usage: upgrade-config <jailname>|all
# Description: Upgrade configuration to new convention
# Usage: upgrade-config [<jailname>|all]
#
# shellcheck source=./includes

View File

@ -51,11 +51,10 @@ Options
Subcommands:
EOF
for subcommand in ${LIBDIR}/bkctld-*; do
name=$(basename "${subcommand}"|sed 's/^bkctld-//')
desc=$(grep -E "^#" "${subcommand}"|sed -n '3p'|sed "s/^# //")
usage=$(grep -E "^# Usage: ${name}" "${subcommand}"|sed "s/^# Usage: ${name}//")
printf " %- 15s %- 30s %- 40s\n" "${name}" "${usage}" "${desc}"
for filename in ${LIBDIR}/bkctld-*; do
desc=$(grep -E "^# Description:" "${filename}"|sed "s/^# Description: //")
usage=$(grep -E "^# Usage:" "${filename}"|sed "s/^# Usage: //")
printf " %- 32s %s\n" "${usage}" "${desc}"
done
printf "\n"
@ -380,8 +379,8 @@ is_mounted_inside_jail() {
target=${1:?}
# TODO: try to find why it doesn't work with this findmnt(8) command
# findmnt --target "${target}" --tab-file /proc/mounts
grep -q "${target}" /proc/mounts
# findmnt --target "${target}" --tab-file /proc/mounts
grep -q "${target}" /proc/mounts
}
mount_jail_fs() {