dotfiles/scripts/riot
Dict Xiong 9a4c9556f6
[dev] common.sh parses args; riot; getdfs; install.sh -x KEY=VAL (#35)
* common.sh: export vars in env; zshrc: gdebug

* fix error when locale not exists

* DFS_COLOR

* common.sh: parse args automatically

* ci: test common.sh getopts

* common.sh: argparser supports spaces

* ciot: init

* ciot -> diot; remove sibd, sob and snasp

* rename diot -> riot

* update home0 ssh pubkey; fix ci temperarily

* gdebug will record time

* gdebug supports empty; --dry-run wip

* get.dotfiles.cn

* bug fix (Thu Jan  5 20:53:58 CST 2023)

* fix ci

* fix ci

* install.sh: -d will set -x

* ci: -asl

* getdfs: install for another user using -u <uname>

* try fix when su doesnot exist

* bug fix (Thu Jan  5 22:58:40 CST 2023)

* bug fix (Thu Jan  5 22:59:33 CST 2023)

* introduce SUDOE and so debug

* ask_for_yn now use stdout to return

* getdfs: support multiple users

* install.sh: -x to set dfs config; ci

* fix ci

* bug fix (Fri Jan  6 15:11:24 CST 2023)

* auto-detect DFS_NO_WALL

* bug fix (Fri Jan  6 15:43:25 CST 2023)

* getdfs: ${repo}

* bug fix (Fri Jan  6 16:08:41 CST 2023)

* getdfs: prompt user

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2023-01-06 16:14:41 +08:00

81 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# connect to iot services
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
# get target settings
# provides:
SERVER=""
PORT=""
SSH_USERNAME=""
SSH_OPTIONS=""
get_server_meta()
{
local domain=${1##*.}
local host=${1%.*}
if [[ "$host" == "$domain" ]]; then
domain=""
fi
case $domain in
ibd )
SERVER=$host.ibd.ink
PORT=12022
SSH_USERNAME=root
;;
ob )
SERVER=$host.ob.ac.cn
PORT=24022
SSH_USERNAME=root
;;
nasp )
SERVER=$host
PORT=22
SSH_USERNAME=dictxiong
SSH_OPTIONS='-o ProxyJump="ssh@nasp.ob.ac.cn:36022"'
;;
"" )
SERVER=bj1.ob.ac.cn
local tmp=$(sha256sum <<< "$host" | tr -cd "[:digit:]")
tmp=${tmp:0:4}
PORT=$((tmp+36000))
SSH_USERNAME=root
;;
* )
fmt_fatal "unknown domain: $domain"
esac
}
# ssh
_ssh()
{
get_server_meta "$1"
fmt_note "--> ssh to $SERVER:$PORT"
eval ssh -p $PORT $SSH_OPTIONS $SSH_USERNAME@$SERVER
}
# main
print_help()
{
fmt_info "usage: $0 <command> <service> [options]"
echo "available commands: ssh"
}
router()
{
test $# -eq 2 || (print_help && fmt_fatal "invalid arguments")
case $1 in
-h|--help)
print_help
;;
ssh )
_ssh "$2"
;;
* )
print_help
fmt_fatal "unknown command: $1"
;;
esac
}
router "${GOT_OPTS[@]}"