installer.sh.in 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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.org (@@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.org (@@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. # Device Mapper
  365. for p in /dev/mapper/*; do
  366. part=$(basename $p)
  367. [ "${part}" = "live-rw" ] && continue
  368. [ "${part}" = "live-base" ] && continue
  369. [ "${part}" = "control" ] && continue
  370. fstype=$(lsblk -nfr $p|awk '{print $2}'|head -1)
  371. fssize=$(lsblk -nr $p|awk '{print $4}'|head -1)
  372. echo "${p}"
  373. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  374. done
  375. # Software raid (md)
  376. for p in $(ls -d /dev/md* 2>/dev/null|grep '[0-9]'); do
  377. part=$(basename $p)
  378. if cat /proc/mdstat|grep -qw $part; then
  379. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  380. [ "$fstype" = "crypto_LUKS" ] && continue
  381. [ "$fstype" = "LVM2_member" ] && continue
  382. fssize=$(lsblk -nr /dev/$part|awk '{print $4}')
  383. echo "$p"
  384. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  385. fi
  386. done
  387. # cciss(4) devices
  388. for part in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]p[0-9]+'); do
  389. fstype=$(lsblk -nfr /dev/cciss/$part|awk '{print $2}')
  390. [ "$fstype" = "crypto_LUKS" ] && continue
  391. [ "$fstype" = "LVM2_member" ] && continue
  392. fssize=$(lsblk -nr /dev/cciss/$part|awk '{print $4}')
  393. echo "/dev/cciss/$part"
  394. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  395. done
  396. if [ -e /sbin/lvs ]; then
  397. # LVM
  398. lvs --noheadings|while read lvname vgname perms size; do
  399. echo "/dev/mapper/${vgname}-${lvname}"
  400. echo "size:${size};fstype:lvm"
  401. done
  402. fi
  403. }
  404. menu_filesystems() {
  405. local dev fstype fssize mntpoint reformat
  406. while true; do
  407. DIALOG --ok-label "Change" --cancel-label "Done" \
  408. --title " Select the partition to edit " --menu "$MENULABEL" \
  409. ${MENUSIZE} $(show_partitions)
  410. [ $? -ne 0 ] && return
  411. dev=$(cat $ANSWER)
  412. DIALOG --title " Select the filesystem type for $dev " \
  413. --menu "$MENULABEL" ${MENUSIZE} \
  414. "btrfs" "Oracle's Btrfs" \
  415. "ext2" "Linux ext2 (no journaling)" \
  416. "ext3" "Linux ext3 (journal)" \
  417. "ext4" "Linux ext4 (journal)" \
  418. "f2fs" "Flash-Friendly Filesystem" \
  419. "swap" "Linux swap" \
  420. "vfat" "FAT32" \
  421. "xfs" "SGI's XFS"
  422. if [ $? -eq 0 ]; then
  423. fstype=$(cat $ANSWER)
  424. else
  425. continue
  426. fi
  427. if [ "$fstype" != "swap" ]; then
  428. DIALOG --inputbox "Please specify the mount point for $dev:" ${INPUTSIZE}
  429. if [ $? -eq 0 ]; then
  430. mntpoint=$(cat $ANSWER)
  431. elif [ $? -eq 1 ]; then
  432. continue
  433. fi
  434. else
  435. mntpoint=swap
  436. fi
  437. DIALOG --yesno "Do you want to create a new filesystem on $dev?" ${YESNOSIZE}
  438. if [ $? -eq 0 ]; then
  439. reformat=1
  440. elif [ $? -eq 1 ]; then
  441. reformat=0
  442. else
  443. continue
  444. fi
  445. fssize=$(lsblk -nr $dev|awk '{print $4}')
  446. set -- "$fstype" "$fssize" "$mntpoint" "$reformat"
  447. if [ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ]; then
  448. local bdev=$(basename $dev)
  449. local ddev=$(basename $(dirname $dev))
  450. if [ "$ddev" != "dev" ]; then
  451. sed -i -e "/^MOUNTPOINT \/dev\/${ddev}\/${bdev}.*/d" $CONF_FILE
  452. else
  453. sed -i -e "/^MOUNTPOINT \/dev\/${bdev}.*/d" $CONF_FILE
  454. fi
  455. echo "MOUNTPOINT $dev $1 $2 $3 $4" >>$CONF_FILE
  456. fi
  457. done
  458. }
  459. menu_partitions() {
  460. DIALOG --title " Select the disk to partition " \
  461. --menu "$MENULABEL" ${MENUSIZE} $(show_disks)
  462. if [ $? -eq 0 ]; then
  463. local device=$(cat $ANSWER)
  464. DIALOG --title " Select the software for partitioning " \
  465. --menu "$MENULABEL" ${MENUSIZE} \
  466. "cfdisk" "Easy to use" \
  467. "fdisk" "More advanced"
  468. if [ $? -eq 0 ]; then
  469. local software=$(cat $ANSWER)
  470. DIALOG --title "Modify Partition Table on $device" --msgbox "\n
  471. ${BOLD}${software} will be executed in disk $device.${RESET}\n\n
  472. For BIOS systems, MBR or GPT partition tables are supported.\n
  473. To use GPT on PC BIOS systems an empty partition of 1MB must be added\n
  474. at the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n
  475. ${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n
  476. For EFI systems GPT is mandatory and a FAT32 partition with at least\n
  477. 100MB must be created with the TOGGLE \`boot', this will be used as\n
  478. EFI System Partition. This partition must have mountpoint as \`/boot/efi'.\n\n
  479. At least 1 partition is required for the rootfs (/).\n
  480. For swap, RAM*2 must be really enough. For / 600MB are required.\n\n
  481. ${BOLD}WARNING: /usr is not supported as a separate partition.${RESET}\n
  482. ${RESET}\n" 18 80
  483. if [ $? -eq 0 ]; then
  484. while true; do
  485. clear; $software $device; PARTITIONS_DONE=1
  486. break
  487. done
  488. else
  489. return
  490. fi
  491. fi
  492. fi
  493. }
  494. menu_keymap() {
  495. local _keymaps="$(find /usr/share/kbd/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sort)"
  496. local _KEYMAPS=
  497. for f in ${_keymaps}; do
  498. _KEYMAPS="${_KEYMAPS} ${f} -"
  499. done
  500. while true; do
  501. DIALOG --title " Select your keymap " --menu "$MENULABEL" 14 70 14 ${_KEYMAPS}
  502. if [ $? -eq 0 ]; then
  503. set_option KEYMAP "$(cat $ANSWER)"
  504. loadkeys "$(cat $ANSWER)"
  505. KEYBOARD_DONE=1
  506. break
  507. else
  508. return
  509. fi
  510. done
  511. }
  512. set_keymap() {
  513. local KEYMAP=$(get_option KEYMAP)
  514. if [ -f /etc/vconsole.conf ]; then
  515. sed -i -e "s|KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/vconsole.conf
  516. else
  517. sed -i -e "s|#\?KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/rc.conf
  518. fi
  519. }
  520. menu_locale() {
  521. local _locales="$(grep -E '\.UTF-8' /etc/default/libc-locales|awk '{print $1}'|sed -e 's/^#//')"
  522. local LOCALES ISO639 ISO3166
  523. local TMPFILE=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  524. INFOBOX "Scanning locales ..." 4 60
  525. for f in ${_locales}; do
  526. eval $(echo $f | awk 'BEGIN { FS="." } \
  527. { FS="_"; split($1, a); printf "ISO639=%s ISO3166=%s\n", a[1], a[2] }')
  528. echo "$f|$(iso639_language $ISO639) ($(iso3166_country $ISO3166))|" >> $TMPFILE
  529. done
  530. clear
  531. # Sort by ISO-639 language names
  532. LOCALES=$(sort -t '|' -k 2 < $TMPFILE | xargs | sed -e's/| /|/g')
  533. rm -f $TMPFILE
  534. while true; do
  535. (IFS="|"; DIALOG --title " Select your locale " --menu "$MENULABEL" 18 70 18 ${LOCALES})
  536. if [ $? -eq 0 ]; then
  537. set_option LOCALE "$(cat $ANSWER)"
  538. LOCALE_DONE=1
  539. break
  540. else
  541. return
  542. fi
  543. done
  544. }
  545. set_locale() {
  546. if [ -f $TARGETDIR/etc/default/libc-locales ]; then
  547. local LOCALE="$(get_option LOCALE)"
  548. : "${LOCALE:=C.UTF-8}"
  549. sed -i -e "s|LANG=.*|LANG=$LOCALE|g" $TARGETDIR/etc/locale.conf
  550. # Uncomment locale from /etc/default/libc-locales and regenerate it.
  551. sed -e "/${LOCALE}/s/^\#//" -i $TARGETDIR/etc/default/libc-locales
  552. echo "Running xbps-reconfigure -f glibc-locales ..." >$LOG
  553. chroot $TARGETDIR xbps-reconfigure -f glibc-locales >$LOG 2>&1
  554. fi
  555. }
  556. menu_timezone() {
  557. local areas=(Africa America Antarctica Arctic Asia Atlantic Australia Europe Indian Pacific)
  558. local area locations location
  559. while (IFS='|'; DIALOG ${area:+--default-item|"$area"} --title " Select area " --menu "$MENULABEL" 19 51 19 $(printf '%s||' "${areas[@]}")); do
  560. area=$(cat $ANSWER)
  561. read -a locations -d '\n' < <(find /usr/share/zoneinfo/$area -type f -printf '%P\n' | sort)
  562. if (IFS='|'; DIALOG --title " Select location (${area}) " --menu "$MENULABEL" 19 51 19 $(printf '%s||' "${locations[@]//_/ }")); then
  563. location=$(tr ' ' '_' < $ANSWER)
  564. set_option TIMEZONE "$area/$location"
  565. TIMEZONE_DONE=1
  566. return 0
  567. else
  568. continue
  569. fi
  570. done
  571. return 1
  572. }
  573. set_timezone() {
  574. local TIMEZONE="$(get_option TIMEZONE)"
  575. ln -sf "/usr/share/zoneinfo/${TIMEZONE}" "${TARGETDIR}/etc/localtime"
  576. }
  577. menu_hostname() {
  578. while true; do
  579. DIALOG --inputbox "Set the machine hostname:" ${INPUTSIZE}
  580. if [ $? -eq 0 ]; then
  581. set_option HOSTNAME "$(cat $ANSWER)"
  582. HOSTNAME_DONE=1
  583. break
  584. else
  585. return
  586. fi
  587. done
  588. }
  589. set_hostname() {
  590. echo $(get_option HOSTNAME) > $TARGETDIR/etc/hostname
  591. }
  592. menu_rootpassword() {
  593. local _firstpass _secondpass _again _desc
  594. while true; do
  595. if [ -z "${_firstpass}" ]; then
  596. _desc="Enter the root password"
  597. else
  598. _again=" again"
  599. fi
  600. DIALOG --insecure --passwordbox "${_desc}${_again}" ${INPUTSIZE}
  601. if [ $? -eq 0 ]; then
  602. if [ -z "${_firstpass}" ]; then
  603. _firstpass="$(cat $ANSWER)"
  604. else
  605. _secondpass="$(cat $ANSWER)"
  606. fi
  607. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  608. if [ "${_firstpass}" != "${_secondpass}" ]; then
  609. INFOBOX "Passwords do not match! Please enter again." 6 60
  610. unset _firstpass _secondpass _again
  611. sleep 2 && clear && continue
  612. fi
  613. set_option ROOTPASSWORD "${_firstpass}"
  614. ROOTPASSWORD_DONE=1
  615. break
  616. fi
  617. else
  618. return
  619. fi
  620. done
  621. }
  622. set_rootpassword() {
  623. echo "root:$(get_option ROOTPASSWORD)" | chpasswd -R $TARGETDIR -c SHA512
  624. }
  625. menu_useraccount() {
  626. local _firstpass _secondpass _desc _again
  627. local _groups _status _group _checklist
  628. local _preset _userlogin
  629. while true; do
  630. _preset=$(get_option USERLOGIN)
  631. [ -z "$_preset" ] && _preset="void"
  632. DIALOG --inputbox "Enter a primary login name:" ${INPUTSIZE} "$_preset"
  633. if [ $? -eq 0 ]; then
  634. _userlogin="$(cat $ANSWER)"
  635. # based on useradd(8) § Caveats
  636. if [ "${#_userlogin}" -le 32 ] && [[ "${_userlogin}" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]]; then
  637. set_option USERLOGIN "${_userlogin}"
  638. USERLOGIN_DONE=1
  639. break
  640. else
  641. INFOBOX "Invalid login name! Please try again." 6 60
  642. unset _userlogin
  643. sleep 2 && clear && continue
  644. fi
  645. else
  646. return
  647. fi
  648. done
  649. while true; do
  650. _preset=$(get_option USERNAME)
  651. [ -z "$_preset" ] && _preset="Void User"
  652. DIALOG --inputbox "Enter a user name for login '$(get_option USERLOGIN)' :" \
  653. ${INPUTSIZE} "$_preset"
  654. if [ $? -eq 0 ]; then
  655. set_option USERNAME "$(cat $ANSWER)"
  656. USERNAME_DONE=1
  657. break
  658. else
  659. return
  660. fi
  661. done
  662. while true; do
  663. if [ -z "${_firstpass}" ]; then
  664. _desc="Enter the password for login '$(get_option USERLOGIN)'"
  665. else
  666. _again=" again"
  667. fi
  668. DIALOG --insecure --passwordbox "${_desc}${_again}" ${INPUTSIZE}
  669. if [ $? -eq 0 ]; then
  670. if [ -z "${_firstpass}" ]; then
  671. _firstpass="$(cat $ANSWER)"
  672. else
  673. _secondpass="$(cat $ANSWER)"
  674. fi
  675. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  676. if [ "${_firstpass}" != "${_secondpass}" ]; then
  677. INFOBOX "Passwords do not match! Please enter again." 6 60
  678. unset _firstpass _secondpass _again
  679. sleep 2 && clear && continue
  680. fi
  681. set_option USERPASSWORD "${_firstpass}"
  682. USERPASSWORD_DONE=1
  683. break
  684. fi
  685. else
  686. return
  687. fi
  688. done
  689. _groups="wheel,audio,video,floppy,cdrom,optical,kvm,xbuilder"
  690. while true; do
  691. _desc="Select group membership for login '$(get_option USERLOGIN)':"
  692. for _group in $(cat /etc/group); do
  693. _gid="$(echo ${_group} | cut -d: -f3)"
  694. _group="$(echo ${_group} | cut -d: -f1)"
  695. _status="$(echo ${_groups} | grep -w ${_group})"
  696. if [ -z "${_status}" ]; then
  697. _status=off
  698. else
  699. _status=on
  700. fi
  701. # ignore the groups of existing users and package groups
  702. if [[ "${_gid}" -ge 1000 || "${_group}" = "_"* ]]; then
  703. continue
  704. fi
  705. if [ -z "${_checklist}" ]; then
  706. _checklist="${_group} ${_group}:${_gid} ${_status}"
  707. else
  708. _checklist="${_checklist} ${_group} ${_group}:${_gid} ${_status}"
  709. fi
  710. done
  711. DIALOG --no-tags --checklist "${_desc}" 20 60 18 ${_checklist}
  712. if [ $? -eq 0 ]; then
  713. set_option USERGROUPS $(cat $ANSWER | sed -e's| |,|g')
  714. USERGROUPS_DONE=1
  715. break
  716. else
  717. return
  718. fi
  719. done
  720. }
  721. set_useraccount() {
  722. [ -z "$USERLOGIN_DONE" ] && return
  723. [ -z "$USERPASSWORD_DONE" ] && return
  724. [ -z "$USERNAME_DONE" ] && return
  725. [ -z "$USERGROUPS_DONE" ] && return
  726. useradd -R "$TARGETDIR" -m -G "$(get_option USERGROUPS)" \
  727. -c "$(get_option USERNAME)" "$(get_option USERLOGIN)"
  728. echo "$(get_option USERLOGIN):$(get_option USERPASSWORD)" | \
  729. chpasswd -R $TARGETDIR -c SHA512
  730. }
  731. menu_bootloader() {
  732. while true; do
  733. DIALOG --title " Select the disk to install the bootloader" \
  734. --menu "$MENULABEL" ${MENUSIZE} $(show_disks) none "Manage bootloader otherwise"
  735. if [ $? -eq 0 ]; then
  736. set_option BOOTLOADER "$(cat $ANSWER)"
  737. BOOTLOADER_DONE=1
  738. break
  739. else
  740. return
  741. fi
  742. done
  743. while true; do
  744. DIALOG --yesno "Use a graphical terminal for the boot loader?" ${YESNOSIZE}
  745. if [ $? -eq 0 ]; then
  746. set_option TEXTCONSOLE 0
  747. break
  748. elif [ $? -eq 1 ]; then
  749. set_option TEXTCONSOLE 1
  750. break
  751. else
  752. return
  753. fi
  754. done
  755. }
  756. set_bootloader() {
  757. local dev=$(get_option BOOTLOADER) grub_args=
  758. if [ "$dev" = "none" ]; then return; fi
  759. # Check if it's an EFI system via efivars module.
  760. if [ -n "$EFI_SYSTEM" ]; then
  761. grub_args="--target=$EFI_TARGET --efi-directory=/boot/efi --bootloader-id=void_grub --recheck"
  762. fi
  763. echo "Running grub-install $grub_args $dev..." >$LOG
  764. chroot $TARGETDIR grub-install $grub_args $dev >$LOG 2>&1
  765. if [ $? -ne 0 ]; then
  766. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  767. failed to install GRUB to $dev!\nCheck $LOG for errors." ${MSGBOXSIZE}
  768. DIE 1
  769. fi
  770. echo "Running grub-mkconfig on $TARGETDIR..." >$LOG
  771. chroot $TARGETDIR grub-mkconfig -o /boot/grub/grub.cfg >$LOG 2>&1
  772. if [ $? -ne 0 ]; then
  773. DIALOG --msgbox "${BOLD}${RED}ERROR${RESET}: \
  774. failed to run grub-mkconfig!\nCheck $LOG for errors." ${MSGBOXSIZE}
  775. DIE 1
  776. fi
  777. }
  778. test_network() {
  779. rm -f otime && \
  780. xbps-uhelper fetch https://repo-default.voidlinux.org/current/otime >$LOG 2>&1
  781. if [ $? -eq 0 ]; then
  782. DIALOG --msgbox "Network is working properly!" ${MSGBOXSIZE}
  783. NETWORK_DONE=1
  784. return 1
  785. fi
  786. if [ "$1" = "nm" ]; then
  787. DIALOG --msgbox "Network Manager is enabled but network is inaccessible, please set it up externally with nmcli, nmtui, or the Network Manager tray applet." ${MSGBOXSIZE}
  788. else
  789. DIALOG --msgbox "Network is inaccessible, please set it up properly." ${MSGBOXSIZE}
  790. fi
  791. }
  792. configure_wifi() {
  793. local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
  794. DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
  795. "SSID:" 1 1 "" 1 16 30 0 \
  796. "Encryption:" 2 1 "" 2 16 4 3 \
  797. "Password:" 3 1 "" 3 16 63 0 || return 1
  798. readarray -t values <<<$(cat $ANSWER)
  799. ssid="${values[0]}"; enc="${values[1]}"; pass="${values[2]}"
  800. if [ -z "$ssid" ]; then
  801. DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
  802. return 1
  803. elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
  804. DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSGBOXSIZE}
  805. return 1
  806. elif [ -z "$pass" ]; then
  807. DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
  808. fi
  809. # reset the configuration to the default, if necessary
  810. # otherwise backup the configuration
  811. if [ -f ${_wpasupconf}.orig ]; then
  812. cp -f ${_wpasupconf}.orig ${_wpasupconf}
  813. else
  814. cp -f ${_wpasupconf} ${_wpasupconf}.orig
  815. fi
  816. if [ "$enc" = "wep" ]; then
  817. cat << EOF >> ${_wpasupconf}
  818. network={
  819. ssid="$ssid"
  820. wep_key0="$pass"
  821. wep_tx_keyidx=0
  822. auth_alg=SHARED
  823. }
  824. EOF
  825. else
  826. wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf}
  827. fi
  828. sv restart wpa_supplicant
  829. configure_net_dhcp $dev
  830. return $?
  831. }
  832. configure_net() {
  833. local dev="$1" rval
  834. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  835. rval=$?
  836. if [ $rval -eq 0 ]; then
  837. configure_net_dhcp $dev
  838. elif [ $rval -eq 1 ]; then
  839. configure_net_static $dev
  840. fi
  841. }
  842. iface_setup() {
  843. ip addr show dev $1 | grep -q -e 'inet ' -e 'inet6 '
  844. return $?
  845. }
  846. configure_net_dhcp() {
  847. local dev="$1"
  848. iface_setup $dev
  849. if [ $? -eq 1 ]; then
  850. sv restart dhcpcd 2>&1 | tee $LOG | \
  851. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  852. if [ $? -ne 0 ]; then
  853. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
  854. return 1
  855. fi
  856. export -f iface_setup
  857. timeout 10s bash -c "while true; do iface_setup $dev; sleep 0.25; done"
  858. if [ $? -eq 1 ]; then
  859. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  860. return 1
  861. fi
  862. fi
  863. test_network
  864. if [ $? -eq 1 ]; then
  865. set_option NETWORK "${dev} dhcp"
  866. fi
  867. }
  868. configure_net_static() {
  869. local ip gw dns1 dns2 dev=$1
  870. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  871. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  872. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  873. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  874. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  875. set -- $(cat $ANSWER)
  876. ip=$1; gw=$2; dns1=$3; dns2=$4
  877. echo "running: ip link set dev $dev up" >$LOG
  878. ip link set dev $dev up >$LOG 2>&1
  879. if [ $? -ne 0 ]; then
  880. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  881. return 1
  882. fi
  883. echo "running: ip addr add $ip dev $dev" >$LOG
  884. ip addr add $ip dev $dev >$LOG 2>&1
  885. if [ $? -ne 0 ]; then
  886. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  887. return 1
  888. fi
  889. ip route add default via $gw >$LOG 2>&1
  890. if [ $? -ne 0 ]; then
  891. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  892. return 1
  893. fi
  894. echo "nameserver $dns1" >/etc/resolv.conf
  895. echo "nameserver $dns2" >>/etc/resolv.conf
  896. test_network
  897. if [ $? -eq 1 ]; then
  898. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  899. fi
  900. }
  901. menu_network() {
  902. local dev addr f DEVICES
  903. if [ -e /var/service/NetworkManager ]; then
  904. test_network nm
  905. return
  906. fi
  907. for f in $(ls /sys/class/net); do
  908. [ "$f" = "lo" ] && continue
  909. addr=$(cat /sys/class/net/$f/address)
  910. DEVICES="$DEVICES $f $addr"
  911. done
  912. DIALOG --title " Select the network interface to configure " \
  913. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  914. if [ $? -eq 0 ]; then
  915. dev=$(cat $ANSWER)
  916. if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
  917. configure_wifi $dev
  918. else
  919. configure_net $dev
  920. fi
  921. fi
  922. }
  923. validate_filesystems() {
  924. local mnts dev size fstype mntpt mkfs rootfound fmt
  925. local usrfound efi_system_partition
  926. local bootdev=$(get_option BOOTLOADER)
  927. unset TARGETFS
  928. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  929. set -- ${mnts}
  930. while [ $# -ne 0 ]; do
  931. fmt=""
  932. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  933. shift 6
  934. if [ "$mntpt" = "/" ]; then
  935. rootfound=1
  936. elif [ "$mntpt" = "/usr" ]; then
  937. usrfound=1
  938. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  939. efi_system_partition=1
  940. fi
  941. if [ "$mkfs" -eq 1 ]; then
  942. fmt="NEW FILESYSTEM: "
  943. fi
  944. if [ -z "$TARGETFS" ]; then
  945. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  946. else
  947. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  948. fi
  949. done
  950. if [ -z "$rootfound" ]; then
  951. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  952. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  953. return 1
  954. elif [ -n "$usrfound" ]; then
  955. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  956. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  957. return 1
  958. elif [ -n "$EFI_SYSTEM" -a "$bootdev" != "none" -a -z "$efi_system_partition" ]; then
  959. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  960. The EFI System Partition has not yet been configured, please create it\n
  961. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  962. return 1
  963. fi
  964. FILESYSTEMS_DONE=1
  965. }
  966. create_filesystems() {
  967. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  968. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  969. set -- ${mnts}
  970. while [ $# -ne 0 ]; do
  971. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  972. shift 6
  973. # swap partitions
  974. if [ "$fstype" = "swap" ]; then
  975. swapoff $dev >/dev/null 2>&1
  976. if [ "$mkfs" -eq 1 ]; then
  977. mkswap $dev >$LOG 2>&1
  978. if [ $? -ne 0 ]; then
  979. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  980. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  981. DIE 1
  982. fi
  983. fi
  984. swapon $dev >$LOG 2>&1
  985. if [ $? -ne 0 ]; then
  986. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  987. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  988. DIE 1
  989. fi
  990. # Add entry for target fstab
  991. uuid=$(blkid -o value -s UUID "$dev")
  992. echo "UUID=$uuid none swap defaults 0 0" >>$TARGET_FSTAB
  993. continue
  994. fi
  995. if [ "$mkfs" -eq 1 ]; then
  996. case "$fstype" in
  997. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  998. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  999. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  1000. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  1001. f2fs) MKFS="mkfs.f2fs -f"; modprobe f2fs >$LOG 2>&1;;
  1002. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  1003. xfs) MKFS="mkfs.xfs -f -i sparse=0"; modprobe xfs >$LOG 2>&1;;
  1004. esac
  1005. TITLE="Check $LOG for details ..."
  1006. INFOBOX "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  1007. echo "Running $MKFS $dev..." >$LOG
  1008. $MKFS $dev >$LOG 2>&1; rv=$?
  1009. if [ $rv -ne 0 ]; then
  1010. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  1011. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  1012. DIE 1
  1013. fi
  1014. fi
  1015. # Mount rootfs the first one.
  1016. [ "$mntpt" != "/" ] && continue
  1017. mkdir -p $TARGETDIR
  1018. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  1019. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  1020. if [ $? -ne 0 ]; then
  1021. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  1022. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  1023. DIE 1
  1024. fi
  1025. # Add entry to target fstab
  1026. uuid=$(blkid -o value -s UUID "$dev")
  1027. if [ "$fstype" = "f2fs" -o "$fstype" = "btrfs" -o "$fstype" = "xfs" ]; then
  1028. fspassno=0
  1029. else
  1030. fspassno=1
  1031. fi
  1032. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  1033. done
  1034. # mount all filesystems in target rootfs
  1035. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  1036. set -- ${mnts}
  1037. while [ $# -ne 0 ]; do
  1038. dev=$2; fstype=$3; mntpt="$5"
  1039. shift 6
  1040. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  1041. mkdir -p ${TARGETDIR}${mntpt}
  1042. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  1043. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  1044. if [ $? -ne 0 ]; then
  1045. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  1046. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  1047. DIE
  1048. fi
  1049. # Add entry to target fstab
  1050. uuid=$(blkid -o value -s UUID "$dev")
  1051. if [ "$fstype" = "f2fs" -o "$fstype" = "btrfs" -o "$fstype" = "xfs" ]; then
  1052. fspassno=0
  1053. else
  1054. fspassno=2
  1055. fi
  1056. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  1057. done
  1058. }
  1059. mount_filesystems() {
  1060. for f in sys proc dev; do
  1061. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  1062. echo "Mounting $TARGETDIR/$f..." >$LOG
  1063. mount --rbind /$f $TARGETDIR/$f >$LOG 2>&1
  1064. done
  1065. }
  1066. umount_filesystems() {
  1067. local f
  1068. for f in sys/fs/fuse/connections sys proc dev; do
  1069. echo "Unmounting $TARGETDIR/$f..." >$LOG
  1070. umount $TARGETDIR/$f >$LOG 2>&1
  1071. done
  1072. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  1073. set -- ${mnts}
  1074. while [ $# -ne 0 ]; do
  1075. local dev=$2; local fstype=$3; local mntpt=$5
  1076. shift 6
  1077. if [ "$fstype" = "swap" ]; then
  1078. echo "Disabling swap space on $dev..." >$LOG
  1079. swapoff $dev >$LOG 2>&1
  1080. continue
  1081. fi
  1082. if [ "$mntpt" != "/" ]; then
  1083. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  1084. umount $TARGETDIR/$mntpt >$LOG 2>&1
  1085. fi
  1086. done
  1087. echo "Unmounting $TARGETDIR..." >$LOG
  1088. umount $TARGETDIR >$LOG 2>&1
  1089. }
  1090. log_and_count() {
  1091. local progress whole tenth
  1092. while read line; do
  1093. echo "$line" >$LOG
  1094. copy_count=$((copy_count + 1))
  1095. progress=$((1000 * copy_count / copy_total))
  1096. if [ "$progress" != "$copy_progress" ]; then
  1097. whole=$((progress / 10))
  1098. tenth=$((progress % 10))
  1099. printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
  1100. copy_progress=$progress
  1101. fi
  1102. done
  1103. }
  1104. copy_rootfs() {
  1105. local tar_in="--create --one-file-system --xattrs"
  1106. TITLE="Check $LOG for details ..."
  1107. INFOBOX "Counting files, please be patient ..." 4 60
  1108. copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
  1109. export copy_total copy_count=0 copy_progress=
  1110. clear
  1111. tar ${tar_in} -f - / 2>/dev/null | \
  1112. tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
  1113. log_and_count | \
  1114. DIALOG --title "${TITLE}" \
  1115. --progressbox "Copying live image to target rootfs." 5 60
  1116. if [ $? -ne 0 ]; then
  1117. DIE 1
  1118. fi
  1119. unset copy_total copy_count copy_percent
  1120. }
  1121. install_packages() {
  1122. local _grub= _syspkg=
  1123. if [ -n "$EFI_SYSTEM" ]; then
  1124. if [ $EFI_FW_BITS -eq 32 ]; then
  1125. _grub="grub-i386-efi"
  1126. else
  1127. _grub="grub-x86_64-efi"
  1128. fi
  1129. else
  1130. _grub="grub"
  1131. fi
  1132. _syspkg="base-system"
  1133. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  1134. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  1135. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  1136. mkdir -p $TARGETDIR/boot/grub
  1137. _arch=$(xbps-uhelper arch)
  1138. stdbuf -oL env XBPS_ARCH=${_arch} \
  1139. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  1140. DIALOG --title "Installing base system packages..." \
  1141. --programbox 24 80
  1142. if [ $? -ne 0 ]; then
  1143. DIE 1
  1144. fi
  1145. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  1146. chroot $TARGETDIR xbps-reconfigure -a
  1147. }
  1148. enable_dhcpd() {
  1149. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  1150. }
  1151. menu_install() {
  1152. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  1153. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  1154. if [ -z "$ROOTPASSWORD_DONE" ]; then
  1155. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  1156. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1157. return 1
  1158. elif [ -z "$BOOTLOADER_DONE" ]; then
  1159. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  1160. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1161. return 1
  1162. fi
  1163. # Validate filesystems after making sure bootloader is done,
  1164. # so that specific checks can be made based on the selection
  1165. validate_filesystems || return 1
  1166. if [ -z "$FILESYSTEMS_DONE" ]; then
  1167. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  1168. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1169. return 1
  1170. fi
  1171. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  1172. ${BOLD}${TARGETFS}${RESET}\n
  1173. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  1174. filesystems.${RESET}\n\n
  1175. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  1176. unset TARGETFS
  1177. # Create and mount filesystems
  1178. create_filesystems
  1179. # If source not set use defaults.
  1180. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  1181. copy_rootfs
  1182. . /etc/default/live.conf
  1183. rm -f $TARGETDIR/etc/motd
  1184. rm -f $TARGETDIR/etc/issue
  1185. rm -f $TARGETDIR/usr/sbin/void-installer
  1186. # Remove modified sddm.conf to let sddm use the defaults.
  1187. rm -f $TARGETDIR/etc/sddm.conf
  1188. # Remove live user.
  1189. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  1190. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  1191. rm -f $TARGETDIR/etc/sudoers.d/99-void-live
  1192. TITLE="Check $LOG for details ..."
  1193. INFOBOX "Rebuilding initramfs for target ..." 4 60
  1194. echo "Rebuilding initramfs for target ..." >$LOG
  1195. # mount required fs
  1196. mount_filesystems
  1197. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  1198. INFOBOX "Removing temporary packages from target ..." 4 60
  1199. echo "Removing temporary packages from target ..." >$LOG
  1200. xbps-remove -r $TARGETDIR -Ry dialog xtools-minimal >>$LOG 2>&1
  1201. rmdir $TARGETDIR/mnt/target
  1202. else
  1203. # mount required fs
  1204. mount_filesystems
  1205. # network install, use packages.
  1206. install_packages
  1207. fi
  1208. INFOBOX "Applying installer settings..." 4 60
  1209. # copy target fstab.
  1210. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  1211. # Mount /tmp as tmpfs.
  1212. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  1213. # set up keymap, locale, timezone, hostname, root passwd and user account.
  1214. set_keymap
  1215. set_locale
  1216. set_timezone
  1217. set_hostname
  1218. set_rootpassword
  1219. set_useraccount
  1220. # Copy /etc/skel files for root.
  1221. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  1222. # network settings for target
  1223. if [ -n "$NETWORK_DONE" ]; then
  1224. local net="$(get_option NETWORK)"
  1225. set -- ${net}
  1226. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  1227. if [ -z "$_type" ]; then
  1228. # network type empty??!!!
  1229. :
  1230. elif [ "$_type" = "dhcp" ]; then
  1231. if $(echo $_dev|egrep -q "^wl.*" 2>/dev/null); then
  1232. cp /etc/wpa_supplicant/wpa_supplicant.conf $TARGETDIR/etc/wpa_supplicant
  1233. ln -sf /etc/sv/wpa_supplicant $TARGETDIR/etc/runit/runsvdir/default/wpa_supplicant
  1234. fi
  1235. enable_dhcpd
  1236. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  1237. # static IP through dhcpcd.
  1238. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhcpcd.conf.orig
  1239. echo "# Static IP configuration set by the void-installer for $_dev." \
  1240. >$TARGETDIR/etc/dhcpcd.conf
  1241. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  1242. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  1243. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  1244. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  1245. enable_dhcpd
  1246. fi
  1247. fi
  1248. if [ -d $TARGETDIR/etc/sudoers.d ]; then
  1249. USERLOGIN="$(get_option USERLOGIN)"
  1250. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
  1251. # enable sudo for primary user USERLOGIN who is not member of wheel
  1252. echo "# Enable sudo for login '$USERLOGIN'" > "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
  1253. echo "$USERLOGIN ALL=(ALL:ALL) ALL" >> "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
  1254. else
  1255. # enable the sudoers entry for members of group wheel
  1256. echo "%wheel ALL=(ALL:ALL) ALL" > "$TARGETDIR/etc/sudoers.d/wheel"
  1257. fi
  1258. unset USERLOGIN
  1259. fi
  1260. # clean up polkit rule - it's only useful in live systems
  1261. rm -f $TARGETDIR/etc/polkit-1/rules.d/void-live.rules
  1262. # enable text console for grub if chosen
  1263. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  1264. sed -i $TARGETDIR/etc/default/grub \
  1265. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  1266. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  1267. fi
  1268. # install bootloader.
  1269. set_bootloader
  1270. sync && sync && sync
  1271. # unmount all filesystems.
  1272. umount_filesystems
  1273. # installed successfully.
  1274. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  1275. Do you want to reboot the system?" ${YESNOSIZE}
  1276. if [ $? -eq 0 ]; then
  1277. shutdown -r now
  1278. else
  1279. return
  1280. fi
  1281. }
  1282. menu_source() {
  1283. local src=
  1284. DIALOG --title " Select installation source " \
  1285. --menu "$MENULABEL" 8 70 0 \
  1286. "Local" "Packages from ISO image" \
  1287. "Network" "Base system only, downloaded from official repository"
  1288. case "$(cat $ANSWER)" in
  1289. "Local") src="local";;
  1290. "Network") src="net";
  1291. if [ -z "$NETWORK_DONE" ]; then
  1292. menu_network;
  1293. fi;;
  1294. *) return 1;;
  1295. esac
  1296. SOURCE_DONE=1
  1297. set_option SOURCE $src
  1298. }
  1299. menu() {
  1300. local AFTER_HOSTNAME
  1301. if [ -z "$DEFITEM" ]; then
  1302. DEFITEM="Keyboard"
  1303. fi
  1304. if xbps-uhelper arch | grep -qe '-musl$'; then
  1305. AFTER_HOSTNAME="Timezone"
  1306. DIALOG --default-item $DEFITEM \
  1307. --extra-button --extra-label "Settings" \
  1308. --title " Void Linux installation menu " \
  1309. --menu "$MENULABEL" 10 70 0 \
  1310. "Keyboard" "Set system keyboard" \
  1311. "Network" "Set up the network" \
  1312. "Source" "Set source installation" \
  1313. "Hostname" "Set system hostname" \
  1314. "Timezone" "Set system time zone" \
  1315. "RootPassword" "Set system root password" \
  1316. "UserAccount" "Set primary user name and password" \
  1317. "BootLoader" "Set disk to install bootloader" \
  1318. "Partition" "Partition disk(s)" \
  1319. "Filesystems" "Configure filesystems and mount points" \
  1320. "Install" "Start installation with saved settings" \
  1321. "Exit" "Exit installation"
  1322. else
  1323. AFTER_HOSTNAME="Locale"
  1324. DIALOG --default-item $DEFITEM \
  1325. --extra-button --extra-label "Settings" \
  1326. --title " Void Linux installation menu " \
  1327. --menu "$MENULABEL" 10 70 0 \
  1328. "Keyboard" "Set system keyboard" \
  1329. "Network" "Set up the network" \
  1330. "Source" "Set source installation" \
  1331. "Hostname" "Set system hostname" \
  1332. "Locale" "Set system locale" \
  1333. "Timezone" "Set system time zone" \
  1334. "RootPassword" "Set system root password" \
  1335. "UserAccount" "Set primary user name and password" \
  1336. "BootLoader" "Set disk to install bootloader" \
  1337. "Partition" "Partition disk(s)" \
  1338. "Filesystems" "Configure filesystems and mount points" \
  1339. "Install" "Start installation with saved settings" \
  1340. "Exit" "Exit installation"
  1341. fi
  1342. if [ $? -eq 3 ]; then
  1343. # Show settings
  1344. cp $CONF_FILE /tmp/conf_hidden.$$;
  1345. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1346. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1347. rm /tmp/conf_hidden.$$
  1348. return
  1349. fi
  1350. case $(cat $ANSWER) in
  1351. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1352. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1353. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1354. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="$AFTER_HOSTNAME";;
  1355. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1356. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1357. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1358. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1359. && DEFITEM="BootLoader";;
  1360. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1361. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1362. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1363. "Install") menu_install;;
  1364. "Exit") DIE;;
  1365. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1366. esac
  1367. }
  1368. if ! command -v dialog >/dev/null; then
  1369. echo "ERROR: missing dialog command, exiting..."
  1370. exit 1
  1371. fi
  1372. if [ "$(id -u)" != "0" ]; then
  1373. echo "void-installer must run as root" 1>&2
  1374. exit 1
  1375. fi
  1376. #
  1377. # main()
  1378. #
  1379. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1380. Welcome to the Void Linux installation. A simple and minimal \
  1381. Linux distribution made from scratch and built from the source package tree \
  1382. available for XBPS, a new alternative binary package system.\n\n
  1383. The installation should be pretty straightforward. If you are in trouble \
  1384. please join us at ${BOLD}#voidlinux${RESET} on ${BOLD}irc.libera.chat${RESET}.\n\n
  1385. ${BOLD}https://www.voidlinux.org${RESET}\n\n" 16 80
  1386. while true; do
  1387. menu
  1388. done
  1389. exit 0
  1390. # vim: set ts=4 sw=4 et: