From ba79e710072246ee8318719af2801f4f2fc80bff Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:29:42 +0800 Subject: [PATCH 01/27] Missing newline. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 2b2a3c5..4846877 100644 --- a/main.go +++ b/main.go @@ -555,7 +555,7 @@ rrl = report` serrLog.Error("Missing arguments") os.Exit(2) case oTerm, oPlain: - _, _ = fmt.Fprint(os.Stderr, "Missing arguments.") + _, _ = fmt.Fprintln(os.Stderr, "Missing arguments.") os.Exit(2) } } From c9f590fbc63c6c018f79730b372a2ec43841dfa9 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:30:08 +0800 Subject: [PATCH 02/27] Remove feature reading log/op/task from file. --- main.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 4846877..589df8e 100644 --- a/main.go +++ b/main.go @@ -776,16 +776,10 @@ rrl = report` opt.interp = interp } var op string - { - var ok bool - op, ok = os.LookupEnv(cOP) - if !ok { - op = lib.FileRead(cOP) - op = strings.Split(op, "\n")[0] - if op == "" { - op = "UNDEFINED" - } - } + if eop, ok := os.LookupEnv(cOP); !ok { + op = "UNDEFINED" + } else { + op = eop } jsonLog.Info(op, "app", "rr", "id", id, "namespace", namespace, "script", script, "target", hostname) log.Printf("Running %s:%s via %s…", namespace, script, hostname) From ab92cee8ea373a3dca1ff3534578ebb7bedc63f9 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:54:06 +0800 Subject: [PATCH 03/27] Changed environment variable to LOG. Removed OP file feature. --- test/rr_test.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/test/rr_test.go b/test/rr_test.go index ef938e9..6c4010b 100644 --- a/test/rr_test.go +++ b/test/rr_test.go @@ -66,7 +66,7 @@ func TestOp(T *testing.T) { T.Parallel() msg := "Somebody set up us the bomb" T.Run("environment", func(t *testing.T) { - env := []string{fmt.Sprintf("OP=%s", msg)} + env := []string{fmt.Sprintf("LOG=%s", msg)} rr := RunArg{Exe: cEXE, Args: []string{"op:env"}, Env: env} if ret, _ := rr.Run(); !ret { t.Error("wants `true`") @@ -75,19 +75,6 @@ func TestOp(T *testing.T) { t.Error("wants `true`") } }) - T.Run("file", func(t *testing.T) { - StringToFile("OP", msg) - rr := RunArg{Exe: cEXE, Args: []string{"op:file"}} - if ret, _ := rr.Run(); !ret { - t.Error("wants `true`") - } - if got := strings.Contains(FileRead("LOG"), msg); !got { - t.Error("wants `true`") - } - t.Cleanup(func() { - os.Remove("OP") - }) - }) } func TestRepaired(T *testing.T) { From f54e08232845c3dacbb641bef2ddf0671280b6f3 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:54:35 +0800 Subject: [PATCH 04/27] Next release. --- constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/constants.go b/constants.go index 86528a0..ab29ba8 100644 --- a/constants.go +++ b/constants.go @@ -1,7 +1,7 @@ package main -const cVERSION = "2.0.1" -const cCODE = "\"Hypnotic Antennae\"" +const cVERSION = "2.0.2" +const cCODE = "\"Degraded Mastiff\"" const cOP = "LOG" const cINC = "VARS" From 90412dfecbe1d44025a40489241716e6e6e07e78 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:54:44 +0800 Subject: [PATCH 05/27] More hosts file options. --- constants.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/constants.go b/constants.go index ab29ba8..e8c2280 100644 --- a/constants.go +++ b/constants.go @@ -5,7 +5,9 @@ const cCODE = "\"Degraded Mastiff\"" const cOP = "LOG" const cINC = "VARS" -const cHOSTS = "HOSTS" +const cHOSTS0 = "HOSTS" +const cHOSTS1 = "ssh_config" +const cHOSTS2 = ".ssh/config" const cLOG = "LOG" const cREPAIRED = "__REPAIRED__" const cRUN = "script" From 912d88002c9ed21844bacc5225e0e59226d4d631 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:55:00 +0800 Subject: [PATCH 06/27] More hosts file options. --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 589df8e..dc14004 100644 --- a/main.go +++ b/main.go @@ -973,8 +973,15 @@ rrl = report` } } } else { - if lib.IsFile(cHOSTS) && !opt.teleport { - opt.config = cHOSTS + if !opt.teleport { + switch { + case lib.IsFile(cHOSTS1): + opt.config = cHOSTS1 + case lib.IsFile(cHOSTS2): + opt.config = cHOSTS2 + default: + opt.config = cHOSTS0 + } } var realhost string if rh := strings.Split(hostname, "@"); len(rh) == 1 { From d86785baff50009721fc50ab94790463e70949ce Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:55:33 +0800 Subject: [PATCH 07/27] Rename hosts file to another valid one. --- test/{HOSTS => ssh_config} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{HOSTS => ssh_config} (100%) diff --git a/test/HOSTS b/test/ssh_config similarity index 100% rename from test/HOSTS rename to test/ssh_config From 9c56b7efb16910237eb677eeffe3aef20aa74636 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:56:04 +0800 Subject: [PATCH 08/27] Another valid option. --- test/{ssh_config => .ssh/config} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{ssh_config => .ssh/config} (100%) diff --git a/test/ssh_config b/test/.ssh/config similarity index 100% rename from test/ssh_config rename to test/.ssh/config From d6cf1cdcb81741aaaa7231bc29d10a85b5c81ad5 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 09:57:22 +0800 Subject: [PATCH 09/27] Swap priorities. --- constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/constants.go b/constants.go index e8c2280..61df06c 100644 --- a/constants.go +++ b/constants.go @@ -5,9 +5,9 @@ const cCODE = "\"Degraded Mastiff\"" const cOP = "LOG" const cINC = "VARS" -const cHOSTS0 = "HOSTS" +const cHOSTS0 = ".ssh/config" const cHOSTS1 = "ssh_config" -const cHOSTS2 = ".ssh/config" +const cHOSTS2 = "HOSTS" const cLOG = "LOG" const cREPAIRED = "__REPAIRED__" const cRUN = "script" From 9e045bb8b4dadc3d2fad9a52cfc83ffd65a8d713 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:03:44 +0800 Subject: [PATCH 10/27] Replace with readable ANSI code. --- constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants.go b/constants.go index 61df06c..4b1d3fb 100644 --- a/constants.go +++ b/constants.go @@ -20,7 +20,7 @@ const cSTDERR = " ┌─ stderr" const cSTDDBG = " ┌─ debug" const cFOOTER = " └─" -const cANSI = "\n\033[1A\033[K\033[38;2;85;85;85m%s\033[0m" +const cANSI = "\x1b[0036m%s\x1b[0000m" const cTARC = "--no-same-owner --no-same-permissions" const cTARX = "--no-same-owner --no-same-permissions --no-overwrite-dir --no-acls --no-selinux --no-xattrs --touch" From b49a6f256fb50aa782b5307e2cecc9dca967d475 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:04:27 +0800 Subject: [PATCH 11/27] Name after keyword. --- constants.go => const.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename constants.go => const.go (100%) diff --git a/constants.go b/const.go similarity index 100% rename from constants.go rename to const.go From 67d136c240af0c4605e07b15562a6180bd07f7ed Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:29:58 +0800 Subject: [PATCH 12/27] Use terminal output for dump mode. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index dc14004..3c1c7bf 100644 --- a/main.go +++ b/main.go @@ -536,7 +536,7 @@ rrl = report` log.SetFlags(0) var serrLog *slog.Logger - if !mReport && !mDump && opt.mode != oPlain { + if !mReport && opt.mode != oPlain { if isatty.IsTerminal(os.Stdout.Fd()) { opt.mode = oTerm log.SetOutput(new(logWriter)) From 3d3b715b287b48c5c2a18c5b3f0e094f1dcbb9a4 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:30:26 +0800 Subject: [PATCH 13/27] Spurious condition. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 3c1c7bf..9dde257 100644 --- a/main.go +++ b/main.go @@ -536,7 +536,7 @@ rrl = report` log.SetFlags(0) var serrLog *slog.Logger - if !mReport && opt.mode != oPlain { + if opt.mode != oPlain { if isatty.IsTerminal(os.Stdout.Fd()) { opt.mode = oTerm log.SetOutput(new(logWriter)) From cdd17c85d8050b2a88f20f225dcb0429713c0dce Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:31:39 +0800 Subject: [PATCH 14/27] For testing Json mode. --- tools/quiet.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tools/quiet.sh diff --git a/tools/quiet.sh b/tools/quiet.sh new file mode 100644 index 0000000..ea51161 --- /dev/null +++ b/tools/quiet.sh @@ -0,0 +1,3 @@ +exec 0<&- +exec 1<&- +bin/rr make:xxx From 689430a055edcb1f74dec07a21c13b8411281054 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:32:43 +0800 Subject: [PATCH 15/27] No longer used. --- .test/.files/tmp/XXX | 0 .test/.lib/000-header.sh | 4 -- .test/.lib/001-trap.sh | 9 ---- .test/.lib/799-dispatch.sh | 83 ---------------------------------- .test/Makefile | 39 ---------------- .test/TASK | 1 - .test/test/args1/script | 9 ---- .test/test/args1/shell | 1 - .test/test/args2/script | 7 --- .test/test/args2/shell | 1 - .test/test/args3/script | 4 -- .test/test/args3/shell | 1 - .test/test/args4/script | 7 --- .test/test/args4/shell | 1 - .test/test/args6/script | 16 ------- .test/test/args6/shell | 1 - .test/test/fail/script | 4 -- .test/test/fail/shell | 1 - .test/test/files/script | 3 -- .test/test/files/shell | 1 - .test/test/remote_files/script | 2 - .test/test/remote_files/shell | 1 - .test/test/repaired/script | 10 ---- .test/test/repaired/shell | 1 - 24 files changed, 207 deletions(-) delete mode 100644 .test/.files/tmp/XXX delete mode 100644 .test/.lib/000-header.sh delete mode 100644 .test/.lib/001-trap.sh delete mode 100644 .test/.lib/799-dispatch.sh delete mode 100644 .test/Makefile delete mode 100644 .test/TASK delete mode 100644 .test/test/args1/script delete mode 100644 .test/test/args1/shell delete mode 100644 .test/test/args2/script delete mode 100644 .test/test/args2/shell delete mode 100644 .test/test/args3/script delete mode 100644 .test/test/args3/shell delete mode 100644 .test/test/args4/script delete mode 100644 .test/test/args4/shell delete mode 100644 .test/test/args6/script delete mode 100644 .test/test/args6/shell delete mode 100644 .test/test/fail/script delete mode 100644 .test/test/fail/shell delete mode 100644 .test/test/files/script delete mode 100644 .test/test/files/shell delete mode 100644 .test/test/remote_files/script delete mode 100644 .test/test/remote_files/shell delete mode 100644 .test/test/repaired/script delete mode 100644 .test/test/repaired/shell diff --git a/.test/.files/tmp/XXX b/.test/.files/tmp/XXX deleted file mode 100644 index e69de29..0000000 diff --git a/.test/.lib/000-header.sh b/.test/.lib/000-header.sh deleted file mode 100644 index 6af1de1..0000000 --- a/.test/.lib/000-header.sh +++ /dev/null @@ -1,4 +0,0 @@ -set -o pipefail -o nounset -o errexit -o noglob -export LC_ALL=C -export PATH=/usr/bin:/bin:/usr/sbin:/sbin -unset IFS diff --git a/.test/.lib/001-trap.sh b/.test/.lib/001-trap.sh deleted file mode 100644 index 6e3ad61..0000000 --- a/.test/.lib/001-trap.sh +++ /dev/null @@ -1,9 +0,0 @@ -trap '_TRAP_ERROR $? $LINENO $BASH_COMMAND; exit' 1 2 3 15 ERR - -function _TRAP_ERROR() { - local err=$1 - local line=$2 - local command="$3" - >&2 printf ' -- TRAP --\n%s failed at line %s - exited with status: %s' $command $line $err - return $err -} diff --git a/.test/.lib/799-dispatch.sh b/.test/.lib/799-dispatch.sh deleted file mode 100644 index 099c74c..0000000 --- a/.test/.lib/799-dispatch.sh +++ /dev/null @@ -1,83 +0,0 @@ -# https://github.com/rubiojr/lstack/blob/master/lib/dispatch.sh -# -# Command line dispatcher from workshop with some small tweaks to improve -# error output when the commands are not found. -# -# https://github.com/Mosai/workshop/blob/develop/doc/dispatch.md -# -# Copyright (C) 2014 Alexandre Gaigalas -# -# 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. -# - -unsetopt NO_MATCH >/dev/null 2>&1 || : - -# Dispatches calls of commands and arguments -dispatch () -{ - namespace="$1" # Namespace to be dispatched - arg="${2:-}" # First argument - short="${arg#*-}" # First argument without trailing - - long="${short#*-}" # First argument without trailing -- - - # Exit and warn if no first argument is found - if [ -z "$arg" ]; then - # Call empty call placeholder - "${namespace}_"; return $? - fi - - shift 2 # Remove namespace and first argument from $@ - - # Detects if a command, --long or -short option was called - if [ "$arg" = "--$long" ];then - longname="${long%%=*}" # Long argument before the first = sign - - # Detects if the --long=option has = sign - if [ "$long" != "$longname" ]; then - longval="${long#*=}" - long="$longname" - set -- "$longval" "${@:-}" - fi - - main_call=${namespace}_option_${long} - - - elif [ "$arg" = "-$short" ];then - main_call=${namespace}_option_${short} - else - main_call=${namespace}_command_${long} - fi - - type $main_call > /dev/null 2>&1 || { - >&2 echo -e "Invalid arguments.\n" - type ${namespace}_command_help > /dev/null 2>&1 && \ - ${namespace}_command_help - return 1 - } - - $main_call "${@:-}" && dispatch_returned=$? || dispatch_returned=$? - - if [ $dispatch_returned = 127 ]; then - >&2 echo -e "Invalid command.\n" - "${namespace}_call_" "$namespace" "$arg" # Empty placeholder - return 1 - fi - - return $dispatch_returned -} diff --git a/.test/Makefile b/.test/Makefile deleted file mode 100644 index 6aea5b8..0000000 --- a/.test/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -.ONESHELL: -.SILENT: -.SHELL := /usr/bin/env bash -.PHONY: test -SRC= "main.go" -BOLD=$(shell tput bold) -RED=$(shell tput setaf 1) -GREEN=$(shell tput setaf 2) -YELLOW=$(shell tput setaf 3) -BLUE=$(shell tput setaf 4) -MAGENTA=$(shell tput setaf 5) -CYAN=$(shell tput setaf 6) -RESET=$(shell tput sgr0) -TIME=$(shell date "+%Y-%m-%d %H:%M:%S") - -test: - rm -f rr.json - @echo "$(BLUE)$(TIME)$(YELLOW) + TEST START $(RESET)" - @echo "$(BLUE)$(TIME)$(MAGENTA) . arguments handling 1$(RESET)" - ../bin/rr local test:args1 --one --two --three - @echo "$(BLUE)$(TIME)$(MAGENTA) . arguments handling 2$(RESET)" - ../bin/rr local test:args2 one 1 - @echo "$(BLUE)$(TIME)$(MAGENTA) . arguments handling 3$(RESET)" - ../bin/rr local test:args3 -v - @echo "$(BLUE)$(TIME)$(MAGENTA) . arguments handling 4$(RESET)" - ../bin/rr local test:args4:1 - @echo "$(BLUE)$(TIME)$(MAGENTA) . arguments handling 5$(RESET)" - ../bin/rr test:args4:1 - @echo "$(BLUE)$(TIME)$(MAGENTA) . arguments handling 6$(RESET)" - ../bin/rr test:args6:1 2 3 4 - @echo "$(BLUE)$(TIME)$(MAGENTA) . task reporting$(RESET)" - env TASK="task/op field" ../bin/rr test:args4:1 - @echo "$(BLUE)$(TIME)$(MAGENTA) . repaired status $(RESET)" - ../bin/rr test:repaired - @echo "$(BLUE)$(TIME)$(MAGENTA) . untar files $(RESET)" - ../bin/rr local test:files - @echo "$(BLUE)$(TIME)$(MAGENTA) . failure conditioin $(RESET)" - ../bin/rr local test:fail || true - @echo "$(BLUE)$(TIME)$(CYAN) ! TEST DONE $(RESET)" diff --git a/.test/TASK b/.test/TASK deleted file mode 100644 index 2b29f27..0000000 --- a/.test/TASK +++ /dev/null @@ -1 +0,0 @@ -tests diff --git a/.test/test/args1/script b/.test/test/args1/script deleted file mode 100644 index caadddc..0000000 --- a/.test/test/args1/script +++ /dev/null @@ -1,9 +0,0 @@ -echo "$1" > /tmp/.__rr_ONE -echo "$2" > /tmp/.__rr_TWO -echo "$3" > /tmp/.__rr_THREE -[ $(&2 "Arg did not match!"; exit 1; } -[ $(&2 "Arg did not match!"; exit 1; } -[ $(&2 "Arg did not match!"; exit 1; } -rm -f /tmp/.__rr_ONE -rm -f /tmp/.__rr_TWO -rm -f /tmp/.__rr_THREE diff --git a/.test/test/args1/shell b/.test/test/args1/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/args1/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/args2/script b/.test/test/args2/script deleted file mode 100644 index 55a781b..0000000 --- a/.test/test/args2/script +++ /dev/null @@ -1,7 +0,0 @@ -whatever_command_one() -{ - echo "$1" > /tmp/.__rr_ONE -} -dispatch whatever "$@" -[ $(&2 "Arg did not match!"; exit 1; } -rm -f /tmp/.__rr_ONE diff --git a/.test/test/args2/shell b/.test/test/args2/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/args2/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/args3/script b/.test/test/args3/script deleted file mode 100644 index 4b37979..0000000 --- a/.test/test/args3/script +++ /dev/null @@ -1,4 +0,0 @@ -what_option_v() ( echo "v" > /tmp/.__rr_V ) -dispatch what "$@" -[ $(&2 "Arg did not match!"; exit 1; } -rm -f /tmp/.__rr_V diff --git a/.test/test/args3/shell b/.test/test/args3/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/args3/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/args4/script b/.test/test/args4/script deleted file mode 100644 index b6b3163..0000000 --- a/.test/test/args4/script +++ /dev/null @@ -1,7 +0,0 @@ -one() -{ - echo "$1" > /tmp/.__rr_ONE -} -one $1 -[ $(&2 "Arg did not match!"; exit 1; } -rm -f /tmp/.__rr_ONE diff --git a/.test/test/args4/shell b/.test/test/args4/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/args4/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/args6/script b/.test/test/args6/script deleted file mode 100644 index e2d5187..0000000 --- a/.test/test/args6/script +++ /dev/null @@ -1,16 +0,0 @@ -one() -{ - echo "$1" > /tmp/.__rr_ONE - echo "$2" > /tmp/.__rr_TWO - echo "$3" > /tmp/.__rr_THREE - echo "$4" > /tmp/.__rr_FOUR -} -one $1 $2 $3 $4 -[ $(&2 "Arg did not match!"; exit 1; } -[ $(&2 "Arg did not match!"; exit 1; } -[ $(&2 "Arg did not match!"; exit 1; } -[ $(&2 "Arg did not match!"; exit 1; } -rm -f /tmp/.__rr_ONE -rm -f /tmp/.__rr_TWO -rm -f /tmp/.__rr_THREE -rm -f /tmp/.__rr_FOUR diff --git a/.test/test/args6/shell b/.test/test/args6/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/args6/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/fail/script b/.test/test/fail/script deleted file mode 100644 index 7d07d7d..0000000 --- a/.test/test/fail/script +++ /dev/null @@ -1,4 +0,0 @@ -rm -f /XXX -echo "OK" -echo >&2 "Expected to fail!" -exit 1 diff --git a/.test/test/fail/shell b/.test/test/fail/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/fail/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/files/script b/.test/test/files/script deleted file mode 100644 index 2704540..0000000 --- a/.test/test/files/script +++ /dev/null @@ -1,3 +0,0 @@ -test -f /tmp/XXX || { printf >&2 'test:top_level_files failed!\n'; exit 1; } -test -d /tmp/YYY || { printf >&2 'test:module_level_files failed!\n'; exit 1; } -rm -rf /tmp/YYY diff --git a/.test/test/files/shell b/.test/test/files/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/files/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/remote_files/script b/.test/test/remote_files/script deleted file mode 100644 index 9f8e818..0000000 --- a/.test/test/remote_files/script +++ /dev/null @@ -1,2 +0,0 @@ -test -f /tmp/XXX -test -d /tmp/YYY diff --git a/.test/test/remote_files/shell b/.test/test/remote_files/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/remote_files/shell +++ /dev/null @@ -1 +0,0 @@ -bash diff --git a/.test/test/repaired/script b/.test/test/repaired/script deleted file mode 100644 index 6743540..0000000 --- a/.test/test/repaired/script +++ /dev/null @@ -1,10 +0,0 @@ -if test -d /some_dir -then - exit 0 -else - { - true - } >/dev/null 2>&1 || exit 1 - printf "+++++repaired+++++\\n" - exit 0 -fi diff --git a/.test/test/repaired/shell b/.test/test/repaired/shell deleted file mode 100644 index 705963a..0000000 --- a/.test/test/repaired/shell +++ /dev/null @@ -1 +0,0 @@ -bash From 35470fcaa025860223d4821025436d92dd6fa2d8 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:37:18 +0800 Subject: [PATCH 16/27] Breaks some compatibility. --- const.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/const.go b/const.go index 4b1d3fb..4fd7f3d 100644 --- a/const.go +++ b/const.go @@ -1,6 +1,6 @@ package main -const cVERSION = "2.0.2" +const cVERSION = "2.1.0" const cCODE = "\"Degraded Mastiff\"" const cOP = "LOG" From 5bf3ecddace38a7b86dc62ca6d3372a98020d879 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:37:27 +0800 Subject: [PATCH 17/27] Changelog for new release. --- changelog.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/changelog.md b/changelog.md index e31dd60..13357f6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,15 @@ +#### 2.1.0 + +Degraded Mastiff + +* Colorized rrl output +* Changed rrl headers +* Changed OP to LOG environment variable +* Removed reading from OP file feature +* Added `.ssh/config` and `ssh_config` as valid hosts files +* Various code fixes and improvements + + #### 2.0.1 Hypnotic Antennae From 87d7d795b145154ccc3465a7447c542af7af52ce Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:38:43 +0800 Subject: [PATCH 18/27] Markup. --- changelog.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 13357f6..1c9c8bb 100644 --- a/changelog.md +++ b/changelog.md @@ -2,14 +2,13 @@ Degraded Mastiff -* Colorized rrl output -* Changed rrl headers -* Changed OP to LOG environment variable -* Removed reading from OP file feature +* Colorized `rrl` output +* Changed `rrl` headers +* Changed `OP` to `LOG` environment variable +* Removed reading from `OP` file feature * Added `.ssh/config` and `ssh_config` as valid hosts files * Various code fixes and improvements - #### 2.0.1 Hypnotic Antennae From 94b15c801db32afafc3cef04e725bc0d45846761 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 10:40:01 +0800 Subject: [PATCH 19/27] Changed color. --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 1c9c8bb..7b6063f 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ Degraded Mastiff * Changed `OP` to `LOG` environment variable * Removed reading from `OP` file feature * Added `.ssh/config` and `ssh_config` as valid hosts files +* Changed terminal log line color to cyan * Various code fixes and improvements #### 2.0.1 From 7bebc50a4eb06934fdfff6ae6521b43963358d05 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 12:28:54 +0800 Subject: [PATCH 20/27] Conver to empty switch for readability. --- rrl.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rrl.go b/rrl.go index 97f30f4..9c4c7ae 100644 --- a/rrl.go +++ b/rrl.go @@ -79,12 +79,14 @@ func rrlMain() { _, _ = fmt.Fprintf(os.Stderr, "Unable to decode `%s`.\n", cLOG) os.Exit(1) } - colors := []rrlColor{rrlCyan, rrlGreen, rrlMagenta, rrlCyan, rrlGreen, rrlBlue, rrlMagenta, rrlWhite} - if log["msg"] == "failed" { + var colors []rrlColor + switch { + case log["msg"] == "failed": colors = []rrlColor{rrlRed, rrlRed, rrlRed, rrlRed, rrlRed, rrlRed, rrlRed, rrlRed} - } - if log["msg"] == "repaired" { + case log["msg"] == "repaired": colors = []rrlColor{rrlCyan, rrlGreen, rrlMagenta, rrlCyan, rrlGreen, rrlBlue, rrlMagenta, rrlYellow} + default: + colors = []rrlColor{rrlCyan, rrlGreen, rrlMagenta, rrlCyan, rrlGreen, rrlBlue, rrlMagenta, rrlWhite} } if log["duration"] != "" { rrlPrint(w, rrlPaintRow(colors, []string{ From 6809c6ead8d5cf3f982f55ff0e3650df67aaac0d Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 12:33:37 +0800 Subject: [PATCH 21/27] Move printing quotes. --- const.go | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/const.go b/const.go index 4fd7f3d..d1b1e35 100644 --- a/const.go +++ b/const.go @@ -1,7 +1,7 @@ package main const cVERSION = "2.1.0" -const cCODE = "\"Degraded Mastiff\"" +const cCODE = "Degraded Mastiff" const cOP = "LOG" const cINC = "VARS" diff --git a/main.go b/main.go index 9dde257..2923bf9 100644 --- a/main.go +++ b/main.go @@ -540,7 +540,7 @@ rrl = report` if isatty.IsTerminal(os.Stdout.Fd()) { opt.mode = oTerm log.SetOutput(new(logWriter)) - log.Printf("rr %s %s", cVERSION, cCODE) + log.Printf("rr %s \"%s\"", cVERSION, cCODE) } else { serrLog = slog.New(slog.NewJSONHandler(os.Stderr, nil)) } From f43287690d559b3b53fdf3759fc27f68cb8b100e Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 12:35:25 +0800 Subject: [PATCH 22/27] Unicode quotes. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 2923bf9..5babd5c 100644 --- a/main.go +++ b/main.go @@ -540,7 +540,7 @@ rrl = report` if isatty.IsTerminal(os.Stdout.Fd()) { opt.mode = oTerm log.SetOutput(new(logWriter)) - log.Printf("rr %s \"%s\"", cVERSION, cCODE) + log.Printf("rr %s “%s”", cVERSION, cCODE) } else { serrLog = slog.New(slog.NewJSONHandler(os.Stderr, nil)) } From c6b8439ff77aa0d8859cc96dea271e5af544ff89 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 1 Jun 2024 12:38:08 +0800 Subject: [PATCH 23/27] Quote log. --- rrl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rrl.go b/rrl.go index 9c4c7ae..b05e5a4 100644 --- a/rrl.go +++ b/rrl.go @@ -95,7 +95,7 @@ func rrlMain() { log["start"], log["namespace"], log["script"], - log["task"], + "“"+log["task"]+"”", log["duration"], log["msg"], })) From 4409b8dd0aa1f9819890f0d06524ec81c00b7113 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sun, 2 Jun 2024 00:32:58 +0800 Subject: [PATCH 24/27] go fmt. --- rrl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rrl.go b/rrl.go index b05e5a4..aa25b05 100644 --- a/rrl.go +++ b/rrl.go @@ -95,7 +95,7 @@ func rrlMain() { log["start"], log["namespace"], log["script"], - "“"+log["task"]+"”", + "“" + log["task"] + "”", log["duration"], log["msg"], })) From 3ef5c515d8a8c060a0fb79bdb5992d432f804a04 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Mon, 3 Jun 2024 12:20:28 +0800 Subject: [PATCH 25/27] Unified error message. --- const.go | 2 ++ main.go | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/const.go b/const.go index d1b1e35..d2b4a47 100644 --- a/const.go +++ b/const.go @@ -28,3 +28,5 @@ const cTARX = "--no-same-owner --no-same-permissions --no-overwrite-dir --no-acl const oJson int = 0 const oTerm int = 1 const oPlain int = 2 + +const eUNSPECIFIED = "You must specify the `namespace:script`." diff --git a/main.go b/main.go index 5babd5c..ebd2398 100644 --- a/main.go +++ b/main.go @@ -523,7 +523,7 @@ rro = teleport + sudo rrd = dump rrv = forced verbose rrl = report` - _, _ = fmt.Fprintf(os.Stderr, "Unsupported executable name. Valid modes:\n%s\n", lib.PipeStr("", valid)) + _, _ = fmt.Fprintf(os.Stderr, "ERROR: Unsupported executable name. Valid modes:\n%s\n", lib.PipeStr("", valid)) os.Exit(2) } } @@ -552,10 +552,10 @@ rrl = report` if len(os.Args) < 2 { switch opt.mode { case oJson: - serrLog.Error("Missing arguments") + serrLog.Error(eUNSPECIFIED) os.Exit(2) case oTerm, oPlain: - _, _ = fmt.Fprintln(os.Stderr, "Missing arguments.") + _, _ = fmt.Fprintln(os.Stderr, eUNSPECIFIED) os.Exit(2) } } @@ -628,10 +628,10 @@ rrl = report` if len(os.Args) < offset+1 { switch opt.mode { case oTerm, oPlain: - _, _ = fmt.Fprintf(os.Stderr, "`namespace:script` not specified.\n") + _, _ = fmt.Fprintln(os.Stderr, eUNSPECIFIED) os.Exit(2) case oJson: - serrLog.Error("namespace:script not specified") + serrLog.Error(eUNSPECIFIED) os.Exit(2) } } @@ -655,7 +655,7 @@ rrl = report` if len(s) < 2 { switch opt.mode { case oTerm, oPlain: - _, _ = fmt.Fprint(os.Stderr, "`namespace:script` not specified.") + _, _ = fmt.Fprintln(os.Stderr, eUNSPECIFIED) os.Exit(2) case oJson: serrLog.Error("namespace:script not specified") From 42c4f795efa9cc77928ce583a03c023784145ee8 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Mon, 3 Jun 2024 12:24:32 +0800 Subject: [PATCH 26/27] No period. --- const.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/const.go b/const.go index d2b4a47..5810e23 100644 --- a/const.go +++ b/const.go @@ -29,4 +29,4 @@ const oJson int = 0 const oTerm int = 1 const oPlain int = 2 -const eUNSPECIFIED = "You must specify the `namespace:script`." +const eUNSPECIFIED = "You must specify the `namespace:script`" From 18485d89d4c243c9b93f8a2b3dddf300eb21c6f7 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Mon, 3 Jun 2024 12:29:20 +0800 Subject: [PATCH 27/27] Better error messages. --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index ebd2398..fe3728d 100644 --- a/main.go +++ b/main.go @@ -523,7 +523,7 @@ rro = teleport + sudo rrd = dump rrv = forced verbose rrl = report` - _, _ = fmt.Fprintf(os.Stderr, "ERROR: Unsupported executable name. Valid modes:\n%s\n", lib.PipeStr("", valid)) + _, _ = fmt.Fprintf(os.Stderr, "ERROR: Unsupported executable name. Valid modes:\n%s\n", lib.PipeStr("", valid)) os.Exit(2) } } @@ -666,7 +666,7 @@ rrl = report` if !lib.IsDir(namespace) { switch opt.mode { case oTerm, oPlain: - _, _ = fmt.Fprintf(os.Stderr, "`%s`(namespace) is not a directory.\n", namespace) + _, _ = fmt.Fprintf(os.Stderr, "Namespace `%s` is not a directory\n", namespace) os.Exit(2) case oJson: serrLog.Error("Namespace is not a directory", "namespace", namespace) @@ -676,7 +676,7 @@ rrl = report` if !lib.IsDir(fmt.Sprintf("%s/%s", namespace, script)) { switch opt.mode { case oTerm, oPlain: - _, _ = fmt.Fprintf(os.Stderr, "`%s/%s` is not a directory.\n", namespace, script) + _, _ = fmt.Fprintf(os.Stderr, "`%s/%s` is not a directory\n", namespace, script) os.Exit(2) case oJson: serrLog.Error("namespace/script is not a directory", "namespace", namespace, "script", script) @@ -686,10 +686,10 @@ rrl = report` if !lib.IsFile(fmt.Sprintf("%s/%s/%s", namespace, script, cRUN)) { switch opt.mode { case oTerm, oPlain: - _, _ = fmt.Fprintf(os.Stderr, "`%s/%s/%s` script not found.\n", namespace, script, cRUN) + _, _ = fmt.Fprintf(os.Stderr, "`%s/%s/%s` script not found\n", namespace, script, cRUN) os.Exit(2) case oJson: - serrLog.Error("Actual script is missing", "namespace", namespace, "script", script) + serrLog.Error("Script not found", "namespace", namespace, "script", script) os.Exit(2) } }