uk revisou este gist 2 weeks ago. Ir para a revisão
1 file changed, 1 insertion, 1 deletion
init_hostname.sh
| @@ -72,5 +72,5 @@ case "$OCTET3" in | |||
| 72 | 72 | esac | |
| 73 | 73 | ||
| 74 | 74 | SYSTEM_NAME="${REGION}-${IP//./-}" | |
| 75 | - | ||
| 75 | + | echo "hostnamectl set-hostname $SYSTEM_NAME" | |
| 76 | 76 | echo "$SYSTEM_NAME" | |
uk revisou este gist 2 weeks ago. Ir para a revisão
1 file changed, 54 insertions
install_beszel-agent.sh(arquivo criado)
| @@ -0,0 +1,54 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | set -euo pipefail | |
| 4 | + | ||
| 5 | + | BASE_DIR="/uk/container/beszel-agent" | |
| 6 | + | COMPOSE_FILE="${BASE_DIR}/docker-compose.yaml" | |
| 7 | + | HOSTNAME_SCRIPT_URL="https://gist.smtx.fun/uk/shell/raw/HEAD/init_hostname.sh" | |
| 8 | + | ||
| 9 | + | mkdir -p "${BASE_DIR}/data/beszel_agent_data" | |
| 10 | + | ||
| 11 | + | SYSTEM_NAME="$( | |
| 12 | + | curl -fsSL "${HOSTNAME_SCRIPT_URL}" | bash | |
| 13 | + | )" | |
| 14 | + | ||
| 15 | + | if [[ -z "${SYSTEM_NAME}" ]]; then | |
| 16 | + | echo "错误:未能生成 Beszel Agent 主机名" >&2 | |
| 17 | + | exit 1 | |
| 18 | + | fi | |
| 19 | + | ||
| 20 | + | if [[ ! "${SYSTEM_NAME}" =~ ^[a-z0-9][a-z0-9-]*$ ]]; then | |
| 21 | + | echo "错误:生成的主机名不合法:${SYSTEM_NAME}" >&2 | |
| 22 | + | exit 1 | |
| 23 | + | fi | |
| 24 | + | ||
| 25 | + | cat > "${COMPOSE_FILE}" <<EOF | |
| 26 | + | services: | |
| 27 | + | beszel-agent: | |
| 28 | + | hostname: "${SYSTEM_NAME}" | |
| 29 | + | container_name: beszel-agent | |
| 30 | + | image: henrygd/beszel-agent:latest | |
| 31 | + | restart: unless-stopped | |
| 32 | + | network_mode: host | |
| 33 | + | ||
| 34 | + | volumes: | |
| 35 | + | - /var/run/docker.sock:/var/run/docker.sock:ro | |
| 36 | + | - ./data/beszel_agent_data:/var/lib/beszel-agent | |
| 37 | + | ||
| 38 | + | environment: | |
| 39 | + | LISTEN: "45876" | |
| 40 | + | KEY: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBwdGhEA5KNbeNt761qa4iAu8bL6JsTZtuooEjtYS7z4" | |
| 41 | + | TOKEN: "5840c830-5842-4e4e-b6e3-c0ca5191d4a6" | |
| 42 | + | HUB_URL: "http://192.168.49.1:8022" | |
| 43 | + | ||
| 44 | + | healthcheck: | |
| 45 | + | test: ["CMD", "/agent", "health"] | |
| 46 | + | interval: 120s | |
| 47 | + | EOF | |
| 48 | + | ||
| 49 | + | echo "生成的系统名称:${SYSTEM_NAME}" | |
| 50 | + | echo "Compose 文件:${COMPOSE_FILE}" | |
| 51 | + | ||
| 52 | + | docker compose --project-directory "${BASE_DIR}" -f "${COMPOSE_FILE}" up -d --pull always | |
| 53 | + | ||
| 54 | + | docker compose --project-directory "${BASE_DIR}" -f "${COMPOSE_FILE}" ps | |
uk revisou este gist 2 weeks ago. Ir para a revisão
1 file changed, 76 insertions
init_hostname.sh(arquivo criado)
| @@ -0,0 +1,76 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | set -euo pipefail | |
| 4 | + | ||
| 5 | + | # 获取默认路由接口 | |
| 6 | + | IFACE=$( | |
| 7 | + | ip -4 route show default \ | |
| 8 | + | | awk 'NR == 1 {print $5}' | |
| 9 | + | ) | |
| 10 | + | ||
| 11 | + | if [[ -z "${IFACE:-}" ]]; then | |
| 12 | + | echo "错误:未找到默认路由接口" >&2 | |
| 13 | + | exit 1 | |
| 14 | + | fi | |
| 15 | + | ||
| 16 | + | # 获取默认路由接口上的 IPv4 地址: | |
| 17 | + | # 先匹配 192.168.*,没有则匹配 172.29.* | |
| 18 | + | IP=$( | |
| 19 | + | ip -4 -o addr show dev "$IFACE" scope global \ | |
| 20 | + | | awk ' | |
| 21 | + | { | |
| 22 | + | split($4, addr, "/") | |
| 23 | + | ip = addr[1] | |
| 24 | + | ||
| 25 | + | if (ip ~ /^192\.168\./ && ip_192 == "") { | |
| 26 | + | ip_192 = ip | |
| 27 | + | } | |
| 28 | + | ||
| 29 | + | if (ip ~ /^172\.29\./ && ip_172 == "") { | |
| 30 | + | ip_172 = ip | |
| 31 | + | } | |
| 32 | + | } | |
| 33 | + | END { | |
| 34 | + | if (ip_192 != "") { | |
| 35 | + | print ip_192 | |
| 36 | + | } else if (ip_172 != "") { | |
| 37 | + | print ip_172 | |
| 38 | + | } | |
| 39 | + | } | |
| 40 | + | ' | |
| 41 | + | ) | |
| 42 | + | ||
| 43 | + | if [[ -z "${IP:-}" ]]; then | |
| 44 | + | echo "错误:接口 ${IFACE} 上未找到 192.168.* 或 172.29.* 地址" >&2 | |
| 45 | + | exit 1 | |
| 46 | + | fi | |
| 47 | + | ||
| 48 | + | # 拆分 IP | |
| 49 | + | IFS='.' read -r OCTET1 OCTET2 OCTET3 OCTET4 <<< "$IP" | |
| 50 | + | ||
| 51 | + | # 按 /20 网段判断区域 | |
| 52 | + | case "$OCTET3" in | |
| 53 | + | 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31) | |
| 54 | + | REGION="idc" | |
| 55 | + | ;; | |
| 56 | + | 48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63) | |
| 57 | + | REGION="sz" | |
| 58 | + | ;; | |
| 59 | + | 64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79) | |
| 60 | + | REGION="bj" | |
| 61 | + | ;; | |
| 62 | + | 80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95) | |
| 63 | + | REGION="sh" | |
| 64 | + | ;; | |
| 65 | + | 96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111) | |
| 66 | + | REGION="cd" | |
| 67 | + | ;; | |
| 68 | + | *) | |
| 69 | + | echo "错误:IP ${IP} 不属于已配置的区域网段" >&2 | |
| 70 | + | exit 1 | |
| 71 | + | ;; | |
| 72 | + | esac | |
| 73 | + | ||
| 74 | + | SYSTEM_NAME="${REGION}-${IP//./-}" | |
| 75 | + | ||
| 76 | + | echo "$SYSTEM_NAME" | |
uk revisou este gist 4 months ago. Ir para a revisão
1 file changed, 8 insertions, 9 deletions
install_ohmyzsh.sh
| @@ -19,31 +19,28 @@ else | |||
| 19 | 19 | fi | |
| 20 | 20 | ||
| 21 | 21 | # install oh-my-zsh | |
| 22 | - | git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git | |
| 23 | - | REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh ohmyzsh/tools/install.sh && rm -rf ohmyzsh | |
| 22 | + | # git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git | |
| 23 | + | # REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh ohmyzsh/tools/install.sh && rm -rf ohmyzsh | |
| 24 | + | REPO=sjtug/ohmyzsh REMOTE=https://git.sjtu.edu.cn/${REPO}.git sh -c "$(curl -fsSL https://git.sjtu.edu.cn/sjtug/ohmyzsh/-/raw/master/tools/install.sh\?inline\=false)" | |
| 24 | 25 | ||
| 25 | 26 | ZSH=$HOME/.oh-my-zsh | |
| 26 | 27 | ||
| 27 | 28 | # install zsh-syntax-highlighting | |
| 28 | 29 | # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting | |
| 29 | 30 | git clone https://mirrors.nju.edu.cn/git/zsh-syntax-highlighting.git $ZSH/custom/plugins/zsh-syntax-highlighting | |
| 30 | - | # echo "source $ZSH_CUSTOM/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc | |
| 31 | 31 | ||
| 32 | 32 | # install zsh-autosuggestions | |
| 33 | 33 | # git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions | |
| 34 | 34 | git clone https://mirrors.nju.edu.cn/git/zsh-autosuggestions.git $ZSH/custom/plugins/zsh-autosuggestions | |
| 35 | - | # echo "source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc | |
| 36 | 35 | ||
| 37 | 36 | # install zsh-you-should-use | |
| 38 | 37 | # git clone https://github.com/MichaelAquilina/zsh-you-should-use.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use | |
| 39 | - | git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 38 | + | # git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 40 | 39 | ||
| 41 | 40 | # replace plugins and theme | |
| 42 | 41 | cp $HOME/.zshrc $HOME/.zshrc.bak | |
| 43 | - | zsh -c 'source ~/.zshrc && omz plugin enable zsh-autosuggestions zsh-syntax-highlighting sudo you-should-use' | |
| 42 | + | zsh -c 'source ~/.zshrc && omz plugin enable zsh-autosuggestions zsh-syntax-highlighting sudo' | |
| 44 | 43 | zsh -c 'source ~/.zshrc && omz theme set ys' | |
| 45 | - | # sed -i 's/(git/(git zsh-syntax-highlighting zsh-autosuggestions sudo/g' ~/.zshrc | |
| 46 | - | # sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="ys"/g' ~/.zshrc | |
| 47 | 44 | ||
| 48 | 45 | cat >> ~/.zshrc <<UK | |
| 49 | 46 | ||
| @@ -51,4 +48,6 @@ cat >> ~/.zshrc <<UK | |||
| 51 | 48 | zstyle ':omz:update' mode disabled | |
| 52 | 49 | HIST_STAMPS="yyyy-mm-dd" | |
| 53 | 50 | alias vi="vim" | |
| 54 | - | UK | |
| 51 | + | UK | |
| 52 | + | ||
| 53 | + | source ~/.zshrc | |
uk revisou este gist 4 months ago. Ir para a revisão
1 file changed, 1 insertion, 2 deletions
install_ohmyzsh.sh
| @@ -23,7 +23,6 @@ git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git | |||
| 23 | 23 | REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh ohmyzsh/tools/install.sh && rm -rf ohmyzsh | |
| 24 | 24 | ||
| 25 | 25 | ZSH=$HOME/.oh-my-zsh | |
| 26 | - | PROXY=https://pp.ukto.top | |
| 27 | 26 | ||
| 28 | 27 | # install zsh-syntax-highlighting | |
| 29 | 28 | # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting | |
| @@ -37,7 +36,7 @@ git clone https://mirrors.nju.edu.cn/git/zsh-autosuggestions.git $ZSH/custom/plu | |||
| 37 | 36 | ||
| 38 | 37 | # install zsh-you-should-use | |
| 39 | 38 | # git clone https://github.com/MichaelAquilina/zsh-you-should-use.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use | |
| 40 | - | git clone $PROXY/https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 39 | + | git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 41 | 40 | ||
| 42 | 41 | # replace plugins and theme | |
| 43 | 42 | cp $HOME/.zshrc $HOME/.zshrc.bak | |
uk revisou este gist 11 months ago. Ir para a revisão
1 file changed, 3 insertions, 1 deletion
install_ohmyzsh.sh
| @@ -23,6 +23,8 @@ git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git | |||
| 23 | 23 | REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh ohmyzsh/tools/install.sh && rm -rf ohmyzsh | |
| 24 | 24 | ||
| 25 | 25 | ZSH=$HOME/.oh-my-zsh | |
| 26 | + | PROXY=https://pp.ukto.top | |
| 27 | + | ||
| 26 | 28 | # install zsh-syntax-highlighting | |
| 27 | 29 | # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting | |
| 28 | 30 | git clone https://mirrors.nju.edu.cn/git/zsh-syntax-highlighting.git $ZSH/custom/plugins/zsh-syntax-highlighting | |
| @@ -35,7 +37,7 @@ git clone https://mirrors.nju.edu.cn/git/zsh-autosuggestions.git $ZSH/custom/plu | |||
| 35 | 37 | ||
| 36 | 38 | # install zsh-you-should-use | |
| 37 | 39 | # git clone https://github.com/MichaelAquilina/zsh-you-should-use.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use | |
| 38 | - | git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 40 | + | git clone $PROXY/https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 39 | 41 | ||
| 40 | 42 | # replace plugins and theme | |
| 41 | 43 | cp $HOME/.zshrc $HOME/.zshrc.bak | |
uk revisou este gist 11 months ago. Ir para a revisão
1 file changed, 5 insertions, 1 deletion
install_ohmyzsh.sh
| @@ -33,9 +33,13 @@ git clone https://mirrors.nju.edu.cn/git/zsh-syntax-highlighting.git $ZSH/custom | |||
| 33 | 33 | git clone https://mirrors.nju.edu.cn/git/zsh-autosuggestions.git $ZSH/custom/plugins/zsh-autosuggestions | |
| 34 | 34 | # echo "source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc | |
| 35 | 35 | ||
| 36 | + | # install zsh-you-should-use | |
| 37 | + | # git clone https://github.com/MichaelAquilina/zsh-you-should-use.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use | |
| 38 | + | git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH/custom/plugins/you-should-use | |
| 39 | + | ||
| 36 | 40 | # replace plugins and theme | |
| 37 | 41 | cp $HOME/.zshrc $HOME/.zshrc.bak | |
| 38 | - | zsh -c 'source ~/.zshrc && omz plugin enable zsh-autosuggestions zsh-syntax-highlighting sudo' | |
| 42 | + | zsh -c 'source ~/.zshrc && omz plugin enable zsh-autosuggestions zsh-syntax-highlighting sudo you-should-use' | |
| 39 | 43 | zsh -c 'source ~/.zshrc && omz theme set ys' | |
| 40 | 44 | # sed -i 's/(git/(git zsh-syntax-highlighting zsh-autosuggestions sudo/g' ~/.zshrc | |
| 41 | 45 | # sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="ys"/g' ~/.zshrc | |
uk revisou este gist 1 year ago. Ir para a revisão
1 file changed, 1 insertion, 1 deletion
install_vmtools.sh
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | set -e | |
| 3 | 3 | ||
| 4 | 4 | # Define variables | |
| 5 | - | ISO_FILENAME="SMTX_VMTOOLS-3.2.2-2505290843.iso" | |
| 5 | + | ISO_FILENAME="SMTX_VMTOOLS-4.0.0-2506271023.iso" | |
| 6 | 6 | ISO_FILE="/tmp/${ISO_FILENAME}" | |
| 7 | 7 | MOUNT_POINT="/mnt/wuke-vmtools" | |
| 8 | 8 | ||
uk revisou este gist 1 year ago. Ir para a revisão
1 file changed, 45 insertions
set-docker-prosy.sh(arquivo criado)
| @@ -0,0 +1,45 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | # 获取默认网关地址 | |
| 4 | + | GATEWAY=$(ip route | awk '/default/ {print $3}' | uniq | head -n 1) | |
| 5 | + | ||
| 6 | + | # 创建配置目录 | |
| 7 | + | sudo mkdir -p /etc/systemd/system/docker.service.d | |
| 8 | + | ||
| 9 | + | # 根据默认网关设置对应的代理地址 | |
| 10 | + | case "$GATEWAY" in | |
| 11 | + | 192.168.48.1) | |
| 12 | + | PROXY="http://192.168.48.48:7891" | |
| 13 | + | ;; | |
| 14 | + | 172.29.48.1) | |
| 15 | + | PROXY="http://172.29.48.3:7891" | |
| 16 | + | ;; | |
| 17 | + | 172.29.16.1) | |
| 18 | + | PROXY="http://172.29.16.3:7891" | |
| 19 | + | ;; | |
| 20 | + | 172.29.80.1) | |
| 21 | + | PROXY="http://172.29.80.3:7891" | |
| 22 | + | ;; | |
| 23 | + | 172.29.112.1) | |
| 24 | + | PROXY="http://172.29.112.3:7891" | |
| 25 | + | ;; | |
| 26 | + | *) | |
| 27 | + | echo "未识别的默认网关: $GATEWAY" | |
| 28 | + | exit 1 | |
| 29 | + | ;; | |
| 30 | + | esac | |
| 31 | + | ||
| 32 | + | # 写入 docker 的代理配置 | |
| 33 | + | sudo bash -c "cat << UK > /etc/systemd/system/docker.service.d/http-proxy.conf | |
| 34 | + | [Service] | |
| 35 | + | Environment=\"HTTP_PROXY=$PROXY\" | |
| 36 | + | Environment=\"HTTPS_PROXY=$PROXY\" | |
| 37 | + | Environment=\"NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,192.168.0.0/16,10.0.0.0/8,172.29.0.0/16,localhost,registry.smtx.io\" | |
| 38 | + | UK" | |
| 39 | + | ||
| 40 | + | # 应用更改 | |
| 41 | + | sudo systemctl daemon-reload | |
| 42 | + | sudo systemctl restart docker | |
| 43 | + | ||
| 44 | + | # 检查代理配置是否生效 | |
| 45 | + | docker info | grep -i proxy | |
uk revisou este gist 1 year ago. Ir para a revisão
1 file changed, 9 insertions, 3 deletions
git-reset.sh
| @@ -3,11 +3,17 @@ | |||
| 3 | 3 | git status | |
| 4 | 4 | ||
| 5 | 5 | echo | |
| 6 | - | read -p "Are you sure you want to reset all local changes and pull from origin/main? This will discard all uncommitted changes. (y/n): " confirm | |
| 6 | + | read -p "Type 'y' to confirm reset and pull (Enter = yes, n = cancel): " confirm </dev/tty | |
| 7 | 7 | ||
| 8 | - | if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then | |
| 8 | + | # Treat empty input (Enter) as "y" | |
| 9 | + | confirm="${confirm:-y}" | |
| 10 | + | ||
| 11 | + | if [[ "$confirm" == "y" ]]; then | |
| 12 | + | echo "Proceeding with reset and pull..." | |
| 9 | 13 | git reset --hard HEAD && git clean -fd && git fetch origin && git pull origin main | |
| 10 | 14 | git status | |
| 15 | + | elif [[ "$confirm" == "n" ]]; then | |
| 16 | + | echo "Operation cancelled by user (n)." | |
| 11 | 17 | else | |
| 12 | - | echo "Operation cancelled." | |
| 18 | + | echo "Operation cancelled. Only 'y' or Enter will proceed." | |
| 13 | 19 | fi | |