-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev] ddns; better ssh agent; riot sshl; sys.online; zsh hist import;…
… DFS_DEBUG; cbd/cbds (#36) * riot: bj1 -> proxy * ci: test ask_for_yn * --wip-- [skip ci] * install.sh: will prompt version * zshrc: piv-agent now can re-use agents * zshrc: in docker use theme robbyrussell * update.sh: will send online beacon * beacon: support meta with limited len 64 * bug fix (Sat Jan 21 16:45:35 CST 2023) * well, finally add ssh key for ltp1-bd * set DFS_INITED and do not send login beacon if it was set * rewrite piv-agent to sagent; fmt_note and fmt_into will write to stderr * bug fix (Mon Jan 30 19:41:00 CST 2023) * bug fix (Mon Jan 30 19:46:27 CST 2023) * login beacon add details * $DFS_ORPHAN turns logger off * disable more beacons in CI * install.sh: prepare config earlier * init pbin * install.sh: -H|--hist|--history * install.sh: -H hint * install.sh: -H support multiple keys * fix zsh hist with no new line at the end * remove ^M in hist * bug fix (Wed Feb 1 21:11:41 CST 2023) * bug fix (Wed Feb 1 21:16:29 CST 2023) * bug fix (Wed Feb 1 21:20:21 CST 2023) * ci will send gh.ci.fail * show install opts * DFS_DEBUG to set -x * bug fix: install.sh re-start itself with no args incorrectly * bug fix (Thu Feb 2 18:43:16 CST 2023) * riot: ob->ebd, swap option $1 and $2 and $2 is default to ssh * riot: introduce sshl * logger.sh: support ddns * bug fix (Wed Mar 1 16:37:42 CST 2023) * dfs.ddns.failed -> dfs.ddns.fail * login beacon 2>/dev/null * logger.sh -> frigg-client.sh; curl add time limit 10s * to-install.sh: improve docker-ce * use $DFS_CURL_OPTIONS * ci: add ddns * bug fix (Wed Mar 15 19:37:21 CST 2023) * Revert "bug fix (Wed Mar 15 19:37:21 CST 2023)" This reverts commit 2df87ce. * Revert "ci: add ddns" This reverts commit 4fe8321. * alias cbd and cbds, riot nasp port to 12022 * .zshrc: sagent -> sagt * fix ci * riot: bug fix when 'tmp' has leading zeros * add ci for cbds --------- Co-authored-by: xiongdian.me <[email protected]>
- Loading branch information
Showing
15 changed files
with
461 additions
and
170 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
set -e | ||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) | ||
source "$THIS_DIR/../tools/common.sh" | ||
|
||
get() | ||
{ | ||
local key=$1 | ||
if [[ -z "$key" ]]; then | ||
fmt_fatal "missing key" | ||
fi | ||
local output=${2:-/dev/stdout} | ||
local url="https://pastebin.com/raw/$key" | ||
curl -fsSL "$url" > "$output" | ||
} | ||
|
||
put() | ||
{ | ||
local input=${1:-/dev/stdin} | ||
(echo -n api_paste_code=; cat "$input") | curl -fsSL -X POST -d 'api_dev_key=SKZLfq9y_zW2hkgQOKZz1b5rw8hGiqxZ' -d 'api_option=paste' --data-binary @- "https://pastebin.com/api/api_post.php" | ||
} | ||
|
||
route() | ||
{ | ||
local cmd=$1 | ||
if [[ -z "$cmd" ]]; then | ||
put | ||
exit | ||
else | ||
shift | ||
fi | ||
case $cmd in | ||
get ) | ||
get "$@" | ||
;; | ||
put ) | ||
put "$@" | ||
;; | ||
* ) | ||
fmt_fatal "unknown command: $cmd" | ||
esac | ||
} | ||
|
||
route "${GOT_OPTS[@]}" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,27 +17,22 @@ get_server_meta() | |
domain="" | ||
fi | ||
case $domain in | ||
ibd ) | ||
SERVER=$host.ibd.ink | ||
ibd|ebd ) | ||
SERVER=$host.$domain.ink | ||
PORT=12022 | ||
SSH_USERNAME=root | ||
;; | ||
ob ) | ||
SERVER=$host.ob.ac.cn | ||
PORT=24022 | ||
SSH_USERNAME=root | ||
;; | ||
nasp ) | ||
SERVER=$host | ||
PORT=22 | ||
PORT=12022 | ||
SSH_USERNAME=dictxiong | ||
SSH_OPTIONS='-o ProxyJump="[email protected]:36022"' | ||
;; | ||
"" ) | ||
SERVER=bj1.ob.ac.cn | ||
SERVER=proxy.beardic.cn | ||
local tmp=$(sha256sum <<< "$host" | tr -cd "[:digit:]") | ||
tmp=${tmp:0:4} | ||
PORT=$((tmp+36000)) | ||
PORT=$((10#$tmp+36000)) | ||
SSH_USERNAME=root | ||
;; | ||
* ) | ||
|
@@ -46,33 +41,59 @@ get_server_meta() | |
} | ||
|
||
# ssh | ||
_ssh() | ||
run_ssh() | ||
{ | ||
get_server_meta "$1" | ||
fmt_note "--> ssh to $SERVER:$PORT" | ||
eval ssh -p $PORT $SSH_OPTIONS $SSH_USERNAME@$SERVER | ||
CMD="ssh -p $PORT $SSH_OPTIONS $SSH_USERNAME@$SERVER" | ||
fmt_note "-->" $CMD | ||
eval $CMD | ||
} | ||
|
||
# sshl | ||
run_sshl() | ||
{ | ||
if [[ -z "$1" || "$1" != *":"* ]]; then | ||
fmt_fatal "invalid remote address: $1" | ||
fi | ||
while | ||
local port=$(shuf -n 1 -i 49152-65535) | ||
netstat -atun | grep -q "$port" | ||
do | ||
continue | ||
done | ||
CMD="ssh -p $PORT $SSH_OPTIONS -NC -L $port:$1 $SSH_USERNAME@$SERVER" | ||
fmt_note "-->" $CMD | ||
fmt_note " > please access localhost:$port" | ||
eval $CMD | ||
} | ||
|
||
# main | ||
print_help() | ||
{ | ||
fmt_info "usage: $0 <command> <service> [options]" | ||
echo "available commands: ssh" | ||
fmt_info "usage: $0 <service> [command] [options]" | ||
echo "available commands: ssh (default), sshl (ssh -L)" | ||
} | ||
|
||
router() | ||
{ | ||
test $# -eq 2 || (print_help && fmt_fatal "invalid arguments") | ||
case $1 in | ||
if [[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]]; then | ||
print_help | ||
exit | ||
fi | ||
get_server_meta "$1" | ||
case $2 in | ||
-h|--help) | ||
print_help | ||
exit | ||
;; | ||
ssh|"" ) | ||
run_ssh | ||
;; | ||
ssh ) | ||
_ssh "$2" | ||
sshl ) | ||
run_sshl "$3" | ||
;; | ||
* ) | ||
print_help | ||
fmt_fatal "unknown command: $1" | ||
fmt_fatal "unknown command: $2" | ||
;; | ||
esac | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
set -e | ||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) | ||
source "$THIS_DIR/common.sh" | ||
|
||
zsh_hist_file="$HOME/.zsh_history" | ||
|
||
do_append() | ||
{ | ||
timestamp=$(date +%s) | ||
while read -r line; do | ||
if [[ -n "$line" ]]; then | ||
echo ": $timestamp:0;$line" >> "$zsh_hist_file" | ||
fi | ||
done | ||
} | ||
|
||
main() | ||
{ | ||
key=$1 | ||
if [[ -z "$key" ]]; then | ||
fmt_fatal "missing key" | ||
fi | ||
IFS=',' read -r -a keys<<<"$key" | ||
for k in "${keys[@]}";do | ||
if [[ -z "$k" ]]; then | ||
continue | ||
fi | ||
(curl -fsSL "https://pastebin.com/raw/$k" && echo) | sed 's/\r//' | do_append | ||
done | ||
} | ||
|
||
main "${GOT_OPTS[@]}" |
Oops, something went wrong.