auto.sh 36 KB

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