Core_Install_v3.1.sh 36 KB

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