diff --git a/CHANGELOG.md b/CHANGELOG.md index 88b1c2e..69d1688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bkctld b/bkctld index 03342a8..b46810d 100755 --- a/bkctld +++ b/bkctld @@ -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") diff --git a/lib/bkctld-check-incs b/lib/bkctld-check-incs index d862e70..1a1f5c3 100755 --- a/lib/bkctld-check-incs +++ b/lib/bkctld-check-incs @@ -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 # diff --git a/lib/bkctld-check-jails b/lib/bkctld-check-jails index 531ab27..aafa456 100755 --- a/lib/bkctld-check-jails +++ b/lib/bkctld-check-jails @@ -1,6 +1,6 @@ #!/bin/sh # -# Run check on jails (NRPE output) +# Description: Run check on jails (NRPE output) # Usage: check-jails # diff --git a/lib/bkctld-check-last-incs b/lib/bkctld-check-last-incs index c73e302..e0cafa1 100755 --- a/lib/bkctld-check-last-incs +++ b/lib/bkctld-check-last-incs @@ -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 # diff --git a/lib/bkctld-check-setup b/lib/bkctld-check-setup index a66b357..d2632a0 100755 --- a/lib/bkctld-check-setup +++ b/lib/bkctld-check-setup @@ -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 diff --git a/lib/bkctld-firewall b/lib/bkctld-firewall index 2c1293f..7cb434c 100755 --- a/lib/bkctld-firewall +++ b/lib/bkctld-firewall @@ -1,7 +1,7 @@ #!/bin/sh # -# Update firewall rules of or all -# Usage: firewall |all +# Description: Update firewall rules +# Usage: firewall [|all] # # shellcheck source=./includes diff --git a/lib/bkctld-inc b/lib/bkctld-inc index 7c81404..d29c752 100755 --- a/lib/bkctld-inc +++ b/lib/bkctld-inc @@ -1,6 +1,6 @@ #!/bin/sh # -# Make incremental inc of all jails +# Description: Make dated copies (incs) of jails # Usage: inc # diff --git a/lib/bkctld-init b/lib/bkctld-init index a7dec49..6b52815 100755 --- a/lib/bkctld-init +++ b/lib/bkctld-init @@ -1,6 +1,6 @@ #!/bin/sh # -# Init jail +# Description: Initialize a new jail # Usage: init # diff --git a/lib/bkctld-ip b/lib/bkctld-ip index dae1913..83e8e33 100755 --- a/lib/bkctld-ip +++ b/lib/bkctld-ip @@ -1,6 +1,6 @@ #!/bin/sh # -# Set or get allowed(s) ip(s) of +# Description: Set or get allowed(s) ip(s) # Usage: ip [|all] # diff --git a/lib/bkctld-is-on b/lib/bkctld-is-on index 36deafb..9c2b904 100755 --- a/lib/bkctld-is-on +++ b/lib/bkctld-is-on @@ -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 # diff --git a/lib/bkctld-key b/lib/bkctld-key index bfe6e51..393afd7 100755 --- a/lib/bkctld-key +++ b/lib/bkctld-key @@ -1,6 +1,6 @@ #!/bin/sh # -# Set or get ssh pubic key of +# Description: Set or get ssh pubic key # Usage: key [] # diff --git a/lib/bkctld-list b/lib/bkctld-list index 3815871..10b11bf 100755 --- a/lib/bkctld-list +++ b/lib/bkctld-list @@ -1,6 +1,6 @@ #!/bin/sh # -# List jails +# Description: List jails # Usage: list # diff --git a/lib/bkctld-port b/lib/bkctld-port index dffe4e9..2b1f17d 100755 --- a/lib/bkctld-port +++ b/lib/bkctld-port @@ -1,6 +1,6 @@ #!/bin/sh # -# Set or get ssh port of +# Description: Set or get SSH port # Usage: port [|auto] # diff --git a/lib/bkctld-reload b/lib/bkctld-reload index 5feec92..1036618 100755 --- a/lib/bkctld-reload +++ b/lib/bkctld-reload @@ -1,7 +1,7 @@ #!/bin/sh # -# Reload jail or all -# Usage: reload |all +# Description: Reload SSH server +# Usage: reload [|all] # # shellcheck source=./includes diff --git a/lib/bkctld-remove b/lib/bkctld-remove index 7b4b152..30d2594 100755 --- a/lib/bkctld-remove +++ b/lib/bkctld-remove @@ -1,6 +1,6 @@ #!/bin/sh # -# Remove jail or all +# Description: Remove jail and all dated copies (incs) # Usage: remove |all # diff --git a/lib/bkctld-restart b/lib/bkctld-restart index 7aaa314..9394b9a 100755 --- a/lib/bkctld-restart +++ b/lib/bkctld-restart @@ -1,7 +1,7 @@ #!/bin/sh # -# Restart jail or all -# Usage: restart |all +# Description: Restart SSH server +# Usage: restart [|all] # set -eu diff --git a/lib/bkctld-rm b/lib/bkctld-rm index 59035da..1c448c8 100755 --- a/lib/bkctld-rm +++ b/lib/bkctld-rm @@ -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 diff --git a/lib/bkctld-start b/lib/bkctld-start index a0d6f9c..343e2db 100755 --- a/lib/bkctld-start +++ b/lib/bkctld-start @@ -1,6 +1,6 @@ #!/bin/sh # -# Start jail or all +# Description: Start SSH Server # Usage: start |all # diff --git a/lib/bkctld-stats b/lib/bkctld-stats index c619b2d..8e69f12 100755 --- a/lib/bkctld-stats +++ b/lib/bkctld-stats @@ -1,6 +1,6 @@ #!/bin/sh # -# Make and display stats on jails (size, lastconn) +# Description: Display stats on jails (size, last connection…) # Usage: stats # diff --git a/lib/bkctld-status b/lib/bkctld-status index 80e6769..e815927 100755 --- a/lib/bkctld-status +++ b/lib/bkctld-status @@ -1,7 +1,7 @@ #!/bin/sh # -# Print status of (default all jail) -# Usage: status [] +# Description: Display status of SSH server +# Usage: status [|all] # # shellcheck source=./includes diff --git a/lib/bkctld-stop b/lib/bkctld-stop index 2d8a76f..fa8809d 100755 --- a/lib/bkctld-stop +++ b/lib/bkctld-stop @@ -1,7 +1,7 @@ #!/bin/sh # -# Stop jail or all -# Usage: stop |all +# Description: Stop SSH server +# Usage: stop [|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" diff --git a/lib/bkctld-sync b/lib/bkctld-sync index df18917..e982af3 100755 --- a/lib/bkctld-sync +++ b/lib/bkctld-sync @@ -1,7 +1,7 @@ #!/bin/sh # -# Sync jail or all to another node -# Usage: sync |all +# Description: Sync jail configuration and state on other node(s) +# Usage: sync [|all] # # shellcheck source=./includes diff --git a/lib/bkctld-update b/lib/bkctld-update index 3309030..c6af12a 100755 --- a/lib/bkctld-update +++ b/lib/bkctld-update @@ -1,7 +1,7 @@ #!/bin/sh # -# Update jail or all -# Usage: update |all +# Description: Update binaries and libraries +# Usage: update [|all] # # shellcheck source=./includes diff --git a/lib/bkctld-upgrade-config b/lib/bkctld-upgrade-config index 054ade4..e835f7b 100644 --- a/lib/bkctld-upgrade-config +++ b/lib/bkctld-upgrade-config @@ -1,7 +1,7 @@ #!/bin/sh # -# Upgrade chroot components for jail or all -# Usage: upgrade-config |all +# Description: Upgrade configuration to new convention +# Usage: upgrade-config [|all] # # shellcheck source=./includes diff --git a/lib/includes b/lib/includes index 2196e5e..4d6c9cc 100755 --- a/lib/includes +++ b/lib/includes @@ -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() {