Last active
June 22, 2025 13:38
-
-
Save iwconfig/74ff874e21045a4a66e8a8f29ef20189 to your computer and use it in GitHub Desktop.
executes a set of commands in sequence and each output can be wrapped in html <details> code. useful for reproducing stuff in GH issues. WIP: will perhaps make it usable for anything thus not hardcode stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# reproduce commands and wrap output in spoilers | |
set -eu | |
export LC_ALL=C | |
# defaults: | |
FILE=test.txt | |
DIR=/tmp | |
REMOTE=teldrive-testbench: | |
WRAP_HTML=false | |
SHOW_COMMANDS=false | |
_SHOW_COMMANDS=${_SHOW_COMMANDS-false} | |
OUTPUT= | |
usage(){ | |
cat <<EOF | |
Usage: $0 [--file=F] [--dir=D] [--remote=R] [--saveoutput=OUT] [--html] [--showcommands] | |
--file=F filename under DIR (default: $FILE) | |
--dir=D directory to use (default: $DIR) | |
--remote=R rclone remote (default: $REMOTE) | |
--saveoutput=OUT write log to OUT (stdout if empty) | |
--html wrap each step in <details>…</details> | |
--showcommands show all commands, wrapped in a bash oneliner | |
EOF | |
exit 1 | |
} | |
# parse args | |
for arg in "$@"; do | |
case $arg in | |
--file=*) FILE=${arg#*=};; | |
--dir=*) DIR=${arg#*=};; | |
--remote=*) REMOTE=${arg#*=};; | |
--saveoutput=*) OUTPUT=${arg#*=};; | |
--html) WRAP_HTML=true;; | |
--showcommands) SHOW_COMMANDS=true;; | |
-h|--help) usage;; | |
*) echo "Unknown arg: $arg" >&2; usage;; | |
esac | |
done | |
# if OUTPUT, make sure it's empty | |
if [[ -n $OUTPUT ]]; then | |
: > "$OUTPUT" | |
fi | |
# if SHOW_COMMANDS and not @WRAP_HTML, wrap it in a bash command | |
if $SHOW_COMMANDS && ! $_SHOW_COMMANDS && ! $WRAP_HTML; then | |
export _SHOW_COMMANDS=true | |
cat <<EOF | |
bash -xc ' | |
$(bash "$0" "$@") | |
' | |
EOF | |
exit | |
fi | |
# run_cmd: show prompt+cmd, eval it, capture output | |
run_cmd(){ | |
local cmdstr="$1" | |
printf '%s%s\n' "$($WRAP_HTML && echo 'root@host:/# ' || $SHOW_COMMANDS || echo '# ')" "$cmdstr" | |
# eval so that redirections work | |
local out | |
out="$(eval "$cmdstr" 2>&1)" || true | |
printf '%s\n' "$out" | |
[[ -z $out ]] || echo | |
} | |
# run: group a title + multiple cmd-strings into one spoiler or plain block | |
run(){ | |
local title="$1" | |
shift | |
$WRAP_HTML || printf '%s==== %s ====\n' "$($SHOW_COMMANDS && echo '# ')" "$title" | |
{ | |
$WRAP_HTML && printf '<details><summary>%s</summary>\n\n```%s\n' "$title" $($SHOW_COMMANDS && echo bash || echo console) | |
$SHOW_COMMANDS && ! $_SHOW_COMMANDS && echo "bash -xc '" | |
for cmd in "$@"; do | |
$SHOW_COMMANDS && echo "$cmd" || run_cmd "$cmd" | |
done | |
$SHOW_COMMANDS && ! $_SHOW_COMMANDS && echo "'" | |
$WRAP_HTML && printf '```\n\n</details>\n' | |
} | tee -a "${OUTPUT:-/dev/null}" | |
} | |
# (0) VERSION | |
run "(0) Teldrive and rclone version" \ | |
"ssh [email protected] -- 'cd /root/teldrive-testbench && docker compose pull teldrive-server && docker compose down teldrive-server && docker compose up -d teldrive-server'" \ | |
"curl -s 'http://192.168.0.189:8585/api/version' | jq" \ | |
"rclone version" | |
# (1) UPLOAD ENCRYPTED | |
run "(1) Upload encrypted" \ | |
"echo \$RANDOM | tee $DIR/$FILE" \ | |
"rclone copy -vvv $DIR/$FILE $REMOTE --teldrive-encrypt-files=true" \ | |
"head -v $DIR/$FILE" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && /bin/docker compose exec -it teldrive-db psql -d \\\"\\\$(awk -F'\\\"' '/^\\s*data-source/{print \\\$2}' teldrive/config.toml)\\\" -c \\\"select name, encrypted, parts from files where name = '$FILE';\\\"\"" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && docker compose logs -n100 teldrive-server\" | sed -E 's/(\\\"id\\\": |\\\"channel_id\\\": |\\\"user\\\": |\\\"bot\\\": |\\\"username\\\": |\\\"channel\\\": ) *([^,}]+)/\1\\\"redacted\\\"/gi' | cat -n" | |
# (2) READ ENCRYPTED | |
run "(2) Read encrypted" \ | |
"rm -fv $DIR/$FILE" \ | |
"rclone copy -vvv $REMOTE/$FILE $DIR/ --teldrive-encrypt-files=true" \ | |
"head -v $DIR/$FILE" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && /bin/docker compose exec -it teldrive-db psql -d \\\"\\\$(awk -F'\\\"' '/^\\s*data-source/{print \\\$2}' teldrive/config.toml)\\\" -c \\\"select name, encrypted, parts from files where name = '$FILE';\\\"\"" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && docker compose logs -n100 teldrive-server\" | sed -E 's/(\\\"id\\\": |\\\"channel_id\\\": |\\\"user\\\": |\\\"bot\\\": |\\\"username\\\": |\\\"channel\\\": ) *([^,}]+)/\1\\\"redacted\\\"/gi' | cat -n" | |
# (3) UPLOAD CLEAR | |
run "(3) Upload unencrypted" \ | |
"echo \$RANDOM | tee $DIR/$FILE" \ | |
"rclone copy -vvv $DIR/$FILE $REMOTE --teldrive-encrypt-files=false" \ | |
"head -v $DIR/$FILE" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && /bin/docker compose exec -it teldrive-db psql -d \\\"\\\$(awk -F'\\\"' '/^\\s*data-source/{print \\\$2}' teldrive/config.toml)\\\" -c \\\"select name, encrypted, parts from files where name = '$FILE';\\\"\"" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && docker compose logs -n100 teldrive-server\" | sed -E 's/(\\\"id\\\": |\\\"channel_id\\\": |\\\"user\\\": |\\\"bot\\\": |\\\"username\\\": |\\\"channel\\\": ) *([^,}]+)/\1\\\"redacted\\\"/gi' | cat -n" | |
# (4) READ CLEAR | |
run "(4) Read unencrypted" \ | |
"rm -fv $DIR/$FILE" \ | |
"rclone copy -vvv --low-level-retries=1 $REMOTE/$FILE $DIR/ --teldrive-encrypt-files=false" \ | |
"head -v $DIR/$FILE" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && /bin/docker compose exec -it teldrive-db psql -d \\\"\\\$(awk -F'\\\"' '/^\\s*data-source/{print \\\$2}' teldrive/config.toml)\\\" -c \\\"select name, encrypted, parts from files where name = '$FILE';\\\"\"" \ | |
"ssh [email protected] -- \"cd /root/teldrive-testbench && docker compose logs -n100 teldrive-server\" | sed -E 's/(\\\"id\\\": |\\\"channel_id\\\": |\\\"user\\\": |\\\"bot\\\": |\\\"username\\\": |\\\"channel\\\": ) *([^,}]+)/\1\\\"redacted\\\"/gi' | cat -n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment