diff --git a/.gitconfig2 b/.gitconfig2 index 09a899e..c731d12 100644 --- a/.gitconfig2 +++ b/.gitconfig2 @@ -9,6 +9,8 @@ quotepath = false # chinese chars [push] autoSetupRemote = true +[pull] + ff = only [branch] # Show most recently changed branches first. sort = -committerdate diff --git a/.zshrc2 b/.zshrc2 index 9d8df17..2ac4246 100644 --- a/.zshrc2 +++ b/.zshrc2 @@ -102,6 +102,9 @@ fi alias "pls"='sudo $(fc -ln -1)' alias "se"='sudo -sE' alias "sl"='sudo zsh -l' +alias "cps"='rsync -avh --info=progress2' +alias "mvs"='rsync -avh --info=progress2 --remove-source-files' +if [[ $("$DOTFILES/tools/common.sh" get_os_type) == "linux" ]]; then alias "ping"='ping -n'; fi alias "pbd"='ping baidu.com' alias "p114"='ping 114.114.114.114' alias "p666"='ping6 2001:da8::666' @@ -110,9 +113,6 @@ alias "cbds"='curl https://www.baidu.com' alias "gdebug"='git add -A; git commit --allow-empty -m "bug fix ($(date))"' alias "ls"='ls --color=tty' alias "l"='ls -lAGh --time-style="+%y-%m-%d %H:%M"' -if [[ -x $(command -v trash) ]]; then - alias "rm"="echo use the full path i.e. '/bin/rm'\; consider using trash" -fi gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX } sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" } diff --git a/install.sh b/install.sh index 7ecdc94..24ffba3 100755 --- a/install.sh +++ b/install.sh @@ -203,9 +203,10 @@ install_crontab() if [[ -x $(command -v crontab) ]]; then fmt_note "installing \"$CRON_JOB\" to crontab ..." if ! crontab -l 1>/dev/null 2>&1; then - echo -n | crontab - + echo "$CRON_JOB" | crontab - + else + ( crontab -l | grep -vxF "${CRON_JOB}" | grep -v "no crontab for"; echo "$CRON_JOB" ) | crontab - fi - ( crontab -l | grep -vxF "${CRON_JOB}" | grep -v "no crontab for"; echo "$CRON_JOB" ) | crontab - else fmt_warning "crontab does not exist. skipping ..." fi @@ -330,7 +331,7 @@ for i in ${GOT_OPTS[@]}; do -a|--auto ) INSTALL_DEP=1 ;; -H|--hist|--history ) store_hist=1 ;; -x ) store_config=1 ;; - --no-ssh ) unset HOME_SYMLINKS_SRC[0]; unset HOME_SYMLINKS_DST[0] ;; + --no-auth-info ) HOME_SYMLINKS_SRC=(); HOME_SYMLINKS_DST=() ;; * ) fmt_fatal "unknown option \"$i\"" ;; esac done diff --git a/riot-config.sh b/riot-config.sh new file mode 100644 index 0000000..03199a3 --- /dev/null +++ b/riot-config.sh @@ -0,0 +1,56 @@ +#!/bin/false + +# remotes +j.remote() { + remote=ssh.beardic.cn + RET_PORT=${RET_PORT:-24022} + RET_USERNAME=${RET_USERNAME:-root} + RET_TRUST_SERVER=1 +} + +nasp.remote() { + remote=nasp.fit + RET_PORT=${RET_PORT:-36022} + RET_USERNAME=${RET_USERNAME:-ssh} + RET_TRUST_SERVER=1 +} + +# domains +.domain() { + RET_USERNAME=${RET_USERNAME:-root} +} + +i.domain() { + RET_HOSTNAME=$host.ibd.ink + RET_PORT=${RET_PORT:-12022} + RET_USERNAME=${RET_USERNAME:-root} + RET_TRUST_SERVER=1 +} + +42.domain() { + RET_HOSTNAME=$host.i.bd.dn42 + RET_PORT=${RET_PORT:-12022} + RET_USERNAME=${RET_USERNAME:-root} + RET_TRUST_SERVER=1 +} + +x.domain() { + RET_HOSTNAME=ssh.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 +} + +nasp.domain() { + RET_HOSTNAME=$host + RET_PORT=${RET_PORT:-12022} + RET_USERNAME=${RET_USERNAME:-dictxiong} + RET_JUMP_SERVER="ssh@nasp.fit:36022" + RET_TRUST_SERVER=1 +} + +default.domain() { + i.domain +} diff --git a/scripts/doll b/scripts/doll index 6da3a6d..22075a8 100755 --- a/scripts/doll +++ b/scripts/doll @@ -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 diff --git a/scripts/riot b/scripts/riot index 9827750..c9b8d3b 100755 --- a/scripts/riot +++ b/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() { @@ -150,7 +134,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 +162,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 +210,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 +229,9 @@ router() { ssh|"" ) run_ssh ssh "${@:3}" ;; + ping|ping6 ) + run_ssh ssh "${@:2}" + ;; zssh ) run_ssh zssh ;; @@ -234,6 +242,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" diff --git a/tools/common.sh b/tools/common.sh index ddae15f..2705aca 100755 --- a/tools/common.sh +++ b/tools/common.sh @@ -258,6 +258,10 @@ get_free_port() { echo $port } +is_function() { + test "$(type -t "$1")" = "function" +} + # if bash-ed, else source-d if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then $1 "${@:2}" diff --git a/tools/frigg-client.sh b/tools/frigg-client.sh index cb68efd..4d5d3da 100755 --- a/tools/frigg-client.sh +++ b/tools/frigg-client.sh @@ -103,6 +103,7 @@ update_dns() ip4="" elif [[ "$DFS_DDNS_IP4" == "auto" ]]; then ip4="auto" + api_url="https://api4.beardic.cn" elif [[ "$DFS_DDNS_IP4" == "api" ]]; then ip4=$(curl $DFS_CURL_OPTIONS -sSL "https://api.ipify.org") elif [[ "$DFS_DDNS_IP4" == "http"* ]]; then diff --git a/tools/sagent.sh b/tools/sagent.sh index 8f2545f..083ef4e 100755 --- a/tools/sagent.sh +++ b/tools/sagent.sh @@ -25,7 +25,7 @@ find_so_file() create_agent() { local IFS="," - ssh-agent -P "${SO_PATHS[*]}" + ssh-agent -P "${SO_PATHS[*]},/nix/store/*" } kill_agent() diff --git a/tools/test.zsh b/tools/test.zsh index 68edf99..4625b36 100644 --- a/tools/test.zsh +++ b/tools/test.zsh @@ -38,7 +38,7 @@ 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 ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes -o ProxyJump=time@is.impt:2222,yes@you-r.right,you@are.really.recht.,ibd. -r try@it.ibd.ink:"/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 ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes -o ProxyJump=time@is.impt:2222,yes@you-r.right,you@are.really.recht.,root@ibd. -r try@it.ibd.ink:"/tmp/" "./tmp" scp -P 12022 -o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes -o ForwardX11=yes -o ForwardAgent=yes -r another@host.ibd.ink:"/tmp/" "./tmp"' # check alias diff --git a/tools/to-install.sh b/tools/to-install.sh index 04b019e..93f9d80 100755 --- a/tools/to-install.sh +++ b/tools/to-install.sh @@ -10,8 +10,9 @@ INSTALL_COMMANDS=(\ [v2fly]="bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) #--remove" \ [zerotier-one]='curl -s https://install.zerotier.com | sudo bash' \ [docker-ce]='curl -fsSL https://get.docker.com | sudo bash -s - --mirror Aliyun #--dry-run' \ - [lemonbench]='curl -fsSL https://ilemonra.in/LemonBenchIntl | bash -s fast # or full' \ + [lemonbench]='curl -fsSL https://raw.githubusercontent.com/LemonBench/LemonBench/main/LemonBench.sh | bash -s fast # or full' \ [nix]='sh <(curl -L https://nixos.org/nix/install) #--daemon' \ + [alist]='curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s install' \ ) install() diff --git a/tools/ubuntu.sh b/tools/ubuntu.sh index 8f7e611..1bcd158 100755 --- a/tools/ubuntu.sh +++ b/tools/ubuntu.sh @@ -14,11 +14,11 @@ apt_install() { apt-get update -y # lite - apt-get install -y git zsh bash tmux vim curl inetutils-ping less bsdmainutils + DEBIAN_FRONTEND=noninteractive apt-get install -y git zsh bash tmux vim curl iputils-ping less bsdmainutils # full if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then - apt-get install -y wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron openssh-client openssh-server htop gcc g++ cmake make zip - for i in {fzf,ripgrep,man-db}; do apt-get install -y $i; done + DEBIAN_FRONTEND=noninteractive apt-get install -y wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron openssh-client openssh-server htop gcc g++ cmake make zip + for i in {fzf,ripgrep,man-db}; do DEBIAN_FRONTEND=noninteractive apt-get install -y $i; done fi }