fix: make log viewer optional and document runtime dependencies
This commit is contained in:
@@ -10,4 +10,5 @@ Also read and consider the repository state file when it exists:
|
||||
When this file is present:
|
||||
- use it as evolving project context,
|
||||
- keep recommendations aligned with it,
|
||||
- update suggestions to remain consistent with documented architecture, constraints, and review notes.
|
||||
- update suggestions to remain consistent with documented architecture, constraints, and review notes,
|
||||
- update `state.md` as part of the same task whenever changes materially affect repository behavior, architecture, constraints, or review notes.
|
||||
@@ -27,12 +27,19 @@ Supported actions:
|
||||
|
||||
## Requirements
|
||||
|
||||
Required:
|
||||
|
||||
- `bash`
|
||||
- `ssh`
|
||||
- `whiptail`
|
||||
- `nano`
|
||||
- `sed`
|
||||
- `tee`
|
||||
- core utilities such as `rm` and `touch`
|
||||
|
||||
Optional log viewer:
|
||||
|
||||
- `$EDITOR` if it points to an installed command
|
||||
- otherwise one of: `nano`, `vi`, `less`
|
||||
|
||||
## Install
|
||||
|
||||
@@ -101,5 +108,6 @@ Options:
|
||||
|
||||
- SSH connections currently use `root@host`
|
||||
- The tool is interactive and intended for manual administration workflows
|
||||
- After execution, the log file is opened in `nano`
|
||||
- After execution, the log file is opened with `$EDITOR` when available, otherwise with `nano`, `vi`, or `less`
|
||||
- If no supported log viewer is available, the script keeps running and prints the log file path
|
||||
- The configuration file is sourced as shell code, so only use trusted config files
|
||||
|
||||
+39
-6
@@ -10,11 +10,38 @@ showHelp() {
|
||||
}
|
||||
|
||||
checkDependencies() {
|
||||
command -v ssh >/dev/null 2>&1 || { echo "Error: ssh is required"; exit 1; }
|
||||
command -v whiptail >/dev/null 2>&1 || { echo "Error: whiptail is required"; exit 1; }
|
||||
command -v nano >/dev/null 2>&1 || { echo "Error: nano is required"; exit 1; }
|
||||
command -v sed >/dev/null 2>&1 || { echo "Error: sed is required"; exit 1; }
|
||||
command -v tee >/dev/null 2>&1 || { echo "Error: tee is required"; exit 1; }
|
||||
local -a REQUIRED_CMDS=(ssh whiptail sed tee rm touch)
|
||||
local -a MISSING_CMDS=()
|
||||
local CMD
|
||||
|
||||
for CMD in "${REQUIRED_CMDS[@]}"; do
|
||||
if ! command -v "${CMD}" >/dev/null 2>&1; then
|
||||
MISSING_CMDS+=("${CMD}")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#MISSING_CMDS[@]} -gt 0 ]; then
|
||||
echo "Error: missing required dependencies: ${MISSING_CMDS[*]}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
resolveLogViewer() {
|
||||
if [ -n "${EDITOR}" ] && command -v "${EDITOR}" >/dev/null 2>&1; then
|
||||
LOGVIEWER="${EDITOR}"
|
||||
return
|
||||
fi
|
||||
|
||||
local -a CANDIDATES=(nano vi less)
|
||||
local CANDIDATE
|
||||
for CANDIDATE in "${CANDIDATES[@]}"; do
|
||||
if command -v "${CANDIDATE}" >/dev/null 2>&1; then
|
||||
LOGVIEWER="${CANDIDATE}"
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
LOGVIEWER=""
|
||||
}
|
||||
|
||||
pressAnyKey(){
|
||||
@@ -88,7 +115,11 @@ selectNodes(){
|
||||
sed -i "1s/^/${RESULT//\//\\\/}\n\n\n\n/" "${LOGFILENAME}"
|
||||
sed -i "1s/^/---------\n\n/" "${LOGFILENAME}"
|
||||
sed -i "1s/^/Results :\n/" "${LOGFILENAME}"
|
||||
nano "${LOGFILENAME}"
|
||||
if [ -n "${LOGVIEWER}" ]; then
|
||||
"${LOGVIEWER}" "${LOGFILENAME}"
|
||||
else
|
||||
echo "Warning: no log viewer found, showing log path instead: ${LOGFILENAME}"
|
||||
fi
|
||||
rm -i "${LOGFILENAME}"
|
||||
echo ""
|
||||
echo "Results :"
|
||||
@@ -235,6 +266,7 @@ declare -i YES=0
|
||||
declare -i FULL=0
|
||||
declare CONFIGFILENAME="${HOME}/.config/netupgrade/index.cfg"
|
||||
declare LOGFILENAME="${HOME}/netupgrade.log"
|
||||
declare LOGVIEWER=""
|
||||
declare -a NODES=()
|
||||
|
||||
while [[ ${#} -gt 0 ]]; do
|
||||
@@ -247,6 +279,7 @@ while [[ ${#} -gt 0 ]]; do
|
||||
done
|
||||
|
||||
checkDependencies
|
||||
resolveLogViewer
|
||||
loadConfig
|
||||
selectNodes
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ The tool:
|
||||
3. Displays an interactive multi-select checklist using `whiptail`
|
||||
4. Executes the selected actions on each selected host through `ssh root@host`
|
||||
5. Writes execution logs to `~/netupgrade.log`
|
||||
6. Opens the log in `nano`, then optionally removes it
|
||||
6. Opens the log with `$EDITOR` when available, otherwise `nano`, `vi`, or `less`; if none is available, it prints the log path, then optionally removes the log file
|
||||
|
||||
Supported action types currently include:
|
||||
- `apt`
|
||||
@@ -71,7 +71,9 @@ Supported action types currently include:
|
||||
- The `docker-stacks` remote loop should be reviewed carefully for quoting and path safety
|
||||
|
||||
### 4. UX and dependency issues
|
||||
- Required runtime dependencies are now checked at startup (`ssh`, `whiptail`, `nano`, `sed`, `tee`)
|
||||
- Required runtime dependencies are now checked at startup (`ssh`, `whiptail`, `sed`, `tee`, `rm`, `touch`)
|
||||
- Log viewing no longer depends strictly on `nano`; the script now falls back to `$EDITOR`, then `nano`, `vi`, or `less`
|
||||
- If no supported log viewer is available, execution continues and the log path is shown
|
||||
- The workflow is highly interactive and not well suited for automation
|
||||
- `rm -i` introduces an extra prompt even when the rest of the flow is meant to be streamlined
|
||||
|
||||
@@ -111,6 +113,8 @@ Supported action types currently include:
|
||||
- `README.md` was expanded to document installation, requirements, usage, configuration format, and supported actions
|
||||
- `bin/netupgrade` help output was aligned with actual CLI behavior and now documents `--help`
|
||||
- A startup dependency check was added before loading configuration or opening the interactive selector
|
||||
- Log viewer selection was made more flexible: `$EDITOR` is preferred, then `nano`, `vi`, or `less`
|
||||
- `nano` is no longer a strict runtime dependency
|
||||
- The unsupported `-b` option remains unimplemented and is no longer shown in help output
|
||||
|
||||
## Change guidance
|
||||
|
||||
Reference in New Issue
Block a user