蘭雅sRGB 3 gadi atpakaļ
vecāks
revīzija
dd57dadd1c
1 mainītis faili ar 274 papildinājumiem un 365 dzēšanām
  1. 274 365
      auto.sh

+ 274 - 365
auto.sh

@@ -6,19 +6,20 @@
 ## Blog: https://moeclub.org
 ## Written By MoeClub.org
 
-export ssh_port='22'
-
 export tmpVER=''
 export tmpDIST=''
 export tmpURL=''
 export tmpWORD=''
 export tmpMirror=''
-export tmpSSL=''
-export tmpINS=''
 export ipAddr=''
 export ipMask=''
 export ipGate=''
+export ipDNS='8.8.8.8'
+export IncDisk='default'
+export interface=''
+export interfaceSelect=''
 export Relese=''
+export sshPORT='22'
 export ddMode='0'
 export setNet='0'
 export setRDP='0'
@@ -31,6 +32,11 @@ export SpikCheckDIST='0'
 export setInterfaceName='0'
 export UNKNOWHW='0'
 export UNVER='6.4'
+export GRUBDIR=''
+export GRUBFILE=''
+export GRUBVER=''
+export VER=''
+export setCMD=''
 
 while [[ $# -ge 1 ]]; do
   case $1 in
@@ -70,7 +76,7 @@ while [[ $# -ge 1 ]]; do
       ;;
     -i|--interface)
       shift
-      interface="$1"
+      interfaceSelect="$1"
       shift
       ;;
     --ip-addr)
@@ -88,6 +94,11 @@ while [[ $# -ge 1 ]]; do
       ipGate="$1"
       shift
       ;;
+    --ip-dns)
+      shift
+      ipDNS="$1"
+      shift
+      ;;
     --dev-net)
       shift
       setInterfaceName='1'
@@ -96,19 +107,6 @@ while [[ $# -ge 1 ]]; do
       shift
       loaderMode='1'
       ;;
-    --prefer)
-      shift
-      tmpPrefer="$1"
-      shift
-      ;;
-    -a|--auto)
-      shift
-      tmpINS='auto'
-      ;;
-    -m|--manual)
-      shift
-      tmpINS='manual'
-      ;;
     -apt|-yum|--mirror)
       shift
       isMirror='1'
@@ -121,25 +119,30 @@ while [[ $# -ge 1 ]]; do
       WinRemote="$1"
       shift
       ;;
-    -ssl)
+    -cmd)
       shift
-      tmpSSL="$1"
+      setCMD="$1"
       shift
       ;;
     -firmware)
       shift
       IncFirmware="1"
       ;;
-    --ipv6)
+    -port)
+      shift
+      sshPORT="$1"
+      shift
+      ;;
+    --noipv6)
       shift
       setIPv6='1'
       ;;
+    -a|--auto|-m|--manual|-ssl)
+      shift
+      ;;
     *)
       if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
-      echo -ne " Usage:\n\tbash $(basename $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-c/--centos [\033[33m\033[04mdists-verison\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/-yum/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n\t\t\t\t-p PassWord\n"
+      echo -ne " Usage:\n\tbash $(basename $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-c/--centos [\033[04mdists-name\033[0m]\n\t\t\t\t-v/--ver [32/i386|64/\033[33m\033[04mamd64\033[0m] [\033[33m\033[04mdists-verison\033[0m]\n\t\t\t\t--ip-addr/--ip-gate/--ip-mask\n\t\t\t\t-apt/-yum/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-p [linux password]\n\t\t\t\t-port [linux ssh port]\n"
       exit 1;
       ;;
     esac
@@ -147,121 +150,195 @@ while [[ $# -ge 1 ]]; do
 
 [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
 
-function CheckDependence(){
-FullDependence='0';
-for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
-  do
-    if [[ -n "$BIN_DEP" ]]; then
-      Founded='0';
-      for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
-        do
-          ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
-          if [ $? == '0' ]; then
-            Founded='1';
-            break;
-          fi
-        done
-      if [ "$Founded" == '1' ]; then
-        echo -en "[\033[32mok\033[0m]\t";
-      else
-        FullDependence='1';
-        echo -en "[\033[31mNot Install\033[0m]";
+function dependence(){
+  Full='0';
+  for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
+    do
+      if [[ -n "$BIN_DEP" ]]; then
+        Found='0';
+        for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
+          do
+            ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
+            if [ $? == '0' ]; then
+              Found='1';
+              break;
+            fi
+          done
+        if [ "$Found" == '1' ]; then
+          echo -en "[\033[32mok\033[0m]\t";
+        else
+          Full='1';
+          echo -en "[\033[31mNot Install\033[0m]";
+        fi
+        echo -en "\t$BIN_DEP\n";
       fi
-      echo -en "\t$BIN_DEP\n";
-    fi
-  done
-if [ "$FullDependence" == '1' ]; then
-  echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
-  exit 1;
-fi
+    done
+  if [ "$Full" == '1' ]; then
+    echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
+    exit 1;
+  fi
 }
 
-function SelectMirror(){
+function selectMirror(){
   [ $# -ge 3 ] || exit 1
-  Relese="$1"
+  Relese=$(echo "$1" |sed -r 's/(.*)/\L\1/')
   DIST=$(echo "$2" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
   VER=$(echo "$3" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
   New=$(echo "$4" |sed 's/\ //g')
-  [ -n "$Relese" ] || exit 1
-  [ -n "$DIST" ] || exit 1
-  [ -n "$VER" ] || exit 1
-  relese=$(echo $Relese |sed -r 's/(.*)/\L\1/')
-  if [ "$Relese" == "Debian" ] || [ "$Relese" == "Ubuntu" ]; then
-    inUpdate=''; [ "$Relese" == "Ubuntu" ] && inUpdate='-updates'
-    if [[ "$isDigital" == '20.04' ]] || [[ "$DIST" == 'focal' ]]; then
-      MirrorTEMP="SUB_MIRROR/dists/${DIST}/main/installer-${VER}/current/legacy-images/netboot/${relese}-installer/${VER}/initrd.gz"
-    else
-      MirrorTEMP="SUB_MIRROR/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${relese}-installer/${VER}/initrd.gz"
-    fi
-  elif [ "$Relese" == "CentOS" ]; then
-    MirrorTEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img"
+  [ -n "$Relese" ] && [ -n "$DIST" ] && [ -n "$VER" ] || exit 1
+  if [ "$Relese" == "debian" ] || [ "$Relese" == "ubuntu" ]; then
+    [ "$DIST" == "focal" ] && legacy="legacy-" || legacy=""
+    TEMP="SUB_MIRROR/dists/${DIST}/main/installer-${VER}/current/${legacy}images/netboot/${Relese}-installer/${VER}/initrd.gz"
+  elif [ "$Relese" == "centos" ]; then
+    TEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img"
   fi
-  [ -n "$MirrorTEMP" ] || exit 1
-  MirrorStatus=0
+  [ -n "$TEMP" ] || exit 1
+  mirrorStatus=0
   declare -A MirrorBackup
-  MirrorBackup=(["Debian0"]="" ["Debian1"]="http://deb.debian.org/debian" ["Debian2"]="http://archive.debian.org/debian" ["Ubuntu0"]="" ["Ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["CentOS0"]="" ["CentOS1"]="http://mirror.centos.org/centos" ["CentOS2"]="http://vault.centos.org")
+  MirrorBackup=(["debian0"]="" ["debian1"]="http://deb.debian.org/debian" ["debian2"]="http://archive.debian.org/debian" ["ubuntu0"]="" ["ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["ubuntu2"]="http://ports.ubuntu.com" ["centos0"]="" ["centos1"]="http://mirror.centos.org/centos" ["centos2"]="http://vault.centos.org")
   echo "$New" |grep -q '^http://\|^https://\|^ftp://' && MirrorBackup[${Relese}0]="$New"
   for mirror in $(echo "${!MirrorBackup[@]}" |sed 's/\ /\n/g' |sort -n |grep "^$Relese")
     do
-      CurMirror="${MirrorBackup[$mirror]}"
-      [ -n "$CurMirror" ] || continue
-      MirrorURL=`echo "$MirrorTEMP" |sed "s#SUB_MIRROR#${CurMirror}#g"`
+      Current="${MirrorBackup[$mirror]}"
+      [ -n "$Current" ] || continue
+      MirrorURL=`echo "$TEMP" |sed "s#SUB_MIRROR#${Current}#g"`
       wget --no-check-certificate --spider --timeout=3 -o /dev/null "$MirrorURL"
-      [ $? -eq 0 ] && MirrorStatus=1 && break
+      [ $? -eq 0 ] && mirrorStatus=1 && break
     done
-  [ $MirrorStatus -eq 1 ] && echo "$CurMirror" || exit 1
+  [ $mirrorStatus -eq 1 ] && echo "$Current" || exit 1
+}
+
+function netmask() {
+  n="${1:-32}"
+  b=""
+  m=""
+  for((i=0;i<32;i++)){
+    [ $i -lt $n ] && b="${b}1" || b="${b}0"
+  }
+  for((i=0;i<4;i++)){
+    s=`echo "$b"|cut -c$[$[$i*8]+1]-$[$[$i+1]*8]`
+    [ "$m" == "" ] && m="$((2#${s}))" || m="${m}.$((2#${s}))"
+  }
+  echo "$m"
+}
+
+function getInterface(){
+  interface=""
+  Interfaces=`cat /proc/net/dev |grep ':' |cut -d':' -f1 |sed 's/\s//g' |grep -iv '^lo\|^sit\|^stf\|^gif\|^dummy\|^vmnet\|^vir\|^gre\|^ipip\|^ppp\|^bond\|^tun\|^tap\|^ip6gre\|^ip6tnl\|^teql\|^ocserv\|^vpn'`
+  defaultRoute=`ip route show default |grep "^default"`
+  for item in `echo "$Interfaces"`
+    do
+      [ -n "$item" ] || continue
+      echo "$defaultRoute" |grep -q "$item"
+      [ $? -eq 0 ] && interface="$item" && break
+    done
+  echo "$interface"
+}
+
+function getDisk(){
+  disks=`lsblk | sed 's/[[:space:]]*$//g' |grep "disk$" |cut -d' ' -f1 |grep -v "fd[0-9]*\|sr[0-9]*" |head -n1`
+  [ -n "$disks" ] || echo ""
+  echo "$disks" |grep -q "/dev"
+  [ $? -eq 0 ] && echo "$disks" || echo "/dev/$disks"
+}
+
+function diskType(){
+  echo `udevadm info --query all "$1" 2>/dev/null |grep 'ID_PART_TABLE_TYPE' |cut -d'=' -f2`
+}
+
+function getGrub(){
+  Boot="${1:-/boot}"
+  folder=`find "$Boot" -type d -name "grub*" 2>/dev/null |head -n1`
+  [ -n "$folder" ] || return
+  fileName=`ls -1 "$folder" 2>/dev/null |grep '^grub.conf$\|^grub.cfg$'`
+  if [ -z "$fileName" ]; then
+    ls -1 "$folder" 2>/dev/null |grep -q '^grubenv$'
+    [ $? -eq 0 ] || return
+    folder=`find "$Boot" -type f -name "grubenv" 2>/dev/null |xargs dirname |grep -v "^$folder" |head -n1`
+    [ -n "$folder" ] || return
+    fileName=`ls -1 "$folder" 2>/dev/null |grep '^grub.conf$\|^grub.cfg$'`
+  fi
+  [ -n "$fileName" ] || return
+  [ "$fileName" == "grub.cfg" ] && ver="0" || ver="1"
+  echo "${folder}:${fileName}:${ver}"
 }
 
+function lowMem(){
+  mem=`grep "^MemTotal:" /proc/meminfo 2>/dev/null |grep -o "[0-9]*"`
+  [ -n "$mem" ] || return 0
+  [ "$mem" -le "524288" ] && return 1 || return 0
+}
+
+if [[ "$loaderMode" == "0" ]]; then
+  Grub=`getGrub "/boot"`
+  [ -z "$Grub" ] && echo -ne "Error! Not Found grub.\n" && exit 1;
+  GRUBDIR=`echo "$Grub" |cut -d':' -f1`
+  GRUBFILE=`echo "$Grub" |cut -d':' -f2`
+  GRUBVER=`echo "$Grub" |cut -d':' -f3`
+fi
+
 [ -n "$Relese" ] || Relese='Debian'
 linux_relese=$(echo "$Relese" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
 clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
 
 if [[ "$ddMode" == '1' ]]; then
-  CheckDependence iconv;
+  dependence iconv;
   linux_relese='debian';
-  tmpDIST='stretch';
+  tmpDIST='bullseye';
   tmpVER='amd64';
-  tmpINS='auto';
 fi
 
+[ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
+if [ "$setNet" == "0" ]; then
+  dependence ip
+  [ -n "$interface" ] || interface=`getInterface`
+  iAddr=`ip addr show dev $interface |grep "inet.*" |head -n1 |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,2\}'`
+  ipAddr=`echo ${iAddr} |cut -d'/' -f1`
+  ipMask=`netmask $(echo ${iAddr} |cut -d'/' -f2)`
+  ipGate=`ip route show default |grep "^default" |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' |head -n1`
+fi
+if [ -z "$interface" ]; then
+    dependence ip
+    [ -n "$interface" ] || interface=`getInterface`
+fi
+IPv4="$ipAddr"; MASK="$ipMask"; GATE="$ipGate";
+
+[ -n "$IPv4" ] && [ -n "$MASK" ] && [ -n "$GATE" ] && [ -n "$ipDNS" ] || {
+  echo -ne '\nError: Invalid network config\n\n'
+  bash $0 error;
+  exit 1;
+}
+
 if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
-  CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename;
+  dependence wget,awk,grep,sed,cut,cat,lsblk,cpio,gzip,find,dirname,basename;
 elif [[ "$Relese" == 'CentOS' ]]; then
-  CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz;
+  dependence wget,awk,grep,sed,cut,cat,lsblk,cpio,gzip,find,dirname,basename,file,xz;
 fi
-[ -n "$tmpWORD" ] && CheckDependence openssl
+[ -n "$tmpWORD" ] && dependence openssl
+[[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
+[[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
 
-if [[ "$loaderMode" == "0" ]]; then
-  [[ -f '/boot/grub/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
-  [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
-  [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBVER='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
-  [ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNot Found grub.\n" && exit 1;
-else
-  tmpINS='auto'
+tempDisk=`getDisk`; [ -n "$tempDisk" ] && IncDisk="$tempDisk"
+
+case `uname -m` in aarch64|arm64) VER="arm64";; x86|i386|i686) VER="i386";; x86_64|amd64) VER="amd64";; *) VER="";; esac
+tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
+if [[ "$VER" != "arm64" ]] && [[ -n "$tmpVER" ]]; then
+  case "$tmpVER" in i386|i686|x86|32) VER="i386";; amd64|x86_64|x64|64) [[ "$Relese" == 'CentOS' ]] && VER='x86_64' || VER='amd64';; *) VER='';; esac
 fi
 
-if [[ -n "$tmpVER" ]]; then
-  tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
-  if  [[ "$tmpVER" == '32' ]] || [[ "$tmpVER" == 'i386' ]] || [[ "$tmpVER" == 'x86' ]]; then
-    VER='i386';
-  fi
-  if  [[ "$tmpVER" == '64' ]] || [[ "$tmpVER" == 'amd64' ]] || [[ "$tmpVER" == 'x86_64' ]] || [[ "$tmpVER" == 'x64' ]]; then
-    if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
-      VER='amd64';
-    elif [[ "$Relese" == 'CentOS' ]]; then
-      VER='x86_64';
-    fi
-  fi
+if [[ ! -n "$VER" ]]; then
+  echo "Error! Not Architecture."
+  bash $0 error;
+  exit 1;
 fi
-[ -z "$VER" ] && VER='amd64'
 
 if [[ -z "$tmpDIST" ]]; then
-  [ "$Relese" == 'Debian' ] && tmpDIST='jessie' && DIST='jessie';
-  [ "$Relese" == 'Ubuntu' ] && tmpDIST='bionic' && DIST='bionic';
-  [ "$Relese" == 'CentOS' ] && tmpDIST='6.10' && DIST='6.10';
+  [ "$Relese" == 'Debian' ] && tmpDIST='buster';
+  [ "$Relese" == 'Ubuntu' ] && tmpDIST='bionic';
+  [ "$Relese" == 'CentOS' ] && tmpDIST='6.10';
 fi
 
-if [[ -z "$DIST" ]]; then
+if [[ -n "$tmpDIST" ]]; then
   if [[ "$Relese" == 'Debian' ]]; then
     SpikCheckDIST='0'
     DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
@@ -276,7 +353,7 @@ if [[ -z "$DIST" ]]; then
         [[ "$isDigital" == '11' ]] && DIST='bullseye';
       }
     }
-    LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
+    LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
   fi
   if [[ "$Relese" == 'Ubuntu' ]]; then
     SpikCheckDIST='0'
@@ -292,12 +369,12 @@ if [[ -z "$DIST" ]]; then
         [[ "$isDigital" == '20.04' ]] && DIST='focal';
       }
     }
-    LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
+    LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
   fi
   if [[ "$Relese" == 'CentOS' ]]; then
     SpikCheckDIST='1'
-    DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}')";
-    LinuxMirror=$(SelectMirror "$Relese" "$DISTCheck" "$VER" "$tmpMirror")
+    DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}' |head -n1)";
+    LinuxMirror=$(selectMirror "$Relese" "$DISTCheck" "$VER" "$tmpMirror")
     ListDIST="$(wget --no-check-certificate -qO- "$LinuxMirror/dir_sizes" |cut -f2 |grep '^[0-9]')"
     DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)"
     [[ -z "$DIST" ]] && {
@@ -335,59 +412,28 @@ if [[ "$SpikCheckDIST" == '0' ]]; then
   }
 fi
 
-[[ "$ddMode" == '1' ]] && {
-  export SSL_SUPPORT='https://github.com/MoeClub/MoeClub.github.io/raw/master/lib/wget_udeb_amd64.tar.gz';
+if [[ "$ddMode" == '1' ]]; then
   if [[ -n "$tmpURL" ]]; then
     DDURL="$tmpURL"
     echo "$DDURL" |grep -q '^http://\|^ftp://\|^https://';
     [[ $? -ne '0' ]] && echo 'Please input vaild URL,Only support http://, ftp:// and https:// !' && exit 1;
-    [[ -n "$tmpSSL" ]] && SSL_SUPPORT="$tmpSSL";
   else
     echo 'Please input vaild image URL! ';
     exit 1;
   fi
-}
-
-[[ -n "$tmpINS" ]] && {
-  [[ "$tmpINS" == 'auto' ]] && inVNC='n';
-  [[ "$tmpINS" == 'manual' ]] && inVNC='y';
-}
-
-[ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
-[[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
-[[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
-
-if [[ -n "$interface" ]]; then
-  IFETH="$interface"
-else
-  if [[ "$linux_relese" == 'centos' ]]; then
-    IFETH="link"
-  else
-    IFETH="auto"
-  fi
 fi
 
 clear && echo -e "\n\033[36m# Install\033[0m\n"
 
-ASKVNC(){
-  inVNC='y';
-  [[ "$ddMode" == '0' ]] && {
-    echo -ne "\033[34mDo you want to install os manually?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m "
-    read tmpinVNC
-    [[ -n "$inVNCtmp" ]] && inVNC="$tmpinVNC"
-  }
-  [ "$inVNC" == 'y' -o "$inVNC" == 'Y' ] && inVNC='y';
-  [ "$inVNC" == 'n' -o "$inVNC" == 'N' ] && inVNC='n';
-}
+[[ "$ddMode" == '1' ]] && echo -ne "\033[34mAuto Mode\033[0m insatll \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
 
-[ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC;
-[[ "$ddMode" == '0' ]] && { 
-  [[ "$inVNC" == 'y' ]] && echo -e "\033[34mManual Mode\033[0m insatll [\033[33m$Relese\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$Relese\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"
-}
+if [ -z "$interfaceSelect" ]; then
+  if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
+    interfaceSelect="auto"
+  elif [[ "$linux_relese" == 'centos' ]]; then
+    interfaceSelect="link"
+  fi
+fi
 
 if [[ "$linux_relese" == 'centos' ]]; then
   if [[ "$DIST" != "$UNVER" ]]; then
@@ -395,11 +441,6 @@ if [[ "$linux_relese" == 'centos' ]]; then
     if [ $? != '0' ]; then
       UNKNOWHW='1';
       echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n";
-      if [[ "$inVNC" == 'n' ]]; then
-        echo -en "\033[35mYou can connect VNC with \033[32mPublic IP\033[35m and port \033[32m1\033[35m/\033[32m5901\033[35m in vnc viewer.\033[0m\n"
-        read -n 1 -p "Press Enter to continue..." INP
-        [[ "$INP" != '' ]] && echo -ne '\b \n\n';
-      fi
     fi
     awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'
     if [ $? == '0' ]; then
@@ -412,24 +453,18 @@ fi
 echo -e "\n[\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
 
 if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
-  inUpdate=''; [ "$linux_relese" == 'ubuntu' ] && inUpdate='-updates'
-  if [[ "$isDigital" == '20.04' ]] || [[ "$DIST" == 'focal' ]]; then
-    wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/dists/${DIST}/main/installer-${VER}/current/legacy-images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
-    [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
-    wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/dists/${DIST}/main/installer-${VER}/current/legacy-images/netboot/${linux_relese}-installer/${VER}/linux"
-    [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
-  else
-    wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
-    [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
-    wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${linux_relese}-installer/${VER}/linux"
-    [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
-  fi
+  [ "$DIST" == "focal" ] && legacy="legacy-" || legacy=""
+  wget --no-check-certificate -qO '/tmp/initrd.img' "${LinuxMirror}/dists/${DIST}/main/installer-${VER}/current/${legacy}images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
+  [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
+  wget --no-check-certificate -qO '/tmp/vmlinuz' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/${legacy}images/netboot/${linux_relese}-installer/${VER}/linux"
+  [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
   MirrorHost="$(echo "$LinuxMirror" |awk -F'://|/' '{print $2}')";
   MirrorFolder="$(echo "$LinuxMirror" |awk -F''${MirrorHost}'' '{print $2}')";
+  [ -n "$MirrorFolder" ] || MirrorFolder="/"
 elif [[ "$linux_relese" == 'centos' ]]; then
-  wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/initrd.img"
+  wget --no-check-certificate -qO '/tmp/initrd.img' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/initrd.img"
   [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
-  wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/vmlinuz"
+  wget --no-check-certificate -qO '/tmp/vmlinuz' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/vmlinuz"
   [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
 else
   bash $0 error;
@@ -437,94 +472,23 @@ else
 fi
 if [[ "$linux_relese" == 'debian' ]]; then
   if [[ "$IncFirmware" == '1' ]]; then
-    wget --no-check-certificate -qO '/boot/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/${DIST}/current/firmware.cpio.gz"
+    wget --no-check-certificate -qO '/tmp/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' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
   fi
   if [[ "$ddMode" == '1' ]]; then
     vKernel_udeb=$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/$DIST/main/installer-$VER/current/images/udeb.list" |grep '^acpi-modules' |head -n1 |grep -o '[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}-[0-9]\{1,2\}' |head -n1)
-    [[ -z "vKernel_udeb" ]] && vKernel_udeb="3.16.0-6"
+    [[ -z "vKernel_udeb" ]] && vKernel_udeb="4.19.0-17"
   fi
 fi
 
-[[ "$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() {
-  local IFS='.';
-  read ip1 ip2 ip3 ip4 <<<"$1";
-  echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<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="$(ipNum $IPITEM)";
-    eval "arrayNum[$ii]='$NumTMP,$IPITEM'";
-    ii=$[$ii+1];
-  done
-echo ${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. ";
-  exit 1;
-}
-}
-
-[[ "$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' ]] && {
-      for NetCFG in `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' ]] && {
-    for NetCFG in `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
-  }
-}
-
 if [[ "$loaderMode" == "0" ]]; then
-  [[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! Not Found $GRUBFILE. " && exit 1;
+  [[ ! -f "${GRUBDIR}/${GRUBFILE}" ]] && echo "Error! Not Found ${GRUBFILE}. " && exit 1;
 
-  [[ ! -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;
+  [[ ! -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}";
 else
-  GRUBVER='2'
+  GRUBVER='-1'
 fi
 
 [[ "$GRUBVER" == '0' ]] && {
@@ -570,76 +534,62 @@ fi
 }
 
 if [[ "$loaderMode" == "0" ]]; then
-[[ -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! " && exit 1;
-LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
-[ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
-
-if [[ "$setInterfaceName" == "1" ]]; then
-  Add_OPTION="net.ifnames=0 biosdevname=0";
-else
-  Add_OPTION="";
-fi
-
-if [[ "$setIPv6" == "1" ]]; then
-  Add_OPTION="$Add_OPTION ipv6.disable=1";
-fi
-
-if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
-  BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain= -- quiet"
-elif [[ "$linux_relese" == 'centos' ]]; then
-  BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$IFETH"
-fi
-
-[[ "$Type" == 'InBoot' ]] && {
-  sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
-  sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
-}
-
-[[ "$Type" == 'NoBoot' ]] && {
-  sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
-  sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
-}
-
-sed -i '$a\\n' /tmp/grub.new;
-fi
+  [[ -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! " && exit 1;
+  LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
+  [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
+
+  [[ "$setInterfaceName" == "1" ]] && Add_OPTION="net.ifnames=0 biosdevname=0" || Add_OPTION=""
+  [[ "$setIPv6" == "1" ]] && Add_OPTION="$Add_OPTION ipv6.disable=1"
+  
+  lowMem || Add_OPTION="$Add_OPTION lowmem=+0"
+
+  if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
+    BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain= -- quiet"
+  elif [[ "$linux_relese" == 'centos' ]]; then
+    BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$interfaceSelect"
+  fi
 
-[[ "$inVNC" == 'n' ]] && {
-GRUBPATCH='0';
+  [[ "$Type" == 'InBoot' ]] && {
+    sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
+    sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
+  }
 
-if [[ "$loaderMode" == "0" ]]; then
-[ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || {
-  echo "Error, Not found interfaces config.";
-  exit 1;
-}
+  [[ "$Type" == 'NoBoot' ]] && {
+    sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
+    sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
+  }
 
-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;
+  sed -i '$a\\n' /tmp/grub.new;
+  
+  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;
 fi
 
 [[ -d /tmp/boot ]] && rm -rf /tmp/boot;
 mkdir -p /tmp/boot;
 cd /tmp/boot;
+
 if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
   COMPTYPE="gzip";
 elif [[ "$linux_relese" == 'centos' ]]; then
-  COMPTYPE="$(file /boot/initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
+  COMPTYPE="$(file ../initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
   [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1;
 fi
 CompDected='0'
-for ListCOMP in `echo -en 'gzip\nlzma\nxz'`
+for COMP in `echo -en 'gzip\nlzma\nxz'`
   do
-    if [[ "$COMPTYPE" == "$ListCOMP" ]]; then
+    if [[ "$COMPTYPE" == "$COMP" ]]; then
       CompDected='1'
       if [[ "$COMPTYPE" == 'gzip' ]]; then
         NewIMG="initrd.img.gz"
       else
         NewIMG="initrd.img.$COMPTYPE"
       fi
-      mv -f "/boot/initrd.img" "/tmp/$NewIMG"
+      mv -f "/tmp/initrd.img" "/tmp/$NewIMG"
       break;
     fi
   done
@@ -657,7 +607,7 @@ d-i console-setup/layoutcode string us
 
 d-i keyboard-configuration/xkb-keymap string us
 
-d-i netcfg/choose_interface select $IFETH
+d-i netcfg/choose_interface select $interfaceSelect
 
 d-i netcfg/disable_autoconfig boolean true
 d-i netcfg/dhcp_failed note
@@ -665,7 +615,7 @@ 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/get_nameservers string $ipDNS
 d-i netcfg/no_default_route boolean true
 d-i netcfg/confirm_static boolean true
 
@@ -675,7 +625,6 @@ d-i mirror/country string manual
 d-i mirror/http/hostname string $MirrorHost
 d-i mirror/http/directory string $MirrorFolder
 d-i mirror/http/proxy string
-d-i apt-setup/services-select multiselect
 
 d-i passwd/root-login boolean ture
 d-i passwd/make-user boolean false
@@ -685,9 +634,9 @@ 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 clock-setup/ntp boolean false
 
-d-i preseed/early_command string anna-install libfuse2-udeb fuse-udeb ntfs-3g-udeb fuse-modules-${vKernel_udeb}-amd64-di
+d-i preseed/early_command string anna-install libfuse2-udeb fuse-udeb ntfs-3g-udeb libcrypto1.1-udeb libpcre2-8-0-udeb libssl1.1-udeb libuuid1-udeb zlib1g-udeb wget-udeb
 d-i partman/early_command string [[ -n "\$(blkid -t TYPE='vfat' -o device)" ]] && umount "\$(blkid -t TYPE='vfat' -o device)"; \
 debconf-set partman-auto/disk "\$(list-devices disk |head -n1)"; \
 wget -qO- '$DDURL' |gunzip -dc |/bin/dd of=\$(list-devices disk |head -n1); \
@@ -696,18 +645,16 @@ cd '/mnt/ProgramData/Microsoft/Windows/Start Menu/Programs'; \
 cd Start* || cd start*; \
 cp -f '/net.bat' './net.bat'; \
 /sbin/reboot; \
-debconf-set grub-installer/bootdev string "\$(list-devices disk |head -n1)"; \
 umount /media || true; \
 
+d-i partman-partitioning/confirm_write_new_label boolean true
 d-i partman/mount_style select uuid
+d-i partman/choose_partition select finish
+d-i partman-auto/method string regular
 d-i partman-auto/init_automatically_partition select Guided - use entire disk
 d-i partman-auto/choose_recipe select All files in one partition (recommended for new users)
-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/device_remove_lvm boolean true
 d-i partman-lvm/confirm boolean true
 d-i partman-lvm/confirm_nooverwrite boolean true
 d-i partman/confirm boolean true
@@ -723,51 +670,39 @@ 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 grub-installer/force-efi-extra-removable boolean true
+d-i grub-installer/bootdev string $IncDisk
+d-i grub-installer/force-efi-extra-removable boolean true
 d-i finish-install/reboot_in_progress note
 d-i debian-installer/exit/reboot boolean true
 d-i preseed/late_command string	\
+sed -ri 's/^#?Port.*/Port ${sshPORT}/g' /target/etc/ssh/sshd_config; \
 sed -ri 's/^#?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \
 sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config; \
-sed -ri 's/^#Port 22/Port ${ssh_port}/g' /target/etc/ssh/sshd_config;
+echo '@reboot root cat /etc/run.sh 2>/dev/null |base64 -d >/tmp/run.sh; rm -rf /etc/run.sh; sed -i /^@reboot/d /etc/crontab; bash /tmp/run.sh' >>/target/etc/crontab; \
+echo '' >>/target/etc/crontab; \
+echo '${setCMD}' >/target/etc/run.sh;
 EOF
 
-[[ "$loaderMode" != "0" ]] && AutoNet='1'
-
-[[ "$setNet" == '0' ]] && [[ "$AutoNet" == '1' ]] && {
+if [[ "$loaderMode" != "0" ]] && [[ "$setNet" == '0' ]]; then
   sed -i '/netcfg\/disable_autoconfig/d' /tmp/boot/preseed.cfg
   sed -i '/netcfg\/dhcp_options/d' /tmp/boot/preseed.cfg
   sed -i '/netcfg\/get_.*/d' /tmp/boot/preseed.cfg
   sed -i '/netcfg\/confirm_static/d' /tmp/boot/preseed.cfg
-}
-
-[[ "$DIST" == 'trusty' ]] && GRUBPATCH='1'
-[[ "$DIST" == 'wily' ]] && GRUBPATCH='1'
-[[ "$DIST" == 'xenial' ]] && {
-  sed -i 's/^d-i\ clock-setup\/ntp\ boolean\ true/d-i\ clock-setup\/ntp\ boolean\ false/g' /tmp/boot/preseed.cfg
-}
-
-[[ "$GRUBPATCH" == '1' ]] && {
-  sed -i 's/^d-i\ grub-installer\/bootdev\ string\ default//g' /tmp/boot/preseed.cfg
-}
-[[ "$GRUBPATCH" == '0' ]] && {
-  sed -i 's/debconf-set\ grub-installer\/bootdev.*\"\;//g' /tmp/boot/preseed.cfg
-}
+fi
 
-[[ "$linux_relese" == 'debian' ]] && {
+if [[ "$linux_relese" == 'debian' ]]; then
   sed -i '/user-setup\/allow-password-weak/d' /tmp/boot/preseed.cfg
   sed -i '/user-setup\/encrypt-home/d' /tmp/boot/preseed.cfg
   sed -i '/pkgsel\/update-policy/d' /tmp/boot/preseed.cfg
   sed -i 's/umount\ \/media.*true\;\ //g' /tmp/boot/preseed.cfg
-}
-[[ "$linux_relese" == 'debian' ]] && [[ -f '/boot/firmware.cpio.gz' ]] && {
-  gzip -d < /boot/firmware.cpio.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
-}
+  [[ -f '/tmp/firmware.cpio.gz' ]] && gzip -d < /tmp/firmware.cpio.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
+else
+  sed -i '/d-i\ grub-installer\/force-efi-extra-removable/d' /tmp/boot/preseed.cfg
+fi
 
 [[ "$ddMode" == '1' ]] && {
 WinNoDHCP(){
-  echo -ne "for\0040\0057f\0040\0042tokens\00753\0052\0042\0040\0045\0045i\0040in\0040\0050\0047netsh\0040interface\0040show\0040interface\0040\0136\0174more\0040\00533\0040\0136\0174findstr\0040\0057I\0040\0057R\0040\0042本地\0056\0052\0040以太\0056\0052\0040Local\0056\0052\0040Ethernet\0042\0047\0051\0040do\0040\0050set\0040EthName\0075\0045\0045j\0051\r\nnetsh\0040\0055c\0040interface\0040ip\0040set\0040address\0040name\0075\0042\0045EthName\0045\0042\0040source\0075static\0040address\0075$IPv4\0040mask\0075$MASK\0040gateway\0075$GATE\r\nnetsh\0040\0055c\0040interface\0040ip\0040add\0040dnsservers\0040name\0075\0042\0045EthName\0045\0042\0040address\00758\00568\00568\00568\0040index\00751\0040validate\0075no\r\n\r\n" >>'/tmp/boot/net.tmp';
+  echo -ne "for\0040\0057f\0040\0042tokens\00753\0052\0042\0040\0045\0045i\0040in\0040\0050\0047netsh\0040interface\0040show\0040interface\0040\0136\0174more\0040\00533\0040\0136\0174findstr\0040\0057I\0040\0057R\0040\0042鏈湴\0056\0052\0040浠ュお\0056\0052\0040Local\0056\0052\0040Ethernet\0042\0047\0051\0040do\0040\0050set\0040EthName\0075\0045\0045j\0051\r\nnetsh\0040\0055c\0040interface\0040ip\0040set\0040address\0040name\0075\0042\0045EthName\0045\0042\0040source\0075static\0040address\0075$IPv4\0040mask\0075$MASK\0040gateway\0075$GATE\r\nnetsh\0040\0055c\0040interface\0040ip\0040add\0040dnsservers\0040name\0075\0042\0045EthName\0045\0042\0040address\00758\00568\00568\00568\0040index\00751\0040validate\0075no\r\n\r\n" >>'/tmp/boot/net.tmp';
 }
 WinRDP(){
   echo -ne "netsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075ALL\r\nnetsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075CURRENT\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Network\0134NewNetworkWindowOff\0042\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0042\0040\0057v\0040fDenyTSConnections\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134Wds\0134rdpwd\0134Tds\0134tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040UserAuthentication\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040TermService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040UmRdpService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nSC\0040START\0040TermService\r\n\r\n" >>'/tmp/boot/net.tmp';
@@ -780,19 +715,6 @@ WinRDP(){
   echo -ne "cd\0040\0057d\0040\0042\0045ProgramData\0045\0057Microsoft\0057Windows\0057Start\0040Menu\0057Programs\0057Startup\0042\r\ndel\0040\0057f\0040\0057q\0040net\0056bat\r\n\r\n\r\n" >>'/tmp/boot/net.tmp';
   iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
   rm -rf '/tmp/boot/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  /tmp/boot/usr/bin/wget ]] && echo 'Error! SSL_SUPPORT.' && exit 1;
-      sed -i 's/wget\ -qO-/\/usr\/bin\/wget\ --no-check-certificate\ --retry-connrefused\ --tries=7\ --continue\ -qO-/g' /tmp/boot/preseed.cfg
-      [[ $? -eq '0' ]] && echo -ne 'Success! \n\n'
-    } || {
-    echo -ne 'Not ssl support package! \n\n';
-    exit 1;
-    }
-  }
 }
 
 [[ "$ddMode" == '0' ]] && {
@@ -820,7 +742,7 @@ vnc
 skipx
 timezone --isUtc Asia/Hong_Kong
 #ONDHCP network --bootproto=dhcp --onboot=on
-#NODHCP network --bootproto=static --ip=$IPv4 --netmask=$MASK --gateway=$GATE --nameserver=8.8.8.8 --onboot=on
+network --bootproto=static --ip=$IPv4 --netmask=$MASK --gateway=$GATE --nameserver=$ipDNS --onboot=on
 bootloader --location=mbr --append="rhgb quiet crashkernel=auto"
 zerombr
 clearpart --all --initlabel 
@@ -837,35 +759,20 @@ rm -rf /root/install.*log
 
 EOF
 
-[[ "$setNet" == '0' ]] && [[ "$AutoNet" == '1' ]] && {
-  sed -i 's/#ONDHCP\ //g' /tmp/boot/ks.cfg
-} || {
-  sed -i 's/#NODHCP\ //g' /tmp/boot/ks.cfg
-}
+
 [[ "$UNKNOWHW" == '1' ]] && sed -i 's/^unsupported_hardware/#unsupported_hardware/g' /tmp/boot/ks.cfg
 [[ "$(echo "$DIST" |grep -o '^[0-9]\{1\}')" == '5' ]] && sed -i '0,/^%end/s//#%end/' /tmp/boot/ks.cfg
 fi
 
-find . | cpio -H newc --create --verbose | gzip -9 > /boot/initrd.img;
-rm -rf /tmp/boot;
-}
-
-[[ "$inVNC" == 'y' ]] && {
-  sed -i '$i\\n' $GRUBDIR/$GRUBFILE
-  sed -i '$r /tmp/grub.new' $GRUBDIR/$GRUBFILE
-  echo -e "\n\033[33m\033[04mIt will reboot! \nPlease connect 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';
-}
+find . | cpio -H newc --create --verbose | gzip -9 > /tmp/initrd.img;
+cp -f /tmp/initrd.img /boot/initrd.img || sudo cp -f /tmp/initrd.img /boot/initrd.img
+cp -f /tmp/vmlinuz /boot/vmlinuz || sudo cp -f /tmp/vmlinuz /boot/vmlinuz
 
 chown root:root $GRUBDIR/$GRUBFILE
 chmod 444 $GRUBDIR/$GRUBFILE
 
 if [[ "$loaderMode" == "0" ]]; then
-  sleep 3 && reboot >/dev/null 2>&1
+  sleep 3 && reboot || sudo reboot >/dev/null 2>&1
 else
   rm -rf "$HOME/loader"
   mkdir -p "$HOME/loader"
@@ -875,3 +782,5 @@ else
   [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
   echo && ls -AR1 "$HOME/loader"
 fi
+
+