2021-08-27 17:19:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2021-02-05 21:43:50 +01:00
|
|
|
|
2021-02-05 22:25:04 +01:00
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021 Joe Testa (jtesta@positronsecurity.com)
|
|
|
|
# Copyright (C) 2021 Adam Russell (<adam[at]thecliguy[dot]co[dot]uk>)
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
#
|
|
|
|
|
2021-02-05 21:43:50 +01:00
|
|
|
################################################################################
|
2021-02-05 22:25:04 +01:00
|
|
|
# update_windows_man_page.sh
|
2021-02-05 21:43:50 +01:00
|
|
|
#
|
|
|
|
# PURPOSE
|
|
|
|
# Since Windows lacks a manual reader it's necessary to provide an alternative
|
2021-08-27 17:19:18 +02:00
|
|
|
# means of reading the man page.
|
2021-02-05 21:43:50 +01:00
|
|
|
#
|
2021-08-27 17:19:18 +02:00
|
|
|
# This script should be run as part of the ssh-audit packaging process for
|
|
|
|
# Windows. It populates the 'WINDOWS_MAN_PAGE' variable in 'globals.py' with
|
|
|
|
# the contents of the man page. Windows users can then print the content of
|
|
|
|
# 'WINDOWS_MAN_PAGE' by invoking ssh-audit with the manual parameters
|
2021-02-05 21:43:50 +01:00
|
|
|
# (--manual / -m).
|
|
|
|
#
|
2021-02-05 22:25:04 +01:00
|
|
|
# Cygwin is required.
|
|
|
|
#
|
2021-02-05 21:43:50 +01:00
|
|
|
# USAGE
|
2021-02-05 22:25:04 +01:00
|
|
|
# update_windows_man_page.sh [-m <path-to-man-page>] [-g <path-to-globals.py>]
|
2021-02-05 21:43:50 +01:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2021-08-27 17:19:18 +02:00
|
|
|
usage() {
|
2021-02-05 22:25:04 +01:00
|
|
|
echo >&2 "Usage: $0 [-m <path-to-man-page>] [-g <path-to-globals.py>] [-h]"
|
|
|
|
echo >&2 " -m Specify an alternate man page path (default: ./ssh-audit.1)"
|
|
|
|
echo >&2 " -g Specify an alternate globals.py path (default: ./src/ssh_audit/globals.py)"
|
|
|
|
echo >&2 " -h This help message"
|
|
|
|
}
|
|
|
|
|
2021-02-18 20:52:08 +01:00
|
|
|
PLATFORM="$(uname -s)"
|
|
|
|
|
|
|
|
# This script is intended for use on Linux and Cygwin only.
|
2023-09-05 19:14:21 +02:00
|
|
|
case "${PLATFORM}" in
|
2021-08-27 17:19:18 +02:00
|
|
|
Linux | CYGWIN*) ;;
|
|
|
|
*)
|
2023-09-05 19:14:21 +02:00
|
|
|
echo "Platform not supported: ${PLATFORM}"
|
2021-08-27 17:19:18 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
2021-02-18 20:52:08 +01:00
|
|
|
esac
|
2021-02-05 22:25:04 +01:00
|
|
|
|
2021-02-18 20:52:08 +01:00
|
|
|
MAN_PAGE=./ssh-audit.1
|
|
|
|
GLOBALS_PY=./src/ssh_audit/globals.py
|
2021-02-05 22:25:04 +01:00
|
|
|
|
2021-08-27 17:19:18 +02:00
|
|
|
while getopts "m: g: h" OPTION; do
|
2023-09-05 19:14:21 +02:00
|
|
|
case "${OPTION}" in
|
2021-02-05 21:43:50 +01:00
|
|
|
m)
|
2023-09-05 19:14:21 +02:00
|
|
|
MAN_PAGE="${OPTARG}"
|
2021-02-05 21:43:50 +01:00
|
|
|
;;
|
|
|
|
g)
|
2023-09-05 19:14:21 +02:00
|
|
|
GLOBALS_PY="${OPTARG}"
|
2021-02-05 21:43:50 +01:00
|
|
|
;;
|
2021-02-05 22:25:04 +01:00
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2021-02-05 21:43:50 +01:00
|
|
|
*)
|
|
|
|
echo >&2 "Invalid parameter(s) provided"
|
2021-02-05 22:25:04 +01:00
|
|
|
usage
|
2021-02-05 21:43:50 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Check that the specified files exist.
|
2021-08-27 17:19:18 +02:00
|
|
|
[[ -f "$MAN_PAGE" ]] || { echo >&2 "man page file not found: $MAN_PAGE"; exit 1; }
|
2023-09-05 19:14:21 +02:00
|
|
|
[[ -f "${GLOBALS_PY}" ]] || { echo >&2 "globals.py file not found: ${GLOBALS_PY}"; exit 1; }
|
2021-02-05 21:43:50 +01:00
|
|
|
|
2021-02-18 20:52:08 +01:00
|
|
|
# Check that the 'ul' (do underlining) binary exists.
|
2023-09-05 19:14:21 +02:00
|
|
|
if [[ "${PLATFORM}" == "Linux" ]]; then
|
2021-02-18 20:52:08 +01:00
|
|
|
command -v ul >/dev/null 2>&1 || { echo >&2 "ul not found."; exit 1; }
|
|
|
|
fi
|
2021-02-05 21:43:50 +01:00
|
|
|
|
|
|
|
# Check that the 'sed' (stream editor) binary exists.
|
|
|
|
command -v sed >/dev/null 2>&1 || { echo >&2 "sed not found."; exit 1; }
|
|
|
|
|
2021-02-24 01:54:12 +01:00
|
|
|
# Reset the globals.py file, in case it was modified from a prior run.
|
2023-09-05 19:14:21 +02:00
|
|
|
git checkout "${GLOBALS_PY}" > /dev/null 2>&1
|
2021-02-24 01:54:12 +01:00
|
|
|
|
2021-02-05 21:43:50 +01:00
|
|
|
# Remove the Windows man page placeholder from 'globals.py'.
|
2023-09-05 19:14:21 +02:00
|
|
|
sed -i '/^WINDOWS_MAN_PAGE/d' "${GLOBALS_PY}"
|
2021-02-05 21:43:50 +01:00
|
|
|
|
2021-02-05 22:25:04 +01:00
|
|
|
echo "Processing man page at ${MAN_PAGE} and placing output into ${GLOBALS_PY}..."
|
|
|
|
|
2021-02-05 21:43:50 +01:00
|
|
|
# Append the man page content to 'globals.py'.
|
2021-08-27 17:19:18 +02:00
|
|
|
# * man outputs a backspace-overwrite sequence rather than an ANSI escape
|
2021-02-05 21:43:50 +01:00
|
|
|
# sequence.
|
2021-08-27 17:19:18 +02:00
|
|
|
# * 'MAN_KEEP_FORMATTING' preserves the backspace-overwrite sequence when
|
2021-02-05 21:43:50 +01:00
|
|
|
# redirected to a file or a pipe.
|
2021-02-18 20:52:08 +01:00
|
|
|
# * sed converts unicode hyphens into an ASCI equivalent.
|
2021-08-27 17:19:18 +02:00
|
|
|
# * The 'ul' command converts the backspace-overwrite sequence to an ANSI
|
|
|
|
# escape sequence. Not required under Cygwin because man outputs ANSI escape
|
2021-02-18 20:52:08 +01:00
|
|
|
# codes automatically.
|
|
|
|
|
2023-09-05 19:14:21 +02:00
|
|
|
echo WINDOWS_MAN_PAGE = '"""' >> "${GLOBALS_PY}"
|
2021-02-18 20:52:08 +01:00
|
|
|
|
2023-09-05 19:14:21 +02:00
|
|
|
if [[ "${PLATFORM}" == CYGWIN* ]]; then
|
|
|
|
MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "${MAN_PAGE}" | sed $'s/\u2010/-/g' >> "${GLOBALS_PY}"
|
2021-02-18 20:52:08 +01:00
|
|
|
else
|
2023-09-05 19:14:21 +02:00
|
|
|
MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "${MAN_PAGE}" | ul | sed $'s/\u2010/-/g' >> "${GLOBALS_PY}"
|
2021-02-18 20:52:08 +01:00
|
|
|
fi
|
|
|
|
|
2023-09-05 19:14:21 +02:00
|
|
|
echo '"""' >> "${GLOBALS_PY}"
|
2021-02-05 22:25:04 +01:00
|
|
|
|
|
|
|
echo "Done."
|
2021-02-24 01:54:12 +01:00
|
|
|
exit 0
|