#!/usr/bin/env bash export DEBIAN_FRONTEND=noninteractive progress_bar_task() { local pid="$1" local label="$2" local width=40 local percent=0 while kill -0 "$pid" 2>/dev/null; do percent=$((percent + 1)) ((percent > 99)) && percent=99 local filled=$((percent * width / 100)) local empty=$((width - filled)) printf "\r\033[K" >&2 printf "[%s] [" "$label" >&2 printf "\033[42m%${filled}s\033[0m" "" | tr ' ' ' ' >&2 printf "%${empty}s" "" >&2 printf "] %3d%%" "$percent" >&2 sleep 0.2 done printf "\r\033[K[%s] [" "$label" >&2 printf "\033[42m%${width}s\033[0m" "" | tr ' ' ' ' >&2 printf "] 100%%\n" >&2 } cecho() { local color="$1" local style="$2" local text if [[ $# -eq 2 ]]; then text="$2" style="" else text="$3" fi local code="" case "$color" in black) code="30" ;; red) code="31" ;; green) code="32" ;; yellow) code="33" ;; blue) code="34" ;; purple) code="35" ;; cyan) code="36" ;; white) code="37" ;; *) code="0" ;; esac case "$style" in bold) code="1;${code}" ;; dim) code="2;${code}" ;; underline) code="4;${code}" ;; esac printf "\033[%sm%s\033[0m\n" "$code" "$text" >&2 } retry() { local max=3 local n=0 until "$@"; do ((n++)) if [[ $n -ge $max ]]; then cecho red bold "[FAIL] $*(已重试 $n 次)" return 1 fi cecho yellow "[RETRY] $*(第 $n 次)" sleep 2 done } apt_run() { local msg="$1" shift apt -o Dpkg::Progress-Fancy="0" "$@" >/dev/null 2>&1 & local pid=$! progress_bar_task "$pid" "$msg" wait "$pid" } clear cecho blue bold "╭─────────────── 初始开荒脚本 ───────────────╮" cecho blue bold "│ " cecho blue bold "├── 系统更新 " cecho blue bold "│ " cecho blue bold "╰───────────────────────────────────────────╯" apt_run "获取资源" update apt_run "更新" upgrade --only-upgrade -y clear cecho blue bold "╭─────────────── 初始开荒脚本 ───────────────╮" cecho blue bold "│" cecho blue bold "├── 系统更新" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 安装常用工具" cecho blue bold "│" cecho blue bold "╰───────────────────────────────────────────╯" TOOLS=( sudo curl wget vim git zip unzip jq tree lsof trash-cli npm tmux command-not-found uuid-runtime ca-certificates unzip iproute2 whois inetutils-traceroute bash-completion psmisc file gnupg lsb-release dnsutils build-essential ) for pkg in "${TOOLS[@]}"; do if dpkg -s "$pkg" >/dev/null 2>&1; then cecho green " —— $pkg 已安装" continue fi apt -o Dpkg::Progress-Fancy="0" install -y "$pkg" >/dev/null 2>&1 & pid=$! progress_bar_task "$pid" "$pkg" wait "$pid" if dpkg -s "$pkg" >/dev/null 2>&1; then cecho green " —— $pkg 已安装" else cecho yellow " —— $pkg 失败" apt_run "修复" --fix-broken install -y dpkg --configure -a >/dev/null 2>&1 apt -o Dpkg::Progress-Fancy="0" install -y "$pkg" >/dev/null 2>&1 & pid=$! progress_bar_task "$pid" "$pkg" wait "$pid" dpkg -s "$pkg" >/dev/null 2>&1 \ && cecho green " —— $pkg 已安装" \ || cecho red " —— $pkg 放弃 " fi done clear cecho blue bold "╭─────────────── 初始开荒脚本 ───────────────╮" cecho blue bold "│" cecho blue bold "├── 系统更新" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 安装常用工具" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 环境设置" cecho blue bold "│" cecho blue bold "╰───────────────────────────────────────────╯" update-alternatives --set editor /usr/bin/vim.basic >/dev/null 2>&1 && \ DEBIAN_FRONTEND=noninteractive apt install -y unattended-upgrades \ >/dev/null 2>&1 printf "\n" >&2 dpkg-reconfigure --priority=low unattended-upgrades \ >/dev/null 2>&1 cat > /etc/ssh/sshd_config <<'EOF' #────────────────────────────────────────────────# Include /etc/ssh/sshd_config.d/*.conf #────────────────────────────────────────────────# Port 36222 #────────────────────────────────────────────────# ClientAliveInterval 30 ClientAliveCountMax 99999 TCPKeepAlive yes UseDNS no AllowAgentForwarding yes AllowTcpForwarding yes UsePAM yes X11Forwarding no GatewayPorts yes PrintMotd no #AddressFamily any ListenAddress 0.0.0.0 ListenAddress :: PermitRootLogin yes KbdInteractiveAuthentication no #────────────────────────────────────────────────# AcceptEnv LANG LC_* Subsystem sftp /usr/lib/openssh/sftp-server #────────────────────────────────────────────────# PasswordAuthentication no PubkeyAuthentication yes #────────────────────────────────────────────────# EOF sed -i 's/^session\s\+optional\s\+pam_motd.so/#&/' /etc/pam.d/sshd sed -i 's/^session\s\+optional\s\+pam_motd.so/#&/' /etc/pam.d/login sed -i 's/^ENABLED=.*/ENABLED=0/' /etc/default/motd-news cat > /root/.bashrc <<'EOF' #────────────────────────────────────────────────────────────────────# case $- in *i*) ;; *) return;; esac #────────────────────────────────────────────────────────────────────# HISTCONTROL=ignoreboth shopt -s histappend HISTSIZE=1000 HISTFILESIZE=2000 shopt -s checkwinsize #────────────────────────────────────────────────────────────────────# [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" #────────────────────────────────────────────────────────────────────# if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi #────────────────────────────────────────────────────────────────────# case "$TERM" in xterm-color|*-256color) color_prompt=yes;; esac #────────────────────────────────────────────────────────────────────# force_color_prompt=yes #────────────────────────────────────────────────────────────────────# if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then color_prompt=yes else color_prompt= fi fi #────────────────────────────────────────────────────────────────────# if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt #────────────────────────────────────────────────────────────────────# case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac #────────────────────────────────────────────────────────────────────# if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi #────────────────────────────────────────────────────────────────────# export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' alias nr='systemctl restart nginx' #────────────────────────────────────────────────────────────────────# alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' #────────────────────────────────────────────────────────────────────# if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi #────────────────────────────────────────────────────────────────────# if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi #────────────────────────────────────────────────────────────────────# export PNPM_HOME="/root/.local/share/pnpm" case ":$PATH:" in *":$PNPM_HOME:"*) ;; *) export PATH="$PNPM_HOME:$PATH" ;; esac #────────────────────────────────────────────────────────────────────# export BUN_INSTALL="$HOME/.bun" export PATH="$BUN_INSTALL/bin:$PATH" alias rm='trash-put' alias php81='php81 -c /www/server/php/81/etc/php-cli.ini' #────────────────────────────────────────────────────────────────────# EOF sourc ~/.bashrc echo "root:Cici080306" | chpasswd mkdir -p ~/.ssh echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE8JPWLWvE+kYH6vPHi3hsF4+vxTKLKmwnq8lFEmjOzE Vesper-SSH" >> ~/.ssh/authorized_keys echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMhyl2z6m5nPMze0pkZNDNLlXssvcyIk7o3WUjJXLYwv yomo@iPhone' >> ~/.ssh/authorized_keys chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys timedatectl set-timezone Asia/Shanghai >/dev/null 2>&1 locale >/dev/null 2>&1 locale-gen zh_CN.UTF-8 >/dev/null 2>&1 update-locale LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 >/dev/null 2>&1 cat /etc/default/locale >/dev/null 2>&1 export LANG=zh_CN.UTF-8 >/dev/null 2>&1 export LC_ALL=zh_CN.UTF-8 >/dev/null 2>&1 apt_run "安装zh语言包" install -y language-pack-zh-hans clear cecho blue bold "╭─────────────── 初始开荒脚本 ───────────────╮" cecho blue bold "│" cecho blue bold "├── 系统更新" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 安装常用工具" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 环境设置" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 清理系统垃圾" cecho blue bold "│" cecho blue bold "╰───────────────────────────────────────────╯" apt_run "apt autoremove" autoremove -y apt autoclean -y >/dev/null 2>&1 clear cecho blue bold "╭─────────────── 初始开荒脚本 ───────────────╮" cecho blue bold "│" cecho blue bold "├── 系统更新" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 安装常用工具" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 环境设置" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "├── 清理系统垃圾" cecho blue bold "│ └─ [完成]" cecho blue bold "│" cecho blue bold "╰────────────────感谢使用本脚本───────────────╯"