installer.sh.in 49 KB

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