installer.sh.in 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. #!/bin/bash
  2. #-
  3. # Copyright (c) 2012-2015 Juan Romero Pardines <[email protected]>.
  4. # 2012 Dave Elusive <[email protected]>.
  5. # All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. #-
  27. # Make sure we don't inherit these from env.
  28. SOURCE_DONE=
  29. HOSTNAME_DONE=
  30. KEYBOARD_DONE=
  31. LOCALE_DONE=
  32. TIMEZONE_DONE=
  33. ROOTPASSWORD_DONE=
  34. USERLOGIN_DONE=
  35. USERPASSWORD_DONE=
  36. USERNAME_DONE=
  37. USERGROUPS_DONE=
  38. BOOTLOADER_DONE=
  39. PARTITIONS_DONE=
  40. NETWORK_DONE=
  41. FILESYSTEMS_DONE=
  42. TARGETDIR=/mnt/target
  43. LOG=/dev/tty8
  44. CONF_FILE=/tmp/.void-installer.conf
  45. if [ ! -f $CONF_FILE ]; then
  46. touch -f $CONF_FILE
  47. fi
  48. ANSWER=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  49. TARGET_FSTAB=$(mktemp -t vinstall-fstab-XXXXXXXX || exit 1)
  50. trap "DIE" INT TERM QUIT
  51. # disable printk
  52. if [ -w /proc/sys/kernel/printk ]; then
  53. echo 0 >/proc/sys/kernel/printk
  54. fi
  55. # Detect if this is an EFI system.
  56. if [ -e /sys/firmware/efi/systab ]; then
  57. EFI_SYSTEM=1
  58. EFI_FW_BITS=$(cat /sys/firmware/efi/fw_platform_size)
  59. if [ $EFI_FW_BITS -eq 32 ]; then
  60. EFI_TARGET=i386-efi
  61. else
  62. EFI_TARGET=x86_64-efi
  63. fi
  64. fi
  65. # dialog colors
  66. BLACK="\Z0"
  67. RED="\Z1"
  68. GREEN="\Z2"
  69. YELLOW="\Z3"
  70. BLUE="\Z4"
  71. MAGENTA="\Z5"
  72. CYAN="\Z6"
  73. WHITE="\Z7"
  74. BOLD="\Zb"
  75. REVERSE="\Zr"
  76. UNDERLINE="\Zu"
  77. RESET="\Zn"
  78. # Properties shared per widget.
  79. MENULABEL="${BOLD}Use UP and DOWN keys to navigate \
  80. menus. Use TAB to switch between buttons and ENTER to select.${RESET}"
  81. MENUSIZE="14 60 0"
  82. INPUTSIZE="8 60"
  83. MSGBOXSIZE="8 70"
  84. YESNOSIZE="$INPUTSIZE"
  85. WIDGET_SIZE="10 70"
  86. DIALOG() {
  87. rm -f $ANSWER
  88. dialog --colors --keep-tite --no-shadow --no-mouse \
  89. --backtitle "${BOLD}${WHITE}Void Linux installation -- https://www.voidlinux.eu/ (@@MKLIVE_VERSION@@)${RESET}" \
  90. --cancel-label "Back" --aspect 20 "$@" 2>$ANSWER
  91. return $?
  92. }
  93. INFOBOX() {
  94. # Note: dialog --infobox and --keep-tite don't work together
  95. dialog --colors --no-shadow --no-mouse \
  96. --backtitle "${BOLD}${WHITE}Void Linux installation -- https://www.voidlinux.eu/ (@@MKLIVE_VERSION@@)${RESET}" \
  97. --title "${TITLE}" --aspect 20 --infobox "$@"
  98. }
  99. DIE() {
  100. rval=$1
  101. [ -z "$rval" ] && rval=0
  102. clear
  103. rm -f $ANSWER $TARGET_FSTAB
  104. # reenable printk
  105. if [ -w /proc/sys/kernel/printk ]; then
  106. echo 4 >/proc/sys/kernel/printk
  107. fi
  108. umount_filesystems
  109. exit $rval
  110. }
  111. set_option() {
  112. if grep -Eq "^${1}.*" $CONF_FILE; then
  113. sed -i -e "/^${1}.*/d" $CONF_FILE
  114. fi
  115. echo "${1} ${2}" >>$CONF_FILE
  116. }
  117. get_option() {
  118. echo $(grep -E "^${1}.*" $CONF_FILE|sed -e "s|${1}||")
  119. }
  120. # ISO-639 language names for locales
  121. iso639_language() {
  122. case "$1" in
  123. aa) echo "Afar" ;;
  124. af) echo "Afrikaans" ;;
  125. an) echo "Aragonese" ;;
  126. ar) echo "Arabic" ;;
  127. ast) echo "Asturian" ;;
  128. be) echo "Belgian" ;;
  129. bg) echo "Bulgarian" ;;
  130. bhb) echo "Bhili" ;;
  131. br) echo "Breton" ;;
  132. bs) echo "Bosnian" ;;
  133. ca) echo "Catalan" ;;
  134. cs) echo "Czech" ;;
  135. cy) echo "Welsh" ;;
  136. da) echo "Danish" ;;
  137. de) echo "German" ;;
  138. el) echo "Greek" ;;
  139. en) echo "English" ;;
  140. es) echo "Spanish" ;;
  141. et) echo "Estonian" ;;
  142. eu) echo "Basque" ;;
  143. fi) echo "Finnish" ;;
  144. fo) echo "Faroese" ;;
  145. fr) echo "French" ;;
  146. ga) echo "Irish" ;;
  147. gd) echo "Scottish Gaelic" ;;
  148. gl) echo "Galician" ;;
  149. gv) echo "Manx" ;;
  150. he) echo "Hebrew" ;;
  151. hr) echo "Croatian" ;;
  152. hsb) echo "Upper Sorbian" ;;
  153. hu) echo "Hungarian" ;;
  154. id) echo "Indonesian" ;;
  155. is) echo "Icelandic" ;;
  156. it) echo "Italian" ;;
  157. iw) echo "Hebrew" ;;
  158. ja) echo "Japanese" ;;
  159. ka) echo "Georgian" ;;
  160. kk) echo "Kazakh" ;;
  161. kl) echo "Kalaallisut" ;;
  162. ko) echo "Korean" ;;
  163. ku) echo "Kurdish" ;;
  164. kw) echo "Cornish" ;;
  165. lg) echo "Ganda" ;;
  166. lt) echo "Lithuanian" ;;
  167. lv) echo "Latvian" ;;
  168. mg) echo "Malagasy" ;;
  169. mi) echo "Maori" ;;
  170. mk) echo "Macedonian" ;;
  171. ms) echo "Malay" ;;
  172. mt) echo "Maltese" ;;
  173. nb) echo "Norwegian Bokmål" ;;
  174. nl) echo "Dutch" ;;
  175. nn) echo "Norwegian Nynorsk" ;;
  176. oc) echo "Occitan" ;;
  177. om) echo "Oromo" ;;
  178. pl) echo "Polish" ;;
  179. pt) echo "Portugese" ;;
  180. ro) echo "Romanian" ;;
  181. ru) echo "Russian" ;;
  182. sk) echo "Slovak" ;;
  183. sl) echo "Slovenian" ;;
  184. so) echo "Somali" ;;
  185. sq) echo "Albanian" ;;
  186. st) echo "Southern Sotho" ;;
  187. sv) echo "Swedish" ;;
  188. tcy) echo "Tulu" ;;
  189. tg) echo "Tajik" ;;
  190. th) echo "Thai" ;;
  191. tl) echo "Tagalog" ;;
  192. tr) echo "Turkish" ;;
  193. uk) echo "Ukrainian" ;;
  194. uz) echo "Uzbek" ;;
  195. wa) echo "Walloon" ;;
  196. xh) echo "Xhosa" ;;
  197. yi) echo "Yiddish" ;;
  198. zh) echo "Chinese" ;;
  199. zu) echo "Zulu" ;;
  200. *) echo "$1" ;;
  201. esac
  202. }
  203. # ISO-3166 country codes for locales
  204. iso3166_country() {
  205. case "$1" in
  206. AD) echo "Andorra" ;;
  207. AE) echo "United Arab Emirates" ;;
  208. AL) echo "Albania" ;;
  209. AR) echo "Argentina" ;;
  210. AT) echo "Austria" ;;
  211. AU) echo "Australia" ;;
  212. BA) echo "Bonsia and Herzegovina" ;;
  213. BE) echo "Belgium" ;;
  214. BG) echo "Bulgaria" ;;
  215. BH) echo "Bahrain" ;;
  216. BO) echo "Bolivia" ;;
  217. BR) echo "Brazil" ;;
  218. BW) echo "Botswana" ;;
  219. BY) echo "Belarus" ;;
  220. CA) echo "Canada" ;;
  221. CH) echo "Switzerland" ;;
  222. CL) echo "Chile" ;;
  223. CN) echo "China" ;;
  224. CO) echo "Colombia" ;;
  225. CR) echo "Costa Rica" ;;
  226. CY) echo "Cyprus" ;;
  227. CZ) echo "Czech Republic" ;;
  228. DE) echo "Germany" ;;
  229. DJ) echo "Djibouti" ;;
  230. DK) echo "Denmark" ;;
  231. DO) echo "Dominican Republic" ;;
  232. DZ) echo "Algeria" ;;
  233. EC) echo "Ecuador" ;;
  234. EE) echo "Estonia" ;;
  235. EG) echo "Egypt" ;;
  236. ES) echo "Spain" ;;
  237. FI) echo "Finland" ;;
  238. FO) echo "Faroe Islands" ;;
  239. FR) echo "France" ;;
  240. GB) echo "Great Britain" ;;
  241. GE) echo "Georgia" ;;
  242. GL) echo "Greenland" ;;
  243. GR) echo "Greece" ;;
  244. GT) echo "Guatemala" ;;
  245. HK) echo "Hong Kong" ;;
  246. HN) echo "Honduras" ;;
  247. HR) echo "Croatia" ;;
  248. HU) echo "Hungary" ;;
  249. ID) echo "Indonesia" ;;
  250. IE) echo "Ireland" ;;
  251. IL) echo "Israel" ;;
  252. IN) echo "India" ;;
  253. IQ) echo "Iraq" ;;
  254. IS) echo "Iceland" ;;
  255. IT) echo "Italy" ;;
  256. JO) echo "Jordan" ;;
  257. JP) echo "Japan" ;;
  258. KE) echo "Kenya" ;;
  259. KR) echo "Korea, Republic of" ;;
  260. KW) echo "Kuwait" ;;
  261. KZ) echo "Kazakhstan" ;;
  262. LB) echo "Lebanon" ;;
  263. LT) echo "Lithuania" ;;
  264. LU) echo "Luxembourg" ;;
  265. LV) echo "Latvia" ;;
  266. LY) echo "Libya" ;;
  267. MA) echo "Morocco" ;;
  268. MG) echo "Madagascar" ;;
  269. MK) echo "Macedonia" ;;
  270. MT) echo "Malta" ;;
  271. MX) echo "Mexico" ;;
  272. MY) echo "Malaysia" ;;
  273. NI) echo "Nicaragua" ;;
  274. NL) echo "Netherlands" ;;
  275. NO) echo "Norway" ;;
  276. NZ) echo "New Zealand" ;;
  277. OM) echo "Oman" ;;
  278. PA) echo "Panama" ;;
  279. PE) echo "Peru" ;;
  280. PH) echo "Philippines" ;;
  281. PL) echo "Poland" ;;
  282. PR) echo "Puerto Rico" ;;
  283. PT) echo "Portugal" ;;
  284. PY) echo "Paraguay" ;;
  285. QA) echo "Qatar" ;;
  286. RO) echo "Romania" ;;
  287. RU) echo "Russian Federation" ;;
  288. SA) echo "Saudi Arabia" ;;
  289. SD) echo "Sudan" ;;
  290. SE) echo "Sweden" ;;
  291. SG) echo "Singapore" ;;
  292. SI) echo "Slovenia" ;;
  293. SK) echo "Slovakia" ;;
  294. SO) echo "Somalia" ;;
  295. SV) echo "El Salvador" ;;
  296. SY) echo "Syria" ;;
  297. TH) echo "Thailand" ;;
  298. TJ) echo "Tajikistan" ;;
  299. TN) echo "Tunisia" ;;
  300. TR) echo "Turkey" ;;
  301. TW) echo "Taiwan" ;;
  302. UA) echo "Ukraine" ;;
  303. UG) echo "Uganda" ;;
  304. US) echo "United States of America" ;;
  305. UY) echo "Uruguay" ;;
  306. UZ) echo "Uzbekistan" ;;
  307. VE) echo "Venezuela" ;;
  308. YE) echo "Yemen" ;;
  309. ZA) echo "South Africa" ;;
  310. ZW) echo "Zimbabwe" ;;
  311. *) echo "$1" ;;
  312. esac
  313. }
  314. show_disks() {
  315. local dev size sectorsize gbytes
  316. # IDE
  317. for dev in $(ls /sys/block|grep -E '^hd'); do
  318. if [ "$(cat /sys/block/$dev/device/media)" = "disk" ]; then
  319. # Find out nr sectors and bytes per sector;
  320. echo "/dev/$dev"
  321. size=$(cat /sys/block/$dev/size)
  322. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  323. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  324. echo "size:${gbytes}GB;sector_size:$sectorsize"
  325. fi
  326. done
  327. # SATA/SCSI and Virtual disks (virtio)
  328. for dev in $(ls /sys/block|grep -E '^([sv]|xv)d|mmcblk|nvme'); do
  329. echo "/dev/$dev"
  330. size=$(cat /sys/block/$dev/size)
  331. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  332. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  333. echo "size:${gbytes}GB;sector_size:$sectorsize"
  334. done
  335. # cciss(4) devices
  336. for dev in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]$'); do
  337. echo "/dev/cciss/$dev"
  338. size=$(cat /sys/block/cciss\!$dev/size)
  339. sectorsize=$(cat /sys/block/cciss\!$dev/queue/hw_sector_size)
  340. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  341. echo "size:${gbytes}GB;sector_size:$sectorsize"
  342. done
  343. }
  344. show_partitions() {
  345. local dev fstype fssize p part
  346. set -- $(show_disks)
  347. while [ $# -ne 0 ]; do
  348. disk=$(basename $1)
  349. shift 2
  350. # ATA/SCSI/SATA
  351. for p in /sys/block/$disk/$disk*; do
  352. if [ -d $p ]; then
  353. part=$(basename $p)
  354. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}'|head -1)
  355. [ "$fstype" = "iso9660" ] && continue
  356. [ "$fstype" = "crypto_LUKS" ] && continue
  357. [ "$fstype" = "LVM2_member" ] && continue
  358. fssize=$(lsblk -nr /dev/$part|awk '{print $4}'|head -1)
  359. echo "/dev/$part"
  360. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  361. fi
  362. done
  363. done
  364. # Software raid (md)
  365. for p in $(ls -d /dev/md* 2>/dev/null|grep '[0-9]'); do
  366. part=$(basename $p)
  367. if cat /proc/mdstat|grep -qw $part; then
  368. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  369. [ "$fstype" = "crypto_LUKS" ] && continue
  370. [ "$fstype" = "LVM2_member" ] && continue
  371. fssize=$(lsblk -nr /dev/$part|awk '{print $4}')
  372. echo "$p"
  373. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  374. fi
  375. done
  376. # cciss(4) devices
  377. for part in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]p[0-9]+'); do
  378. fstype=$(lsblk -nfr /dev/cciss/$part|awk '{print $2}')
  379. [ "$fstype" = "crypto_LUKS" ] && continue
  380. [ "$fstype" = "LVM2_member" ] && continue
  381. fssize=$(lsblk -nr /dev/cciss/$part|awk '{print $4}')
  382. echo "/dev/cciss/$part"
  383. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  384. done
  385. if [ -e /sbin/lvs ]; then
  386. # LVM
  387. lvs --noheadings|while read lvname vgname perms size; do
  388. echo "/dev/mapper/${vgname}-${lvname}"
  389. echo "size:${size};fstype:lvm"
  390. done
  391. fi
  392. }
  393. menu_filesystems() {
  394. local dev fstype fssize mntpoint reformat
  395. while true; do
  396. DIALOG --ok-label "Change" --cancel-label "Done" \
  397. --title " Select the partition to edit " --menu "$MENULABEL" \
  398. ${MENUSIZE} $(show_partitions)
  399. [ $? -ne 0 ] && return
  400. dev=$(cat $ANSWER)
  401. DIALOG --title " Select the filesystem type for $dev " \
  402. --menu "$MENULABEL" ${MENUSIZE} \
  403. "btrfs" "Oracle's Btrfs" \
  404. "ext2" "Linux ext2 (no journaling)" \
  405. "ext3" "Linux ext3 (journal)" \
  406. "ext4" "Linux ext4 (journal)" \
  407. "f2fs" "Flash-Friendly Filesystem" \
  408. "swap" "Linux swap" \
  409. "vfat" "FAT32" \
  410. "xfs" "SGI's XFS"
  411. if [ $? -eq 0 ]; then
  412. fstype=$(cat $ANSWER)
  413. else
  414. continue
  415. fi
  416. if [ "$fstype" != "swap" ]; then
  417. DIALOG --inputbox "Please specify the mount point for $dev:" ${INPUTSIZE}
  418. if [ $? -eq 0 ]; then
  419. mntpoint=$(cat $ANSWER)
  420. elif [ $? -eq 1 ]; then
  421. continue
  422. fi
  423. else
  424. mntpoint=swap
  425. fi
  426. DIALOG --yesno "Do you want to create a new filesystem on $dev?" ${YESNOSIZE}
  427. if [ $? -eq 0 ]; then
  428. reformat=1
  429. elif [ $? -eq 1 ]; then
  430. reformat=0
  431. else
  432. continue
  433. fi
  434. fssize=$(lsblk -nr $dev|awk '{print $4}')
  435. set -- "$fstype" "$fssize" "$mntpoint" "$reformat"
  436. if [ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ]; then
  437. local bdev=$(basename $dev)
  438. local ddev=$(basename $(dirname $dev))
  439. if [ "$ddev" != "dev" ]; then
  440. sed -i -e "/^MOUNTPOINT \/dev\/${ddev}\/${bdev}.*/d" $CONF_FILE
  441. else
  442. sed -i -e "/^MOUNTPOINT \/dev\/${bdev}.*/d" $CONF_FILE
  443. fi
  444. echo "MOUNTPOINT $dev $1 $2 $3 $4" >>$CONF_FILE
  445. fi
  446. done
  447. }
  448. menu_partitions() {
  449. DIALOG --title " Select the disk to partition " \
  450. --menu "$MENULABEL" ${MENUSIZE} $(show_disks)
  451. if [ $? -eq 0 ]; then
  452. local device=$(cat $ANSWER)
  453. DIALOG --title "Modify Partition Table on $device" --msgbox "\n
  454. ${BOLD}cfdisk will be executed in disk $device.${RESET}\n\n
  455. For BIOS systems, MBR or GPT partition tables are supported.\n
  456. To use GPT on PC BIOS systems an empty partition of 1MB must be added\n
  457. at the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n
  458. ${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n
  459. For EFI systems GPT is mandatory and a FAT32 partition with at least\n
  460. 100MB must be created with the TOGGLE \`boot', this will be used as\n
  461. EFI System Partition. This partition must have mountpoint as \`/boot/efi'.\n\n
  462. At least 1 partitions is required for the rootfs (/).\n
  463. For swap, RAM*2 must be really enough. For / 600MB are required.\n\n
  464. ${BOLD}WARNING: /usr is not supported as a separate partition.${RESET}\n
  465. ${RESET}\n" 18 80
  466. if [ $? -eq 0 ]; then
  467. while true; do
  468. clear; cfdisk $device; PARTITIONS_DONE=1
  469. break
  470. done
  471. else
  472. return
  473. fi
  474. fi
  475. }
  476. menu_keymap() {
  477. local _keymaps="$(find /usr/share/kbd/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sort)"
  478. local _KEYMAPS=
  479. for f in ${_keymaps}; do
  480. _KEYMAPS="${_KEYMAPS} ${f} -"
  481. done
  482. while true; do
  483. DIALOG --title " Select your keymap " --menu "$MENULABEL" 14 70 14 ${_KEYMAPS}
  484. if [ $? -eq 0 ]; then
  485. set_option KEYMAP "$(cat $ANSWER)"
  486. loadkeys "$(cat $ANSWER)"
  487. KEYBOARD_DONE=1
  488. break
  489. else
  490. return
  491. fi
  492. done
  493. }
  494. set_keymap() {
  495. local KEYMAP=$(get_option KEYMAP)
  496. if [ -f /etc/vconsole.conf ]; then
  497. sed -i -e "s|KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/vconsole.conf
  498. else
  499. sed -i -e "s|#\?KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/rc.conf
  500. fi
  501. }
  502. menu_locale() {
  503. local _locales="$(grep -E '\.UTF-8' /etc/default/libc-locales|awk '{print $1}'|sed -e 's/^#//')"
  504. local LOCALES ISO639 ISO3166
  505. local TMPFILE=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  506. INFOBOX "Scanning locales ..." 4 60
  507. for f in ${_locales}; do
  508. eval $(echo $f | awk 'BEGIN { FS="." } \
  509. { FS="_"; split($1, a); printf "ISO639=%s ISO3166=%s\n", a[1], a[2] }')
  510. echo "$f|$(iso639_language $ISO639) ($(iso3166_country $ISO3166))|" >> $TMPFILE
  511. done
  512. clear
  513. # Sort by ISO-639 language names
  514. LOCALES=$(sort -t '|' -k 2 < $TMPFILE | xargs | sed -e's/| /|/g')
  515. rm -f $TMPFILE
  516. while true; do
  517. (IFS="|"; DIALOG --title " Select your locale " --menu "$MENULABEL" 18 70 18 ${LOCALES})
  518. if [ $? -eq 0 ]; then
  519. set_option LOCALE "$(cat $ANSWER)"
  520. LOCALE_DONE=1
  521. break
  522. else
  523. return
  524. fi
  525. done
  526. }
  527. set_locale() {
  528. if [ -f $TARGETDIR/etc/default/libc-locales ]; then
  529. local LOCALE=$(get_option LOCALE)
  530. sed -i -e "s|LANG=.*|LANG=$LOCALE|g" $TARGETDIR/etc/locale.conf
  531. # Uncomment locale from /etc/default/libc-locales and regenerate it.
  532. sed -e "/${LOCALE}/s/^\#//" -i $TARGETDIR/etc/default/libc-locales
  533. echo "Running xbps-reconfigure -f glibc-locales ..." >$LOG
  534. chroot $TARGETDIR xbps-reconfigure -f glibc-locales >$LOG 2>&1
  535. fi
  536. }
  537. menu_timezone() {
  538. local _tzones="$(cd /usr/share/zoneinfo; find Africa/ America/ Antarctica/ Arctic/ Asia/ Atlantic/ Australia/ Europe/ Indian/ Pacific/ posix/ -type f | sort)"
  539. local _TIMEZONES=
  540. for f in ${_tzones}; do
  541. _TIMEZONES="${_TIMEZONES} ${f} -"
  542. done
  543. while true; do
  544. DIALOG --title " Select your timezone " --menu "$MENULABEL" 14 70 14 ${_TIMEZONES}
  545. if [ $? -eq 0 ]; then
  546. set_option TIMEZONE "$(cat $ANSWER)"
  547. TIMEZONE_DONE=1
  548. break
  549. else
  550. return
  551. fi
  552. done
  553. }
  554. set_timezone() {
  555. local TIMEZONE="$(get_option TIMEZONE)"
  556. sed -i -e "s|#TIMEZONE=.*|TIMEZONE=$TIMEZONE|g" $TARGETDIR/etc/rc.conf
  557. }
  558. menu_hostname() {
  559. while true; do
  560. DIALOG --inputbox "Set the machine hostname:" ${INPUTSIZE}
  561. if [ $? -eq 0 ]; then
  562. set_option HOSTNAME "$(cat $ANSWER)"
  563. HOSTNAME_DONE=1
  564. break
  565. else
  566. return
  567. fi
  568. done
  569. }
  570. set_hostname() {
  571. echo $(get_option HOSTNAME) > $TARGETDIR/etc/hostname
  572. }
  573. menu_rootpassword() {
  574. local _firstpass _secondpass _desc
  575. while true; do
  576. if [ -z "${_firstpass}" ]; then
  577. _desc="Enter the root password"
  578. else
  579. _desc="$_desc again"
  580. fi
  581. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  582. if [ $? -eq 0 ]; then
  583. if [ -z "${_firstpass}" ]; then
  584. _firstpass="$(cat $ANSWER)"
  585. else
  586. _secondpass="$(cat $ANSWER)"
  587. fi
  588. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  589. if [ "${_firstpass}" != "${_secondpass}" ]; then
  590. INFOBOX "Passwords do not match! Please enter again." 6 60
  591. unset _firstpass _secondpass
  592. sleep 2 && clear && continue
  593. fi
  594. set_option ROOTPASSWORD "${_firstpass}"
  595. ROOTPASSWORD_DONE=1
  596. break
  597. fi
  598. else
  599. return
  600. fi
  601. done
  602. }
  603. set_rootpassword() {
  604. echo "root:$(get_option ROOTPASSWORD)" | chpasswd -R $TARGETDIR -c SHA512
  605. }
  606. menu_useraccount() {
  607. local _firstpass _secondpass _desc
  608. local _groups _status _group _checklist
  609. local _preset
  610. while true; do
  611. _preset=$(get_option USERLOGIN)
  612. [ -z "$_preset" ] && _preset="void"
  613. DIALOG --inputbox "Enter a primary login name:" ${INPUTSIZE} "$_preset"
  614. if [ $? -eq 0 ]; then
  615. set_option USERLOGIN "$(cat $ANSWER)"
  616. USERLOGIN_DONE=1
  617. break
  618. else
  619. return
  620. fi
  621. done
  622. while true; do
  623. _preset=$(get_option USERNAME)
  624. [ -z "$_preset" ] && _preset="Void User"
  625. DIALOG --inputbox "Enter a user name for login '$(get_option USERLOGIN)' :" \
  626. ${INPUTSIZE} "$_preset"
  627. if [ $? -eq 0 ]; then
  628. set_option USERNAME "$(cat $ANSWER)"
  629. USERNAME_DONE=1
  630. break
  631. else
  632. return
  633. fi
  634. done
  635. while true; do
  636. if [ -z "${_firstpass}" ]; then
  637. _desc="Enter the password for login '$(get_option USERLOGIN)'"
  638. else
  639. _desc="$_desc again"
  640. fi
  641. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  642. if [ $? -eq 0 ]; then
  643. if [ -z "${_firstpass}" ]; then
  644. _firstpass="$(cat $ANSWER)"
  645. else
  646. _secondpass="$(cat $ANSWER)"
  647. fi
  648. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  649. if [ "${_firstpass}" != "${_secondpass}" ]; then
  650. INFOBOX "Passwords do not match! Please enter again." 6 60
  651. unset _firstpass _secondpass
  652. sleep 2 && clear && continue
  653. fi
  654. set_option USERPASSWORD "${_firstpass}"
  655. USERPASSWORD_DONE=1
  656. break
  657. fi
  658. else
  659. return
  660. fi
  661. done
  662. _groups="wheel,audio,video,floppy,cdrom,optical,kvm,xbuilder"
  663. while true; do
  664. _desc="Select group membership for login '$(get_option USERLOGIN)':"
  665. for _group in $(cat /etc/group); do
  666. _gid="$(echo ${_group} | cut -d: -f3)"
  667. _group="$(echo ${_group} | cut -d: -f1)"
  668. _status="$(echo ${_groups} | grep -w ${_group})"
  669. if [ -z "${_status}" ]; then
  670. _status=off
  671. else
  672. _status=on
  673. fi
  674. if [ -z "${_checklist}" ]; then
  675. _checklist="${_group} ${_group}:${_gid} ${_status}"
  676. else
  677. _checklist="${_checklist} ${_group} ${_group}:${_gid} ${_status}"
  678. fi
  679. done
  680. DIALOG --no-tags --checklist "${_desc}" 20 60 18 ${_checklist}
  681. if [ $? -eq 0 ]; then
  682. set_option USERGROUPS $(cat $ANSWER | sed -e's| |,|g')
  683. USERGROUPS_DONE=1
  684. break
  685. else
  686. return
  687. fi
  688. done
  689. }
  690. set_useraccount() {
  691. [ -z "$USERLOGIN_DONE" ] && return
  692. [ -z "$USERPASSWORD_DONE" ] && return
  693. [ -z "$USERNAME_DONE" ] && return
  694. [ -z "$USERGROUPS_DONE" ] && return
  695. useradd -R $TARGETDIR -m -G $(get_option USERGROUPS) \
  696. -c "$(get_option USERNAME)" $(get_option USERLOGIN)
  697. echo "$(get_option USERLOGIN):$(get_option USERPASSWORD)" | \
  698. chpasswd -R $TARGETDIR -c SHA512
  699. }
  700. menu_bootloader() {
  701. while true; do
  702. DIALOG --title " Select the disk to install the bootloader" \
  703. --menu "$MENULABEL" ${MENUSIZE} $(show_disks) none "Manage bootloader otherwise"
  704. if [ $? -eq 0 ]; then
  705. set_option BOOTLOADER "$(cat $ANSWER)"
  706. BOOTLOADER_DONE=1
  707. break
  708. else
  709. return
  710. fi
  711. done
  712. while true; do
  713. DIALOG --yesno "Use a graphical terminal for the boot loader?" ${YESNOSIZE}
  714. if [ $? -eq 0 ]; then
  715. set_option TEXTCONSOLE 0
  716. break
  717. elif [ $? -eq 1 ]; then
  718. set_option TEXTCONSOLE 1
  719. break
  720. else
  721. return
  722. fi
  723. done
  724. }
  725. set_bootloader() {
  726. local dev=$(get_option BOOTLOADER) grub_args=
  727. if [ "$dev" = "none" ]; then return; fi
  728. # Check if it's an EFI system via efivars module.
  729. if [ -n "$EFI_SYSTEM" ]; then
  730. grub_args="--target=$EFI_TARGET --efi-directory=/boot/efi --bootloader-id=void_grub --recheck"
  731. fi
  732. echo "Running grub-install $grub_args $dev..." >$LOG
  733. chroot $TARGETDIR grub-install $grub_args $dev >$LOG 2>&1
  734. if [ $? -ne 0 ]; then
  735. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  736. failed to install GRUB to $dev!\nCheck $LOG for errors." ${MSGBOXSIZE}
  737. DIE 1
  738. fi
  739. echo "Running grub-mkconfig on $TARGETDIR..." >$LOG
  740. chroot $TARGETDIR grub-mkconfig -o /boot/grub/grub.cfg >$LOG 2>&1
  741. if [ $? -ne 0 ]; then
  742. DIALOG --msgbox "${BOLD}${RED}ERROR${RESET}: \
  743. failed to run grub-mkconfig!\nCheck $LOG for errors." ${MSGBOXSIZE}
  744. DIE 1
  745. fi
  746. }
  747. test_network() {
  748. rm -f xtraeme.asc && \
  749. xbps-uhelper fetch http://repo.voidlinux.eu/live/xtraeme.asc >$LOG 2>&1
  750. if [ $? -eq 0 ]; then
  751. DIALOG --msgbox "Network is working properly!" ${MSGBOXSIZE}
  752. NETWORK_DONE=1
  753. return 1
  754. fi
  755. DIALOG --msgbox "Network is inaccessible, please set it up properly." ${MSGBOXSIZE}
  756. }
  757. configure_wifi() {
  758. local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
  759. DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
  760. "SSID:" 1 1 "" 1 16 30 0 \
  761. "Encryption:" 2 1 "" 2 16 4 3 \
  762. "Password:" 3 1 "" 3 16 63 0 || return 1
  763. set -- $(cat $ANSWER)
  764. ssid="$1"; enc="$2"; pass="$3";
  765. if [ -z "$ssid" ]; then
  766. DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
  767. return 1
  768. elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
  769. DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSXBOXSIZE}
  770. return 1
  771. elif [ -z "$pass" ]; then
  772. DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
  773. fi
  774. rm -f ${_wpasupconf%.conf}-${dev}.conf
  775. cp -f ${_wpasupconf} ${_wpasupconf%.conf}-${dev}.conf
  776. if [ "$enc" = "wep" ]; then
  777. echo "network={" >> ${_wpasupconf%.conf}-${dev}.conf
  778. echo " ssid=\"$ssid\"" >> ${_wpasupconf%.conf}-${dev}.conf
  779. echo " wep_key0=\"$pass\"" >> ${_wpasupconf%.conf}-${dev}.conf
  780. echo " wep_tx_keyidx=0" >> ${_wpasupconf%.conf}-${dev}.conf
  781. echo " auth_alg=SHARED" >> ${_wpasupconf%.conf}-${dev}.conf
  782. echo "}" >> ${_wpasupconf%.conf}-${dev}.conf
  783. else
  784. wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf%.conf}-${dev}.conf
  785. fi
  786. configure_net_dhcp $dev
  787. return $?
  788. }
  789. configure_net() {
  790. local dev="$1" rval
  791. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  792. rval=$?
  793. if [ $rval -eq 0 ]; then
  794. configure_net_dhcp $dev
  795. elif [ $rval -eq 1 ]; then
  796. configure_net_static $dev
  797. fi
  798. }
  799. iface_setup() {
  800. ip addr show dev $1|grep -q 'inet '
  801. return $?
  802. }
  803. configure_net_dhcp() {
  804. local dev="$1"
  805. iface_setup $dev
  806. if [ $? -eq 1 ]; then
  807. dhcpcd -t 10 -w -4 -L $dev -e "wpa_supplicant_conf=/etc/wpa_supplicant/wpa_supplicant-${dev}.conf" 2>&1 | tee $LOG | \
  808. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  809. if [ $? -ne 0 ]; then
  810. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
  811. return 1
  812. fi
  813. iface_setup $dev
  814. if [ $? -eq 1 ]; then
  815. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  816. return 1
  817. fi
  818. fi
  819. test_network
  820. if [ $? -eq 1 ]; then
  821. set_option NETWORK "${dev} dhcp"
  822. fi
  823. }
  824. configure_net_static() {
  825. local ip gw dns1 dns2 dev=$1
  826. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  827. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  828. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  829. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  830. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  831. set -- $(cat $ANSWER)
  832. ip=$1; gw=$2; dns1=$3; dns2=$4
  833. echo "running: ip link set dev $dev up" >$LOG
  834. ip link set dev $dev up >$LOG 2>&1
  835. if [ $? -ne 0 ]; then
  836. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  837. return 1
  838. fi
  839. echo "running: ip addr add $ip dev $dev"
  840. ip addr add $ip dev $dev >$LOG 2>&1
  841. if [ $? -ne 0 ]; then
  842. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  843. return 1
  844. fi
  845. ip route add $gw dev $dev >$LOG 2>&1
  846. if [ $? -ne 0 ]; then
  847. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  848. return 1
  849. fi
  850. echo "nameserver $dns1" >/etc/resolv.conf
  851. echo "nameserver $dns2" >>/etc/resolv.conf
  852. test_network
  853. if [ $? -eq 1 ]; then
  854. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  855. fi
  856. }
  857. menu_network() {
  858. local dev addr f DEVICES
  859. for f in $(ls /sys/class/net); do
  860. [ "$f" = "lo" ] && continue
  861. addr=$(cat /sys/class/net/$f/address)
  862. DEVICES="$DEVICES $f $addr"
  863. done
  864. DIALOG --title " Select the network interface to configure " \
  865. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  866. if [ $? -eq 0 ]; then
  867. dev=$(cat $ANSWER)
  868. if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
  869. configure_wifi $dev
  870. else
  871. configure_net $dev
  872. fi
  873. fi
  874. }
  875. validate_filesystems() {
  876. local mnts dev size fstype mntpt mkfs rootfound fmt
  877. local usrfound efi_system_partition
  878. unset TARGETFS
  879. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  880. set -- ${mnts}
  881. while [ $# -ne 0 ]; do
  882. fmt=""
  883. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  884. shift 6
  885. if [ "$mntpt" = "/" ]; then
  886. rootfound=1
  887. elif [ "$mntpt" = "/usr" ]; then
  888. usrfound=1
  889. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  890. efi_system_partition=1
  891. fi
  892. if [ "$mkfs" -eq 1 ]; then
  893. fmt="NEW FILESYSTEM: "
  894. fi
  895. if [ -z "$TARGETFS" ]; then
  896. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  897. else
  898. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  899. fi
  900. done
  901. if [ -z "$rootfound" ]; then
  902. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  903. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  904. return 1
  905. elif [ -n "$usrfound" ]; then
  906. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  907. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  908. return 1
  909. elif [ -n "$EFI_SYSTEM" -a -z "$efi_system_partition" ]; then
  910. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  911. The EFI System Partition has not yet been configured, please create it\n
  912. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  913. fi
  914. FILESYSTEMS_DONE=1
  915. }
  916. create_filesystems() {
  917. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  918. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  919. set -- ${mnts}
  920. while [ $# -ne 0 ]; do
  921. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  922. shift 6
  923. # swap partitions
  924. if [ "$fstype" = "swap" ]; then
  925. swapoff $dev >/dev/null 2>&1
  926. if [ "$mkfs" -eq 1 ]; then
  927. mkswap $dev >$LOG 2>&1
  928. if [ $? -ne 0 ]; then
  929. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  930. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  931. DIE 1
  932. fi
  933. fi
  934. swapon $dev >$LOG 2>&1
  935. if [ $? -ne 0 ]; then
  936. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  937. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  938. DIE 1
  939. fi
  940. # Add entry for target fstab
  941. uuid=$(blkid -o value -s UUID "$dev")
  942. echo "UUID=$uuid none swap sw 0 0" >>$TARGET_FSTAB
  943. continue
  944. fi
  945. if [ "$mkfs" -eq 1 ]; then
  946. case "$fstype" in
  947. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  948. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  949. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  950. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  951. f2fs) MKFS="mkfs.f2fs"; modprobe f2fs >$LOG 2>&1;;
  952. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  953. xfs) MKFS="mkfs.xfs -f"; modprobe xfs >$LOG 2>&1;;
  954. esac
  955. TITLE="Check $LOG for details ..."
  956. INFOBOX "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  957. echo "Running $MKFS $dev..." >$LOG
  958. $MKFS $dev >$LOG 2>&1; rv=$?
  959. if [ $rv -ne 0 ]; then
  960. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  961. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  962. DIE 1
  963. fi
  964. fi
  965. # Mount rootfs the first one.
  966. [ "$mntpt" != "/" ] && continue
  967. mkdir -p $TARGETDIR
  968. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  969. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  970. if [ $? -ne 0 ]; then
  971. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  972. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  973. DIE 1
  974. fi
  975. # Add entry to target fstab
  976. uuid=$(blkid -o value -s UUID "$dev")
  977. if [ "$fstype" = "f2fs" ]; then
  978. fspassno=0
  979. else
  980. fspassno=1
  981. fi
  982. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  983. done
  984. # mount all filesystems in target rootfs
  985. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  986. set -- ${mnts}
  987. while [ $# -ne 0 ]; do
  988. dev=$2; fstype=$3; mntpt="$5"
  989. shift 6
  990. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  991. mkdir -p ${TARGETDIR}${mntpt}
  992. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  993. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  994. if [ $? -ne 0 ]; then
  995. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  996. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  997. DIE
  998. fi
  999. # Add entry to target fstab
  1000. uuid=$(blkid -o value -s UUID "$dev")
  1001. echo "UUID=$uuid $mntpt $fstype defaults 0 2" >>$TARGET_FSTAB
  1002. done
  1003. }
  1004. mount_filesystems() {
  1005. for f in sys proc dev; do
  1006. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  1007. echo "Mounting $TARGETDIR/$f..." >$LOG
  1008. mount --bind /$f $TARGETDIR/$f >$LOG 2>&1
  1009. done
  1010. }
  1011. umount_filesystems() {
  1012. local f
  1013. for f in sys/fs/fuse/connections sys proc dev; do
  1014. echo "Unmounting $TARGETDIR/$f..." >$LOG
  1015. umount $TARGETDIR/$f >$LOG 2>&1
  1016. done
  1017. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  1018. set -- ${mnts}
  1019. while [ $# -ne 0 ]; do
  1020. local dev=$2; local fstype=$3; local mntpt=$5
  1021. shift 6
  1022. if [ "$fstype" = "swap" ]; then
  1023. echo "Disabling swap space on $dev..." >$LOG
  1024. swapoff $dev >$LOG 2>&1
  1025. continue
  1026. fi
  1027. if [ "$mntpt" != "/" ]; then
  1028. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  1029. umount $TARGETDIR/$mntpt >$LOG 2>&1
  1030. fi
  1031. done
  1032. echo "Unmounting $TARGETDIR..." >$LOG
  1033. umount $TARGETDIR >$LOG 2>&1
  1034. }
  1035. log_and_count() {
  1036. local progress whole tenth
  1037. while read line; do
  1038. echo "$line" >$LOG
  1039. copy_count=$((copy_count + 1))
  1040. progress=$((1000 * copy_count / copy_total))
  1041. if [ "$progress" != "$copy_progress" ]; then
  1042. whole=$((progress / 10))
  1043. tenth=$((progress % 10))
  1044. printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
  1045. copy_progress=$progress
  1046. fi
  1047. done
  1048. }
  1049. copy_rootfs() {
  1050. local tar_in="--create --one-file-system --xattrs"
  1051. TITLE="Check $LOG for details ..."
  1052. INFOBOX "Counting files, please be patient ..." 4 60
  1053. copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
  1054. export copy_total copy_count=0 copy_progress=
  1055. clear
  1056. tar ${tar_in} -f - / 2>/dev/null | \
  1057. tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
  1058. log_and_count | \
  1059. DIALOG --title "${TITLE}" \
  1060. --progressbox "Copying live image to target rootfs." 5 60
  1061. if [ $? -ne 0 ]; then
  1062. DIE 1
  1063. fi
  1064. unset copy_total copy_count copy_percent
  1065. }
  1066. install_packages() {
  1067. local _grub= _syspkg=
  1068. if [ -n "$EFI_SYSTEM" ]; then
  1069. if [ $EFI_FW_BITS -eq 32 ]; then
  1070. _grub="grub-i386-efi"
  1071. else
  1072. _grub="grub-x86_64-efi"
  1073. fi
  1074. else
  1075. _grub="grub"
  1076. fi
  1077. _syspkg="base-system"
  1078. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  1079. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  1080. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  1081. mkdir -p $TARGETDIR/boot/grub
  1082. _arch=$(xbps-uhelper arch)
  1083. stdbuf -oL env XBPS_ARCH=${_arch} \
  1084. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  1085. DIALOG --title "Installing base system packages..." \
  1086. --programbox 24 80
  1087. if [ $? -ne 0 ]; then
  1088. DIE 1
  1089. fi
  1090. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  1091. chroot $TARGETDIR xbps-reconfigure -a
  1092. }
  1093. enable_dhcpd() {
  1094. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  1095. }
  1096. menu_install() {
  1097. # Don't continue if filesystems are not ready.
  1098. validate_filesystems || return 1
  1099. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  1100. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  1101. if [ -z "$FILESYSTEMS_DONE" ]; then
  1102. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  1103. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1104. return 1
  1105. elif [ -z "$ROOTPASSWORD_DONE" ]; then
  1106. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  1107. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1108. return 1
  1109. elif [ -z "$BOOTLOADER_DONE" ]; then
  1110. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  1111. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1112. return 1
  1113. fi
  1114. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  1115. ${BOLD}${TARGETFS}${RESET}\n
  1116. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  1117. filesystems.${RESET}\n\n
  1118. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  1119. unset TARGETFS
  1120. # Create and mount filesystems
  1121. create_filesystems
  1122. # If source not set use defaults.
  1123. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  1124. copy_rootfs
  1125. . /etc/default/live.conf
  1126. rm -f $TARGETDIR/etc/motd
  1127. rm -f $TARGETDIR/etc/issue
  1128. rm -f $TARGETDIR/usr/sbin/void-installer
  1129. # Remove live user.
  1130. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  1131. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  1132. sed -i -e "/$USERNAME ALL=.*/d" $TARGETDIR/etc/sudoers
  1133. TITLE="Check $LOG for details ..."
  1134. INFOBOX "Rebuilding initramfs for target ..." 4 60
  1135. echo "Rebuilding initramfs for target ..." >$LOG
  1136. # mount required fs
  1137. mount_filesystems
  1138. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  1139. INFOBOX "Removing temporary packages from target ..." 4 60
  1140. echo "Removing temporary packages from target ..." >$LOG
  1141. xbps-remove -r $TARGETDIR -Ry dialog >>$LOG 2>&1
  1142. rmdir $TARGETDIR/mnt/target
  1143. else
  1144. # mount required fs
  1145. mount_filesystems
  1146. # network install, use packages.
  1147. install_packages
  1148. fi
  1149. INFOBOX "Applying installer settings..." 4 60
  1150. # copy target fstab.
  1151. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  1152. # Mount /tmp as tmpfs.
  1153. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  1154. # set up keymap, locale, timezone, hostname, root passwd and user account.
  1155. set_keymap
  1156. set_locale
  1157. set_timezone
  1158. set_hostname
  1159. set_rootpassword
  1160. set_useraccount
  1161. # Copy /etc/skel files for root.
  1162. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  1163. # network settings for target
  1164. if [ -n "$NETWORK_DONE" ]; then
  1165. local net="$(get_option NETWORK)"
  1166. set -- ${net}
  1167. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  1168. if [ -z "$_type" ]; then
  1169. # network type empty??!!!
  1170. :
  1171. elif [ "$_type" = "dhcp" ]; then
  1172. if [ -f /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf ]; then
  1173. cp /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf $TARGETDIR/etc/wpa_supplicant
  1174. ln -sf /etc/sv/dhcpcd-${_dev} $TARGETDIR/etc/runit/runsvdir/default/dhcpcd-${_dev}
  1175. else
  1176. enable_dhcpd
  1177. fi
  1178. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  1179. # static IP through dhcpcd.
  1180. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig
  1181. echo "# Static IP configuration set by the void-installer for $_dev." \
  1182. >$TARGETDIR/etc/dhcpcd.conf
  1183. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  1184. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  1185. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  1186. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  1187. enable_dhcpd
  1188. fi
  1189. fi
  1190. if [ -f $TARGETDIR/etc/sudoers ]; then
  1191. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" ]; then
  1192. # enable sudo for primary user USERLOGIN
  1193. echo "# Enable sudo for login '$(get_option USERLOGIN)'" >> $TARGETDIR/etc/sudoers
  1194. echo "$(get_option USERLOGIN) ALL=(ALL) ALL" >> $TARGETDIR/etc/sudoers
  1195. else
  1196. # enable sudoers entry for members of group wheel for primary user
  1197. sed -i $TARGETDIR/etc/sudoers \
  1198. -e "s;#.*%wheel ALL=(ALL) ALL;%wheel ALL=(ALL) ALL;"
  1199. fi
  1200. fi
  1201. # enable text console for grub if chosen
  1202. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  1203. sed -i $TARGETDIR/etc/default/grub \
  1204. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  1205. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  1206. fi
  1207. # install bootloader.
  1208. set_bootloader
  1209. sync && sync && sync
  1210. # unmount all filesystems.
  1211. umount_filesystems
  1212. # installed successfully.
  1213. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  1214. Do you want to reboot the system?" ${YESNOSIZE}
  1215. if [ $? -eq 0 ]; then
  1216. shutdown -r now
  1217. else
  1218. return
  1219. fi
  1220. }
  1221. menu_source() {
  1222. local src=
  1223. DIALOG --title " Select installation source " \
  1224. --menu "$MENULABEL" 8 70 0 \
  1225. "Local" "Packages from ISO image" \
  1226. "Network" "Packages from official remote reposity"
  1227. case "$(cat $ANSWER)" in
  1228. "Local") src="local";;
  1229. "Network") src="net";
  1230. if [ -z "$NETWORK_DONE" ]; then
  1231. menu_network;
  1232. fi;;
  1233. *) return 1;;
  1234. esac
  1235. SOURCE_DONE=1
  1236. set_option SOURCE $src
  1237. }
  1238. menu() {
  1239. if [ -z "$DEFITEM" ]; then
  1240. DEFITEM="Keyboard"
  1241. fi
  1242. DIALOG --default-item $DEFITEM \
  1243. --extra-button --extra-label "Settings" \
  1244. --title " Void Linux installation menu " \
  1245. --menu "$MENULABEL" 10 70 0 \
  1246. "Keyboard" "Set system keyboard" \
  1247. "Network" "Set up the network" \
  1248. "Source" "Set source installation" \
  1249. "Hostname" "Set system hostname" \
  1250. "Locale" "Set system locale" \
  1251. "Timezone" "Set system time zone" \
  1252. "RootPassword" "Set system root password" \
  1253. "UserAccount" "Set primary user name and password" \
  1254. "BootLoader" "Set disk to install bootloader" \
  1255. "Partition" "Partition disk(s)" \
  1256. "Filesystems" "Configure filesystems and mount points" \
  1257. "Install" "Start installation with saved settings" \
  1258. "Exit" "Exit installation"
  1259. if [ $? -eq 3 ]; then
  1260. # Show settings
  1261. cp $CONF_FILE /tmp/conf_hidden.$$;
  1262. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1263. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1264. rm /tmp/conf_hidden.$$
  1265. return
  1266. fi
  1267. case $(cat $ANSWER) in
  1268. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1269. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1270. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1271. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="Locale";;
  1272. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1273. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1274. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1275. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1276. && DEFITEM="BootLoader";;
  1277. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1278. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1279. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1280. "Install") menu_install;;
  1281. "Exit") DIE;;
  1282. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1283. esac
  1284. }
  1285. if [ ! -x /bin/dialog ]; then
  1286. echo "ERROR: missing dialog command, exiting..."
  1287. exit 1
  1288. fi
  1289. if [ "$(id -u)" != "0" ]; then
  1290. echo "void-installer must run as root" 1>&2
  1291. exit 1
  1292. fi
  1293. #
  1294. # main()
  1295. #
  1296. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1297. Welcome to the Void Linux installation. A simple and minimal \
  1298. Linux distribution made from scratch and built from the source package tree \
  1299. available for XBPS, a new alternative binary package system.\n\n
  1300. The installation should be pretty straightforward. If you are in trouble \
  1301. please join us at ${BOLD}#voidlinux${RESET} on ${BOLD}irc.freenode.org${RESET}.\n\n
  1302. ${BOLD}http://www.voidlinux.eu${RESET}\n\n" 16 80
  1303. while true; do
  1304. menu
  1305. done
  1306. exit 0
  1307. # vim: set ts=4 sw=4 et: