From 2a2be8237598aed0a10f8f731ad67320d4303d31 Mon Sep 17 00:00:00 2001 From: Luk Date: Fri, 6 Feb 2026 18:47:43 +0800 Subject: [PATCH] u --- caddy-install.sh | 5 +++ debian-setup.Dockerfile | 2 +- docker-search-tags.sh | 6 +-- mac-create-vdisk.sh | 2 +- nixhome/.bashrc | 6 +-- nodejs-install.sh | 2 +- nodejs-remove.sh | 2 +- ssh.sh | 99 +++++++++++++++++++++++------------------ ts-run-as-exit.sh | 5 +++ 9 files changed, 76 insertions(+), 53 deletions(-) diff --git a/caddy-install.sh b/caddy-install.sh index 8f11769..66c4d85 100755 --- a/caddy-install.sh +++ b/caddy-install.sh @@ -9,3 +9,8 @@ sudo apt install caddy echo echo Certificates will be saved automatically in ~/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/ echo Config file of caddy started by systemctl : /etc/caddy/Caddyfile + +# 202601 注意到 caddy 的 gpg.key 过时了,导致 apt update 报错。更新: +# https://github.com/caddyserver/caddy/issues/7411 +# [Solved] Caddy's APT repo (ubuntu/debian) GPG key has expired · Issue #7411 · caddyserver/caddy +# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg diff --git a/debian-setup.Dockerfile b/debian-setup.Dockerfile index 972e500..b08c9cd 100644 --- a/debian-setup.Dockerfile +++ b/debian-setup.Dockerfile @@ -6,7 +6,7 @@ RUN curl -s https://git.tic.cc/npm/sysconfig/raw/branch/main/debian-setup.sh | b CMD bash -# mv $(basename "$0") Dockerfile +# mv $(basename $0) Dockerfile # docker build -t debian-faronear . # docker tag debian-faronear anolaxy/debian-faronear:11.5-20221205 # docker login diff --git a/docker-search-tags.sh b/docker-search-tags.sh index f66dae4..0f9c059 100755 --- a/docker-search-tags.sh +++ b/docker-search-tags.sh @@ -1,9 +1,9 @@ #!/bin/sh echo "Usage:" -echo ' "this-script.sh [imageName]" to search library/[imageName]' -echo ' "this-script.sh [imageName] [ownerName]" to search [ownerName]/[imageName]' -echo ' "this.script.sh" to interactive enter [ownerName] and [imageName] to search' +echo " $(basename $0) [imageName] ===> to search library/[imageName]" +echo " $(basename $0) [imageName] [ownerName] ===> to search [ownerName]/[imageName]" +echo " $(basename $0) ===> to interactive enter [ownerName] and [imageName] to search" echo IMAGE=$1 diff --git a/mac-create-vdisk.sh b/mac-create-vdisk.sh index 1257a9f..0fa4634 100755 --- a/mac-create-vdisk.sh +++ b/mac-create-vdisk.sh @@ -13,6 +13,6 @@ else diskutil apfs create ${DISKID} $DISKNAME fi -# copy this script to some public folder, e.g. `sudo cp this-script.sh /etc/`, because in my test, it doesn't work in /Users/... +# copy this script to some public folder, e.g. `sudo cp $(basename $0) /etc/`, because in my test, it doesn't work in /Users/... # copy the corresponding plist file to /Library/LaunchDaemons/, # optionally run `sudo launchctl load /Library/LaunchDaemons/my-launch-file.plist` immediately for test. diff --git a/nixhome/.bashrc b/nixhome/.bashrc index a51ea47..7a61197 100644 --- a/nixhome/.bashrc +++ b/nixhome/.bashrc @@ -133,12 +133,12 @@ elif [ -f /etc/ubuntu_version ]; then MYOSVERSION=Ubt`cat /etc/ubuntu_version 2>/dev/null` fi if [[ -n "$SSH_CONNECTION" ]]; then - IN_SSH="[ssh]" + IN_SSH="ssh" fi if [ "$color_prompt" = yes ]; then - PS1='<\[\033[07;32m\]\t\[\033[00m\]#\[\033[07;35m\]\u\[\033[00m\]@\[\033[07;31m\]\h\[\033[00m\]^\[\033[07;34m\]$(uname -m),$(uname),$MYOSVERSION\[\033[00m\]:$IN_SSH:\[\033[07;36m\]\w\[\033[00m\]> ' + PS1='<\[\033[07;32m\]\t\[\033[00m\]#\[\033[07;35m\]\u\[\033[00m\]@\[\033[07;31m\]\h\[\033[00m\]=\[\033[07;34m\]$(uname -m),$(uname),$MYOSVERSION\[\033[00m\]:$IN_SSH:\[\033[07;36m\]\w\[\033[00m\]> ' else - PS1='<\t#\u@\h^$(uname -m),$(uname),$MYOSVERSION:$IN_SSH:\w> ' # \w shows absolute path, \W shows current folder. + PS1='<\t#\u@\h=$(uname -m),$(uname),$MYOSVERSION:$IN_SSH:\w> ' # \w shows absolute path, \W shows current folder. fi unset color_prompt force_color_prompt diff --git a/nodejs-install.sh b/nodejs-install.sh index 80029ce..77eff87 100755 --- a/nodejs-install.sh +++ b/nodejs-install.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo "Usage: this-script.sh [VERSION]" +echo "Usage: $(basename $0) [VERSION]" defaultVERSION=18.12.1 diff --git a/nodejs-remove.sh b/nodejs-remove.sh index e554859..29602f3 100755 --- a/nodejs-remove.sh +++ b/nodejs-remove.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo "Usage: this-script.sh [VERSION]" +echo "Usage: $(basename $0) [VERSION]" sudo rm -fr /usr/local/bin/node sudo rm -fr /usr/local/bin/npm diff --git a/ssh.sh b/ssh.sh index 06db7f2..7f3f487 100755 --- a/ssh.sh +++ b/ssh.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo Usage: this_script.sh [selected_index] [to_run_cmd] +echo "Usage: $(basename $0) [selected_index] [to_run_cmd]" # Ensure jq is installed if ! command -v jq &> /dev/null; then @@ -11,21 +11,13 @@ fi # Path to the settings.json file SETTINGS_FILE="$HOME/Library/Application Support/Code/User/settings.json" if [[ ! -f "$SETTINGS_FILE" ]]; then - SETTINGS_FILE="$HOME/product_产品/.vscode/settings.json" - if [[ ! -f "$SETTINGS_FILE" ]]; then - echo "settings.json file not found!" - exit 1 - fi + SETTINGS_FILE="$HOME/product_产品/.vscode/settings.json" + if [[ ! -f "$SETTINGS_FILE" ]]; then + echo "settings.json file not found!" + exit 1 + fi fi -# 自定义的列表,但是测试有问题,只有第一行被select添加了序号 -# targets=$(jq -r '.["sshfs.configs"][] | "\(.name)"' "$SETTINGS_FILE") -# if [ -z "$targets" ] -# then -# echo "No configurations found in the settings.json file." -# exit 1 -# fi - # Parse the JSON to get labels and corresponding details labels=($(jq -r '.["sshfs.configs"][] | .label' "$SETTINGS_FILE")) hosts=($(jq -r '.["sshfs.configs"][] | .host' "$SETTINGS_FILE")) @@ -35,22 +27,46 @@ usernames=($(jq -r '.["sshfs.configs"][] | .username' "$SETTINGS_FILE")) passwords=($(jq -r '.["sshfs.configs"][] | .password' "$SETTINGS_FILE")) privateKeyPaths=($(jq -r '.["sshfs.configs"][] | .privateKeyPath' "$SETTINGS_FILE")) -if [ "$1" -ge 0 ] 2>/dev/null && [ "$1" -le ${#hosts[@]} ] 2>/dev/null -then - selected_index=$1-1 +options=() +prefixes=() +for i in "${!labels[@]}"; do + option=$(echo "${labels[$i]}" | sed 's/[^[:alnum:]].*//') # 提取前几个字母和数字 + options+=("$option: ${labels[$i]}") # 去掉序号,保留前缀和完整label + prefixes+=("$option") # 保存前缀 +done + +# Check if a command-line argument is provided +if [ "$1" != "" ]; then + # 如果提供了参数,则直接使用这个前缀 + user_input=$1 else - echo "Select a target to connect via SSH, or press 0 to exit:" - select target in "${labels[@]}" - do - if [[ -n "$target" ]]; then - selected_index=$REPLY-1 - break - elif [ "$REPLY" = '0' ]; then - exit 0 - else - echo "Invalid selection. Try again." + echo "Select a target to connect via SSH, or press 0 to exit:" + echo + + # Display options without numbers + for opt in "${options[@]}"; do + echo "$opt" + done + + echo + read -p "请输入要连接的主机前缀: " user_input +fi + +echo + +# 查找用户输入对应的索引 +selected_index=-1 +for i in "${!prefixes[@]}"; do + if [[ "${prefixes[$i]}" == "$user_input" ]]; then + selected_index=$i + break fi - done +done + +# 如果没有找到匹配的索引 +if [ "$selected_index" -eq -1 ]; then + echo "无效的选择,请重试。" + exit 1 fi label="${labels[$selected_index]}" @@ -61,23 +77,20 @@ username="${usernames[$selected_index]}" password="${passwords[$selected_index]}" privateKeyPath="${privateKeyPaths[$selected_index]}" -if [ "$port" = "null" ] -then - port=22 +if [ "$port" = "null" ]; then + port=22 fi echo "::*** Connecting to ${label}" -if [ "$password" != "null" ] -then - if [ "$(which sshpass)" ] - then - echo "::*** sshpass -p $password -Y -p $port $username@$host" - sshpass -p $password ssh -Y -p $port "$username@$host" $2 - else - echo "::*** ssh -Y -p $port $username@$host" - ssh -Y -p $port "$username@$host" $2 # -X 在 linux 安装 xrdp 后连接时报错,改 -Y 就可。 - fi +if [ "$password" != "null" ]; then + if command -v sshpass &> /dev/null; then + echo "::*** sshpass -p $password -Y -p $port $username@$host" + sshpass -p "$password" ssh -Y -p "$port" "$username@$host" $2 + else + echo "::*** ssh -Y -p $port $username@$host" + ssh -Y -p "$port" "$username@$host" $2 + fi else - echo "::*** ssh -Y -p $port $username@$host" - ssh -Y -p $port "$username@$host" $2 + echo "::*** ssh -Y -p $port $username@$host" + ssh -Y -p "$port" "$username@$host" $2 fi \ No newline at end of file diff --git a/ts-run-as-exit.sh b/ts-run-as-exit.sh index b2b78cd..86e0661 100755 --- a/ts-run-as-exit.sh +++ b/ts-run-as-exit.sh @@ -1 +1,6 @@ +## 这应该是一次性即可,然后在 Admin Console 网页里这个 exit node 上就不会有警告标记。但实际上即使有警告也能用做 exit node。 +echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf +echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf +sudo sysctl -p /etc/sysctl.conf + sudo tailscale up --advertise-exit-node