[dev] refactor riot; use command; remove log; sagt op (#45)

* feat(riot-config): default port 12022

* fix(ci)

* feat(riot-config): remove tailing dot from .domain; remove j.remote and x.domain

* feat(riot): *.batch

* feat(riot): run command in tmux window(s)

note that spaces in ssh commands are still not supported

* feat(riot): -o RequestTTY=yes

* fix(riot): SSH_OPTIONS

* fix(riot): tmux use bash

* feat(zshrc): use()

* fix(riot): scp, and ci

note that riot still has problems with spaces. we should use array to
handle parameters.

* fix(ci): update macos image

* feat: update email

* feat: revert git email

* feat(ssh): update keys

* feat(sagent): sagt op

* fix(sagent): error note

* fix(ci): test of auto-dep

* feat(ssh): remove keys ltp1-bd and ltp1

* feat(riot): rm - remove host keys

* build(ci): update to ubuntu-latest and Yikun/hub-mirror-action@v1.5

* feat: remove frigg-client.log

* feat(riot): -t or --trust to set RIOT_TRUST_SERVER

* feat(zshrc/alias): add sc and t, remove cps and mvs

feat(zshrc/plugins): add man and web-search, remove ufw

* feat(riot): refactor argparse

feat(riot): add `--password` and `--`

feat(common.sh): argparse supports `--`

feat(riot): refactor ping to ping remote

* feat(riot): sshd can specify the local port

* feat(riot): print help when no argument or no remote

* fix(riot): ci

* feat(riot): better print_cmd with escape

* feat(riot-config): support sed*

* fix(frigg): hostname converted into lower case
This commit is contained in:
2025-06-24 19:56:04 +08:00
committed by GitHub
parent 055d44886b
commit 891bbcacff
14 changed files with 265 additions and 160 deletions

View File

@@ -13,7 +13,10 @@ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
ARG=""
GOT_OPTS=()
while [[ $# > 0 || -n "$ARG" ]]; do
if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
if [[ -z "$ARG" ]]; then
if [[ "$1" == "--" ]]; then GOT_OPTS+=("$@"); break; fi
ARG="$1"; shift;
fi
case $ARG in
-q*|--quite ) export DFS_QUIET=1 ;;
-l*|--lite ) export DFS_LITE=1 ;;
@@ -162,19 +165,6 @@ ask_for_Yn()
fi
}
post_log()
{
if [[ $# != 3 || -z "$1" || -z "$2" || -z "$3" ]]; then
fmt_fatal "usage: post_log <level> <section> <content>"
fi
"${DOTFILES}/tools/frigg-client.sh" "log" "[$1][$2] $3"
}
apost_log()
{
post_log "$@" 1>/dev/null &
}
post_beacon()
{
if [[ $# < 1 || -z "$1" ]]; then

View File

@@ -25,6 +25,7 @@ elif [[ -f /etc/hostname ]]; then
else
fmt_fatal "unable to get hostname"
fi
hostname=$(echo $hostname | tr '[:upper:]' '[:lower:]')
init_uuid()
{
@@ -63,8 +64,8 @@ handle_resp()
post_beacon()
{
local beacon_type=$1
local meta=$2
local beacon_type="$1"
local meta="$2"
if [[ -n "$CI" && "$beacon_type" != "gh.ci" && "$beacon_type" != "dfs.invalid-commit" && "$beacon_type" != "dfs.dirty" ]]; then
return
fi
@@ -75,17 +76,6 @@ post_beacon()
handle_resp "$resp"
}
post_log()
{
local log_content=$1
if [[ -z "$log_content" ]]; then
fmt_fatal "log content is required"
fi
init_uuid
resp=$(curl $DFS_CURL_OPTIONS -sSL -X POST -H "Content-Type: text/plain" -d "$log_content" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid")
handle_resp "$resp"
}
update_dns()
{
if [[ -z "$DFS_DDNS_IP4$DFS_DDNS_IP6" ]]; then
@@ -138,7 +128,7 @@ update_dns()
print_help()
{
fmt_info "usage: $0 <beacon|log|ddns> [beacon_type|log_content]"
fmt_info "usage: $0 <beacon|ddns> [beacon_type] [beacon_meta]"
}
router()
@@ -150,9 +140,6 @@ router()
beacon)
post_beacon "$2" "$3"
;;
log)
post_log "$2"
;;
ddns)
update_dns
;;

9
tools/sagent-op.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
op=$(command -v op || command -v op.exe || true)
if [[ ! -x $op ]]; then
echo "1password cli not found" > /dev/stderr
exit -1
fi
"$op" read "op://Personal/id25519-passphrase/$(hostname)"

View File

@@ -47,6 +47,12 @@ add_piv()
list
}
add_id25519_with_op()
{
SSH_ASKPASS_REQUIRE=force SSH_ASKPASS="$THIS_DIR/sagent-op.sh" timeout 60s ssh-add ~/.ssh/id_ed25519 || fmt_fatal "timed out when adding the key. probably the passphrase is wrong or 1password-cli is not working"
list
}
list()
{
echo echo "available keys:"
@@ -96,6 +102,9 @@ route()
piv)
add_piv
;;
op)
add_id25519_with_op
;;
reset)
reset
;;

View File

@@ -27,7 +27,6 @@ fi
# check scripts and functions
dfs version
dfs log 1
dfs beacon gh.ci $GITHUB_SHA
z ~
test ~ -ef "$(pwd)"
@@ -41,8 +40,9 @@ test $(echo n | tools/common.sh ask_for_yN "test") = "0"
test $(echo | tools/common.sh ask_for_yN "test") = "0"
test $(echo | tools/common.sh ask_for_Yn "test") = "1"
test $(DFS_QUIET=1 tools/common.sh ask_for_Yn "test") = "1"
test "$(DFS_TRUST=1 riot time@is.impt:2222/yes@you-r.right/you@are.really.recht./ibd./try@it,another@host scp /tmp/ ./tmp -D 2>/dev/null)" = 'scp -P 12022 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ProxyJump=time@is.impt:2222,yes@you-r.right,you@are.really.recht.,root@ibd. -r try@it.dxng.net:"/tmp/" "./tmp"
scp -P 12022 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ForwardX11=yes -o ForwardAgent=yes -r another@host.dxng.net:"/tmp/" "./tmp"'
test "$(DFS_TRUST=1 riot time@is.impt:2222/yes@you-r.right/you@are.really.recht./ibd./try@it,another@host scp /tmp/ ./tmp -D 2>/dev/null)" = 'scp -P 12022 -o RequestTTY=yes -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ProxyJump=time@is.impt:2222,yes@you-r.right:12022,you@are.really.recht:12022,root@ibd:12022 -r try@it.dxng.net:/tmp/ ./tmp
scp -P 12022 -o RequestTTY=yes -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ForwardX11=yes -o ForwardAgent=yes -r another@host.dxng.net:/tmp/ ./tmp'
test "$(riot you@example.com:55 -tD ssh --password -- ping -c 1 2>/dev/null)" = 'ssh -p 55 -o RequestTTY=yes -o ForwardX11=yes -o ForwardAgent=yes -o PasswordAuthentication=yes -o PubkeyAuthentication=no you@example.com ping -c 1'
# check alias
alias p114

View File

@@ -4,7 +4,7 @@ declare -A INSTALL_COMMANDS
INSTALL_COMMANDS=(\
[git]="apt update && apt install git" \
[fzf]="git clone --depth 1 https://gitee.com/dictxiong/fzf.git ~/.fzf && ~/.fzf/install" \
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-me@beardic.cn}" \
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-acme@dxng.net}" \
[oh-my-zsh]='sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' \
[oh-my-tuna]='wget https://tuna.moe/oh-my-tuna/oh-my-tuna.py && sudo python oh-my-tuna.py --global' \
[v2fly]="bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) #--remove" \