[ Linux Shell ] 通用无限制在 Linux VPS 上一键全自动 dd 安装 Windows 系统

突破没有VNC,没有救援模式,内存比dd包小的限制.

使用Debian Live CD中的busybox做中间媒介,经过复杂的处理,

使本机的网络参数传进Windows操作系统中,

即使没有DHCP能够让Windows获取网络参数,

也能让Windows操作系统在开机的第一时间能够连通网络.

更新:

[2018.04.03]

功能合并: [ Linux VPS ] Debian/Ubuntu/CentOS 网络安装/重装系统/纯净安装 一键脚本

[2018.03.30]

优化GRUB检测测逻辑. 添加组件依赖检测. 修复一些已知BUG.

[2018.03.25]

优化判断逻辑. 增加手动指定网络参数选项,可有效避免自动获取网络参数无效造成无法直接联网的问题.

背景:

1.带Windows的为什么就卖得那么贵? 2.当然是为了更自由的使用自己的机器.

需求:

萌咖博客中的Debian(Ubuntu)网络安装/重装一键脚本需求一样.

无DHCP时额外需求: iconv

#Debian/Ubuntu## 一般自带#RedHat/CentOSyum install glibc-common

限制:

需要定制dd包.

开启内置Administrator账户登录(配置自动登陆)..

开启远程桌面(默认3389端口).

禁用UAC..

适当的调整防火墙.(可选)

需要相关的虚拟化驱动.

VirtIO驱动(备份下载) XEN驱动(备份下载)

dd包解压后的体积不能超过机器第一块硬盘的最大容积.

相关教程:

从零开始:在Linux上覆盖安装WINDOWS通用教程(dd)

#制作可用的镜像文件

关于在Windows上关闭Ctrl+Alt+Del登陆

注册表开启远程桌面服务和3389端口

Windows通过注册表禁用或开启服务项

Windows通过注册表禁用UAC

Windows自动应答文件示例

使用方法:

wget--no-check-certificate -qO InstallNET.sh'https://moeclub.org/attachment/LinuxShell/InstallNET.sh'&& bash InstallNET.sh -dd'[Windows dd包直连地址]'

萌咖提供的demo包(1.19G;已激活):

https://moeclub.org/onedrive/IMAGE/Windows/win7emb_x86.tar.gz# 谷歌文件ID: 1srhylymTjYS-Ky8uLw4R6LCWfAo1F3s7# 该包只添加了VirtIO驱动,理论上仅能在KVM,Hyper-V构架下正常运行.# 如需在其他虚拟化构架下运行,请自行添加相关虚拟化驱动.

使用的是Windows Embedded Standard 7(Thin PC)作为底包,官方精简. 如需其他组件,例如:完整的桌面特征,Windows照片查看器等. 请参考: Thin PC (Win7 Embedded) 安装组件

使用示例:

#在你的机器上全新安装,如果你有VNC,可以看到全部过程.#在dd的过程中,会卡在分区的界面上,不会走进度条.完成后将会自动重启.wget--no-check-certificate -qO InstallNET.sh'https://moeclub.org/attachment/LinuxShell/InstallNET.sh'&& bash InstallNET.sh -dd'https://moeclub.org/onedrive/IMAGE/Windows/win7emb_x86.tar.gz'

使用示例(指定网络参数):

# 将X.X.X.X替换为自己的网络参数.# --ip-addr :IP Address/IP地址# --ip-mask :Netmask  /子网掩码# --ip-gate :Gateway  /网关#wget --no-check-certificate -qO InstallNET.sh'https://moeclub.org/attachment/LinuxShell/InstallNET.sh'&& bash InstallNET.sh --ip-addr X.X.X.X --ip-mask X.X.X.X --ip-gate X.X.X.X -dd'https://moeclub.org/onedrive/IMAGE/Windows/win7emb_x86.tar.gz'

注意事项:

远程登陆账号为: Administrator

远程登陆密码为: Vicer

仅修改了主机名,可放心使用.(建议自己制作.)

使用的公用网盘,如需长期/大量使用此包请自行备份.

如果因此违反了TOS,萌咖不负任何责任.

可能用到的命令:

::以管理员身份运行CMD::::更改用户的密码net user [用户名] [密码]::激活 Administrator 账户net user Administrator /active:yes::设置 Administrator 账户密码net user Administrator [新密码]::添加用户net user [用户名] [密码] /add::将用户添加至 Administrator 组net localgroup Administrators [用户名] /add::删除用户net user [用户名] /del

温馨提示:

磁盘管理中,点击'C'盘,右键选择'扩展卷',可以直接'增加'C盘的空间. 激活相关请参考: https://moeclub.org/kms

萌咖提供的可用包:

与本地用iso镜像安装过程一样,如果你有VNC,可看到全部过程. 因为全新安装!!! 全新安装!!! 全新安装!!! 所以会等待久一点.

Windows Embedded 8.1 Industry Pro x64 (2.87G;KVM;XEN;Hyper-V;未激活)

直链:https://moeclub.org/onedrive/IMAGE/Windows/win8.1emb_x64.tar.gz谷歌网盘文件ID:1cqVl2wSGx92UTdhOxU9pW3wJgmvZMT_J

预览:

#!/bin/bashexporttmpVER=''exporttmpDIST=''exporttmpURL=''exporttmpWORD=''exporttmpMirror=''exporttmpSSL=''exporttmpINS=''exporttmpFW=''exportipAddr=''exportipMask=''exportipGate=''exportlinuxdists=''exportddMode='0'exportsetNet='0'exportisMirror='0'exportFindDists='0'while[[$#-ge 1 ]];docase$1in-v|--ver)shifttmpVER="$1"shift;;    -d|--debian)shiftlinuxdists='debian'tmpDIST="$1"shift;;    -u|--ubuntu)shiftlinuxdists='ubuntu'tmpDIST="$1"shift;;    -dd|--image)shiftddMode='1'tmpURL="$1"shift;;    -p|--password)shifttmpWORD="$1"shift;;    --ip-addr)shiftipAddr="$1"shift;;    --ip-mask)shiftipMask="$1"shift;;    --ip-gate)shiftipGate="$1"shift;;    -a|--auto)shifttmpINS='auto';;    -m|--manual)shifttmpINS='manual';;    -apt|--mirror)shiftisMirror='1'tmpMirror="$1"shift;;    -ssl)shifttmpSSL="$1"shift;;    --firmware)shifttmpFW='1';;    *)echo-ne" Usage:\n\t$0\t-d/--debian [\033[33m\033[04mdists-name\033[0m]\n\t\t\t\t-u/--ubuntu [\033[04mdists-name\033[0m]\n\t\t\t\t-v/--ver [32/\033[33m\033[04mi386\033[0m|64/amd64]\n\t\t\t\t--ip-addr/--ip-gate/--ip-mask\n\t\t\t\t-apt/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n"exit1;      ;;esacdone[["$EUID"-ne'0']] &&echo"Error:This script must be run as root!"&&exit1;functionCheckDependence(){FullDependence='0';forBIN_DEPin`echo"$1"|sed's/,/\n/g'`doif[[ -n"$BIN_DEP"]];thenFounded='0';forBIN_PATHin`echo"$PATH"|sed's/:/\n/g'`dols$BIN_PATH/$BIN_DEP>/dev/null 2>&1;if[ $? =='0'];thenFounded='1';break;fidoneif["$Founded"=='1'];thenecho-en"$BIN_DEP\t\t[\033[32mok\033[0m]\n";elseFullDependence='1';echo-en"$BIN_DEP\t\t[\033[31mfail\033[0m]\n";fifidoneif["$FullDependence"=='1'];thenexit1;fi}clear &&echo-e"\n\033[36m# Check Dependence\033[0m\n"CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip["$ddMode"=='1'] && {CheckDependence iconv}[[ -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-ne"Error! \nNot Found grub path.\n"&&exit1;[[ -n"$tmpVER"]] && {  ["$tmpVER"=='32'-o"$tmpVER"=='i386'] && VER='i386';  ["$tmpVER"=='64'-o"$tmpVER"=='amd64'] && VER='amd64';}[[ -z"$VER"]] && VER='i386';[[ -z"$linuxdists"]] && linuxdists='debian';[["$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')";}[[ -n"$DebianMirror"]] && {  [["$DebianMirrorDirectory"=='/']] && {    [["$linuxdists"=='debian']] && DebianMirrorDirectory='/debian';    [["$linuxdists"=='ubuntu']] && DebianMirrorDirectory='/ubuntu';  }  [[ -z"$DebianMirrorDirectory"]] && {    [["$linuxdists"=='debian']] && DebianMirrorDirectory='/debian';    [["$linuxdists"=='ubuntu']] && DebianMirrorDirectory='/ubuntu';  }}[[ -z"$tmpDIST"]] && {  [["$linuxdists"=='debian']] && DIST='wheezy';  [["$linuxdists"=='ubuntu']] && DIST='trusty';}[[ -z"$DIST"]] && {  DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";echo"$DIST"|grep -q'[0-9]';  [[ $? -eq'0']] && {    isDigital="$(echo "$DIST" |grep -o '[0-9\.]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p' |cut -d'.' -f1)";    [[ -n$isDigital]] && {      [["$isDigital"=='7']] && DIST='wheezy';      [["$isDigital"=='8']] && DIST='jessie';      [["$isDigital"=='9']] && DIST='stretch';      [["$isDigital"=='10']] && DIST='buster';    }  }}[["$ddMode"=='1']] && {  [[ -n"$tmpURL"]] && {    linuxdists='debian';    DIST='jessie';    VER='amd64';    tmpINS='auto';    DDURL="$tmpURL"echo"$DDURL"|grep -q'^http://\|^ftp://\|^https://';    [[ $? -ne'0']] &&echo'Please input vaild URL,Only support http://, ftp:// and https:// !'&&exit1;    [[ -n"$tmpSSL"]] && SSL_SUPPORT="$tmpSSL";    [[ -z"$SSL_SUPPORT"]] && SSL_SUPPORT='https://moeclub.org/get-wget_udeb_amd64';  } || {echo'Please input vaild URL! ';exit1;  }}DistsList="$(wget --no-check-certificate -qO- "http://$DebianMirror$DebianMirrorDirectory/dists/" |grep -o 'href=.*/"' |cut -d'"' -f2 |sed '/-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d' |grep '^[^/]' |sed -n '1h;1!H;$g;s/\n//g;s/\//\;/g;$p')";forCheckDEBin`echo"$DistsList"|sed's/;/\n/g'`do[["$CheckDEB"=="$DIST"]] && FindDists='1';    [["$FindDists"=='1']] &&break;done[["$FindDists"=='0']] && {echo-ne'\nThe dists version not found, Please check it! \n\n'bash$0error;exit1;}[[ -n"$tmpINS"]] && {  [["$tmpINS"=='auto']] && inVNC='n';  [["$tmpINS"=='manual']] && inVNC='y';}[ -n"$ipAddr"] && [ -n"$ipMask"] && [ -n"$ipGate"] && setNet='1';[[ -n"$tmpWORD"]] && myPASSWORD="$tmpWORD";[[ -n"$tmpFW"]] && INCFW="$tmpFW";[[ -z"$myPASSWORD"]] && myPASSWORD='Vicer';[[ -z"$INCFW"]] && INCFW='0';clear &&echo-e"\n\033[36m# Install\033[0m\n"ASKVNC(){  inVNC='y';  [["$ddMode"=='0']] && {echo-ne"\033[34mCan you login VNC?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m "readtmpinVNC    [[ -n"$tmpinVNC"]] && inVNCtmp="$tmpinVNC"}  ["$inVNCtmp"=='y'-o"$inVNCtmp"=='Y'] && inVNC='y';  ["$inVNCtmp"=='n'-o"$inVNCtmp"=='N'] && inVNC='n';}["$inVNC"=='y'-o"$inVNC"=='n'] || ASKVNC;[["$linuxdists"=='debian']] && LinuxName='Debian';[["$linuxdists"=='ubuntu']] && LinuxName='Ubuntu';[["$ddMode"=='0']] && {  [["$inVNC"=='y']] &&echo-e"\033[34mManual Mode\033[0m insatll \033[33m$LinuxName\033[0m [\033[33m$DIST\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$DIST\033[0m] [\033[33m$VER\033[0m]. "}[["$ddMode"=='1']] && {echo-ne"\033[34mAuto Mode\033[0m insatll \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"}echo-e"\n[\033[33m$LinuxName\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."[[ -z"$DebianMirror"]] &&echo-ne"\033[31mError! \033[0mGet debian mirror fail! \n"&&exit1[[ -z"$DebianMirrorDirectory"]] &&echo-ne"\033[31mError! \033[0mGet debian mirror directory fail! \n"&&exit1wget --no-check-certificate -qO'/boot/initrd.gz'"http://$DebianMirror$DebianMirrorDirectory/dists/$DIST/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/initrd.gz"[[ $? -ne'0']] &&echo-ne"\033[31mError! \033[0mDownload 'initrd.gz' failed! \n"&&exit1wget --no-check-certificate -qO'/boot/linux'"http://$DebianMirror$DebianMirrorDirectory/dists/$DIST/main/installer-$VER/current/images/netboot/$linuxdists-installer/$VER/linux"[[ $? -ne'0']] &&echo-ne"\033[31mError! \033[0mDownload 'linux' failed! \n"&&exit1[["$INCFW"=='1']] && [["$linuxdists"=='debian']] && {  wget --no-check-certificate -qO'/boot/firmware.cpio.gz'"http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$DIST/current/firmware.cpio.gz"[[ $? -ne'0']] &&echo-ne"\033[31mError! \033[0mDownload 'firmware' failed! \n"&&exit1}[["$setNet"=='1']] && {  IPv4="$ipAddr";  MASK="$ipMask";  GATE="$ipGate";} || {  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() {localIFS='.';readip1 ip2 ip3 ip4 <<<"$1";echo$((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));}SelectMax(){ii=0;forIPITEMin`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\}'`doNumTMP="$(ipNum $IPITEM)";eval"arrayNum[$ii]='$NumTMP,$IPITEM'";    ii=$[$ii+1];doneecho${arrayNum[@]}|sed's/\s/\n/g'|sort -n -k 1 -t','|tail -n1 |cut -d','-f2;}[[ -z$IPv4]] && IPv4="$(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)";[[ -z$GATE]] && GATE="$(SelectMax 2)";[[ -z$MASK]] && MASK="$(SelectMax 3)";[[ -n"$GATE"]] && [[ -n"$MASK"]] && [[ -n"$IPv4"]] || {echo"Error! Not configure network. ";exit1;}}[["$setNet"!='1']] && [[ -f'/etc/network/interfaces']] && {  [[ -z"$(sed -n '/iface.*inet static/p' /etc/network/interfaces)"]] && AutoNet='1'|| AutoNet='0';  [[ -d /etc/network/interfaces.d ]] && {    ICFGN="$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)"|| ICFGN='0';    [["$ICFGN"-ne'0']] && {forNetCFGin`ls -1 /etc/network/interfaces.d/*.cfg`do[[ -z"$(cat $NetCFG | sed -n '/iface.*inet static/p')"]] && AutoNet='1'|| AutoNet='0';          [["$AutoNet"-eq'0']] &&break;done}  }}[["$setNet"!='1']] && [[ -d'/etc/sysconfig/network-scripts']] && {  ICFGN="$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)"|| ICFGN='0';  [["$ICFGN"-ne'0']] && {forNetCFGin`ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v'lo$'|grep -v':[0-9]\{1,\}'`do[[ -n"$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')"]] && AutoNet='1'|| {          AutoNet='0'&& .$NetCFG;          [[ -n$NETMASK]] && MASK="$NETMASK";          [[ -n$GATEWAY]] && GATE="$GATEWAY";        }        [["$AutoNet"-eq'0']] &&break;done}}[[ ! -f$GRUBDIR/$GRUBFILE]] &&echo"Error! Not Found$GRUBFILE. "&&exit1;[[ ! -f$GRUBDIR/$GRUBFILE.old ]] && [[ -f$GRUBDIR/$GRUBFILE.bak ]] && mv -f$GRUBDIR/$GRUBFILE.bak$GRUBDIR/$GRUBFILE.old;mv -f$GRUBDIR/$GRUBFILE$GRUBDIR/$GRUBFILE.bak;[[ -f$GRUBDIR/$GRUBFILE.old ]] && cat$GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE|| cat$GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;[["$GRUBOLD"=='0']] && {  READGRUB='/tmp/grub.read'cat$GRUBDIR/$GRUBFILE|sed -n'1h;1!H;$g;s/\n/+++/g;$p'|grep -oPm 1'menuentry\ .*\{.*\}\+\+\+'|sed's/\+\+\+/\n/g'>$READGRUBLoadNum="$(cat $READGRUB |grep -c 'menuentry ')"if[["$LoadNum"-eq'1']];thencat$READGRUB|sed'/^$/d'>/tmp/grub.new;elif[["$LoadNum"-gt'1']];thenCFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";    CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";    CFG1="";fortmpCFGin`awk'/}/{print NR}'$READGRUB`do["$tmpCFG"-gt"$CFG0"-a"$tmpCFG"-lt"$CFG2"] && CFG1="$tmpCFG";done[[ -z"$CFG1"]] && {echo"Error! read$GRUBFILE. ";exit1;    }    sed -n"$CFG0,$CFG1"p$READGRUB>/tmp/grub.new;    [[ -f /tmp/grub.new ]] && [["$(grep -c '{' /tmp/grub.new)"-eq"$(grep -c '}' /tmp/grub.new)"]] || {echo-ne"\033[31mError! \033[0mNot configure$GRUBFILE. \n";exit1;    }fi[ ! -f /tmp/grub.new ] &&echo"Error!$GRUBFILE. "&&exit1;  sed -i"/menuentry.*/c\menuentry\ \'Install OS \[$DIST\$VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{"/tmp/grub.new  sed -i"/echo.*Loading/d"/tmp/grub.new;}[["$GRUBOLD"=='1']] && {  CFG0="$(awk '/title /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";  CFG1="$(awk '/title /{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";  [[ -n$CFG0]] && [ -z$CFG1-o$CFG1==$CFG0] && sed -n"$CFG0,$"p$GRUBDIR/$GRUBFILE>/tmp/grub.new;  [[ -n$CFG0]] && [ -z$CFG1-o$CFG1!=$CFG0] && sed -n"$CFG0,$CFG1"p$GRUBDIR/$GRUBFILE>/tmp/grub.new;  [[ ! -f /tmp/grub.new ]] &&echo"Error! configure append$GRUBFILE. "&&exit1;  sed -i"/title.*/c\title\ \'Install OS \[$DIST\$VER\]\'"/tmp/grub.new;  sed -i'/^#/d'/tmp/grub.new;}[[ -n"$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')"]] && Type='InBoot'|| Type='NoBoot';LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)";[[ -z"$LinuxKernel"]] &&echo"Error! read grub config! "&&exit1;LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";[ -z"$LinuxIMG"] && sed -i"/$LinuxKernel.*\//a\\\tinitrd\ \/"/tmp/grub.new && LinuxIMG='initrd';[["$Type"=='InBoot']] && {  sed -i"/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/linux auto=true hostname=$linuxdistsdomain= -- quiet"/tmp/grub.new;  sed -i"/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.gz"/tmp/grub.new;}[["$Type"=='NoBoot']] && {  sed -i"/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/linux auto=true hostname=$linuxdistsdomain= -- quiet"/tmp/grub.new;  sed -i"/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.gz"/tmp/grub.new;}sed -i'$a\\n'/tmp/grub.new;[["$inVNC"=='n']] && {GRUBPATCH='0';[ -f'/etc/network/interfaces'-o -d'/etc/sysconfig/network-scripts'] || {echo"Error, Not found interfaces config.";exit1;}INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"sed -i''${INSERTGRUB}'i\\n'$GRUBDIR/$GRUBFILE;sed -i''${INSERTGRUB}'r /tmp/grub.new'$GRUBDIR/$GRUBFILE;[[ -f$GRUBDIR/grubenv ]] && sed -i's/saved_entry/#saved_entry/g'$GRUBDIR/grubenv;[[ -d /boot/tmp ]] && rm -rf /boot/tmp;mkdir -p /boot/tmp;cd/boot/tmp;gzip -d < ../initrd.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1cat >/boot/tmp/preseed.cfg<'/boot/tmp/net.tmp';}WinNoDHCP(){echo-ne"@ECHO OFF\r\ncd\056\076\045windir\045\GetAdmin\r\nif\040exist\040\045windir\045\GetAdmin\040\050del\040\057f\040\057q\040\042\045windir\045\GetAdmin\042\051\040else\040\050\r\necho\040CreateObject^\050\042Shell\056Application\042^\051\056ShellExecute\040\042\045~s0\042\054\040\042\045\052\042\054\040\042\042\054\040\042runas\042\054\040\061\040\076\076\040\042\045temp\045\Admin\056vbs\042\r\n\042\045temp\045\Admin\056vbs\042\r\ndel\040\057f\040\057q\040\042\045temp\045\Admin\056vbs\042\r\nexit\040\057b\040\062\051\r\nfor\040\057f\040\042tokens=\063\052\042\040\045\045i\040in\040\050\047netsh\040interface\040show\040interface\040^|more\040+3\040^|findstr\040\057R\040\042\u672c\u5730\056\052\040\u4ee5\u592a\056\052\040Local\056\052\040Ethernet\042\047\051\040do\040\050set\040EthName=\045\045j\051\r\nnetsh\040-c\040interface\040ip\040set\040address\040name=\042\045EthName\045\042\040source=static\040address=$IPv4\040mask=$MASK\040gateway=$GATE\r\nnetsh\040-c\040interface\040ip\040add\040dnsservers\040name=\042\045EthName\045\042\040address=\070\056\070\056\070\056\070\040index=1\040validate=no\r\nnetsh\040-c\040interface\040ip\040add\040dnsservers\040name=\042\045EthName\045\042\040address=\070\056\070\056\064\056\064\040index=2\040validate=no\r\ncd\040\057d\040\042\045ProgramData\045\057Microsoft\057Windows\057Start\040Menu\057Programs\057Startup\042\r\ndel\040\057f\040\057q\040net\056bat\r\n\r\n">'/boot/tmp/net.tmp';}  [["$setNet"=='1']] && WinNoDHCP;  [["$setNet"=='0']] && {    [["$AutoNet"-eq'1']] && WinDHCP;    [["$AutoNet"-eq'0']] && WinNoDHCP;  }  iconv -f'UTF-8'-t'GBK''/boot/tmp/net.tmp'-o'/boot/tmp/net.bat'rm -rf'/boot/tmp/net.tmp'echo"$DDURL"|grep -q'^https://'[[ $? -eq'0']] && {echo-ne'\nAdd ssl support...\n'[[ -n$SSL_SUPPORT]] && {      wget --no-check-certificate -qO-"$SSL_SUPPORT"|tar -x      [[ ! -f  /boot/tmp/usr/bin/wget ]] &&echo'Error! SSL_SUPPORT.'&&exit1;      sed -i's/wget\ -qO-/\/usr\/bin\/wget\ --no-check-certificate\ --retry-connrefused\ --tries=7\ --continue\ -qO-/g'/boot/tmp/preseed.cfg      [[ $? -eq'0']] &&echo-ne'Success! \n\n'} || {echo-ne'Not ssl support package! \n\n';exit1;    }  }}[["$ddMode"=='0']] && {  sed -i'/anna-install/d'/boot/tmp/preseed.cfg  sed -i's/wget.*\/sbin\/reboot\;\ //g'/boot/tmp/preseed.cfg}[["$INCFW"=='1']] && [["$linuxdists"=='debian']] && [[ -f'/boot/firmware.cpio.gz']] && {  gzip -d < ../firmware.cpio.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1}rm -rf ../initrd.gz;find . | cpio -H newc --create --verbose | gzip -9 > ../initrd.gz;rm -rf /boot/tmp;}[["$inVNC"=='y']] && {  sed -i'$i\\n'$GRUBDIR/$GRUBFILEsed -i'$r /tmp/grub.new'$GRUBDIR/$GRUBFILEecho-e"\n\033[33m\033[04mIt will reboot! \nPlease look at VNC! \nSelect\033[0m\033[32m Install OS [$DIST$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"echo-e"\033[35mIPv4\t\tNETMASK\t\tGATEWAY\033[0m"echo-e"\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"read-n 1 -p"Press Enter to reboot..."INP  [["$INP"!='']] &&echo-ne'\b \n\n';}chown root:root$GRUBDIR/$GRUBFILEchmod 444$GRUBDIR/$GRUBFILEsleep 3 && reboot >/dev/null 2>&1

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,393评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,790评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,391评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,703评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,613评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,003评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,507评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,158评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,300评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,256评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,274评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,984评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,569评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,662评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,899评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,268评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,840评论 2 339

推荐阅读更多精彩内容