<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="Debian(Ubuntu)网络安装/重装一键脚本">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">admin</a><br />时间:2017-03-25 12:50<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">电脑技术</a><br />内容:
Debian(Ubuntu)网络安装/重装一键脚本背景:

适用于由GRUB引导的CentOS,Ubuntu,Debian系统.

使用官方发行版去掉模板预装的软件.

同时也可以解决内核版本与软件不兼容的问题。

只要有root权限,还您一个纯净的系统。

注意:

全自动安装默认root密码: Vicer,安装完成后请立即更改密码.

请使用 passwd root 命令更改密码.

特别注意: OpenVZ 架不适用.

需要:

1. Debian/Ubuntu/CentOS 系统(由 GRUB 引导)；

2. wget 用来下载文件，获取公网IP;

3. ip 获取网关，掩码等;

4. sed awk grep 处理文本流；

5. VNC 安装系统(此项为可选)。

#Debian/Ubuntu:

apt-get install -y gawk sed grep

#RedHat/CentOS:

yum install -y gawk sed grep

如果出现了错误,请运行:

 #Debian/Ubuntu:

apt-get update

#RedHat/CentOS:

yum update

一键下载及使用:

wget --no-check-certificate -qO DebianNET.sh 'https://moeclub.org/attachment/LinuxShell/DebianNET.sh' &amp;&amp; chmod -x DebianNET.sh

Usage:

bash DebianNET.sh       -d/--debian [7/wheezy|8/jessie|9/stretch]

                                   -v/--ver [32/i386|64/amd64]

安装示例:

全自动安装:

bash DebianNET.sh -d wheezy -v i386 -a

VNC手动安装:

bash DebianNET.sh -d wheezy -v i386 -m

使用:

【默认】安装Debian 7 x32：

bash DebianNET.sh -d wheezy -v i386

-或者

bash DebianNET.sh -d 7 -v 32

安装Debian 7 x64：

bash DebianNET.sh -d wheezy -v amd64

-或者

bash DebianNET.sh -d 7 -v 64

安装Debian 8 x32：

bash DebianNET.sh -d jessie -v i386

-或者

bash DebianNET.sh -d 8 -v 32

安装Debian 8 x64：

bash DebianNET.sh -d jessie -v amd64

-或者

bash DebianNET.sh -d 8 -v 64

安装Debian 9 x32：

bash DebianNET.sh -d stretch -v i386

-或者

bash DebianNET.sh -d 9 -v 32

安装Debian 9 x64：

bash DebianNET.sh -d stretch -v amd64

-或者

bash DebianNET.sh -d 9 -v 64

安装Ubuntu 14.04 x32：

bash DebianNET.sh -d trusty -v 32

安装Ubuntu 14.04 x64：

bash DebianNET.sh -d trusty -v 64

安装Debian 16.04 x32：

bash DebianNET.sh -d xenial -v 32

安装Debian 16.04 x64：

bash DebianNET.sh -d xenial -v 64

安装Debian 17.04 x32：

bash DebianNET.sh -d zesty -v 32

安装Debian 17.04 x64：

bash DebianNET.sh -d zesty -v 64



完整代码:



XML/HTML代码


    #!/bin/bash  

       

    while [[ $# -ge 1 ]]; do  

      case $1 in  

        -v|--ver)  

          shift  

          VERtmp=&quot;$1&quot;  

          shift  

          ;;  

        -d|--debian|--ubuntu)  

          shift  

          vDEBtmp=&quot;$1&quot;  

          shift  

          ;;  

        -p|--password)  

          shift  

          WDtmp=&quot;$1&quot;  

          shift  

          ;;  

        -a|--auto)  

          shift  

          INStmp='auto'  

          ;;  

        -m|--manual)  

          shift  

          INStmp='manual'  

          ;;  

        -apt|--mirror)  

          shift  

          isMirror='1'  

          tmpMirror=&quot;$1&quot;  

          shift  

          ;;  

        *)  

          echo -ne &quot; 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&quot;  

          exit 1;  

          ;;  

        esac  

      done  

       

    [ $EUID -ne 0 ] &amp;&amp; echo &quot;Error:This script must be run as root!&quot; &amp;&amp; exit 1  

    [ -f /boot/grub/grub.cfg ] &amp;&amp; GRUBOLD='0' &amp;&amp; GRUBDIR='/boot/grub' &amp;&amp; GRUBFILE='grub.cfg'  

    [ -z $GRUBDIR ] &amp;&amp; [ -f /boot/grub2/grub.cfg ] &amp;&amp; GRUBOLD='0' &amp;&amp; GRUBDIR='/boot/grub2' &amp;&amp; GRUBFILE='grub.cfg'  

    [ -z $GRUBDIR ] &amp;&amp; [ -f /boot/grub/grub.conf ] &amp;&amp; GRUBOLD='1' &amp;&amp; GRUBDIR='/boot/grub' &amp;&amp; GRUBFILE='grub.conf'  

    [ -z $GRUBDIR -o -z $GRUBFILE ] &amp;&amp; echo &quot;Error! Not Found grub path.&quot; &amp;&amp; exit 1  

       

    [ -n $vDEBtmp ] &amp;&amp; {  

    [ &quot;$vDEBtmp&quot; == '7' -o &quot;$vDEBtmp&quot; == 'wheezy' ] &amp;&amp; linuxdists='debian' &amp;&amp; vDEB='wheezy';  

    [ &quot;$vDEBtmp&quot; == '8' -o &quot;$vDEBtmp&quot; == 'jessie' ] &amp;&amp; linuxdists='debian' &amp;&amp; vDEB='jessie';  

    [ &quot;$vDEBtmp&quot; == '9' -o &quot;$vDEBtmp&quot; == 'stretch' ] &amp;&amp; linuxdists='debian' &amp;&amp; vDEB='stretch';  

    [ &quot;$vDEBtmp&quot; == 'precise' ] &amp;&amp; linuxdists='ubuntu' &amp;&amp; vDEB='precise';  

    [ &quot;$vDEBtmp&quot; == 'trusty' ] &amp;&amp; linuxdists='ubuntu' &amp;&amp; vDEB='trusty';  

    [ &quot;$vDEBtmp&quot; == 'wily' ] &amp;&amp; linuxdists='ubuntu' &amp;&amp; vDEB='wily';  

    [ &quot;$vDEBtmp&quot; == 'xenial' ] &amp;&amp; linuxdists='ubuntu' &amp;&amp; vDEB='xenial';  

    [ &quot;$vDEBtmp&quot; == 'yakkety' ] &amp;&amp; linuxdists='ubuntu' &amp;&amp; vDEB='yakkety';  

    [ &quot;$vDEBtmp&quot; == 'zesty' ] &amp;&amp; linuxdists='ubuntu' &amp;&amp; vDEB='zesty';  

    }  

    [ -n $vDEBtmp ] &amp;&amp; {  

    [ &quot;$VERtmp&quot; == '32' -o &quot;$VERtmp&quot; == 'i386' ] &amp;&amp; VER='i386';  

    [ &quot;$VERtmp&quot; == '64' -o &quot;$VERtmp&quot; == 'amd64' ] &amp;&amp; VER='amd64';  

    }  

       

    [ -z $linuxdists ] &amp;&amp; linuxdists='debian'  

    [ -n $isMirror ] &amp;&amp; [ &quot;$isMirror&quot; == '1' ] &amp;&amp; [ -n $tmpMirror ] &amp;&amp; {  

    tmpDebianMirror=&quot;$(echo -n &quot;$tmpMirror&quot; |grep -Eo '.*\.(\w+)')&quot;  

    echo -n &quot;$tmpDebianMirror&quot; |grep -q '://'  

    [ $? -eq '0' ] &amp;&amp; {  

    DebianMirror=&quot;$(echo -n &quot;$tmpDebianMirror&quot; |awk -F'://' '{print $2}')&quot;  

    } || {  

    DebianMirror=&quot;$(echo -n &quot;$tmpDebianMirror&quot;)&quot;  

    }  

    } || {  

    [[ $linuxdists == 'debian' ]] &amp;&amp; DebianMirror='httpredir.debian.org'  

    [[ $linuxdists == 'ubuntu' ]] &amp;&amp; DebianMirror='archive.ubuntu.com'  

    }  

    [ -z $DebianMirrorDirectory ] &amp;&amp; [ -n $DebianMirror ] &amp;&amp; [ -n $tmpMirror ] &amp;&amp; {  

    DebianMirrorDirectory=&quot;$(echo -n &quot;$tmpMirror&quot; |awk -F''${DebianMirror}'' '{print $2}' |sed 's/\/$//g')&quot;  

    }  

    [ &quot;$DebianMirrorDirectory&quot; == '/' ] &amp;&amp; [ -n $DebianMirror ] &amp;&amp; {  

    [[ $linuxdists == 'debian' ]] &amp;&amp; DebianMirrorDirectory='/debian'  

    [[ $linuxdists == 'ubuntu' ]] &amp;&amp; DebianMirrorDirectory='/ubuntu'  

    }  

    [ -z $DebianMirrorDirectory ] &amp;&amp; [ -n $DebianMirror ] &amp;&amp; {  

    [[ $linuxdists == 'debian' ]] &amp;&amp; DebianMirrorDirectory='/debian'  

    [[ $linuxdists == 'ubuntu' ]] &amp;&amp; DebianMirrorDirectory='/ubuntu'  

    }  

       

    [ -n $INStmp ] &amp;&amp; {  

    [ &quot;$INStmp&quot; == 'auto' ] &amp;&amp; inVNC='n'  

    [ &quot;$INStmp&quot; == 'manual' ] &amp;&amp; inVNC='y'  

    }  

    [ -n $WDtmp ] &amp;&amp; myPASSWORD=&quot;$WDtmp&quot;  

       

    [ -z $vDEB ] &amp;&amp; vDEB='wheezy';  

    [ -z $VER ] &amp;&amp; VER='i386';  

    [ -z $myPASSWORD ] &amp;&amp; myPASSWORD='Vicer'  

       

    clear &amp;&amp; echo -e &quot;\n\033[36m# Install\033[0m\n&quot;  

       

    [ -z $inVNC ] &amp;&amp; ASKVNC(){  

    inVNC='y';  

    echo -ne &quot;\033[34mCan you login VNC?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m &quot;  

    read inVNCtmp  

    [[ -n &quot;$inVNCtmp&quot; ]] &amp;&amp; inVNC=$inVNCtmp  

    [ &quot;$inVNC&quot; == 'y' -o &quot;$inVNC&quot; == 'Y' ] &amp;&amp; inVNC='y'  

    [ &quot;$inVNC&quot; == 'n' -o &quot;$inVNC&quot; == 'N' ] &amp;&amp; inVNC='n'  

    }  

       

    [ &quot;$inVNC&quot; == 'y' -o &quot;$inVNC&quot; == 'n' ] || ASKVNC;  

       

    [[ $linuxdists == 'debian' ]] &amp;&amp; LinuxName='Debian'  

    [[ $linuxdists == 'ubuntu' ]] &amp;&amp; LinuxName='Ubuntu'  

    [ &quot;$inVNC&quot; == 'y' ] &amp;&amp; echo -e &quot;\033[34mManual Mode\033[0m insatll \033[33m$LinuxName\033[0m [\033[33m$vDEB\033[0m] [\033[33m$VER\033[0m] in VNC. &quot;  

    [ &quot;$inVNC&quot; == 'n' ] &amp;&amp; echo -e &quot;\033[34mAuto Mode\033[0m insatll \033[33m$LinuxName\033[0m [\033[33m$vDEB\033[0m] [\033[33m$VER\033[0m]. &quot;  

       

    echo -e &quot;\n[\033[33m$vDEB\033[0m] [\033[33m$VER\033[0m] Downloading...&quot;  

    [ -z $DebianMirror ] &amp;&amp; echo -ne &quot;\033[31mError! \033[0mGet debian mirror fail! \n&quot; &amp;&amp; exit 1  

    [ -z $DebianMirrorDirectory ] &amp;&amp; echo -ne &quot;\033[31mError! \033[0mGet debian mirror directory fail! \n&quot; &amp;&amp; exit 1  

    wget --no-check-certificate -qO '/boot/initrd.gz' &quot;http://$DebianMirror$DebianMirrorDirectory/dists/$vDEB/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/initrd.gz&quot;  

    [ $? -ne '0' ] &amp;&amp; echo -ne &quot;\033[31mError! \033[0mDownload 'initrd.gz' failed! \n&quot; &amp;&amp; exit 1  

    wget --no-check-certificate -qO '/boot/linux' &quot;http://$DebianMirror$DebianMirrorDirectory/dists/$vDEB/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/linux&quot;  

    [ $? -ne '0' ] &amp;&amp; echo -ne &quot;\033[31mError! \033[0mDownload 'linux' failed! \n&quot; &amp;&amp; exit 1  

       

    DEFAULTNET=&quot;$(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}')&quot;  

    [ -n &quot;$DEFAULTNET&quot; ] &amp;&amp; IPSUB=&quot;$(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\}')&quot;  

    IPv4=&quot;$(echo -n &quot;$IPSUB&quot; |cut -d'/' -f1)&quot;  

    NETSUB=&quot;$(echo -n &quot;$IPSUB&quot; |grep -o '/[0-9]\{1,2\}')&quot;  

    GATE=&quot;$(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\}')&quot;  

    [ -n &quot;$NETSUB&quot; ] &amp;&amp; MASK=&quot;$(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)&quot;  

       

    [ -n &quot;$GATE&quot; ] &amp;&amp; [ -n &quot;$MASK&quot; ] &amp;&amp; [ -n &quot;$IPv4&quot; ] || {  

    echo &quot;Not found `ip command`, It will use `route command`.&quot;  

    ipNum() {  

      local IFS='.'  

      read ip1 ip2 ip3 ip4 &lt;&lt;&lt;&quot;$1&quot;  

      echo $((ip1*(1&lt;&lt;24)+ip2*(1&lt;&lt;16)+ip3*(1&lt;&lt;8)+ip4))  

    }  

       

    SelectMax(){  

    ii=0  

    for IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'`  

      do  

        NumTMP=&quot;$(ipNum $IPITEM)&quot;  

        eval &quot;arrayNum[$ii]='$NumTMP,$IPITEM'&quot;  

        ii=$[$ii+1]  

      done  

    echo ${arrayNum[@]} |sed 's/\s/\n/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2  

    }  

       

    [[ -z $IPv4 ]] &amp;&amp; IPv4=&quot;$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1)&quot;  

    [[ -z $GATE ]] &amp;&amp; GATE=&quot;$(SelectMax 2)&quot;  

    [[ -z $MASK ]] &amp;&amp; MASK=&quot;$(SelectMax 3)&quot;  

       

    [ -n &quot;$GATE&quot; ] &amp;&amp; [ -n &quot;$MASK&quot; ] &amp;&amp; [ -n &quot;$IPv4&quot; ] || {  

    echo &quot;Error! Not configure network. &quot;  

    exit 1  

    }  

    }  

       

    [ -f /etc/network/interfaces ] &amp;&amp; {  

    [[ -z &quot;$(sed -n '/iface.*inet static/p' /etc/network/interfaces)&quot; ]] &amp;&amp; AutoNet='1' || AutoNet='0'  

    [ -d /etc/network/interfaces.d ] &amp;&amp; {  

    ICFGN=&quot;$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)&quot; || ICFGN='0'  

    [ &quot;$ICFGN&quot; -ne '0' ] &amp;&amp; {  

    for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`  

    do   

      [[ -z &quot;$(cat $NetCFG | sed -n '/iface.*inet static/p')&quot; ]] &amp;&amp; AutoNet='1' || AutoNet='0'  

      [ &quot;$AutoNet&quot; -eq '0' ] &amp;&amp; break  

    done  

    }  

    }  

    }  

    [ -d /etc/sysconfig/network-scripts ] &amp;&amp; {  

    ICFGN=&quot;$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)&quot; || ICFGN='0'  

    [ &quot;$ICFGN&quot; -ne '0' ] &amp;&amp; {  

    for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\{1,\}'`  

    do   

      [[ -n &quot;$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')&quot; ]] &amp;&amp; AutoNet='1' || {  

      AutoNet='0' &amp;&amp; . $NetCFG  

      [ -n $NETMASK ] &amp;&amp; MASK=&quot;$NETMASK&quot;  

      [ -n $GATEWAY ] &amp;&amp; GATE=&quot;$GATEWAY&quot;  

    }  

      [ &quot;$AutoNet&quot; -eq '0' ] &amp;&amp; break  

    done  

    }  

    }  

       

    [ ! -f $GRUBDIR/$GRUBFILE ] &amp;&amp; echo &quot;Error! Not Found $GRUBFILE. &quot; &amp;&amp; exit 1  

       

    [ ! -f $GRUBDIR/$GRUBFILE.old ] &amp;&amp; [ -f $GRUBDIR/$GRUBFILE.bak ] &amp;&amp; mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old  

    mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak  

    [ -f $GRUBDIR/$GRUBFILE.old ] &amp;&amp; cat $GRUBDIR/$GRUBFILE.old &gt;$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak &gt;$GRUBDIR/$GRUBFILE  

       

    [ &quot;$GRUBOLD&quot; == '0' ] &amp;&amp; {  

    CFG0=&quot;$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)&quot;  

    CFG2=&quot;$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)&quot;  

    CFG1=&quot;&quot;  

    for CFGtmp in `awk '/}/{print NR}' $GRUBDIR/$GRUBFILE`  

    do  

      [ $CFGtmp -gt &quot;$CFG0&quot; -a $CFGtmp -lt &quot;$CFG2&quot; ] &amp;&amp; CFG1=&quot;$CFGtmp&quot;;  

    done  

    [ -z &quot;$CFG1&quot; ] &amp;&amp; {  

    echo &quot;Error! read $GRUBFILE. &quot;  

    exit 1  

    }  

    sed -n &quot;$CFG0,$CFG1&quot;p $GRUBDIR/$GRUBFILE &gt;/tmp/grub.new  

    [ -f /tmp/grub.new ] &amp;&amp; [ &quot;$(grep -c '{' /tmp/grub.new)&quot; -eq &quot;$(grep -c '}' /tmp/grub.new)&quot; ] || {  

    echo -ne &quot;\033[31mError! \033[0mNot configure $GRUBFILE. \n&quot;  

    exit 1  

    }  

       

    sed -i &quot;/menuentry.*/c\menuentry\ \'Install OS \[$vDEB\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{&quot; /tmp/grub.new  

    [ &quot;$(grep -c '{' /tmp/grub.new)&quot; -eq &quot;$(grep -c '}' /tmp/grub.new)&quot; ] || {  

    echo &quot;Error! configure append $GRUBFILE. &quot;  

    exit 1  

    }  

    sed -i &quot;/echo.*Loading/d&quot; /tmp/grub.new  

    }  

       

    [ &quot;$GRUBOLD&quot; == '1' ] &amp;&amp; {  

    CFG0=&quot;$(awk '/title /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)&quot;  

    CFG1=&quot;$(awk '/title /{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)&quot;  

    [ -n $CFG0 ] &amp;&amp; [ -z $CFG1 -o $CFG1 == $CFG0 ] &amp;&amp; sed -n &quot;$CFG0,$&quot;p $GRUBDIR/$GRUBFILE &gt;/tmp/grub.new  

    [ -n $CFG0 ] &amp;&amp; [ -z $CFG1 -o $CFG1 != $CFG0 ] &amp;&amp; sed -n &quot;$CFG0,$CFG1&quot;p $GRUBDIR/$GRUBFILE &gt;/tmp/grub.new  

    [ ! -f /tmp/grub.new ] &amp;&amp; echo &quot;Error! configure append $GRUBFILE. &quot; &amp;&amp; exit 1  

    sed -i &quot;/title.*/c\title\ \'Install OS \[$vDEB\ $VER\]\'&quot; /tmp/grub.new  

    sed -i '/^#/d' /tmp/grub.new  

    }  

       

    [ -n &quot;$(grep 'initrd.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')&quot; ] &amp;&amp; Type='InBoot' || Type='NoBoot'  

       

    LinuxKernel=&quot;$(grep 'linux.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)&quot;  

    [ -z $LinuxKernel ] &amp;&amp; LinuxKernel=&quot;$(grep 'kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)&quot;  

    LinuxIMG=&quot;$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)&quot;  

       

    [ &quot;$Type&quot; == 'InBoot' ] &amp;&amp; {  

    sed -i &quot;/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/linux auto=true hostname=$linuxdists domain= -- quiet&quot; /tmp/grub.new  

    sed -i &quot;/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.gz&quot; /tmp/grub.new  

    }  

       

    [ &quot;$Type&quot; == 'NoBoot' ] &amp;&amp; {  

    sed -i &quot;/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/linux auto=true hostname=$linuxdists domain= -- quiet&quot; /tmp/grub.new  

    sed -i &quot;/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.gz&quot; /tmp/grub.new  

    }  

       

    sed -i '$a\\n' /tmp/grub.new  

       

    [ &quot;$inVNC&quot; == 'n' ] &amp;&amp; {  

    GRUBPATCH='0'  

    [ -f /etc/network/interfaces -o -d /etc/sysconfig/network-scripts ] &amp;&amp; {  

    sed -i ''${CFG0}'i\\n' $GRUBDIR/$GRUBFILE  

    sed -i ''${CFG0}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE  

    [ -z $AutoNet ] &amp;&amp; echo &quot;Error, Not found interfaces config.&quot; &amp;&amp; exit 1  

    [ -f  $GRUBDIR/grubenv ] &amp;&amp; sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv  

    [ -d /boot/tmp ] &amp;&amp; rm -rf /boot/tmp  

    mkdir -p /boot/tmp/  

    cd /boot/tmp/  

    gzip -d &lt; ../initrd.gz | cpio --extract --verbose --make-directories --no-absolute-filenames &gt;&gt;/dev/null 2&gt;&amp;1  

    cat &gt;/boot/tmp/preseed.cfg&lt;&lt;EOF  

    d-i debian-installer/locale string en_US  

    d-i console-setup/layoutcode string us  

       

    d-i keyboard-configuration/xkb-keymap string us  

       

    d-i netcfg/choose_interface select auto  

       

    d-i netcfg/disable_autoconfig boolean true  

    d-i netcfg/dhcp_failed note  

    d-i netcfg/dhcp_options select Configure network manually  

    d-i netcfg/get_ipaddress string $IPv4  

    d-i netcfg/get_netmask string $MASK  

    d-i netcfg/get_gateway string $GATE  

    d-i netcfg/get_nameservers string 8.8.8.8  

    d-i netcfg/no_default_route boolean true  

    d-i netcfg/confirm_static boolean true  

       

    d-i mirror/country string manual  

    d-i mirror/http/hostname string $DebianMirror  

    d-i mirror/http/directory string $DebianMirrorDirectory  

    d-i mirror/http/proxy string  

       

    d-i passwd/root-login boolean ture  

    d-i passwd/make-user boolean false  

    d-i passwd/root-password password $myPASSWORD  

    d-i passwd/root-password-again password $myPASSWORD  

    d-i user-setup/allow-password-weak boolean true  

    d-i user-setup/encrypt-home boolean false  

       

    d-i clock-setup/utc boolean true  

    d-i time/zone string US/Eastern  

    d-i clock-setup/ntp boolean true  

       

    d-i partman/early_command string \  

    debconf-set partman-auto/disk &quot;\$(list-devices disk |head -n1)&quot;; \  

    debconf-set grub-installer/bootdev string &quot;\$(list-devices disk |head -n1)&quot;; \  

    umount /media || true;  

    d-i partman/mount_style select uuid  

    d-i partman-auto/init_automatically_partition select Guided - use entire disk  

    d-i partman-auto/method string regular  

    d-i partman-lvm/device_remove_lvm boolean true  

    d-i partman-md/device_remove_md boolean true  

    d-i partman-auto/choose_recipe select atomic  

    d-i partman-partitioning/confirm_write_new_label boolean true  

    d-i partman/choose_partition select finish  

    d-i partman-lvm/confirm boolean true  

    d-i partman-lvm/confirm_nooverwrite boolean true  

    d-i partman/confirm boolean true  

    d-i partman/confirm_nooverwrite boolean true  

       

    d-i debian-installer/allow_unauthenticated boolean true  

       

    tasksel tasksel/first multiselect minimal  

    d-i pkgsel/update-policy select none  

    d-i pkgsel/include string openssh-server  

    d-i pkgsel/upgrade select none  

       

    popularity-contest popularity-contest/participate boolean false  

       

    d-i grub-installer/only_debian boolean true  

    d-i grub-installer/bootdev string default  

    d-i finish-install/reboot_in_progress note  

    d-i debian-installer/exit/reboot boolean true  

    d-i preseed/late_command string \  

    sed -i 's/^.*PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \  

    sed -i 's/^.*PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config;  

    EOF  

    [ &quot;$AutoNet&quot; -eq '1' ] &amp;&amp; {  

    sed -i '/netcfg\/disable_autoconfig/d' /boot/tmp/preseed.cfg  

    sed -i '/netcfg\/dhcp_options/d' /boot/tmp/preseed.cfg  

    sed -i '/netcfg\/get_.*/d' /boot/tmp/preseed.cfg  

    sed -i '/netcfg\/confirm_static/d' /boot/tmp/preseed.cfg  

    }  

    [ &quot;$vDEB&quot; == 'trusty' ] &amp;&amp; GRUBPATCH='1'  

    [ &quot;$vDEB&quot; == 'wily' ] &amp;&amp; GRUBPATCH='1'  

    [ &quot;$GRUBPATCH&quot; == '1' ] &amp;&amp; {  

    sed -i 's/^d-i\ grub-installer\/bootdev\ string\ default//g' /boot/tmp/preseed.cfg  

    }  

    [ &quot;$GRUBPATCH&quot; == '0' ] &amp;&amp; {  

    sed -i 's/debconf-set\ grub-installer\/bootdev.*\&quot;\;//g' /boot/tmp/preseed.cfg  

    }  

    [ &quot;$linuxdists&quot; == 'debian' ] &amp;&amp; {  

    sed -i '/user-setup\/allow-password-weak/d' /boot/tmp/preseed.cfg  

    sed -i '/user-setup\/encrypt-home/d' /boot/tmp/preseed.cfg  

    sed -i '/pkgsel\/update-policy/d' /boot/tmp/preseed.cfg  

    sed -i 's/umount\ \/media.*\;//g' /boot/tmp/preseed.cfg  

    }  

    rm -rf ../initrd.gz  

    find . | cpio -H newc --create --verbose | gzip -9 &gt; ../initrd.gz  

    rm -rf /boot/tmp  

    }  

    }  

       

    [ &quot;$inVNC&quot; == 'y' ] &amp;&amp; {  

    sed -i '$i\\n' $GRUBDIR/$GRUBFILE  

    sed -i '$r /tmp/grub.new' $GRUBDIR/$GRUBFILE  

    echo -e &quot;\n\033[33m\033[04mIt will reboot! \nPlease look at VNC! \nSelect\033[0m\033[32m Install OS [$vDEB $VER] \033[33m\033[4mto install system.\033[04m\n\n\033[31m\033[04mThere is some information for you.\nDO NOT CLOSE THE WINDOW! \033[0m\n&quot;  

    echo -e &quot;\033[35mIPv4\t\tNETMASK\t\tGATEWAY\033[0m&quot;  

    echo -e &quot;\033[36m\033[04m$IPv4\033[0m\t\033[36m\033[04m$MASK\033[0m\t\033[36m\033[04m$GATE\033[0m\n\n&quot;  

       

    read -n 1 -p &quot;Press Enter to reboot...&quot; INP  

    if [ &quot;$INP&quot; != '' ] ; then  

    echo -ne '\b \n'  

    echo &quot;&quot;;  

    fi  

    }  

       

    chown root:root $GRUBDIR/$GRUBFILE  

    chmod 444 $GRUBDIR/$GRUBFILE  

       

    sleep 3 &amp;&amp; reboot &gt;/dev/null 2&gt;&amp;1  




注意事项:

在安装Ubuntu时,可能会遇到:

Getting the time form a network time server...

界面进度条很长时间不会动,可以等待它超时或者更换别的版本.

该问题是Ubuntu系统的问题.

确保安装了所需软件.


</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
