mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-10-23 05:08:16 +08:00
[dev] refactor riot; improve tmux and vim; more plugins; more aliases (#43)
* riot: remove unknown domain warn
* install.sh: --no-ssh -> --no-auth-info
* doll: --restart=unless-stopped
* zshrc: alias cps and mvs
* riot: proxy -> ssh
* zshrc: not alias rm to trash
* (trial) riot devel: separate preset to config dir riot.d
* riot: support extra options and extra -o options
* (experimental) riot config in a single file
* riot config: add nasp remote and null domain
* gitconf: pull.ff = only
* fix ci
* riot: dynamic port forwarding
* riot: only one domain func will be exec
* to-install: update lemonbench
* to-install: alist
* [exp] riot inferred ssh: ping ping6
* sagt: fix nixos
* riot config: domain 42
* ubuntu.sh: DEBIAN_FRONTEND=noninteractive
* zshrc: ping -n
* zshrc: alias ping -n
* riot-config: jumpserver from sir0 to ssh.beardic.cn
* zshrc: alias ping before checking os type
* frigg: support api4.beardic.cn
* fix(install.sh): crontab fails on a new server
* fix(riot-conf): nasp.ob.ac.cn -> nasp.fit
* fix(install.sh): install crontab (exp)
* feat(test.zsh): test crontab
* fix(riot): secure control master
* fix(ci): riot control master
* fix(riot): not mkdir if dry-run
* feat(vimrc): set shiftwidth=4
* feat(ci): sync tmux-yank
* feat(tmux): set-clipboard on and mouse on (experimental)
* feat(zshrc): alias ping6
* build(ci): hub mirror 1.3->1.4
* fix(zshrc): tmux on msys; feat(common): better perf getting os type and linux dist
* fix(common.sh): get_os_type and get_linux_dist
* feat(zshrc): add plugin {magic-enter,per-directory-history,pip,podman,python,rsync,systemd,timer}
* feat(zshrc): journalctl alias
* feat(vimrc): tab=2 for c,cpp,nix,yaml
* build(ci): checkout v3 -> v4
---------
Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
This commit is contained in:
@@ -21,5 +21,5 @@ if [[ -z "$IMAGE" ]]; then
|
||||
fmt_fatal "image not found"
|
||||
else
|
||||
fmt_note "--> ${IMAGE_META[@]}"
|
||||
$SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh
|
||||
$SUDO docker run ${2:+"--name"} $2 -itd --restart=unless-stopped $IMAGE sh
|
||||
fi
|
||||
|
||||
103
scripts/riot
103
scripts/riot
@@ -4,6 +4,19 @@ THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/../tools/common.sh"
|
||||
RIOT_TRUST_CLIENT=${RIOT_TRUST_CLIENT:-${DFS_TRUST:-0}}
|
||||
RIOT_TRUST_SERVER=${RIOT_TRUST_SERVER:-0}
|
||||
RIOT_EXTRA_OPTIONS=""
|
||||
|
||||
# config
|
||||
RIOT_CONFIG_FILES=(
|
||||
"$DOTFILES/riot-config.sh"
|
||||
"$HOME/.config/riot-config.sh"
|
||||
"riot-config.sh"
|
||||
)
|
||||
for file in "${RIOT_CONFIG_FILES[@]}"; do
|
||||
if [[ -f "$file" ]]; then
|
||||
source "$file"
|
||||
fi
|
||||
done
|
||||
|
||||
# check if port number valid
|
||||
check_port() {
|
||||
@@ -29,14 +42,6 @@ get_server_meta() {
|
||||
RET_JUMP_SERVER="" # optional
|
||||
# body
|
||||
local remote="$1"
|
||||
# shortcuts
|
||||
if [[ "$remote" == "i" ]]; then
|
||||
remote="sir0.ibd"
|
||||
elif [[ "$remote" == "x" ]]; then
|
||||
remote="bj1.ibd"
|
||||
elif [[ "$remote" == "j" ]]; then
|
||||
remote="sir0.ibd:36122"
|
||||
fi
|
||||
# if in the form user@...
|
||||
if [[ "$remote" == *@* ]]; then
|
||||
RET_USERNAME=${remote%%@*}
|
||||
@@ -49,46 +54,25 @@ get_server_meta() {
|
||||
remote=${remote%:*}
|
||||
check_port $RET_PORT || fmt_fatal invalid port number \"$RET_PORT\"
|
||||
fi
|
||||
# presets -- match remote
|
||||
local remote_func="$remote.remote"
|
||||
if is_function "$remote_func"; then
|
||||
"$remote_func"
|
||||
fi
|
||||
# presets -- match domain
|
||||
RET_HOSTNAME=${remote}
|
||||
local domain=${remote##*.}
|
||||
local host=${remote%.*}
|
||||
# if there's no dot
|
||||
if [[ "$host" == "$domain" && "$host" != "["*"]" ]]; then
|
||||
domain="ibd"
|
||||
domain="default"
|
||||
fi
|
||||
local domain_func="$domain.domain"
|
||||
if is_function "$domain_func"; then
|
||||
"$domain_func"
|
||||
elif is_function ".domain"; then
|
||||
".domain"
|
||||
fi
|
||||
case $domain in
|
||||
i|ibd )
|
||||
RET_HOSTNAME=$host.ibd.ink
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
;;
|
||||
nasp )
|
||||
RET_HOSTNAME=$host
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-dictxiong}
|
||||
RET_JUMP_SERVER="ssh@nasp.ob.ac.cn:36022"
|
||||
RET_TRUST_SERVER=1
|
||||
;;
|
||||
x|proxied )
|
||||
RET_HOSTNAME=proxy.beardic.cn
|
||||
local tmp=$(sha256sum <<< "$host" | tr -cd "[:digit:]")
|
||||
tmp=${tmp:0:4}
|
||||
RET_PORT=$((10#$tmp+36000))
|
||||
RET_USERNAME=root
|
||||
RET_TRUST_SERVER=1
|
||||
;;
|
||||
box[0-9] )
|
||||
RET_HOSTNAME=$host
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_JUMP_SERVER="root@$domain.ibd.ink:12022"
|
||||
RET_TRUST_SERVER=1
|
||||
;;
|
||||
* )
|
||||
test -z "$domain" || fmt_warning "unknown domain: \"$domain\". will try as host name"
|
||||
RET_HOSTNAME="$remote"
|
||||
esac
|
||||
}
|
||||
|
||||
parse_remote() {
|
||||
@@ -101,7 +85,11 @@ parse_remote() {
|
||||
USERNAME="" # optional
|
||||
SSH_OPTIONS="" # optional
|
||||
if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then
|
||||
SSH_OPTIONS='-o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes'
|
||||
SSH_OPTIONS='-o PermitLocalCommand=yes'
|
||||
if [[ "$(get_os_type)" != "msys" ]]; then
|
||||
test "$DFS_DRY_RUN" = "1" || mkdir -p ~/.ssh/master-socket
|
||||
SSH_OPTIONS="$SSH_OPTIONS -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C"
|
||||
fi
|
||||
fi
|
||||
# handle input
|
||||
local remote="$1"
|
||||
@@ -150,7 +138,7 @@ prepare_ssh_cmd() {
|
||||
else
|
||||
local port_param='-p'
|
||||
fi
|
||||
echo "$ssh_bin ${PORT:+$port_param} $PORT $SSH_OPTIONS $SCP_SRC $USERNAME${USERNAME:+@}$SERVER $SCP_DST ${@:2}"
|
||||
echo "$ssh_bin ${PORT:+$port_param} $PORT $SSH_OPTIONS $RIOT_EXTRA_OPTIONS $SCP_SRC $USERNAME${USERNAME:+@}$SERVER $SCP_DST ${@:2}"
|
||||
}
|
||||
|
||||
# ssh
|
||||
@@ -178,6 +166,18 @@ run_sshl()
|
||||
eval_or_echo $cmd
|
||||
}
|
||||
|
||||
# sshd
|
||||
run_sshd()
|
||||
{
|
||||
local port=$(get_free_port)
|
||||
|
||||
SSH_OPTIONS="$SSH_OPTIONS -NC -D $port"
|
||||
local cmd="$(prepare_ssh_cmd ssh)"
|
||||
fmt_note "-->" $cmd
|
||||
fmt_note " > please access localhost:$port"
|
||||
eval_or_echo $cmd
|
||||
}
|
||||
|
||||
# scp
|
||||
run_scp() {
|
||||
local src="$1"
|
||||
@@ -214,6 +214,15 @@ router() {
|
||||
exit
|
||||
fi
|
||||
|
||||
while [[ "$1" == -* ]]; do
|
||||
RIOT_EXTRA_OPTIONS="$RIOT_EXTRA_OPTIONS $1"
|
||||
if [[ "$1" == "-o" ]]; then
|
||||
RIOT_EXTRA_OPTIONS="$RIOT_EXTRA_OPTIONS $2"
|
||||
shift
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
IFS=',' read -ra remotes <<< "$1"
|
||||
for remote in "${remotes[@]}"; do
|
||||
if [[ -z "$remote" ]]; then
|
||||
@@ -224,6 +233,9 @@ router() {
|
||||
ssh|"" )
|
||||
run_ssh ssh "${@:3}"
|
||||
;;
|
||||
ping|ping6 )
|
||||
run_ssh ssh "${@:2}"
|
||||
;;
|
||||
zssh )
|
||||
run_ssh zssh
|
||||
;;
|
||||
@@ -234,6 +246,9 @@ router() {
|
||||
test -n "$3" || fmt_fatal "no target address provided"
|
||||
run_sshl "$3"
|
||||
;;
|
||||
sshd )
|
||||
run_sshd
|
||||
;;
|
||||
scp )
|
||||
test -n "$3" || fmt_fatal "no source path specified"
|
||||
test -n "$4" || fmt_fatal "no destination path specified"
|
||||
|
||||
Reference in New Issue
Block a user