installer.sh.in 48 KB

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