CentOS/Debian/Ubuntu网络重装系统一键脚本

文章目录
  • 背景
  • 运行要求
  • 安装脚本
  • 注意事项
  • 完整代码

文章转载自 如有乐享 & 萌咖 & 狗仔小分队的博客

特别注意: OpenVZ构架不适用,安装之前备份重要数据。

背景

适用于由GRUB引导的CentOS,Ubuntu,Debian系统. 使用官方发行版去掉模板预装的软件。 同时也可以解决内核版本与软件不兼容的问题。 只要有root权限,还您一个纯净的系统。

运行要求

  • Debian/Ubuntu/CentOS 系统(由 GRUB引导);
  • wget 用来下载文件,获取公网IP;
  • ip 获取网关,掩码等;
  • sed awk grep 处理文本流;
  • VNC 安装系统(此项为可选)。
  • 安装脚本

    全自动安装默认 root 密码: Vicer,安装完成后请立即更改密码。

    Debian 7 x32

    1 2 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d 7 –v 32

    Debian 7 x64

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d 7 –v 64

    Debian 8 x32

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d 8 –v 32

    Debian 8 x64

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d 8 –v 64

    Debian 9 x32

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d 9 –v 32

    Debian 9 x64

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d 9 –v 64

    Ubuntu 14.04 x32

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d trusty –v 32

    Ubuntu 14.04 x64

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d trusty –v 64

    Ubuntu 16.04 x32

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d xenial –v 32

    Ubuntu 16.04 x64

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d xenial –v 64

    Ubuntu 17.04 x32

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d zesty –v 32

    Ubuntu 17.04 x64

    1 wget —no–check–certificate –qO DebianNET.sh ‘https://moeclub.org/attachment/LinuxShell/DebianNET.sh’ && chmod –x DebianNET.sh && bash DebianNET.sh –d zesty –v 64

    CentOS 6+ X64

    1

    wget xiaofd.github.io/centos.sh && bash centos.sh

    安装时间(Vultr 2.5美元机器 重装大概15分钟) root用户密码为 xiaofd.win

    注意事项

    确保安装了所需软件:

    1 2 3 4 5 #Debian/Ubuntu: apt–get install –y gawk sed grep #RedHat/CentOS: yum install –y gawk sed grep
    如果出现了错误,请运行:
    1 2 3 4 5 #Debian/Ubuntu: apt–get update #RedHat/CentOS: yum update

    在安装Ubuntu时,可能会遇到:

    Getting the time form a network time server...

    界面进度条很长时间不会动,可以等待它超时或者更换别的版本. 该问题是Ubuntu系统的问题.

    完整代码

    #!/bin/bash while [[ $# -ge 1 ]]; do case $1 in -v|--ver) shift VERtmp="$1" shift ;; -d|--debian|--ubuntu) shift vDEBtmp="$1" shift ;; -p|--password) shift WDtmp="$1" shift ;; -a|--auto) shift INStmp='auto' ;; -m|--manual) shift INStmp='manual' ;; -apt|--mirror) shift isMirror='1' tmpMirror="$1" shift ;; *) echo -ne " Usage:\n\tbash $0\t-d/--debian [7/\033[33m\033[04mwheezy\033[0m|8/jessie|9/stretch]\n\t\t\t\t-v/--ver [32/\033[33m\033[04mi386\033[0m|64/amd64]\n\t\t\t\t-apt/--mirror\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n" exit 1; ;; esac done [ $EUID -ne 0 ] && echo "Error:This script must be run as root!" && exit 1 [ -f /boot/grub/grub.cfg ] && GRUBOLD='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg' [ -z $GRUBDIR ] && [ -f /boot/grub2/grub.cfg ] && GRUBOLD='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg' [ -z $GRUBDIR ] && [ -f /boot/grub/grub.conf ] && GRUBOLD='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf' [ -z $GRUBDIR -o -z $GRUBFILE ] && echo "Error! Not Found grub path." && exit 1 [ -n $vDEBtmp ] && { [ "$vDEBtmp" == '7' -o "$vDEBtmp" == 'wheezy' ] && linuxdists='debian' && vDEB='wheezy'; [ "$vDEBtmp" == '8' -o "$vDEBtmp" == 'jessie' ] && linuxdists='debian' && vDEB='jessie'; [ "$vDEBtmp" == '9' -o "$vDEBtmp" == 'stretch' ] && linuxdists='debian' && vDEB='stretch'; [ "$vDEBtmp" == 'precise' ] && linuxdists='ubuntu' && vDEB='precise'; [ "$vDEBtmp" == 'trusty' ] && linuxdists='ubuntu' && vDEB='trusty'; [ "$vDEBtmp" == 'wily' ] && linuxdists='ubuntu' && vDEB='wily'; [ "$vDEBtmp" == 'xenial' ] && linuxdists='ubuntu' && vDEB='xenial'; [ "$vDEBtmp" == 'yakkety' ] && linuxdists='ubuntu' && vDEB='yakkety'; [ "$vDEBtmp" == 'zesty' ] && linuxdists='ubuntu' && vDEB='zesty'; } [ -n $vDEBtmp ] && { [ "$VERtmp" == '32' -o "$VERtmp" == 'i386' ] && VER='i386'; [ "$VERtmp" == '64' -o "$VERtmp" == 'amd64' ] && VER='amd64'; } [ -z $linuxdists ] && linuxdists='debian' [ -n $isMirror ] && [ "$isMirror" == '1' ] && [ -n $tmpMirror ] && { tmpDebianMirror="$(echo -n "$tmpMirror" |grep -Eo '.*\.(\w+)')" echo -n "$tmpDebianMirror" |grep -q '://' [ $? -eq '0' ] && { DebianMirror="$(echo -n "$tmpDebianMirror" |awk -F'://' '{print $2}')" } || { DebianMirror="$(echo -n "$tmpDebianMirror")" } } || { [[ $linuxdists == 'debian' ]] && DebianMirror='httpredir.debian.org' [[ $linuxdists == 'ubuntu' ]] && DebianMirror='archive.ubuntu.com' } [ -z $DebianMirrorDirectory ] && [ -n $DebianMirror ] && [ -n $tmpMirror ] && { DebianMirrorDirectory="$(echo -n "$tmpMirror" |awk -F''${DebianMirror}'' '{print $2}' |sed 's/\/$//g')" } [ "$DebianMirrorDirectory" == '/' ] && [ -n $DebianMirror ] && { [[ $linuxdists == 'debian' ]] && DebianMirrorDirectory='/debian' [[ $linuxdists == 'ubuntu' ]] && DebianMirrorDirectory='/ubuntu' } [ -z $DebianMirrorDirectory ] && [ -n $DebianMirror ] && { [[ $linuxdists == 'debian' ]] && DebianMirrorDirectory='/debian' [[ $linuxdists == 'ubuntu' ]] && DebianMirrorDirectory='/ubuntu' } [ -n $INStmp ] && { [ "$INStmp" == 'auto' ] && inVNC='n' [ "$INStmp" == 'manual' ] && inVNC='y' } [ -n $WDtmp ] && myPASSWORD="$WDtmp" [ -z $vDEB ] && vDEB='wheezy'; [ -z $VER ] && VER='i386'; [ -z $myPASSWORD ] && myPASSWORD='Vicer' clear && echo -e "\n\033[36m# Install\033[0m\n" [ -z $inVNC ] && ASKVNC(){ inVNC='y'; echo -ne "\033[34mCan you login VNC?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m " read inVNCtmp [[ -n "$inVNCtmp" ]] && inVNC=$inVNCtmp [ "$inVNC" == 'y' -o "$inVNC" == 'Y' ] && inVNC='y' [ "$inVNC" == 'n' -o "$inVNC" == 'N' ] && inVNC='n' } [ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC; [[ $linuxdists == 'debian' ]] && LinuxName='Debian' [[ $linuxdists == 'ubuntu' ]] && LinuxName='Ubuntu' [ "$inVNC" == 'y' ] && echo -e "\033[34mManual Mode\033[0m insatll \033[33m$LinuxName\033[0m [\033[33m$vDEB\033[0m] [\033[33m$VER\033[0m] in VNC. " [ "$inVNC" == 'n' ] && echo -e "\033[34mAuto Mode\033[0m insatll \033[33m$LinuxName\033[0m [\033[33m$vDEB\033[0m] [\033[33m$VER\033[0m]. " echo -e "\n[\033[33m$vDEB\033[0m] [\033[33m$VER\033[0m] Downloading..." [ -z $DebianMirror ] && echo -ne "\033[31mError! \033[0mGet debian mirror fail! \n" && exit 1 [ -z $DebianMirrorDirectory ] && echo -ne "\033[31mError! \033[0mGet debian mirror directory fail! \n" && exit 1 wget --no-check-certificate -qO '/boot/initrd.gz' "http://$DebianMirror$DebianMirrorDirectory/dists/$vDEB/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/initrd.gz" [ $? -ne '0' ] && echo -ne "\033[31mError! \033[0mDownload 'initrd.gz' failed! \n" && exit 1 wget --no-check-certificate -qO '/boot/linux' "http://$DebianMirror$DebianMirrorDirectory/dists/$vDEB/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/linux" [ $? -ne '0' ] && echo -ne "\033[31mError! \033[0mDownload 'linux' failed! \n" && exit 1 DEFAULTNET="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')" [ -n "$DEFAULTNET" ] && IPSUB="$(ip addr |grep ''${DEFAULTNET}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')" IPv4="$(echo -n "$IPSUB" |cut -d'/' -f1)" NETSUB="$(echo -n "$IPSUB" |grep -o '/[0-9]\{1,2\}')" GATE="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')" [ -n "$NETSUB" ] && MASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${NETSUB}'' |cut -d'/' -f1)" [ -n "$GATE" ] && [ -n "$MASK" ] && [ -n "$IPv4" ] || { echo "Not found `ip command`, It will use `route command`." ipNum() { local IFS='.' read ip1 ip2 ip3 ip4 /boot/tmp/preseed.cfg/dev/null 2>&1

    推荐站内搜索:最新域名查询、国外vps服务器租用、美国主机网、永久免费云服务器地址、租用服务器、国外服务器、国内免备案主机、域名空间注册、域名 注册、美国服务器网站、