Powershell script to remove MSWord password protection
Please note that this script can only remove the password-protected editing restriction.#Requires -Version 5.1 <# .SYNOPSIS A script to process a Word document, remove document protection, and restore its original file format. .DESCRIPTION This script performs a three-stage process on a Word document provided via command-line. It correctly handles both relative and absolute file paths. Stage 1: Converts legacy '.doc' files to the modern '.docx' format if necessary. Stage 2: Treats the .docx file as a ZIP archive to modify its internal 'word/settings.xml'. It removes the entire '<w:documentProtection>...</w:documentProtection>' XML node from this file. Stage 3: If the original file was a '.doc', it converts the modified '.docx' file back to the '.doc' format, preserving the original filename. IMPORTANT: - You must have Microsoft Word installed for the conversion steps. - The .NET Framework 4.5 or higher is required for the ZIP manipulation functions. .PARAMETER InputFilePath The full or relative path to the Word document you want to process. .EXAMPLE # Using a full path .\Process-WordDoc.ps1 -InputFilePath "C:\Shared\ProtectedReport.docx" .EXAMPLE # Using a relative path from the script's location .\Process-WordDoc.ps1 -InputFilePath "..\Reports\LegacyProtected.doc" #> # --- PARAMETERS --- param ( [Parameter(Mandatory = $true, HelpMessage = "Please provide the full or relative path to the Word document.")] [ValidateScript({ if (-not (Test-Path $_ -PathType Leaf)) { throw "File not found at path: $_" } return $true })] [string]$InputFilePath ) # --- SCRIPT INITIALIZATION --- # Convert the provided path (which could be relative) to a fully qualified absolute path. # This is crucial for ensuring the Word COM object and other file operations work reliably. $InputFilePath = (Resolve-Path -LiteralPath $InputFilePath).ProviderPath Write-Host "Processing absolute file path: $InputFilePath" # This flag tracks if the original file was a .doc format. $wasOriginallyDoc = $false # This variable will hold the path to the .docx file we need to modify. $targetDocxPath = $InputFilePath # --- STAGE 1: CONVERT .DOC TO .DOCX (IF NECESSARY) --- if ([System.IO.Path]::GetExtension($InputFilePath).ToLower() -eq ".doc") { $wasOriginallyDoc = $true Write-Host "Stage 1: Legacy '.doc' format detected. Starting conversion." $word = $null $doc = $null try { $word = New-Object -ComObject Word.Application $word.Visible = $false $targetDocxPath = $InputFilePath -replace '\.doc$', '.docx' $doc = $word.Documents.Open($InputFilePath) $wdFormatXMLDocument = 12 # Constant for .docx format $doc.SaveAs2($targetDocxPath, $wdFormatXMLDocument) Write-Host "Successfully converted and saved file to: $targetDocxPath" } catch { Write-Error "An error occurred during the Word conversion process: $_" return # Stop the script if conversion fails. } finally { if ($doc) { $doc.Close($false) } if ($word) { $word.Quit() } if ($doc) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($doc) | Out-Null } if ($word) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null } Remove-Variable doc, word -ErrorAction SilentlyContinue } } else { Write-Host "Stage 1: File is already a .docx. No conversion necessary." } # --- STAGE 2: MODIFY SETTINGS.XML WITHIN THE .DOCX ARCHIVE --- Write-Host "Stage 2: Modifying internal XML for file: $targetDocxPath" # Explicitly load the assembly containing the ZipFile class. # This resolves the "Unable to find type" error on systems where it's not loaded by default. try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { Write-Error "Failed to load the System.IO.Compression.FileSystem assembly. This script requires .NET Framework 4.5 or higher." return } $tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString()) New-Item -Path $tempDir -ItemType Directory -Force | Out-Null try { Write-Host "Extracting archive to temporary location..." [System.IO.Compression.ZipFile]::ExtractToDirectory($targetDocxPath, $tempDir) $settingsXmlPath = Join-Path $tempDir "word\settings.xml" if (Test-Path $settingsXmlPath) { Write-Host "Found word/settings.xml. Attempting to remove document protection node." $xml = [xml](Get-Content $settingsXmlPath) $nsm = New-Object System.Xml.XmlNamespaceManager($xml.NameTable) $nsm.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main") # Find the <w:documentProtection> node using the namespace manager. $protectionNode = $xml.SelectSingleNode("//w:documentProtection", $nsm) if ($protectionNode) { # If the node is found, remove it from its parent. $protectionNode.ParentNode.RemoveChild($protectionNode) | Out-Null $xml.Save($settingsXmlPath) Write-Host "Successfully removed <w:documentProtection> node and saved changes." } else { Write-Host "<w:documentProtection> node not found. No changes made." } } else { Write-Host "File 'word/settings.xml' does not exist in the archive. Skipping modification." } Write-Host "Re-compressing archive..." if (Test-Path $targetDocxPath) { Remove-Item $targetDocxPath -Force } [System.IO.Compression.ZipFile]::CreateFromDirectory($tempDir, $targetDocxPath) Write-Host "Successfully updated the Word document." } catch { Write-Error "An error occurred during the ZIP archive manipulation: $_" } finally { if (Test-Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force Write-Host "Temporary files have been cleaned up." } } # --- STAGE 3: CONVERT BACK TO .DOC (IF NECESSARY) --- if ($wasOriginallyDoc) { Write-Host "Stage 3: Original file was '.doc'. Converting back." $word = $null $doc = $null try { $word = New-Object -ComObject Word.Application $word.Visible = $false $doc = $word.Documents.Open($targetDocxPath) $wdFormatDocument = 0 # Constant for .doc format $doc.SaveAs2($InputFilePath, $wdFormatDocument) # Save back to original filename Write-Host "Successfully converted back and saved to: $InputFilePath" } catch { Write-Error "An error occurred during the final conversion back to .doc: $_" } finally { if ($doc) { $doc.Close($false) } if ($word) { $word.Quit() } if ($doc) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($doc) | Out-Null } if ($word) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null } Remove-Variable doc, word -ErrorAction SilentlyContinue # Clean up the intermediate .docx file. if (Test-Path $targetDocxPath) { Remove-Item $targetDocxPath -Force Write-Host "Cleaned up intermediate .docx file." } } } Write-Host "Processing complete."
Modify Windows RDS port.@echo off color f0 echo Modify the port for RDS(support Windows 2003 2008 2008R2 2012 2012R2 7 8 10 ) echo Add firewall rules automatically echo %date% %time% echo ARK set /p c= Input a new port: if "%c%"=="" goto end goto edit :edit netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%" netsh advfirewall firewall add rule name="Remote PortNumber" dir=in action=allow protocol=TCP localport="%c%" reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp" /v "PortNumber" /t REG_DWORD /d "%c%" /f reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v "PortNumber" /t REG_DWORD /d "%c%" /f echo Modified echo Press any key to restart Windows pause shutdown /r /t 0 exit :end echo Failed pauseInstall serverSpeeder with version choices#!/bin/bash function Welcome() { clear echo -n " Local Time : " && date "+%F [%T] "; echo " ======================================================"; echo " | serverSpeeder |"; echo " | for Linux |"; echo " |----------------------------------------------------|"; echo " | -- By .Vicer |"; echo " ======================================================"; echo ""; rootness; mkdir -p /tmp cd /tmp } function rootness() { if $EUID -ne 0 ; then echo "Error:This script must be run as root!" 1>&2 exit 1 fi } function pause() { read -n 1 -p "Press Enter to Continue..." INP if [ "$INP" != '' ] ; then echo -ne '\b \n' echo ""; fi } function Check() { echo 'Preparatory work...' apt-get >/dev/null 2>&1 [ $? -le '1' ] && apt-get -y -qq install grep unzip ethtool >/dev/null 2>&1 yum >/dev/null 2>&1 [ $? -le '1' ] && yum -y -q install which sed grep awk unzip ethtool >/dev/null 2>&1 [ -z "$KNA" ] && [ -f /etc/redhat-release ] && KNA=$(awk '{print $1}' /etc/redhat-release) [ -z "$KNA" ] && [ -f /etc/os-release ] && KNA=$(awk -F'[= "]' '/PRETTY_NAME/{print $3}' /etc/os-release) [ -z "$KNA" ] && [ -f /etc/lsb-release ] && KNA=$(awk -F'[="]+' '/DISTRIB_ID/{print $2}' /etc/lsb-release) KNB=$(getconf LONG_BIT) ifconfig >/dev/null 2>&1 [ $? -gt '1' ] && echo -ne "I can not run 'ifconfig' successfully! \nPlease check your system, and try again! \n\n" && exit 1; [ ! -f /proc/net/dev ] && echo -ne "I can not find network device! \n\n" && exit 1; [ -n "$(grep 'eth0:' /proc/net/dev)" ] && Eth=eth0 || Eth=`cat /proc/net/dev |awk -F: 'function trim(str){sub(/^[ \t]*/,"",str); sub(/[ \t]*$/,"",str); return str } NR>2 {print trim($1)}' |grep -Ev '^lo|^sit|^stf|^gif|^dummy|^vmnet|^vir|^gre|^ipip|^ppp|^bond|^tun|^tap|^ip6gre|^ip6tnl|^teql|^venet' |awk 'NR==1 {print $0}'` [ -z "$Eth" ] && echo "I can not find the server pubilc Ethernet! " && exit 1 URLKernel='https://raw.githubusercontent.com/snowie2000/serverSpeeder_kernel/master/serverSpeeder.txt' AcceVer=$(wget --no-check-certificate -qO- "$URLKernel" |grep "$KNA/" |grep "/x$KNB/" |grep "/$KNK/" |awk -F'/' '{print $NF}' |sort -n -k 2 -t '_' |tail -n 1) MyKernel=$(wget --no-check-certificate -qO- "$URLKernel" |grep "$KNA/" |grep "/x$KNB/" |grep "/$KNK/" |grep "$AcceVer" |tail -n 1) [ -z "$MyKernel" ] && echo -ne "Kernel not be matched! \nYou should change kernel manually, and try again! \n\nView the link to get detaits: \n"$URLKernel" \n\n\n" && exit 1 pause; } function SelectKernel() { KNN=$(echo $MyKernel |awk -F '/' '{ print $2 }') && [ -z "$KNN" ] && Uninstall && echo "Error,Not Matched! " && exit 1 KNV=$(echo $MyKernel |awk -F '/' '{ print $5 }') && [ -z "$KNV" ] && Uninstall && echo "Error,Not Matched! " && exit 1 wget --no-check-certificate -q -O "/tmp/appex/apxfiles/bin/acce-"$KNV"-["$KNA"_"$KNN"_"$KNK"]" "https://raw.githubusercontent.com/snowie2000/serverSpeeder_kernel/master/$MyKernel" [ ! -f "/tmp/appex/apxfiles/bin/acce-"$KNV"-["$KNA"_"$KNN"_"$KNK"]" ] && Uninstall && echo "Download Error,Not Found acce-$KNV-[$KNA_$KNN_$KNK]! " && exit 1 } function Install() { Welcome; Check; ServerSpeeder; dl-Lic; bash /tmp/appex/install.sh rm -rf /tmp/appex* >/dev/null 2>&1 clear bash /appex/bin/serverSpeeder.sh status exit 0 } function Uninstall() { chattr -R -i /appex >/dev/null 2>&1 [ -d /etc/rc.d ] && rm -rf /etc/rc.d/init.d/serverSpeeder >/dev/null 2>&1 [ -d /etc/rc.d ] && rm -rf /etc/rc.d/rc*.d/*serverSpeeder >/dev/null 2>&1 [ -d /etc/rc.d ] && rm -rf /etc/rc.d/init.d/lotServer >/dev/null 2>&1 [ -d /etc/rc.d ] && rm -rf /etc/rc.d/rc*.d/*lotServer >/dev/null 2>&1 [ -d /etc/init.d ] && rm -rf /etc/init.d/serverSpeeder >/dev/null 2>&1 [ -d /etc/init.d ] && rm -rf /etc/rc*.d/*serverSpeeder >/dev/null 2>&1 [ -d /etc/init.d ] && rm -rf /etc/init.d/lotServer >/dev/null 2>&1 [ -d /etc/init.d ] && rm -rf /etc/rc*.d/*lotServer >/dev/null 2>&1 rm -rf /etc/lotServer.conf >/dev/null 2>&1 rm -rf /etc/serverSpeeder.conf >/dev/null 2>&1 [ -f /appex/bin/lotServer.sh ] && bash /appex/bin/lotServer.sh uninstall -f >/dev/null 2>&1 [ -f /appex/bin/serverSpeeder.sh ] && bash /appex/bin/serverSpeeder.sh uninstall -f >/dev/null 2>&1 rm -rf /appex >/dev/null 2>&1 rm -rf /tmp/appex* >/dev/null 2>&1 echo -ne 'serverSpeeder has been removed! \n\n\n' exit 0 } function dl-Lic() { chattr -R -i /appex >/dev/null 2>&1 rm -rf /appex >/dev/null 2>&1 mkdir -p /appex/etc mkdir -p /appex/bin MAC=$(ifconfig "$Eth" |awk '/HWaddr/{ print $5 }') [ -z "$MAC" ] && MAC=$(ifconfig "$Eth" |awk '/ether/{ print $2 }') [ -z "$MAC" ] && Uninstall && echo "Not Found MAC address! " && exit 1 wget --no-check-certificate -q -O "/appex/etc/apx.lic" "https://moeclub.azurewebsites.net/lic?mac=$MAC" [ "$(du -b /appex/etc/apx.lic |awk '{ print $1 }')" -ne '152' ] && Uninstall && echo "Error! I can not generate the Lic for you, Please try again later! " && exit 1 echo "Lic generate success! " [ -n $(which ethtool) ] && rm -rf /appex/bin/ethtool && cp -f $(which ethtool) /appex/bin } function ServerSpeeder() { [ ! -f /tmp/appex.zip ] && wget --no-check-certificate -q -O "/tmp/appex.zip" "https://raw.githubusercontent.com/snowie2000/serverSpeeder_Install/master/appex.zip" [ ! -f /tmp/appex.zip ] && Uninstall && echo "Error,Not Found appex.zip! " && exit 1 mkdir -p /tmp/appex unzip -o -d /tmp/appex /tmp/appex.zip SelectKernel; APXEXE=$(ls -1 /tmp/appex/apxfiles/bin |grep 'acce-') sed -i "s/^accif\=.*/accif\=\"$Eth\"/" /tmp/appex/apxfiles/etc/config sed -i "s/^apxexe\=.*/apxexe\=\"\/appex\/bin\/$APXEXE\"/" /tmp/appex/apxfiles/etc/config } [ $# == '1' ] && [ "$1" == 'install' ] && KNK="$(uname -r)" && Install; [ $# == '1' ] && [ "$1" == 'uninstall' ] && Welcome && pause && Uninstall; [ $# == '2' ] && [ "$1" == 'install' ] && KNK="$2" && Install; [ $# == '3' ] && [ "$1" == 'install' ] && KNK="$2" && KNA="$3" && Install; echo -ne "Usage:\n bash $0 [install |uninstall |install '{serverSpeeder of Kernel Version}']\n"A PHP script to generate serverSpeeder lic:<?php if ($argc < 4) { echo "Usage: php " . $argv[0] . " mac expireYear bandwidth, Bandwidth=0 means unlimited.\nExample: php " . $argv[0] . " 04:a0:67:a1:05:0b 2999 0 \n"; die; } $lic_tpl = 'b226bc274e220f53e22d863a1ec913dea6961bd046d034e88818e68d260d781345298b8d3b11e00b5061045667c12af4982992ab86ee7a4f84c1ef83020a1adc[serial]c81cb3b404eab69f59993fbf62bd373a[date]0663cea3f326[bw]a366445113ecf74205e40af32cb30c5342cc5ebd981f7e02a9326f3823e8304e4d20f942f20bdfbeaeeff843'; // month/date base: FA43 now 0663 => 1231 we do not change it $date_base = 16245; $bw_base = 3812869942; $mac = $argv[1]; $date = intval($argv[2]); $bw = intval($argv[3]); $mac = explode(':', $mac); $mac_res = array(); for ($i = 0; $i < 16; $i++) { if ($i < 6) { $mac_res[$i] = intval($mac[$i], 16) + $i; } else { $mac_res[$i] = $mac_res[$i % 6] + $i; } } $serial = ''; for ($i = 0; $i < 8; $i++) { $serial .= sprintf('%02X', ($mac_res[$i] + $mac_res[$i + 8]) % 256); } echo 'SerialNo:' . $serial . ' '; $lic = ''; $rd = array(162, 15, 239, 202, 57, 14, 45, 164, 147, 232, 120, 90, 117, 15, 239, 232); for ($i = 0; $i < 16; $i++) { $lic .= sprintf('%02x', (ord($serial[$i]) + $rd[$i]) % 256); } echo 'Lic:' . $lic . ' '; $date_lic = unpack('H*', pack('v', $date_base + $date)); $date_lic = $date_lic[1]; $bw_lic = unpack('H*', pack('V', $bw_base + $bw)); $bw_lic = $bw_lic[1]; $lic = str_replace('[serial]', $lic, $lic_tpl); $lic = str_replace('[date]', $date_lic, $lic); $lic = str_replace('[bw]', $bw_lic, $lic); @file_put_contents("./apx-" . $date . "1231.lic", pack('H*', $lic));run with php apx.php mac expireYear bandwidth such as php apx.php 02:42:ac:11:46:9e 2999 0 bandwidth=0Unattended/VNC linux install#!/bin/bash ## License: GPL ## It can reinstall Debian, Ubuntu, CentOS system with network. ## Default root password: MoeClub.org ## Blog: https://moeclub.org ## Written By MoeClub.org export tmpVER='' export tmpDIST='' export tmpURL='' export tmpWORD='' export tmpMirror='' export tmpSSL='' export tmpINS='' export ipAddr='' export ipMask='' export ipGate='' export Relese='' export ddMode='0' export setNet='0' export setRDP='0' export setIPv6='0' export isMirror='0' export FindDists='0' export loaderMode='0' export IncFirmware='0' export SpikCheckDIST='0' export setInterfaceName='0' export UNKNOWHW='0' export UNVER='6.4' while $# -ge 1 ; do case $1 in -v|--ver) shift tmpVER="$1" shift ;; -d|--debian) shift Relese='Debian' tmpDIST="$1" shift ;; -u|--ubuntu) shift Relese='Ubuntu' tmpDIST="$1" shift ;; -c|--centos) shift Relese='CentOS' tmpDIST="$1" shift ;; -dd|--image) shift ddMode='1' tmpURL="$1" shift ;; -p|--password) shift tmpWORD="$1" shift ;; -i|--interface) shift interface="$1" shift ;; --ip-addr) shift ipAddr="$1" shift ;; --ip-mask) shift ipMask="$1" shift ;; --ip-gate) shift ipGate="$1" shift ;; --dev-net) shift setInterfaceName='1' ;; --loader) shift loaderMode='1' ;; --prefer) shift tmpPrefer="$1" shift ;; -a|--auto) shift tmpINS='auto' ;; -m|--manual) shift tmpINS='manual' ;; -apt|-yum|--mirror) shift isMirror='1' tmpMirror="$1" shift ;; -rdp) shift setRDP='1' WinRemote="$1" shift ;; -ssl) shift tmpSSL="$1" shift ;; -firmware) shift IncFirmware="1" ;; --ipv6) shift setIPv6='1' ;; *) 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" exit 1; ;; esac done "$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]"; 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 } function SelectMirror(){ [ $# -ge 3 ] || exit 1 Relese="$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' MirrorTEMP="SUB_MIRROR/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${relese}-installer/${VER}/initrd.gz" elif [ "$Relese" == "CentOS" ]; then MirrorTEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img" fi [ -n "$MirrorTEMP" ] || 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") 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"` wget --no-check-certificate --spider --timeout=3 -o /dev/null "$MirrorURL" [ $? -eq 0 ] && MirrorStatus=1 && break done [ $MirrorStatus -eq 1 ] && echo "$CurMirror" || exit 1 } [ -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; linux_relese='debian'; tmpDIST='jessie'; tmpVER='amd64'; tmpINS='auto'; fi if "$Relese" == 'Debian' || "$Relese" == 'Ubuntu' ; then CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename; elif "$Relese" == 'CentOS' ; then CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz; fi [ -n "$tmpWORD" ] && CheckDependence openssl 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' 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 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'; fi if -z "$DIST" ; then if "$Relese" == 'Debian' ; then SpikCheckDIST='0' 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'; "$isDigital" == '11' && DIST='bullseye'; "$isDigital" == '12' && DIST='bookworm'; } } LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror") fi if "$Relese" == 'Ubuntu' ; then SpikCheckDIST='0' 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')"; -n $isDigital && { "$isDigital" == '12.04' && DIST='precise'; "$isDigital" == '14.04' && DIST='trusty'; "$isDigital" == '16.04' && DIST='xenial'; "$isDigital" == '18.04' && DIST='bionic'; "$isDigital" == '20.04' && DIST='focal'; "$isDigital" == '22.04' && DIST='jammy'; "$isDigital" == '24.04' && DIST='noble'; } } 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") ListDIST="$(wget --no-check-certificate -qO- "$LinuxMirror/dir_sizes" |cut -f2 |grep '^[0-9]')" DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)" -z "$DIST" && { echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n' bash $0 error; exit 1; } wget --no-check-certificate -qO- "$LinuxMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general'; [[ $? != '0' ]] && { echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n"; exit 1; } fi fi if -z "$LinuxMirror" ; then echo -ne "\033[31mError! \033[0mInvaild mirror! \n" [ "$Relese" == 'Debian' ] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n"; [ "$Relese" == 'Ubuntu' ] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n"; [ "$Relese" == 'CentOS' ] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n"; bash $0 error; exit 1; fi if "$SpikCheckDIST" == '0' ; then DistsList="$(wget --no-check-certificate -qO- "$LinuxMirror/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')"; for CheckDEB in `echo "$DistsList" |sed 's/;/\n/g'` do "$CheckDEB" == "$DIST" && FindDists='1' && break; done "$FindDists" == '0' && { echo -ne '\nThe dists version not found, Please check it! \n\n' bash $0 error; exit 1; } fi "$ddMode" == '1' && { export SSL_SUPPORT='https://moeclub.org/get/wget_udeb_amd64'; 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'; } [ "$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 "$linux_relese" == 'centos' ; then if "$DIST" != "$UNVER" ; then awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-' 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 echo -en "\n\033[31mThe version higher then \033[33m6.10 \033[31mis not support in current! \033[0m\n\n" exit 1; fi fi 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' 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 MirrorHost="$(echo "$LinuxMirror" |awk -F'://|/' '{print $2}')"; MirrorFolder="$(echo "$LinuxMirror" |awk -F''${MirrorHost}'' '{print $2}')"; elif "$linux_relese" == 'centos' ; then wget --no-check-certificate -qO '/boot/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" $? -ne '0' && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1 else bash $0 error; exit 1; 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" $? -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" 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 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.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' fi "$GRUBVER" == '0' && { READGRUB='/tmp/grub.read' cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB LoadNum="$(cat $READGRUB |grep -c 'menuentry ')" if "$LoadNum" -eq '1' ; then cat $READGRUB |sed '/^$/d' >/tmp/grub.new; elif "$LoadNum" -gt '1' ; then CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)"; CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)"; CFG1=""; for tmpCFG in `awk '/}/{print NR}' $READGRUB` do [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG"; done -z "$CFG1" && { echo "Error! read $GRUBFILE. "; exit 1; } 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"; exit 1; } fi [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1; 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; INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)" } "$GRUBVER" == '1' && { CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"; CFG1="$(awk '/title[\ ]|title[\t]/{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-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new; ! -f /tmp/grub.new && echo "Error! configure append $GRUBFILE. " && exit 1; sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new; sed -i '/^#/d' /tmp/grub.new; INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)" } 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 "$inVNC" == 'n' && { GRUBPATCH='0'; if "$loaderMode" == "0" ; then [ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || { echo "Error, Not found interfaces config."; exit 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; 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)" -z "$COMPTYPE" && echo "Detect compressed type fail." && exit 1; fi CompDected='0' for ListCOMP in `echo -en 'gzip\nlzma\nxz'` do if "$COMPTYPE" == "$ListCOMP" ; then CompDected='1' if "$COMPTYPE" == 'gzip' ; then NewIMG="initrd.img.gz" else NewIMG="initrd.img.$COMPTYPE" fi mv -f "/boot/initrd.img" "/tmp/$NewIMG" break; fi done "$CompDected" != '1' && echo "Detect compressed type not support." && exit 1; "$COMPTYPE" == 'lzma' && UNCOMP='xz --format=lzma --decompress'; "$COMPTYPE" == 'xz' && UNCOMP='xz --decompress'; "$COMPTYPE" == 'gzip' && UNCOMP='gzip -d'; $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1 if "$linux_relese" == 'debian' || "$linux_relese" == 'ubuntu' ; then cat >/tmp/boot/preseed.cfg<<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 $IFETH 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 hw-detect/load_firmware boolean true 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 d-i passwd/root-password-crypted 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 preseed/early_command string anna-install libfuse2-udeb fuse-udeb ntfs-3g-udeb fuse-modules-${vKernel_udeb}-amd64-di 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); \ mount.ntfs-3g \$(list-devices partition |head -n1) /mnt; \ 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/mount_style select uuid 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/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 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/^#?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \ sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config; EOF "$loaderMode" != "0" && AutoNet='1' "$setNet" == '0' && "$AutoNet" == '1' && { 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 } "$linux_relese" == 'debian' && { 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 } "$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'; } 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'; } echo -ne "\0100ECHO\0040OFF\r\n\r\ncd\0056\0076\0045WINDIR\0045\0134GetAdmin\r\nif\0040exist\0040\0045WINDIR\0045\0134GetAdmin\0040\0050del\0040\0057f\0040\0057q\0040\0042\0045WINDIR\0045\0134GetAdmin\0042\0051\0040else\0040\0050\r\necho\0040CreateObject\0136\0050\0042Shell\0056Application\0042\0136\0051\0056ShellExecute\0040\0042\0045\0176s0\0042\0054\0040\0042\0045\0052\0042\0054\0040\0042\0042\0054\0040\0042runas\0042\0054\00401\0040\0076\0076\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\n\0042\0045temp\0045\0134Admin\0056vbs\0042\r\ndel\0040\0057f\0040\0057q\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\nexit\0040\0057b\00402\0051\r\n\r\n" >'/tmp/boot/net.tmp'; "$setNet" == '1' && WinNoDHCP; "$setNet" == '0' && "$AutoNet" == '0' && WinNoDHCP; "$setRDP" == '1' && -n "$WinRemote" && WinRDP echo -ne "ECHO\0040SELECT\0040VOLUME\0075\0045\0045SystemDrive\0045\0045\0040\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nECHO\0040EXTEND\0040\0076\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nSTART\0040/WAIT\0040DISKPART\0040\0057S\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nDEL\0040\0057f\0040\0057q\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\n\r\n" >>'/tmp/boot/net.tmp'; 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' && { sed -i '/anna-install/d' /tmp/boot/preseed.cfg sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg } elif "$linux_relese" == 'centos' ; then cat >/tmp/boot/ks.cfg<<EOF #platform=x86, AMD64, or Intel EM64T firewall --enabled --ssh install url --url="$LinuxMirror/$DIST/os/$VER/" rootpw --iscrypted $myPASSWORD auth --useshadow --passalgo=sha512 firstboot --disable lang en_US keyboard us selinux --disabled logging --level=info reboot text unsupported_hardware 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 bootloader --location=mbr --append="rhgb quiet crashkernel=auto" zerombr clearpart --all --initlabel autopart %packages @base %end %post --interpreter=/bin/bash rm -rf /root/anaconda-ks.cfg rm -rf /root/install.*log %end 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'; } chown root:root $GRUBDIR/$GRUBFILE chmod 444 $GRUBDIR/$GRUBFILE if "$loaderMode" == "0" ; then sleep 3 && reboot >/dev/null 2>&1 else rm -rf "$HOME/loader" mkdir -p "$HOME/loader" cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img" cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz" -f "/boot/initrd.img" && rm -rf "/boot/initrd.img" -f "/boot/vmlinuz" && rm -rf "/boot/vmlinuz" echo && ls -AR1 "$HOME/loader" fiUsage: Usage: bash InstallNET.sh -d/--debian [dists-name] -u/--ubuntu [dists-name] -c/--centos [dists-verison] -v/--ver [32/i386|64/amd64] --ip-addr/--ip-gate/--ip-mask -apt/-yum/--mirror -dd/--image -a/--auto -m/--manualPrevent foreground application to lose focusWindows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Control Panel\Desktop] "ForegroundLockTimeout"=dword:0016f598
Reinstall debian/ubuntu/centos with script
Here comes a simple script that reinstalls your existing system with a fresh clean system.Copyright: Vicercode:#!/bin/bash ## It can reinstall Debian, Ubuntu, CentOS system with network. ## Suitable for using by GRUB. ## Default root password: Vicer ## Blog: https://moeclub.org ## Written By Vicer export tmpVER='' export tmpDIST='' export tmpURL='' export tmpWORD='' export tmpMirror='' export tmpSSL='' export tmpINS='' export tmpFW='' export ipAddr='' export ipMask='' export ipGate='' export linuxdists='' export ddMode='0' export setNet='0' export setRDP='0' export isMirror='0' export FindDists='0' export loaderMode='0' export SpikCheckDIST='0' export UNKNOWHW='0' export UNVER='6.4' while $# -ge 1 ; do case $1 in -v|--ver) shift tmpVER="$1" shift ;; -d|--debian) shift linuxdists='debian' tmpDIST="$1" shift ;; -u|--ubuntu) shift linuxdists='ubuntu' tmpDIST="$1" shift ;; -c|--centos) shift linuxdists='centos' tmpDIST="$1" shift ;; -dd|--image) shift ddMode='1' tmpURL="$1" shift ;; -p|--password) shift tmpWORD="$1" shift ;; -i|--interface) shift interface="$1" shift ;; --ip-addr) shift ipAddr="$1" shift ;; --ip-mask) shift ipMask="$1" shift ;; --ip-gate) shift ipGate="$1" shift ;; --loader) shift loaderMode='1' ;; --prefer) shift tmpPrefer="$1" shift ;; -a|--auto) shift tmpINS='auto' ;; -m|--manual) shift tmpINS='manual' ;; -apt|-yum|--mirror) shift isMirror='1' tmpMirror="$1" shift ;; -rdp) shift setRDP='1' WinRemote="$1" shift ;; -ssl) shift tmpSSL="$1" shift ;; --firmware) shift tmpFW='1' ;; *) if "$1" != 'error' ; then echo -ne "\nInvaild option: '$1'\n\n"; fi echo -ne " Usage:\n\tbash DebianNET.sh\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" exit 1; ;; esac done "$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]"; 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 } if -z "$linuxdists" ; then linuxdists='debian'; fi clear && echo -e "\n\033[36m# Check Dependence\033[0m\n" if "$ddMode" == '1' ; then CheckDependence iconv; linuxdists='debian'; tmpDIST='jessie'; tmpVER='amd64'; tmpINS='auto'; fi if "$linuxdists" == 'debian' || "$linuxdists" == 'ubuntu' ; then CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename; elif "$linuxdists" == 'centos' ; then CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz; fi if -n "$tmpWORD" ; then CheckDependence openssl; fi if "$loaderMode" == "0" ; then -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" && exit 1; else tmpINS='auto' fi if "$isMirror" == '1' ; then if -n "$tmpMirror" ; then TMPMirrorHost="$(echo -n "$tmpMirror" |grep -Eo '.*\.(\w+)')"; echo "$TMPMirrorHost" |grep -q '://'; if [[ $? == '0' ]]; then MirrorHost="$(echo "$TMPMirrorHost" |awk -F'://' '{print $2}')"; else echo -en "\n\033[31mInvaild Mirror! \033[0m\n"; "$linuxdists" == 'debian' && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n"; "$linuxdists" == 'ubuntu' && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n"; "$linuxdists" == 'centos' && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n"; exit 1 fi if -n "$MirrorHost" ; then MirrorFolder="$(echo -n "$tmpMirror" |awk -F''${MirrorHost}'' '{print $2}' |sed 's/\/$//g')"; if -z "$MirrorFolder" ; then "$linuxdists" == 'debian' && MirrorFolder='/debian'; "$linuxdists" == 'ubuntu' && MirrorFolder='/ubuntu'; "$linuxdists" == 'centos' && MirrorFolder='/centos'; fi DISTMirror="${MirrorHost}${MirrorFolder}"; fi fi fi if -z "$DISTMirror" ; then "$linuxdists" == 'debian' && MirrorHost='deb.debian.org' && MirrorFolder='/debian' && DISTMirror="${MirrorHost}${MirrorFolder}"; "$linuxdists" == 'ubuntu' && MirrorHost='archive.ubuntu.com' && MirrorFolder='/ubuntu' && DISTMirror="${MirrorHost}${MirrorFolder}"; "$linuxdists" == 'centos' && DISTMirror='vault.centos.org'; 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 "$linuxdists" == 'debian' || "$linuxdists" == 'ubuntu' ; then VER='amd64'; elif "$linuxdists" == 'centos' ; then VER='x86_64'; fi fi fi if -z "$VER" ; then VER='i386'; fi if -n "$tmpPrefer" ; then PreferOption="$(echo "$tmpPrefer" |sed 's/[[:space:]]*//g')" fi if -z "$PreferOption" ; then PreferOption='current'; fi if -z "$tmpDIST" ; then "$linuxdists" == 'debian' && DIST='jessie'; "$linuxdists" == 'ubuntu' && DIST='xenial'; "$linuxdists" == 'centos' && DIST='6.8'; fi if -z "$DIST" ; then if "$linuxdists" == 'debian' ; then SpikCheckDIST='0' 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'; } } fi if "$linuxdists" == 'ubuntu' ; then SpikCheckDIST='0' 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')"; -n $isDigital && { "$isDigital" == '12.04' && DIST='precise'; "$isDigital" == '14.04' && DIST='trusty'; "$isDigital" == '16.04' && DIST='xenial'; "$isDigital" == '18.04' && DIST='bionic'; } } fi if "$linuxdists" == 'centos' ; then SpikCheckDIST='1' DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}')"; ListDIST="$(wget --no-check-certificate -qO- "http://$DISTMirror/dir_sizes" |cut -f2 |grep '^[0-9]')" DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)" -z "$DIST" && { echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n' bash $0 error; exit 1; } wget --no-check-certificate -qO- "http://$DISTMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general'; [[ $? != '0' ]] && { wget --no-check-certificate -qO- "http://$DISTMirror/centos/$DIST/os/$VER/.treeinfo" |grep -q 'general'; [[ $? == '0' ]] && { DISTMirror="${DISTMirror}/${linuxdists}" } || { echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n"; exit 1; } } fi fi if "$SpikCheckDIST" == '0' ; then DistsList="$(wget --no-check-certificate -qO- "http://$DISTMirror/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')"; for CheckDEB in `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 $0 error; exit 1; } fi "$ddMode" == '1' && { export SSL_SUPPORT='https://moeclub.org/get-wget_udeb_amd64'; 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$0shYGfBd$8v189JOozDO1jPqPO645e1'; -n "$tmpFW" && INCFW="$tmpFW"; -z "$INCFW" && INCFW='0'; if -n "$interface" ; then IFETH="$interface" else if "$linuxdists" == '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[34mCan you login VNC?\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'; } [ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC; "$linuxdists" == 'debian' && LinuxName='Debian'; "$linuxdists" == 'ubuntu' && LinuxName='Ubuntu'; "$linuxdists" == 'centos' && LinuxName='CentOS'; "$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" } if "$linuxdists" == 'centos' ; then if "$DIST" != "$UNVER" ; then awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-' 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 echo -en "\n\033[31mThe version higher then \033[33m6.9 \033[31mis not support in current! \033[0m\n\n" exit 1; fi fi fi echo -e "\n[\033[33m$LinuxName\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..." -z "$DISTMirror" && echo -ne "\033[31mError! \033[0mInvaild mirror! \n" && exit 1 if "$linuxdists" == 'debian' || "$linuxdists" == 'ubuntu' ; then wget --no-check-certificate -qO '/boot/initrd.img' "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/netboot/$linuxdists-installer/$VER/initrd.gz" $? -ne '0' && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linuxdists\033[0m failed! \n" && exit 1 wget --no-check-certificate -qO '/boot/vmlinuz' "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/netboot/$linuxdists-installer/$VER/linux" $? -ne '0' && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linuxdists\033[0m failed! \n" && exit 1 elif "$linuxdists" == 'centos' ; then wget --no-check-certificate -qO '/boot/initrd.img' "http://$DISTMirror/$DIST/os/$VER/isolinux/initrd.img" $? -ne '0' && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linuxdists\033[0m failed! \n" && exit 1 wget --no-check-certificate -qO '/boot/vmlinuz' "http://$DISTMirror/$DIST/os/$VER/isolinux/vmlinuz" $? -ne '0' && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linuxdists\033[0m failed! \n" && exit 1 fi if "$linuxdists" == 'debian' ; then if "$INCFW" == '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" $? -ne '0' && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linuxdists\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/$PreferOption/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-4" 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 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.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 GRUBOLD='2' fi "$GRUBOLD" == '0' && { READGRUB='/tmp/grub.read' cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB LoadNum="$(cat $READGRUB |grep -c 'menuentry ')" if "$LoadNum" -eq '1' ; then cat $READGRUB |sed '/^$/d' >/tmp/grub.new; elif "$LoadNum" -gt '1' ; then CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)"; CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)"; CFG1=""; for tmpCFG in `awk '/}/{print NR}' $READGRUB` do [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG"; done -z "$CFG1" && { echo "Error! read $GRUBFILE. "; exit 1; } 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"; exit 1; } fi [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1; 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; INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)" } "$GRUBOLD" == '1' && { CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"; CFG1="$(awk '/title[\ ]|title[\t]/{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-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new; ! -f /tmp/grub.new && echo "Error! configure append $GRUBFILE. " && exit 1; sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new; sed -i '/^#/d' /tmp/grub.new; INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)" } 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 "$linuxdists" == 'debian' || "$linuxdists" == 'ubuntu' ; then BOOT_OPTION="auto=true hostname=$linuxdists domain= -- quiet" elif "$linuxdists" == 'centos' ; then BOOT_OPTION="ks=file://ks.cfg 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 "$inVNC" == 'n' && { GRUBPATCH='0'; if "$loaderMode" == "0" ; then [ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || { echo "Error, Not found interfaces config."; exit 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; fi -d /tmp/boot && rm -rf /tmp/boot; mkdir -p /tmp/boot; cd /tmp/boot; if "$linuxdists" == 'debian' || "$linuxdists" == 'ubuntu' ; then COMPTYPE="gzip"; elif "$linuxdists" == 'centos' ; then COMPTYPE="$(file /boot/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'` do if "$COMPTYPE" == "$ListCOMP" ; then CompDected='1' if "$COMPTYPE" == 'gzip' ; then NewIMG="initrd.img.gz" else NewIMG="initrd.img.$COMPTYPE" fi mv -f "/boot/initrd.img" "/tmp/$NewIMG" break; fi done "$CompDected" != '1' && echo "Detect compressed type not support." && exit 1; "$COMPTYPE" == 'lzma' && UNCOMP='xz --format=lzma --decompress'; "$COMPTYPE" == 'xz' && UNCOMP='xz --decompress'; "$COMPTYPE" == 'gzip' && UNCOMP='gzip -d'; $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1 if "$linuxdists" == 'debian' || "$linuxdists" == 'ubuntu' ; then cat >/tmp/boot/preseed.cfg<<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 $IFETH 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 hw-detect/load_firmware boolean true 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 passwd/root-login boolean ture d-i passwd/make-user boolean false d-i passwd/root-password-crypted 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 preseed/early_command string anna-install libfuse2-udeb fuse-udeb ntfs-3g-udeb fuse-modules-${vKernel_udeb}-amd64-di d-i partman/early_command string \ debconf-set partman-auto/disk "\$(list-devices disk |head -n1)"; \ wget -qO- '$DDURL' |gunzip -dc |/bin/dd of=\$(list-devices disk |head -n1); \ mount.ntfs-3g \$(list-devices partition |head -n1) /mnt; \ 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/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 -ri 's/^#?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \ sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config; EOF "$loaderMode" != "0" && AutoNet='1' "$setNet" == '0' && "$AutoNet" == '1' && { 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' "$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 } "$DIST" == 'xenial' && { sed -i 's/^d-i\ clock-setup\/ntp\ boolean\ true/d-i\ clock-setup\/ntp\ boolean\ false/g' /tmp/boot/preseed.cfg } "$linuxdists" == 'debian' && { 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 } "$INCFW" == '1' && "$linuxdists" == 'debian' && -f '/boot/firmware.cpio.gz' && { gzip -d < /boot/firmware.cpio.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1 } "$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'; } 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'; } echo -ne "\0100ECHO\0040OFF\r\n\r\ncd\0056\0076\0045WINDIR\0045\0134GetAdmin\r\nif\0040exist\0040\0045WINDIR\0045\0134GetAdmin\0040\0050del\0040\0057f\0040\0057q\0040\0042\0045WINDIR\0045\0134GetAdmin\0042\0051\0040else\0040\0050\r\necho\0040CreateObject\0136\0050\0042Shell\0056Application\0042\0136\0051\0056ShellExecute\0040\0042\0045\0176s0\0042\0054\0040\0042\0045\0052\0042\0054\0040\0042\0042\0054\0040\0042runas\0042\0054\00401\0040\0076\0076\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\n\0042\0045temp\0045\0134Admin\0056vbs\0042\r\ndel\0040\0057f\0040\0057q\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\nexit\0040\0057b\00402\0051\r\n\r\n" >'/tmp/boot/net.tmp'; "$setNet" == '1' && WinNoDHCP; "$setNet" == '0' && "$AutoNet" == '0' && WinNoDHCP; "$setRDP" == '1' && -n "$WinRemote" && WinRDP echo -ne "ECHO\0040SELECT\0040VOLUME\0075\0045\0045SystemDrive\0045\0045\0040\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nECHO\0040EXTEND\0040\0076\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nSTART\0040/WAIT\0040DISKPART\0040\0057S\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nDEL\0040\0057f\0040\0057q\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\n\r\n" >>'/tmp/boot/net.tmp'; 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' && { sed -i '/anna-install/d' /tmp/boot/preseed.cfg sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg } elif "$linuxdists" == 'centos' ; then cat >/tmp/boot/ks.cfg<<EOF #platform=x86, AMD64, or Intel EM64T firewall --enabled --ssh install url --url="http://$DISTMirror/$DIST/os/$VER/" rootpw --iscrypted $myPASSWORD auth --useshadow --passalgo=sha512 firstboot --disable lang en_US keyboard us selinux --disabled logging --level=info reboot text unsupported_hardware 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 bootloader --location=mbr --append="rhgb quiet crashkernel=auto" zerombr clearpart --all --initlabel autopart %packages @base %end %post --interpreter=/bin/bash rm -rf /root/anaconda-ks.cfg rm -rf /root/install.*log %end 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 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/$GRUBFILE chmod 444 $GRUBDIR/$GRUBFILE if "$loaderMode" == "0" ; then sleep 3 && reboot >/dev/null 2>&1 else rm -rf "$HOME/loader" mkdir -p "$HOME/loader" cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img" cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz" -f "/boot/initrd.img" && rm -rf "/boot/initrd.img" -f "/boot/vmlinuz" && rm -rf "/boot/vmlinuz" echo && ls -AR1 "$HOME/loader" fiUsage: bash InstallNET.sh -d/--debian [dist-name] -u/--ubuntu [dist-name] -c/--centos [dist-version] -v/--ver [32/i386|64/amd64] --ip-addr/--ip-gate/--ip-mask -apt/-yum/--mirror -dd/--image -a/-mWell known codenames:Debian7 wheezyDebian8 jessieDebian9 stretchUbuntu14 trustyUbuntu16 xenialUbuntu17 zestyDefault password: Vicer