installer.sh.in 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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. DIALOG --msgbox "Network is inaccessible, please set it up properly." ${MSGBOXSIZE}
  782. }
  783. configure_wifi() {
  784. local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
  785. DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
  786. "SSID:" 1 1 "" 1 16 30 0 \
  787. "Encryption:" 2 1 "" 2 16 4 3 \
  788. "Password:" 3 1 "" 3 16 63 0 || return 1
  789. readarray -t values <<<$(cat $ANSWER)
  790. ssid="${values[0]}"; enc="${values[1]}"; pass="${values[2]}"
  791. if [ -z "$ssid" ]; then
  792. DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
  793. return 1
  794. elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
  795. DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSGBOXSIZE}
  796. return 1
  797. elif [ -z "$pass" ]; then
  798. DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
  799. fi
  800. # reset the configuration to the default, if necessary
  801. # otherwise backup the configuration
  802. if [ -f ${_wpasupconf}.orig ]; then
  803. cp -f ${_wpasupconf}.orig ${_wpasupconf}
  804. else
  805. cp -f ${_wpasupconf} ${_wpasupconf}.orig
  806. fi
  807. if [ "$enc" = "wep" ]; then
  808. cat << EOF >> ${_wpasupconf}
  809. network={
  810. ssid="$ssid"
  811. wep_key0="$pass"
  812. wep_tx_keyidx=0
  813. auth_alg=SHARED
  814. }
  815. EOF
  816. else
  817. wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf}
  818. fi
  819. sv restart wpa_supplicant
  820. configure_net_dhcp $dev
  821. return $?
  822. }
  823. configure_net() {
  824. local dev="$1" rval
  825. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  826. rval=$?
  827. if [ $rval -eq 0 ]; then
  828. configure_net_dhcp $dev
  829. elif [ $rval -eq 1 ]; then
  830. configure_net_static $dev
  831. fi
  832. }
  833. iface_setup() {
  834. ip addr show dev $1 | grep -q -e 'inet ' -e 'inet6 '
  835. return $?
  836. }
  837. configure_net_dhcp() {
  838. local dev="$1"
  839. iface_setup $dev
  840. if [ $? -eq 1 ]; then
  841. sv restart dhcpcd 2>&1 | tee $LOG | \
  842. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  843. if [ $? -ne 0 ]; then
  844. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
  845. return 1
  846. fi
  847. export -f iface_setup
  848. timeout 10s bash -c "while true; do iface_setup $dev; sleep 0.25; done"
  849. if [ $? -eq 1 ]; then
  850. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  851. return 1
  852. fi
  853. fi
  854. test_network
  855. if [ $? -eq 1 ]; then
  856. set_option NETWORK "${dev} dhcp"
  857. fi
  858. }
  859. configure_net_static() {
  860. local ip gw dns1 dns2 dev=$1
  861. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  862. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  863. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  864. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  865. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  866. set -- $(cat $ANSWER)
  867. ip=$1; gw=$2; dns1=$3; dns2=$4
  868. echo "running: ip link set dev $dev up" >$LOG
  869. ip link set dev $dev up >$LOG 2>&1
  870. if [ $? -ne 0 ]; then
  871. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  872. return 1
  873. fi
  874. echo "running: ip addr add $ip dev $dev" >$LOG
  875. ip addr add $ip dev $dev >$LOG 2>&1
  876. if [ $? -ne 0 ]; then
  877. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  878. return 1
  879. fi
  880. ip route add default via $gw >$LOG 2>&1
  881. if [ $? -ne 0 ]; then
  882. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  883. return 1
  884. fi
  885. echo "nameserver $dns1" >/etc/resolv.conf
  886. echo "nameserver $dns2" >>/etc/resolv.conf
  887. test_network
  888. if [ $? -eq 1 ]; then
  889. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  890. fi
  891. }
  892. menu_network() {
  893. local dev addr f DEVICES
  894. for f in $(ls /sys/class/net); do
  895. [ "$f" = "lo" ] && continue
  896. addr=$(cat /sys/class/net/$f/address)
  897. DEVICES="$DEVICES $f $addr"
  898. done
  899. DIALOG --title " Select the network interface to configure " \
  900. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  901. if [ $? -eq 0 ]; then
  902. dev=$(cat $ANSWER)
  903. if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
  904. configure_wifi $dev
  905. else
  906. configure_net $dev
  907. fi
  908. fi
  909. }
  910. validate_filesystems() {
  911. local mnts dev size fstype mntpt mkfs rootfound fmt
  912. local usrfound efi_system_partition
  913. local bootdev=$(get_option BOOTLOADER)
  914. unset TARGETFS
  915. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  916. set -- ${mnts}
  917. while [ $# -ne 0 ]; do
  918. fmt=""
  919. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  920. shift 6
  921. if [ "$mntpt" = "/" ]; then
  922. rootfound=1
  923. elif [ "$mntpt" = "/usr" ]; then
  924. usrfound=1
  925. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  926. efi_system_partition=1
  927. fi
  928. if [ "$mkfs" -eq 1 ]; then
  929. fmt="NEW FILESYSTEM: "
  930. fi
  931. if [ -z "$TARGETFS" ]; then
  932. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  933. else
  934. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  935. fi
  936. done
  937. if [ -z "$rootfound" ]; then
  938. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  939. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  940. return 1
  941. elif [ -n "$usrfound" ]; then
  942. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  943. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  944. return 1
  945. elif [ -n "$EFI_SYSTEM" -a "$bootdev" != "none" -a -z "$efi_system_partition" ]; then
  946. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  947. The EFI System Partition has not yet been configured, please create it\n
  948. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  949. return 1
  950. fi
  951. FILESYSTEMS_DONE=1
  952. }
  953. create_filesystems() {
  954. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  955. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  956. set -- ${mnts}
  957. while [ $# -ne 0 ]; do
  958. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  959. shift 6
  960. # swap partitions
  961. if [ "$fstype" = "swap" ]; then
  962. swapoff $dev >/dev/null 2>&1
  963. if [ "$mkfs" -eq 1 ]; then
  964. mkswap $dev >$LOG 2>&1
  965. if [ $? -ne 0 ]; then
  966. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  967. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  968. DIE 1
  969. fi
  970. fi
  971. swapon $dev >$LOG 2>&1
  972. if [ $? -ne 0 ]; then
  973. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  974. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  975. DIE 1
  976. fi
  977. # Add entry for target fstab
  978. uuid=$(blkid -o value -s UUID "$dev")
  979. echo "UUID=$uuid none swap defaults 0 0" >>$TARGET_FSTAB
  980. continue
  981. fi
  982. if [ "$mkfs" -eq 1 ]; then
  983. case "$fstype" in
  984. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  985. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  986. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  987. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  988. f2fs) MKFS="mkfs.f2fs -f"; modprobe f2fs >$LOG 2>&1;;
  989. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  990. xfs) MKFS="mkfs.xfs -f -i sparse=0"; modprobe xfs >$LOG 2>&1;;
  991. esac
  992. TITLE="Check $LOG for details ..."
  993. INFOBOX "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  994. echo "Running $MKFS $dev..." >$LOG
  995. $MKFS $dev >$LOG 2>&1; rv=$?
  996. if [ $rv -ne 0 ]; then
  997. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  998. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  999. DIE 1
  1000. fi
  1001. fi
  1002. # Mount rootfs the first one.
  1003. [ "$mntpt" != "/" ] && continue
  1004. mkdir -p $TARGETDIR
  1005. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  1006. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  1007. if [ $? -ne 0 ]; then
  1008. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  1009. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  1010. DIE 1
  1011. fi
  1012. # Add entry to target fstab
  1013. uuid=$(blkid -o value -s UUID "$dev")
  1014. if [ "$fstype" = "f2fs" -o "$fstype" = "btrfs" -o "$fstype" = "xfs" ]; then
  1015. fspassno=0
  1016. else
  1017. fspassno=1
  1018. fi
  1019. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  1020. done
  1021. # mount all filesystems in target rootfs
  1022. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  1023. set -- ${mnts}
  1024. while [ $# -ne 0 ]; do
  1025. dev=$2; fstype=$3; mntpt="$5"
  1026. shift 6
  1027. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  1028. mkdir -p ${TARGETDIR}${mntpt}
  1029. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  1030. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  1031. if [ $? -ne 0 ]; then
  1032. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  1033. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  1034. DIE
  1035. fi
  1036. # Add entry to target fstab
  1037. uuid=$(blkid -o value -s UUID "$dev")
  1038. if [ "$fstype" = "f2fs" -o "$fstype" = "btrfs" -o "$fstype" = "xfs" ]; then
  1039. fspassno=0
  1040. else
  1041. fspassno=2
  1042. fi
  1043. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  1044. done
  1045. }
  1046. mount_filesystems() {
  1047. for f in sys proc dev; do
  1048. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  1049. echo "Mounting $TARGETDIR/$f..." >$LOG
  1050. mount --rbind /$f $TARGETDIR/$f >$LOG 2>&1
  1051. done
  1052. }
  1053. umount_filesystems() {
  1054. local f
  1055. for f in sys/fs/fuse/connections sys proc dev; do
  1056. echo "Unmounting $TARGETDIR/$f..." >$LOG
  1057. umount $TARGETDIR/$f >$LOG 2>&1
  1058. done
  1059. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  1060. set -- ${mnts}
  1061. while [ $# -ne 0 ]; do
  1062. local dev=$2; local fstype=$3; local mntpt=$5
  1063. shift 6
  1064. if [ "$fstype" = "swap" ]; then
  1065. echo "Disabling swap space on $dev..." >$LOG
  1066. swapoff $dev >$LOG 2>&1
  1067. continue
  1068. fi
  1069. if [ "$mntpt" != "/" ]; then
  1070. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  1071. umount $TARGETDIR/$mntpt >$LOG 2>&1
  1072. fi
  1073. done
  1074. echo "Unmounting $TARGETDIR..." >$LOG
  1075. umount $TARGETDIR >$LOG 2>&1
  1076. }
  1077. log_and_count() {
  1078. local progress whole tenth
  1079. while read line; do
  1080. echo "$line" >$LOG
  1081. copy_count=$((copy_count + 1))
  1082. progress=$((1000 * copy_count / copy_total))
  1083. if [ "$progress" != "$copy_progress" ]; then
  1084. whole=$((progress / 10))
  1085. tenth=$((progress % 10))
  1086. printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
  1087. copy_progress=$progress
  1088. fi
  1089. done
  1090. }
  1091. copy_rootfs() {
  1092. local tar_in="--create --one-file-system --xattrs"
  1093. TITLE="Check $LOG for details ..."
  1094. INFOBOX "Counting files, please be patient ..." 4 60
  1095. copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
  1096. export copy_total copy_count=0 copy_progress=
  1097. clear
  1098. tar ${tar_in} -f - / 2>/dev/null | \
  1099. tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
  1100. log_and_count | \
  1101. DIALOG --title "${TITLE}" \
  1102. --progressbox "Copying live image to target rootfs." 5 60
  1103. if [ $? -ne 0 ]; then
  1104. DIE 1
  1105. fi
  1106. unset copy_total copy_count copy_percent
  1107. }
  1108. install_packages() {
  1109. local _grub= _syspkg=
  1110. if [ -n "$EFI_SYSTEM" ]; then
  1111. if [ $EFI_FW_BITS -eq 32 ]; then
  1112. _grub="grub-i386-efi"
  1113. else
  1114. _grub="grub-x86_64-efi"
  1115. fi
  1116. else
  1117. _grub="grub"
  1118. fi
  1119. _syspkg="base-system"
  1120. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  1121. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  1122. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  1123. mkdir -p $TARGETDIR/boot/grub
  1124. _arch=$(xbps-uhelper arch)
  1125. stdbuf -oL env XBPS_ARCH=${_arch} \
  1126. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  1127. DIALOG --title "Installing base system packages..." \
  1128. --programbox 24 80
  1129. if [ $? -ne 0 ]; then
  1130. DIE 1
  1131. fi
  1132. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  1133. chroot $TARGETDIR xbps-reconfigure -a
  1134. }
  1135. enable_dhcpd() {
  1136. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  1137. }
  1138. menu_install() {
  1139. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  1140. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  1141. if [ -z "$ROOTPASSWORD_DONE" ]; then
  1142. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  1143. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1144. return 1
  1145. elif [ -z "$BOOTLOADER_DONE" ]; then
  1146. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  1147. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1148. return 1
  1149. fi
  1150. # Validate filesystems after making sure bootloader is done,
  1151. # so that specific checks can be made based on the selection
  1152. validate_filesystems || return 1
  1153. if [ -z "$FILESYSTEMS_DONE" ]; then
  1154. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  1155. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1156. return 1
  1157. fi
  1158. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  1159. ${BOLD}${TARGETFS}${RESET}\n
  1160. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  1161. filesystems.${RESET}\n\n
  1162. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  1163. unset TARGETFS
  1164. # Create and mount filesystems
  1165. create_filesystems
  1166. # If source not set use defaults.
  1167. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  1168. copy_rootfs
  1169. . /etc/default/live.conf
  1170. rm -f $TARGETDIR/etc/motd
  1171. rm -f $TARGETDIR/etc/issue
  1172. rm -f $TARGETDIR/usr/sbin/void-installer
  1173. # Remove modified sddm.conf to let sddm use the defaults.
  1174. rm -f $TARGETDIR/etc/sddm.conf
  1175. # Remove live user.
  1176. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  1177. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  1178. rm -f $TARGETDIR/etc/sudoers.d/99-void-live
  1179. TITLE="Check $LOG for details ..."
  1180. INFOBOX "Rebuilding initramfs for target ..." 4 60
  1181. echo "Rebuilding initramfs for target ..." >$LOG
  1182. # mount required fs
  1183. mount_filesystems
  1184. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  1185. INFOBOX "Removing temporary packages from target ..." 4 60
  1186. echo "Removing temporary packages from target ..." >$LOG
  1187. xbps-remove -r $TARGETDIR -Ry dialog xtools-minimal >>$LOG 2>&1
  1188. rmdir $TARGETDIR/mnt/target
  1189. else
  1190. # mount required fs
  1191. mount_filesystems
  1192. # network install, use packages.
  1193. install_packages
  1194. fi
  1195. INFOBOX "Applying installer settings..." 4 60
  1196. # copy target fstab.
  1197. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  1198. # Mount /tmp as tmpfs.
  1199. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  1200. # set up keymap, locale, timezone, hostname, root passwd and user account.
  1201. set_keymap
  1202. set_locale
  1203. set_timezone
  1204. set_hostname
  1205. set_rootpassword
  1206. set_useraccount
  1207. # Copy /etc/skel files for root.
  1208. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  1209. # network settings for target
  1210. if [ -n "$NETWORK_DONE" ]; then
  1211. local net="$(get_option NETWORK)"
  1212. set -- ${net}
  1213. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  1214. if [ -z "$_type" ]; then
  1215. # network type empty??!!!
  1216. :
  1217. elif [ "$_type" = "dhcp" ]; then
  1218. if $(echo $_dev|egrep -q "^wl.*" 2>/dev/null); then
  1219. cp /etc/wpa_supplicant/wpa_supplicant.conf $TARGETDIR/etc/wpa_supplicant
  1220. ln -sf /etc/sv/wpa_supplicant $TARGETDIR/etc/runit/runsvdir/default/wpa_supplicant
  1221. fi
  1222. enable_dhcpd
  1223. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  1224. # static IP through dhcpcd.
  1225. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhcpcd.conf.orig
  1226. echo "# Static IP configuration set by the void-installer for $_dev." \
  1227. >$TARGETDIR/etc/dhcpcd.conf
  1228. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  1229. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  1230. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  1231. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  1232. enable_dhcpd
  1233. fi
  1234. fi
  1235. if [ -d $TARGETDIR/etc/sudoers.d ]; then
  1236. USERLOGIN="$(get_option USERLOGIN)"
  1237. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
  1238. # enable sudo for primary user USERLOGIN who is not member of wheel
  1239. echo "# Enable sudo for login '$USERLOGIN'" > "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
  1240. echo "$USERLOGIN ALL=(ALL:ALL) ALL" >> "$TARGETDIR/etc/sudoers.d/$USERLOGIN"
  1241. else
  1242. # enable the sudoers entry for members of group wheel
  1243. echo "%wheel ALL=(ALL:ALL) ALL" > "$TARGETDIR/etc/sudoers.d/wheel"
  1244. fi
  1245. unset USERLOGIN
  1246. fi
  1247. # clean up polkit rule - it's only useful in live systems
  1248. rm -f $TARGETDIR/etc/polkit-1/rules.d/void-live.rules
  1249. # enable text console for grub if chosen
  1250. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  1251. sed -i $TARGETDIR/etc/default/grub \
  1252. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  1253. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  1254. fi
  1255. # install bootloader.
  1256. set_bootloader
  1257. sync && sync && sync
  1258. # unmount all filesystems.
  1259. umount_filesystems
  1260. # installed successfully.
  1261. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  1262. Do you want to reboot the system?" ${YESNOSIZE}
  1263. if [ $? -eq 0 ]; then
  1264. shutdown -r now
  1265. else
  1266. return
  1267. fi
  1268. }
  1269. menu_source() {
  1270. local src=
  1271. DIALOG --title " Select installation source " \
  1272. --menu "$MENULABEL" 8 70 0 \
  1273. "Local" "Packages from ISO image" \
  1274. "Network" "Base system only, downloaded from official repository"
  1275. case "$(cat $ANSWER)" in
  1276. "Local") src="local";;
  1277. "Network") src="net";
  1278. if [ -z "$NETWORK_DONE" ]; then
  1279. menu_network;
  1280. fi;;
  1281. *) return 1;;
  1282. esac
  1283. SOURCE_DONE=1
  1284. set_option SOURCE $src
  1285. }
  1286. menu() {
  1287. local AFTER_HOSTNAME
  1288. if [ -z "$DEFITEM" ]; then
  1289. DEFITEM="Keyboard"
  1290. fi
  1291. if xbps-uhelper arch | grep -qe '-musl$'; then
  1292. AFTER_HOSTNAME="Timezone"
  1293. DIALOG --default-item $DEFITEM \
  1294. --extra-button --extra-label "Settings" \
  1295. --title " Void Linux installation menu " \
  1296. --menu "$MENULABEL" 10 70 0 \
  1297. "Keyboard" "Set system keyboard" \
  1298. "Network" "Set up the network" \
  1299. "Source" "Set source installation" \
  1300. "Hostname" "Set system hostname" \
  1301. "Timezone" "Set system time zone" \
  1302. "RootPassword" "Set system root password" \
  1303. "UserAccount" "Set primary user name and password" \
  1304. "BootLoader" "Set disk to install bootloader" \
  1305. "Partition" "Partition disk(s)" \
  1306. "Filesystems" "Configure filesystems and mount points" \
  1307. "Install" "Start installation with saved settings" \
  1308. "Exit" "Exit installation"
  1309. else
  1310. AFTER_HOSTNAME="Locale"
  1311. DIALOG --default-item $DEFITEM \
  1312. --extra-button --extra-label "Settings" \
  1313. --title " Void Linux installation menu " \
  1314. --menu "$MENULABEL" 10 70 0 \
  1315. "Keyboard" "Set system keyboard" \
  1316. "Network" "Set up the network" \
  1317. "Source" "Set source installation" \
  1318. "Hostname" "Set system hostname" \
  1319. "Locale" "Set system locale" \
  1320. "Timezone" "Set system time zone" \
  1321. "RootPassword" "Set system root password" \
  1322. "UserAccount" "Set primary user name and password" \
  1323. "BootLoader" "Set disk to install bootloader" \
  1324. "Partition" "Partition disk(s)" \
  1325. "Filesystems" "Configure filesystems and mount points" \
  1326. "Install" "Start installation with saved settings" \
  1327. "Exit" "Exit installation"
  1328. fi
  1329. if [ $? -eq 3 ]; then
  1330. # Show settings
  1331. cp $CONF_FILE /tmp/conf_hidden.$$;
  1332. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1333. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1334. rm /tmp/conf_hidden.$$
  1335. return
  1336. fi
  1337. case $(cat $ANSWER) in
  1338. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1339. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1340. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1341. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="$AFTER_HOSTNAME";;
  1342. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1343. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1344. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1345. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1346. && DEFITEM="BootLoader";;
  1347. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1348. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1349. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1350. "Install") menu_install;;
  1351. "Exit") DIE;;
  1352. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1353. esac
  1354. }
  1355. if ! command -v dialog >/dev/null; then
  1356. echo "ERROR: missing dialog command, exiting..."
  1357. exit 1
  1358. fi
  1359. if [ "$(id -u)" != "0" ]; then
  1360. echo "void-installer must run as root" 1>&2
  1361. exit 1
  1362. fi
  1363. #
  1364. # main()
  1365. #
  1366. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1367. Welcome to the Void Linux installation. A simple and minimal \
  1368. Linux distribution made from scratch and built from the source package tree \
  1369. available for XBPS, a new alternative binary package system.\n\n
  1370. The installation should be pretty straightforward. If you are in trouble \
  1371. please join us at ${BOLD}#voidlinux${RESET} on ${BOLD}irc.libera.chat${RESET}.\n\n
  1372. ${BOLD}https://www.voidlinux.org${RESET}\n\n" 16 80
  1373. while true; do
  1374. menu
  1375. done
  1376. exit 0
  1377. # vim: set ts=4 sw=4 et: