InstallNET.sh 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. #!/bin/bash
  2. ## License: GPL
  3. ## It can reinstall Debian, Ubuntu, CentOS system with network.
  4. ## Default root password: MoeClub.org
  5. ## Blog: https://moeclub.org
  6. ## Written By MoeClub.org
  7. ## Modify By Teddysun <[email protected]>
  8. export tmpVER=''
  9. export tmpDIST=''
  10. export tmpURL=''
  11. export tmpWORD=''
  12. export tmpMirror=''
  13. export ipAddr=''
  14. export ipMask=''
  15. export ipGate=''
  16. export ipDNS='8.8.8.8'
  17. export IncDisk='default'
  18. export interface=''
  19. export interfaceSelect=''
  20. export Relese=''
  21. export sshPORT='22'
  22. export ddMode='0'
  23. export setNet='0'
  24. export setRDP='0'
  25. export setIPv6='0'
  26. export isMirror='0'
  27. export FindDists='0'
  28. export loaderMode='0'
  29. export IncFirmware='0'
  30. export SpikCheckDIST='0'
  31. export setInterfaceName='0'
  32. export UNKNOWHW='0'
  33. export UNVER='6.4'
  34. export GRUBDIR=''
  35. export GRUBFILE=''
  36. export GRUBVER=''
  37. export VER=''
  38. export setCMD=''
  39. export setConsole=''
  40. while [[ $# -ge 1 ]]; do
  41. case $1 in
  42. -v | --ver)
  43. shift
  44. tmpVER="$1"
  45. shift
  46. ;;
  47. -d | --debian)
  48. shift
  49. Relese='Debian'
  50. tmpDIST="$1"
  51. shift
  52. ;;
  53. -u | --ubuntu)
  54. shift
  55. Relese='Ubuntu'
  56. tmpDIST="$1"
  57. shift
  58. ;;
  59. -c | --centos)
  60. shift
  61. Relese='CentOS'
  62. tmpDIST="$1"
  63. shift
  64. ;;
  65. -dd | --image)
  66. shift
  67. ddMode='1'
  68. tmpURL="$1"
  69. shift
  70. ;;
  71. -p | --password)
  72. shift
  73. tmpWORD="$1"
  74. shift
  75. ;;
  76. -i | --interface)
  77. shift
  78. interfaceSelect="$1"
  79. shift
  80. ;;
  81. --ip-addr)
  82. shift
  83. ipAddr="$1"
  84. shift
  85. ;;
  86. --ip-mask)
  87. shift
  88. ipMask="$1"
  89. shift
  90. ;;
  91. --ip-gate)
  92. shift
  93. ipGate="$1"
  94. shift
  95. ;;
  96. --ip-dns)
  97. shift
  98. ipDNS="$1"
  99. shift
  100. ;;
  101. --dev-net)
  102. shift
  103. setInterfaceName='1'
  104. ;;
  105. --loader)
  106. shift
  107. loaderMode='1'
  108. ;;
  109. -apt | -yum | --mirror)
  110. shift
  111. isMirror='1'
  112. tmpMirror="$1"
  113. shift
  114. ;;
  115. -rdp)
  116. shift
  117. setRDP='1'
  118. WinRemote="$1"
  119. shift
  120. ;;
  121. -cmd)
  122. shift
  123. setCMD="$1"
  124. shift
  125. ;;
  126. -console)
  127. shift
  128. setConsole="$1"
  129. shift
  130. ;;
  131. -firmware)
  132. shift
  133. IncFirmware="1"
  134. ;;
  135. -port)
  136. shift
  137. sshPORT="$1"
  138. shift
  139. ;;
  140. --noipv6)
  141. shift
  142. setIPv6='1'
  143. ;;
  144. -a | --auto | -m | --manual | -ssl)
  145. shift
  146. ;;
  147. *)
  148. if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
  149. 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"
  150. exit 1
  151. ;;
  152. esac
  153. done
  154. [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1
  155. function dependence() {
  156. Full='0'
  157. for BIN_DEP in $(echo "$1" | sed 's/,/\n/g'); do
  158. if [[ -n "$BIN_DEP" ]]; then
  159. Found='0'
  160. for BIN_PATH in $(echo "$PATH" | sed 's/:/\n/g'); do
  161. ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1
  162. if [ $? == '0' ]; then
  163. Found='1'
  164. break
  165. fi
  166. done
  167. if [ "$Found" == '1' ]; then
  168. echo -en "[\033[32mok\033[0m]\t"
  169. else
  170. Full='1'
  171. echo -en "[\033[31mNot Install\033[0m]"
  172. fi
  173. echo -en "\t$BIN_DEP\n"
  174. fi
  175. done
  176. if [ "$Full" == '1' ]; then
  177. echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
  178. exit 1
  179. fi
  180. }
  181. function selectMirror() {
  182. [ $# -ge 3 ] || exit 1
  183. Relese=$(echo "$1" | sed -r 's/(.*)/\L\1/')
  184. DIST=$(echo "$2" | sed 's/\ //g' | sed -r 's/(.*)/\L\1/')
  185. VER=$(echo "$3" | sed 's/\ //g' | sed -r 's/(.*)/\L\1/')
  186. New=$(echo "$4" | sed 's/\ //g')
  187. [ -n "$Relese" ] && [ -n "$DIST" ] && [ -n "$VER" ] || exit 1
  188. if [ "$Relese" == "debian" ] || [ "$Relese" == "ubuntu" ]; then
  189. [ "$DIST" == "focal" ] && legacy="legacy-" || legacy=""
  190. TEMP="SUB_MIRROR/dists/${DIST}/main/installer-${VER}/current/${legacy}images/netboot/${Relese}-installer/${VER}/initrd.gz"
  191. elif [ "$Relese" == "centos" ]; then
  192. TEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img"
  193. fi
  194. [ -n "$TEMP" ] || exit 1
  195. mirrorStatus=0
  196. declare -A MirrorBackup
  197. 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")
  198. echo "$New" | grep -q '^http://\|^https://\|^ftp://' && MirrorBackup[${Relese}0]="$New"
  199. for mirror in $(echo "${!MirrorBackup[@]}" | sed 's/\ /\n/g' | sort -n | grep "^$Relese"); do
  200. Current="${MirrorBackup[$mirror]}"
  201. [ -n "$Current" ] || continue
  202. MirrorURL=$(echo "$TEMP" | sed "s#SUB_MIRROR#${Current}#g")
  203. wget --no-check-certificate --spider --timeout=3 -o /dev/null "$MirrorURL"
  204. [ $? -eq 0 ] && mirrorStatus=1 && break
  205. done
  206. [ ${mirrorStatus} -eq 1 ] && echo "$Current" || exit 1
  207. }
  208. function netmask() {
  209. n="${1:-32}"
  210. b=""
  211. m=""
  212. for ((i = 0; i < 32; i++)); do
  213. [ $i -lt $n ] && b="${b}1" || b="${b}0"
  214. done
  215. for ((i = 0; i < 4; i++)); do
  216. s=$(echo "$b" | cut -c$(($(($i * 8)) + 1))-$(($(($i + 1)) * 8)))
  217. [ "$m" == "" ] && m="$((2#${s}))" || m="${m}.$((2#${s}))"
  218. done
  219. echo "$m"
  220. }
  221. function getInterface() {
  222. interface=""
  223. 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')
  224. defaultRoute=$(ip route show default | grep "^default")
  225. for item in $(echo "$Interfaces"); do
  226. [ -n "$item" ] || continue
  227. echo "$defaultRoute" | grep -q "$item"
  228. [ $? -eq 0 ] && interface="$item" && break
  229. done
  230. echo "$interface"
  231. }
  232. function getDisk() {
  233. disks=$(lsblk | sed 's/[[:space:]]*$//g' | grep "disk$" | cut -d' ' -f1 | grep -v "fd[0-9]*\|sr[0-9]*" | head -n1)
  234. [ -n "$disks" ] || echo ""
  235. echo "$disks" | grep -q "/dev"
  236. [ $? -eq 0 ] && echo "$disks" || echo "/dev/$disks"
  237. }
  238. function diskType() {
  239. echo $(udevadm info --query all "$1" 2>/dev/null | grep 'ID_PART_TABLE_TYPE' | cut -d'=' -f2)
  240. }
  241. function getGrub() {
  242. Boot="${1:-/boot}"
  243. folder=$(find "$Boot" -type d -name "grub*" 2>/dev/null | sort | tail -n1)
  244. [ -n "$folder" ] || return
  245. fileName=$(ls -1 "$folder" 2>/dev/null | grep '^grub.conf$\|^grub.cfg$')
  246. if [ -z "$fileName" ]; then
  247. ls -1 "$folder" 2>/dev/null | grep -q '^grubenv$'
  248. [ $? -eq 0 ] || return
  249. folder=$(find "$Boot" -type f -name "grubenv" 2>/dev/null | xargs dirname | grep -v "^$folder" | head -n1)
  250. [ -n "$folder" ] || return
  251. fileName=$(ls -1 "$folder" 2>/dev/null | grep '^grub.conf$\|^grub.cfg$')
  252. fi
  253. [ -n "$fileName" ] || return
  254. [ "$fileName" == "grub.cfg" ] && ver="0" || ver="1"
  255. echo "${folder}:${fileName}:${ver}"
  256. }
  257. function lowMem() {
  258. mem=$(grep "^MemTotal:" /proc/meminfo 2>/dev/null | grep -o "[0-9]*")
  259. [ -n "$mem" ] || return 0
  260. [ "$mem" -le "524288" ] && return 1 || return 0
  261. }
  262. if [[ "$loaderMode" == "0" ]]; then
  263. Grub=$(getGrub "/boot")
  264. [ -z "$Grub" ] && echo -ne "Error! Not Found grub.\n" && exit 1
  265. GRUBDIR=$(echo "$Grub" | cut -d':' -f1)
  266. GRUBFILE=$(echo "$Grub" | cut -d':' -f2)
  267. GRUBVER=$(echo "$Grub" | cut -d':' -f3)
  268. fi
  269. [ -n "$Relese" ] || Relese='Debian'
  270. linux_relese=$(echo "$Relese" | sed 's/\ //g' | sed -r 's/(.*)/\L\1/')
  271. clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
  272. if [[ "$ddMode" == '1' ]]; then
  273. dependence iconv
  274. linux_relese='debian'
  275. tmpDIST='bookworm'
  276. tmpVER='amd64'
  277. fi
  278. [ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1'
  279. if [ "$setNet" == "0" ]; then
  280. dependence ip
  281. [ -n "$interface" ] || interface=$(getInterface)
  282. 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\}')
  283. ipAddr=$(echo ${iAddr} | cut -d'/' -f1)
  284. ipMask=$(netmask $(echo ${iAddr} | cut -d'/' -f2))
  285. 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)
  286. fi
  287. if [ -z "$interface" ]; then
  288. dependence ip
  289. [ -n "$interface" ] || interface=$(getInterface)
  290. fi
  291. IPv4="$ipAddr"
  292. MASK="$ipMask"
  293. GATE="$ipGate"
  294. [ -n "$IPv4" ] && [ -n "$MASK" ] && [ -n "$GATE" ] && [ -n "$ipDNS" ] || {
  295. echo -ne '\nError: Invalid network config\n\n'
  296. bash $0 error
  297. exit 1
  298. }
  299. if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
  300. dependence wget,awk,grep,sed,cut,cat,lsblk,cpio,gzip,find,dirname,basename
  301. elif [[ "$Relese" == 'CentOS' ]]; then
  302. dependence wget,awk,grep,sed,cut,cat,lsblk,cpio,gzip,find,dirname,basename,file,xz
  303. fi
  304. [[ -n "$tmpWORD" ]] && dependence openssl
  305. [[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")"
  306. [[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0'
  307. tempDisk=$(getDisk)
  308. [ -n "$tempDisk" ] && IncDisk="$tempDisk"
  309. case $(uname -m) in aarch64 | arm64) VER="arm64" ;; x86 | i386 | i686) VER="i386" ;; x86_64 | amd64) VER="amd64" ;; *) VER="" ;; esac
  310. tmpVER="$(echo "$tmpVER" | sed -r 's/(.*)/\L\1/')"
  311. if [[ "$VER" != "arm64" ]] && [[ -n "$tmpVER" ]]; then
  312. case "$tmpVER" in i386 | i686 | x86 | 32) VER="i386" ;; amd64 | x86_64 | x64 | 64) [[ "$Relese" == 'CentOS' ]] && VER='x86_64' || VER='amd64' ;; *) VER='' ;; esac
  313. fi
  314. if [[ ! -n "$VER" ]]; then
  315. echo "Error! Not Architecture."
  316. bash $0 error
  317. exit 1
  318. fi
  319. if [[ -z "$tmpDIST" ]]; then
  320. [ "$Relese" == 'Debian' ] && tmpDIST='buster'
  321. [ "$Relese" == 'Ubuntu' ] && tmpDIST='bionic'
  322. [ "$Relese" == 'CentOS' ] && tmpDIST='6.10'
  323. fi
  324. if [[ -n "$tmpDIST" ]]; then
  325. if [[ "$Relese" == 'Debian' ]]; then
  326. SpikCheckDIST='0'
  327. DIST="$(echo "$tmpDIST" | sed -r 's/(.*)/\L\1/')"
  328. echo "$DIST" | grep -q '[0-9]'
  329. [[ $? -eq '0' ]] && {
  330. isDigital="$(echo "$DIST" | grep -o '[\.0-9]\{1,\}' | sed -n '1h;1!H;$g;s/\n//g;$p' | cut -d'.' -f1)"
  331. [[ -n $isDigital ]] && {
  332. [[ "$isDigital" == '7' ]] && DIST='wheezy'
  333. [[ "$isDigital" == '8' ]] && DIST='jessie'
  334. [[ "$isDigital" == '9' ]] && DIST='stretch'
  335. [[ "$isDigital" == '10' ]] && DIST='buster'
  336. [[ "$isDigital" == '11' ]] && DIST='bullseye'
  337. [[ "$isDigital" == '12' ]] && DIST='bookworm'
  338. }
  339. }
  340. LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
  341. fi
  342. if [[ "$Relese" == 'Ubuntu' ]]; then
  343. SpikCheckDIST='0'
  344. DIST="$(echo "$tmpDIST" | sed -r 's/(.*)/\L\1/')"
  345. echo "$DIST" | grep -q '[0-9]'
  346. [[ $? -eq '0' ]] && {
  347. isDigital="$(echo "$DIST" | grep -o '[\.0-9]\{1,\}' | sed -n '1h;1!H;$g;s/\n//g;$p')"
  348. [[ -n $isDigital ]] && {
  349. [[ "$isDigital" == '12.04' ]] && DIST='precise'
  350. [[ "$isDigital" == '14.04' ]] && DIST='trusty'
  351. [[ "$isDigital" == '16.04' ]] && DIST='xenial'
  352. [[ "$isDigital" == '18.04' ]] && DIST='bionic'
  353. [[ "$isDigital" == '20.04' ]] && DIST='focal'
  354. # [[ "$isDigital" == '22.04' ]] && DIST='jammy';
  355. }
  356. }
  357. LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
  358. fi
  359. if [[ "$Relese" == 'CentOS' ]]; then
  360. SpikCheckDIST='1'
  361. DISTCheck="$(echo "$tmpDIST" | grep -o '[\.0-9]\{1,\}' | head -n1)"
  362. LinuxMirror=$(selectMirror "$Relese" "$DISTCheck" "$VER" "$tmpMirror")
  363. ListDIST="$(wget --no-check-certificate -qO- "$LinuxMirror/dir_sizes" | cut -f2 | grep '^[0-9]')"
  364. DIST="$(echo "$ListDIST" | grep "^$DISTCheck" | head -n1)"
  365. [[ -z "$DIST" ]] && {
  366. echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n'
  367. bash $0 error
  368. exit 1
  369. }
  370. wget --no-check-certificate -qO- "$LinuxMirror/$DIST/os/$VER/.treeinfo" | grep -q 'general'
  371. [[ $? != '0' ]] && {
  372. echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n"
  373. exit 1
  374. }
  375. fi
  376. fi
  377. if [[ -z "$LinuxMirror" ]]; then
  378. echo -ne "\033[31mError! \033[0mInvaild mirror! \n"
  379. [ "$Relese" == 'Debian' ] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n"
  380. [ "$Relese" == 'Ubuntu' ] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n"
  381. [ "$Relese" == 'CentOS' ] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n"
  382. bash $0 error
  383. exit 1
  384. fi
  385. if [[ "$SpikCheckDIST" == '0' ]]; then
  386. 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')"
  387. for CheckDEB in $(echo "$DistsList" | sed 's/;/\n/g'); do
  388. [[ "$CheckDEB" == "$DIST" ]] && FindDists='1' && break
  389. done
  390. [[ "$FindDists" == '0' ]] && {
  391. echo -ne '\nThe dists version not found, Please check it! \n\n'
  392. bash $0 error
  393. exit 1
  394. }
  395. fi
  396. if [[ "$ddMode" == '1' ]]; then
  397. if [[ -n "$tmpURL" ]]; then
  398. DDURL="$tmpURL"
  399. echo "$DDURL" | grep -q '^http://\|^ftp://\|^https://'
  400. [[ $? -ne '0' ]] && echo 'Please input vaild URL, Only support http://, ftp:// and https:// !' && exit 1
  401. # Decompress command selection
  402. if echo "$DDURL" | grep -q '.gz'; then
  403. DEC_CMD="gunzip -dc"
  404. elif echo "$DDURL" | grep -q '.xz'; then
  405. DEC_CMD="xzcat"
  406. else
  407. echo 'Please input vaild URL, Only support gz or xz file!' && exit 1
  408. fi
  409. else
  410. echo 'Please input vaild image URL! '
  411. exit 1
  412. fi
  413. fi
  414. clear && echo -e "\n\033[36m# Install\033[0m\n"
  415. [[ "$ddMode" == '1' ]] && echo -ne "\033[34mAuto Mode\033[0m insatll \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
  416. if [ -z "$interfaceSelect" ]; then
  417. if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
  418. interfaceSelect="auto"
  419. elif [[ "$linux_relese" == 'centos' ]]; then
  420. interfaceSelect="link"
  421. fi
  422. fi
  423. if [[ "$linux_relese" == 'centos' ]]; then
  424. if [[ "$DIST" != "$UNVER" ]]; then
  425. awk 'BEGIN{print '${UNVER}'-'${DIST}'}' | grep -q '^-'
  426. if [ $? != '0' ]; then
  427. UNKNOWHW='1'
  428. echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n"
  429. fi
  430. awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' | grep -q '^-'
  431. if [ $? == '0' ]; then
  432. echo -en "\n\033[31mThe version higher then \033[33m6.10 \033[31mis not support in current! \033[0m\n\n"
  433. exit 1
  434. fi
  435. fi
  436. fi
  437. echo -e "\n[\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
  438. if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
  439. [ "$DIST" == "focal" ] && legacy="legacy-" || legacy=""
  440. wget --no-check-certificate -qO '/tmp/initrd.img' "${LinuxMirror}/dists/${DIST}/main/installer-${VER}/current/${legacy}images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
  441. [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
  442. wget --no-check-certificate -qO '/tmp/vmlinuz' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/${legacy}images/netboot/${linux_relese}-installer/${VER}/linux"
  443. [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
  444. MirrorHost="$(echo "$LinuxMirror" | awk -F'://|/' '{print $2}')"
  445. MirrorFolder="$(echo "$LinuxMirror" | awk -F''${MirrorHost}'' '{print $2}')"
  446. [ -n "$MirrorFolder" ] || MirrorFolder="/"
  447. elif [[ "$linux_relese" == 'centos' ]]; then
  448. wget --no-check-certificate -qO '/tmp/initrd.img' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/initrd.img"
  449. [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
  450. wget --no-check-certificate -qO '/tmp/vmlinuz' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/vmlinuz"
  451. [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
  452. else
  453. bash $0 error
  454. exit 1
  455. fi
  456. if [[ "$linux_relese" == 'debian' ]]; then
  457. if [[ "$IncFirmware" == '1' ]]; then
  458. wget --no-check-certificate -qO '/tmp/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/${DIST}/current/firmware.cpio.gz"
  459. [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
  460. fi
  461. if [[ "$ddMode" == '1' ]]; then
  462. vKernel_udeb=$(wget --no-check-certificate -qO- "http://$LinuxMirror/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)
  463. [[ -z "vKernel_udeb" ]] && vKernel_udeb="6.1.0-10"
  464. fi
  465. fi
  466. if [[ "$loaderMode" == "0" ]]; then
  467. [[ ! -f "${GRUBDIR}/${GRUBFILE}" ]] && echo "Error! Not Found ${GRUBFILE}. " && exit 1
  468. [[ ! -f "${GRUBDIR}/${GRUBFILE}.old" ]] && [[ -f "${GRUBDIR}/${GRUBFILE}.bak" ]] && mv -f "${GRUBDIR}/${GRUBFILE}.bak" "${GRUBDIR}/${GRUBFILE}.old"
  469. mv -f "${GRUBDIR}/${GRUBFILE}" "${GRUBDIR}/${GRUBFILE}.bak"
  470. [[ -f "${GRUBDIR}/${GRUBFILE}.old" ]] && cat "${GRUBDIR}/${GRUBFILE}.old" >"${GRUBDIR}/${GRUBFILE}" || cat "${GRUBDIR}/${GRUBFILE}.bak" >"${GRUBDIR}/${GRUBFILE}"
  471. else
  472. GRUBVER='-1'
  473. fi
  474. [[ "$GRUBVER" == '0' ]] && {
  475. READGRUB='/tmp/grub.read'
  476. cat $GRUBDIR/$GRUBFILE | sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' | grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' | sed 's/%%%%%%%/\n/g' >$READGRUB
  477. LoadNum="$(cat $READGRUB | grep -c 'menuentry ')"
  478. if [[ "$LoadNum" -eq '1' ]]; then
  479. cat $READGRUB | sed '/^$/d' >/tmp/grub.new
  480. elif [[ "$LoadNum" -gt '1' ]]; then
  481. CFG0="$(awk '/menuentry /{print NR}' $READGRUB | head -n 1)"
  482. CFG2="$(awk '/menuentry /{print NR}' $READGRUB | head -n 2 | tail -n 1)"
  483. CFG1=""
  484. for tmpCFG in $(awk '/}/{print NR}' $READGRUB); do
  485. [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG"
  486. done
  487. [[ -z "$CFG1" ]] && {
  488. echo "Error! read $GRUBFILE. "
  489. exit 1
  490. }
  491. sed -n "$CFG0,$CFG1"p $READGRUB >/tmp/grub.new
  492. [[ -f /tmp/grub.new ]] && [[ "$(grep -c '{' /tmp/grub.new)" -eq "$(grep -c '}' /tmp/grub.new)" ]] || {
  493. echo -ne "\033[31mError! \033[0mNot configure $GRUBFILE. \n"
  494. exit 1
  495. }
  496. fi
  497. [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1
  498. sed -i "/menuentry.*/c\menuentry\ \'Install OS \[$DIST\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" /tmp/grub.new
  499. sed -i "/echo.*Loading/d" /tmp/grub.new
  500. INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE | head -n 1)"
  501. }
  502. [[ "$GRUBVER" == '1' ]] && {
  503. CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE | head -n 1)"
  504. CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE | head -n 2 | tail -n 1)"
  505. [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >/tmp/grub.new
  506. [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$(($CFG1 - 1))"p $GRUBDIR/$GRUBFILE >/tmp/grub.new
  507. [[ ! -f /tmp/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1
  508. sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new
  509. sed -i '/^#/d' /tmp/grub.new
  510. INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE | head -n 1)"
  511. }
  512. if [[ "$loaderMode" == "0" ]]; then
  513. [[ -n "$(grep 'linux.*/\|kernel.*/' /tmp/grub.new | awk '{print $2}' | tail -n 1 | grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot'
  514. LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new | awk '{print $1}' | head -n 1)"
  515. [[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1
  516. LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new | awk '{print $1}' | tail -n 1)"
  517. [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd'
  518. [[ "$setInterfaceName" == "1" ]] && Add_OPTION="net.ifnames=0 biosdevname=0" || Add_OPTION=""
  519. [[ "$setIPv6" == "1" ]] && Add_OPTION="$Add_OPTION ipv6.disable=1"
  520. lowMem || Add_OPTION="$Add_OPTION lowmem=+2"
  521. if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
  522. BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain=$linux_relese quiet"
  523. elif [[ "$linux_relese" == 'centos' ]]; then
  524. BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$interfaceSelect"
  525. fi
  526. [ -n "$setConsole" ] && BOOT_OPTION="$BOOT_OPTION --- console=$setConsole"
  527. [[ "$Type" == 'InBoot' ]] && {
  528. sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new
  529. sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new
  530. }
  531. [[ "$Type" == 'NoBoot' ]] && {
  532. sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new
  533. sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new
  534. }
  535. sed -i '$a\\n' /tmp/grub.new
  536. sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE
  537. sed -i ''${INSERTGRUB}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE
  538. [[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv
  539. fi
  540. [[ -d /tmp/boot ]] && rm -rf /tmp/boot
  541. mkdir -p /tmp/boot
  542. cd /tmp/boot
  543. if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
  544. COMPTYPE="gzip"
  545. elif [[ "$linux_relese" == 'centos' ]]; then
  546. COMPTYPE="$(file ../initrd.img | grep -o ':.*compressed data' | cut -d' ' -f2 | sed -r 's/(.*)/\L\1/' | head -n1)"
  547. [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1
  548. fi
  549. CompDected='0'
  550. for COMP in $(echo -en 'gzip\nlzma\nxz'); do
  551. if [[ "$COMPTYPE" == "$COMP" ]]; then
  552. CompDected='1'
  553. if [[ "$COMPTYPE" == 'gzip' ]]; then
  554. NewIMG="initrd.img.gz"
  555. else
  556. NewIMG="initrd.img.$COMPTYPE"
  557. fi
  558. mv -f "/tmp/initrd.img" "/tmp/$NewIMG"
  559. break
  560. fi
  561. done
  562. [[ "$CompDected" != '1' ]] && echo "Detect compressed type not support." && exit 1
  563. [[ "$COMPTYPE" == 'lzma' ]] && UNCOMP='xz --format=lzma --decompress'
  564. [[ "$COMPTYPE" == 'xz' ]] && UNCOMP='xz --decompress'
  565. [[ "$COMPTYPE" == 'gzip' ]] && UNCOMP='gzip -d'
  566. $UNCOMP </tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
  567. if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
  568. CurrentKernelVersion=$(ls -1 ./lib/modules 2>/dev/null | head -n1)
  569. [ -n "$CurrentKernelVersion" ] && SelectLowmem="di-utils-exit-installer,driver-injection-disk-detect,fdisk-udeb,netcfg-static,parted-udeb,partman-auto,partman-ext3,ata-modules-${CurrentKernelVersion}-di,efi-modules-${CurrentKernelVersion}-di,sata-modules-${CurrentKernelVersion}-di,scsi-modules-${CurrentKernelVersion}-di,scsi-nic-modules-${CurrentKernelVersion}-di" || SelectLowmem=""
  570. cat >/tmp/boot/preseed.cfg <<EOF
  571. d-i debian-installer/locale string en_US.UTF-8
  572. d-i debian-installer/country string US
  573. d-i debian-installer/language string en
  574. d-i console-setup/layoutcode string us
  575. d-i keyboard-configuration/xkb-keymap string us
  576. d-i lowmem/low note
  577. d-i anna/choose_modules_lowmem multiselect $SelectLowmem
  578. d-i netcfg/choose_interface select $interfaceSelect
  579. d-i netcfg/disable_autoconfig boolean true
  580. d-i netcfg/dhcp_failed note
  581. d-i netcfg/dhcp_options select Configure network manually
  582. d-i netcfg/get_ipaddress string $IPv4
  583. d-i netcfg/get_netmask string $MASK
  584. d-i netcfg/get_gateway string $GATE
  585. d-i netcfg/get_nameservers string $ipDNS
  586. d-i netcfg/no_default_route boolean true
  587. d-i netcfg/confirm_static boolean true
  588. d-i hw-detect/load_firmware boolean true
  589. d-i mirror/country string manual
  590. d-i mirror/http/hostname string $MirrorHost
  591. d-i mirror/http/directory string $MirrorFolder
  592. d-i mirror/http/proxy string
  593. d-i passwd/root-login boolean ture
  594. d-i passwd/make-user boolean false
  595. d-i passwd/root-password-crypted password $myPASSWORD
  596. d-i user-setup/allow-password-weak boolean true
  597. d-i user-setup/encrypt-home boolean false
  598. d-i clock-setup/utc boolean true
  599. d-i time/zone string US/Eastern
  600. d-i clock-setup/ntp boolean false
  601. 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
  602. d-i partman/early_command string [[ -n "\$(blkid -t TYPE='vfat' -o device)" ]] && umount "\$(blkid -t TYPE='vfat' -o device)"; \
  603. debconf-set partman-auto/disk "\$(list-devices disk |head -n1)"; \
  604. wget -qO- '$DDURL' | $DEC_CMD | /bin/dd of=\$(list-devices disk |head -n1); \
  605. mount.ntfs-3g \$(list-devices partition |head -n1) /mnt; \
  606. cd '/mnt/ProgramData/Microsoft/Windows/Start Menu/Programs'; \
  607. cd Start* || cd start*; \
  608. cp -f '/net.bat' './net.bat'; \
  609. /sbin/reboot; \
  610. umount /media || true; \
  611. d-i partman-partitioning/confirm_write_new_label boolean true
  612. d-i partman/mount_style select uuid
  613. d-i partman/choose_partition select finish
  614. d-i partman-auto/method string regular
  615. d-i partman-auto/init_automatically_partition select Guided - use entire disk
  616. d-i partman-auto/choose_recipe select All files in one partition (recommended for new users)
  617. d-i partman-md/device_remove_md boolean true
  618. d-i partman-lvm/device_remove_lvm boolean true
  619. d-i partman-lvm/confirm boolean true
  620. d-i partman-lvm/confirm_nooverwrite boolean true
  621. d-i partman/confirm boolean true
  622. d-i partman/confirm_nooverwrite boolean true
  623. d-i debian-installer/allow_unauthenticated boolean true
  624. tasksel tasksel/first multiselect minimal
  625. d-i pkgsel/update-policy select none
  626. d-i pkgsel/include string openssh-server
  627. d-i pkgsel/upgrade select none
  628. d-i apt-setup/services-select multiselect
  629. popularity-contest popularity-contest/participate boolean false
  630. d-i grub-installer/only_debian boolean true
  631. d-i grub-installer/bootdev string $IncDisk
  632. d-i grub-installer/force-efi-extra-removable boolean true
  633. d-i finish-install/reboot_in_progress note
  634. d-i debian-installer/exit/reboot boolean true
  635. d-i preseed/late_command string \
  636. sed -ri 's/^#?Port.*/Port ${sshPORT}/g' /target/etc/ssh/sshd_config; \
  637. sed -ri 's/^#?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \
  638. sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config; \
  639. 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; \
  640. echo '' >>/target/etc/crontab; \
  641. echo '${setCMD}' >/target/etc/run.sh;
  642. EOF
  643. if [[ "$loaderMode" != "0" ]] && [[ "$setNet" == '0' ]]; then
  644. sed -i '/netcfg\/disable_autoconfig/d' /tmp/boot/preseed.cfg
  645. sed -i '/netcfg\/dhcp_options/d' /tmp/boot/preseed.cfg
  646. sed -i '/netcfg\/get_.*/d' /tmp/boot/preseed.cfg
  647. sed -i '/netcfg\/confirm_static/d' /tmp/boot/preseed.cfg
  648. fi
  649. if [[ "$linux_relese" == 'debian' ]]; then
  650. sed -i '/user-setup\/allow-password-weak/d' /tmp/boot/preseed.cfg
  651. sed -i '/user-setup\/encrypt-home/d' /tmp/boot/preseed.cfg
  652. sed -i '/pkgsel\/update-policy/d' /tmp/boot/preseed.cfg
  653. sed -i 's/umount\ \/media.*true\;\ //g' /tmp/boot/preseed.cfg
  654. [[ -f '/tmp/firmware.cpio.gz' ]] && gzip -d </tmp/firmware.cpio.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
  655. else
  656. sed -i '/d-i\ grub-installer\/force-efi-extra-removable/d' /tmp/boot/preseed.cfg
  657. fi
  658. [[ "$ddMode" == '1' ]] && {
  659. WinNoDHCP() {
  660. 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'
  661. }
  662. WinRDP() {
  663. 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'
  664. }
  665. 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'
  666. [[ "$setNet" == '1' ]] && WinNoDHCP
  667. [[ "$setNet" == '0' ]] && [[ "$AutoNet" == '0' ]] && WinNoDHCP
  668. [[ "$setRDP" == '1' ]] && [[ -n "$WinRemote" ]] && WinRDP
  669. 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'
  670. 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'
  671. iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
  672. rm -rf '/tmp/boot/net.tmp'
  673. }
  674. [[ "$ddMode" == '0' ]] && {
  675. sed -i '/anna-install/d' /tmp/boot/preseed.cfg
  676. sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg
  677. }
  678. elif [[ "$linux_relese" == 'centos' ]]; then
  679. cat >/tmp/boot/ks.cfg <<EOF
  680. #platform=x86, AMD64, or Intel EM64T
  681. firewall --enabled --ssh
  682. install
  683. url --url="$LinuxMirror/$DIST/os/$VER/"
  684. rootpw --iscrypted $myPASSWORD
  685. auth --useshadow --passalgo=sha512
  686. firstboot --disable
  687. lang en_US
  688. keyboard us
  689. selinux --disabled
  690. logging --level=info
  691. reboot
  692. text
  693. unsupported_hardware
  694. vnc
  695. skipx
  696. timezone --isUtc Asia/Hong_Kong
  697. #ONDHCP network --bootproto=dhcp --onboot=on
  698. network --bootproto=static --ip=$IPv4 --netmask=$MASK --gateway=$GATE --nameserver=$ipDNS --onboot=on
  699. bootloader --location=mbr --append="rhgb quiet crashkernel=auto"
  700. zerombr
  701. clearpart --all --initlabel
  702. autopart
  703. %packages
  704. @base
  705. %end
  706. %post --interpreter=/bin/bash
  707. rm -rf /root/anaconda-ks.cfg
  708. rm -rf /root/install.*log
  709. %end
  710. EOF
  711. [[ "$UNKNOWHW" == '1' ]] && sed -i 's/^unsupported_hardware/#unsupported_hardware/g' /tmp/boot/ks.cfg
  712. [[ "$(echo "$DIST" | grep -o '^[0-9]\{1\}')" == '5' ]] && sed -i '0,/^%end/s//#%end/' /tmp/boot/ks.cfg
  713. fi
  714. find . | cpio -H newc --create --verbose | gzip -9 >/tmp/initrd.img
  715. cp -f /tmp/initrd.img /boot/initrd.img || sudo cp -f /tmp/initrd.img /boot/initrd.img
  716. cp -f /tmp/vmlinuz /boot/vmlinuz || sudo cp -f /tmp/vmlinuz /boot/vmlinuz
  717. chown root:root $GRUBDIR/$GRUBFILE
  718. chmod 444 $GRUBDIR/$GRUBFILE
  719. if [[ "$loaderMode" == "0" ]]; then
  720. sleep 3 && reboot || sudo reboot >/dev/null 2>&1
  721. else
  722. rm -rf "$HOME/loader"
  723. mkdir -p "$HOME/loader"
  724. cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img"
  725. cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz"
  726. [[ -f "/boot/initrd.img" ]] && rm -rf "/boot/initrd.img"
  727. [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
  728. echo && ls -AR1 "$HOME/loader"
  729. fi