mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-10-23 05:08:16 +08:00
[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>
This commit is contained in:
@@ -25,6 +25,6 @@ fi
|
||||
if [[ -z "$CONTAINER" ]]; then
|
||||
fmt_fatal "container not found"
|
||||
else
|
||||
echo "--> ${CONTAINER_META[@]}"
|
||||
fmt_note "--> ${CONTAINER_META[@]}"
|
||||
$SUDO docker exec -it $CONTAINER sh -c 'export DFS="bash <(curl dfs.beardic.cn) -a"; if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; unset DFS; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi'
|
||||
fi
|
||||
|
||||
@@ -20,6 +20,6 @@ fi
|
||||
if [[ -z "$IMAGE" ]]; then
|
||||
fmt_fatal "image not found"
|
||||
else
|
||||
echo "--> ${IMAGE_META[@]}"
|
||||
fmt_note "--> ${IMAGE_META[@]}"
|
||||
$SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh
|
||||
fi
|
||||
|
||||
80
scripts/riot
Executable file
80
scripts/riot
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/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[@]}"
|
||||
Reference in New Issue
Block a user