installer.sh.in 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  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. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  883. shift 6
  884. if [ "$mntpt" = "/" ]; then
  885. rootfound=1
  886. elif [ "$mntpt" = "/usr" ]; then
  887. usrfound=1
  888. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  889. efi_system_partition=1
  890. fi
  891. if [ "$mkfs" -eq 1 ]; then
  892. fmt="NEW FILESYSTEM: "
  893. fi
  894. if [ -z "$TARGETFS" ]; then
  895. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  896. else
  897. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  898. fi
  899. done
  900. if [ -z "$rootfound" ]; then
  901. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  902. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  903. return 1
  904. elif [ -n "$usrfound" ]; then
  905. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  906. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  907. return 1
  908. elif [ -n "$EFI_SYSTEM" -a -z "$efi_system_partition" ]; then
  909. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  910. The EFI System Partition has not yet been configured, please create it\n
  911. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  912. fi
  913. FILESYSTEMS_DONE=1
  914. }
  915. create_filesystems() {
  916. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  917. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  918. set -- ${mnts}
  919. while [ $# -ne 0 ]; do
  920. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  921. shift 6
  922. # swap partitions
  923. if [ "$fstype" = "swap" ]; then
  924. swapoff $dev >/dev/null 2>&1
  925. if [ "$mkfs" -eq 1 ]; then
  926. mkswap $dev >$LOG 2>&1
  927. if [ $? -ne 0 ]; then
  928. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  929. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  930. DIE 1
  931. fi
  932. fi
  933. swapon $dev >$LOG 2>&1
  934. if [ $? -ne 0 ]; then
  935. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  936. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  937. DIE 1
  938. fi
  939. # Add entry for target fstab
  940. uuid=$(blkid -o value -s UUID "$dev")
  941. echo "UUID=$uuid none swap sw 0 0" >>$TARGET_FSTAB
  942. continue
  943. fi
  944. if [ "$mkfs" -eq 1 ]; then
  945. case "$fstype" in
  946. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  947. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  948. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  949. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  950. f2fs) MKFS="mkfs.f2fs"; modprobe f2fs >$LOG 2>&1;;
  951. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  952. xfs) MKFS="mkfs.xfs -f"; modprobe xfs >$LOG 2>&1;;
  953. esac
  954. TITLE="Check $LOG for details ..."
  955. INFOBOX "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  956. echo "Running $MKFS $dev..." >$LOG
  957. $MKFS $dev >$LOG 2>&1; rv=$?
  958. if [ $rv -ne 0 ]; then
  959. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  960. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  961. DIE 1
  962. fi
  963. fi
  964. # Mount rootfs the first one.
  965. [ "$mntpt" != "/" ] && continue
  966. mkdir -p $TARGETDIR
  967. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  968. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  969. if [ $? -ne 0 ]; then
  970. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  971. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  972. DIE 1
  973. fi
  974. # Add entry to target fstab
  975. uuid=$(blkid -o value -s UUID "$dev")
  976. if [ "$fstype" = "f2fs" ]; then
  977. fspassno=0
  978. else
  979. fspassno=1
  980. fi
  981. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  982. done
  983. # mount all filesystems in target rootfs
  984. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  985. set -- ${mnts}
  986. while [ $# -ne 0 ]; do
  987. dev=$2; fstype=$3; mntpt="$5"
  988. shift 6
  989. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  990. mkdir -p ${TARGETDIR}${mntpt}
  991. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  992. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  993. if [ $? -ne 0 ]; then
  994. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  995. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  996. DIE
  997. fi
  998. # Add entry to target fstab
  999. uuid=$(blkid -o value -s UUID "$dev")
  1000. echo "UUID=$uuid $mntpt $fstype defaults 0 2" >>$TARGET_FSTAB
  1001. done
  1002. }
  1003. mount_filesystems() {
  1004. for f in sys proc dev; do
  1005. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  1006. echo "Mounting $TARGETDIR/$f..." >$LOG
  1007. mount --bind /$f $TARGETDIR/$f >$LOG 2>&1
  1008. done
  1009. }
  1010. umount_filesystems() {
  1011. local f
  1012. for f in sys/fs/fuse/connections sys proc dev; do
  1013. echo "Unmounting $TARGETDIR/$f..." >$LOG
  1014. umount $TARGETDIR/$f >$LOG 2>&1
  1015. done
  1016. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  1017. set -- ${mnts}
  1018. while [ $# -ne 0 ]; do
  1019. local dev=$2; local fstype=$3; local mntpt=$5
  1020. shift 6
  1021. if [ "$fstype" = "swap" ]; then
  1022. echo "Disabling swap space on $dev..." >$LOG
  1023. swapoff $dev >$LOG 2>&1
  1024. continue
  1025. fi
  1026. if [ "$mntpt" != "/" ]; then
  1027. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  1028. umount $TARGETDIR/$mntpt >$LOG 2>&1
  1029. fi
  1030. done
  1031. echo "Unmounting $TARGETDIR..." >$LOG
  1032. umount $TARGETDIR >$LOG 2>&1
  1033. }
  1034. log_and_count() {
  1035. local progress whole tenth
  1036. while read line; do
  1037. echo "$line" >$LOG
  1038. copy_count=$((copy_count + 1))
  1039. progress=$((1000 * copy_count / copy_total))
  1040. if [ "$progress" != "$copy_progress" ]; then
  1041. whole=$((progress / 10))
  1042. tenth=$((progress % 10))
  1043. printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
  1044. copy_progress=$progress
  1045. fi
  1046. done
  1047. }
  1048. copy_rootfs() {
  1049. local tar_in="--create --one-file-system --xattrs"
  1050. TITLE="Check $LOG for details ..."
  1051. INFOBOX "Counting files, please be patient ..." 4 60
  1052. copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
  1053. export copy_total copy_count=0 copy_progress=
  1054. clear
  1055. tar ${tar_in} -f - / 2>/dev/null | \
  1056. tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
  1057. log_and_count | \
  1058. DIALOG --title "${TITLE}" \
  1059. --progressbox "Copying live image to target rootfs." 5 60
  1060. if [ $? -ne 0 ]; then
  1061. DIE 1
  1062. fi
  1063. unset copy_total copy_count copy_percent
  1064. }
  1065. install_packages() {
  1066. local _grub= _syspkg=
  1067. if [ -n "$EFI_SYSTEM" ]; then
  1068. if [ $EFI_FW_BITS -eq 32 ]; then
  1069. _grub="grub-i386-efi"
  1070. else
  1071. _grub="grub-x86_64-efi"
  1072. fi
  1073. else
  1074. _grub="grub"
  1075. fi
  1076. _syspkg="base-system"
  1077. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  1078. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  1079. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  1080. mkdir -p $TARGETDIR/boot/grub
  1081. _arch=$(xbps-uhelper arch)
  1082. stdbuf -oL env XBPS_ARCH=${_arch} \
  1083. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  1084. DIALOG --title "Installing base system packages..." \
  1085. --programbox 24 80
  1086. if [ $? -ne 0 ]; then
  1087. DIE 1
  1088. fi
  1089. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  1090. chroot $TARGETDIR xbps-reconfigure -a
  1091. }
  1092. enable_dhcpd() {
  1093. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  1094. }
  1095. menu_install() {
  1096. # Don't continue if filesystems are not ready.
  1097. validate_filesystems || return 1
  1098. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  1099. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  1100. if [ -z "$FILESYSTEMS_DONE" ]; then
  1101. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  1102. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1103. return 1
  1104. elif [ -z "$ROOTPASSWORD_DONE" ]; then
  1105. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  1106. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1107. return 1
  1108. elif [ -z "$BOOTLOADER_DONE" ]; then
  1109. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  1110. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1111. return 1
  1112. fi
  1113. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  1114. ${BOLD}${TARGETFS}${RESET}\n
  1115. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  1116. filesystems.${RESET}\n\n
  1117. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  1118. unset TARGETFS
  1119. # Create and mount filesystems
  1120. create_filesystems
  1121. # If source not set use defaults.
  1122. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  1123. copy_rootfs
  1124. . /etc/default/live.conf
  1125. rm -f $TARGETDIR/etc/motd
  1126. rm -f $TARGETDIR/etc/issue
  1127. rm -f $TARGETDIR/usr/sbin/void-installer
  1128. # Remove live user.
  1129. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  1130. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  1131. sed -i -e "/$USERNAME ALL=.*/d" $TARGETDIR/etc/sudoers
  1132. TITLE="Check $LOG for details ..."
  1133. INFOBOX "Rebuilding initramfs for target ..." 4 60
  1134. echo "Rebuilding initramfs for target ..." >$LOG
  1135. # mount required fs
  1136. mount_filesystems
  1137. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  1138. INFOBOX "Removing temporary packages from target ..." 4 60
  1139. echo "Removing temporary packages from target ..." >$LOG
  1140. xbps-remove -r $TARGETDIR -Ry dialog >>$LOG 2>&1
  1141. rmdir $TARGETDIR/mnt/target
  1142. else
  1143. # mount required fs
  1144. mount_filesystems
  1145. # network install, use packages.
  1146. install_packages
  1147. fi
  1148. INFOBOX "Applying installer settings..." 4 60
  1149. # copy target fstab.
  1150. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  1151. # Mount /tmp as tmpfs.
  1152. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  1153. # set up keymap, locale, timezone, hostname, root passwd and user account.
  1154. set_keymap
  1155. set_locale
  1156. set_timezone
  1157. set_hostname
  1158. set_rootpassword
  1159. set_useraccount
  1160. # Copy /etc/skel files for root.
  1161. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  1162. # network settings for target
  1163. if [ -n "$NETWORK_DONE" ]; then
  1164. local net="$(get_option NETWORK)"
  1165. set -- ${net}
  1166. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  1167. if [ -z "$_type" ]; then
  1168. # network type empty??!!!
  1169. :
  1170. elif [ "$_type" = "dhcp" ]; then
  1171. if [ -f /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf ]; then
  1172. cp /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf $TARGETDIR/etc/wpa_supplicant
  1173. ln -sf /etc/sv/dhcpcd-${_dev} $TARGETDIR/etc/runit/runsvdir/default/dhcpcd-${_dev}
  1174. else
  1175. enable_dhcpd
  1176. fi
  1177. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  1178. # static IP through dhcpcd.
  1179. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig
  1180. echo "# Static IP configuration set by the void-installer for $_dev." \
  1181. >$TARGETDIR/etc/dhcpcd.conf
  1182. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  1183. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  1184. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  1185. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  1186. enable_dhcpd
  1187. fi
  1188. fi
  1189. if [ -f $TARGETDIR/etc/sudoers ]; then
  1190. USERLOGIN="$(get_option USERLOGIN)"
  1191. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
  1192. # enable sudo for primary user USERLOGIN who is not member of wheel
  1193. echo "# Enable sudo for login '$USERLOGIN'" >> $TARGETDIR/etc/sudoers
  1194. echo "$USERLOGIN ALL=(ALL) ALL" >> $TARGETDIR/etc/sudoers
  1195. else
  1196. # enable the sudoers entry for members of group wheel
  1197. sed -i $TARGETDIR/etc/sudoers \
  1198. -e "s;#.*%wheel ALL=(ALL) ALL;%wheel ALL=(ALL) ALL;"
  1199. fi
  1200. unset USERLOGIN
  1201. fi
  1202. # enable text console for grub if chosen
  1203. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  1204. sed -i $TARGETDIR/etc/default/grub \
  1205. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  1206. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  1207. fi
  1208. # install bootloader.
  1209. set_bootloader
  1210. sync && sync && sync
  1211. # unmount all filesystems.
  1212. umount_filesystems
  1213. # installed successfully.
  1214. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  1215. Do you want to reboot the system?" ${YESNOSIZE}
  1216. if [ $? -eq 0 ]; then
  1217. shutdown -r now
  1218. else
  1219. return
  1220. fi
  1221. }
  1222. menu_source() {
  1223. local src=
  1224. DIALOG --title " Select installation source " \
  1225. --menu "$MENULABEL" 8 70 0 \
  1226. "Local" "Packages from ISO image" \
  1227. "Network" "Packages from official remote reposity"
  1228. case "$(cat $ANSWER)" in
  1229. "Local") src="local";;
  1230. "Network") src="net";
  1231. if [ -z "$NETWORK_DONE" ]; then
  1232. menu_network;
  1233. fi;;
  1234. *) return 1;;
  1235. esac
  1236. SOURCE_DONE=1
  1237. set_option SOURCE $src
  1238. }
  1239. menu() {
  1240. if [ -z "$DEFITEM" ]; then
  1241. DEFITEM="Keyboard"
  1242. fi
  1243. DIALOG --default-item $DEFITEM \
  1244. --extra-button --extra-label "Settings" \
  1245. --title " Void Linux installation menu " \
  1246. --menu "$MENULABEL" 10 70 0 \
  1247. "Keyboard" "Set system keyboard" \
  1248. "Network" "Set up the network" \
  1249. "Source" "Set source installation" \
  1250. "Hostname" "Set system hostname" \
  1251. "Locale" "Set system locale" \
  1252. "Timezone" "Set system time zone" \
  1253. "RootPassword" "Set system root password" \
  1254. "UserAccount" "Set primary user name and password" \
  1255. "BootLoader" "Set disk to install bootloader" \
  1256. "Partition" "Partition disk(s)" \
  1257. "Filesystems" "Configure filesystems and mount points" \
  1258. "Install" "Start installation with saved settings" \
  1259. "Exit" "Exit installation"
  1260. if [ $? -eq 3 ]; then
  1261. # Show settings
  1262. cp $CONF_FILE /tmp/conf_hidden.$$;
  1263. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1264. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1265. rm /tmp/conf_hidden.$$
  1266. return
  1267. fi
  1268. case $(cat $ANSWER) in
  1269. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1270. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1271. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1272. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="Locale";;
  1273. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1274. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1275. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1276. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1277. && DEFITEM="BootLoader";;
  1278. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1279. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1280. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1281. "Install") menu_install;;
  1282. "Exit") DIE;;
  1283. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1284. esac
  1285. }
  1286. if [ ! -x /bin/dialog ]; then
  1287. echo "ERROR: missing dialog command, exiting..."
  1288. exit 1
  1289. fi
  1290. if [ "$(id -u)" != "0" ]; then
  1291. echo "void-installer must run as root" 1>&2
  1292. exit 1
  1293. fi
  1294. #
  1295. # main()
  1296. #
  1297. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1298. Welcome to the Void Linux installation. A simple and minimal \
  1299. Linux distribution made from scratch and built from the source package tree \
  1300. available for XBPS, a new alternative binary package system.\n\n
  1301. The installation should be pretty straightforward. If you are in trouble \
  1302. please join us at ${BOLD}#voidlinux${RESET} on ${BOLD}irc.freenode.org${RESET}.\n\n
  1303. ${BOLD}http://www.voidlinux.eu${RESET}\n\n" 16 80
  1304. while true; do
  1305. menu
  1306. done
  1307. exit 0
  1308. # vim: set ts=4 sw=4 et: