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 ### Changed
* Better help message composition and formating
### Deprecated ### Deprecated
### Removed ### 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-update: start jail after upgrade if it was started before
* bkctld: don't replace SSH host keys when creating/updating a jail * bkctld: don't replace SSH host keys when creating/updating a jail
* Split check into check-jails and check-setup * 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 * 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 * 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 # Parse options
# based on https://gist.github.com/deshion/10d3cb5f88a21671e17a # based on https://gist.github.com/deshion/10d3cb5f88a21671e17a
if [ "$#" = "0" ]; then
show_help
exit 1
fi
while :; do while :; do
case $1 in case $1 in
-h|-\?|--help) -h|-\?|--help)
@ -81,7 +85,7 @@ case "${subcommand}" in
show_help show_help
exit 1 exit 1
else else
"${LIBDIR}/bkctld-${subcommand}" "${jail_name}" "${LIBDIR}/bkctld-${subcommand}" "${jail_name}"
fi fi
;; ;;
"key" | "port" | "ip") "key" | "port" | "ip")

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/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 # Usage: check-incs all
# #

View file

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

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/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 # Usage: check-incs last
# #

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/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> # Usage: is-on <jailname>
# #

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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