installer.sh.in 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  1. #!/bin/bash
  2. #-
  3. # Copyright (c) 2012-2015 Juan Romero Pardines <[email protected]>.
  4. # 2012 Dave Elusive <[email protected]>.
  5. # All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. #-
  27. # Make sure we don't inherit these from env.
  28. SOURCE_DONE=
  29. HOSTNAME_DONE=
  30. KEYBOARD_DONE=
  31. LOCALE_DONE=
  32. TIMEZONE_DONE=
  33. ROOTPASSWORD_DONE=
  34. USERLOGIN_DONE=
  35. USERPASSWORD_DONE=
  36. USERNAME_DONE=
  37. USERGROUPS_DONE=
  38. BOOTLOADER_DONE=
  39. PARTITIONS_DONE=
  40. NETWORK_DONE=
  41. FILESYSTEMS_DONE=
  42. TARGETDIR=/mnt/target
  43. LOG=/dev/tty8
  44. CONF_FILE=/tmp/.void-installer.conf
  45. if [ ! -f $CONF_FILE ]; then
  46. touch -f $CONF_FILE
  47. fi
  48. ANSWER=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  49. TARGET_FSTAB=$(mktemp -t vinstall-fstab-XXXXXXXX || exit 1)
  50. trap "DIE" INT TERM QUIT
  51. # disable printk
  52. if [ -w /proc/sys/kernel/printk ]; then
  53. echo 0 >/proc/sys/kernel/printk
  54. fi
  55. # Detect if this is an EFI system.
  56. if [ -e /sys/firmware/efi/systab ]; then
  57. EFI_SYSTEM=1
  58. EFI_FW_BITS=$(cat /sys/firmware/efi/fw_platform_size)
  59. if [ $EFI_FW_BITS -eq 32 ]; then
  60. EFI_TARGET=i386-efi
  61. else
  62. EFI_TARGET=x86_64-efi
  63. fi
  64. fi
  65. # dialog colors
  66. BLACK="\Z0"
  67. RED="\Z1"
  68. GREEN="\Z2"
  69. YELLOW="\Z3"
  70. BLUE="\Z4"
  71. MAGENTA="\Z5"
  72. CYAN="\Z6"
  73. WHITE="\Z7"
  74. BOLD="\Zb"
  75. REVERSE="\Zr"
  76. UNDERLINE="\Zu"
  77. RESET="\Zn"
  78. # Properties shared per widget.
  79. MENULABEL="${BOLD}Use UP and DOWN keys to navigate \
  80. menus. Use TAB to switch between buttons and ENTER to select.${RESET}"
  81. MENUSIZE="14 60 0"
  82. INPUTSIZE="8 60"
  83. MSGBOXSIZE="8 70"
  84. YESNOSIZE="$INPUTSIZE"
  85. WIDGET_SIZE="10 70"
  86. DIALOG() {
  87. rm -f $ANSWER
  88. dialog --colors --keep-tite --no-shadow --no-mouse \
  89. --backtitle "${BOLD}${WHITE}Void Linux installation -- https://www.voidlinux.eu/ (@@MKLIVE_VERSION@@)${RESET}" \
  90. --cancel-label "Back" --aspect 20 "$@" 2>$ANSWER
  91. return $?
  92. }
  93. INFOBOX() {
  94. # Note: dialog --infobox and --keep-tite don't work together
  95. dialog --colors --no-shadow --no-mouse \
  96. --backtitle "${BOLD}${WHITE}Void Linux installation -- https://www.voidlinux.eu/ (@@MKLIVE_VERSION@@)${RESET}" \
  97. --title "${TITLE}" --aspect 20 --infobox "$@"
  98. }
  99. DIE() {
  100. rval=$1
  101. [ -z "$rval" ] && rval=0
  102. clear
  103. rm -f $ANSWER $TARGET_FSTAB
  104. # reenable printk
  105. if [ -w /proc/sys/kernel/printk ]; then
  106. echo 4 >/proc/sys/kernel/printk
  107. fi
  108. umount_filesystems
  109. exit $rval
  110. }
  111. set_option() {
  112. if grep -Eq "^${1}.*" $CONF_FILE; then
  113. sed -i -e "/^${1}.*/d" $CONF_FILE
  114. fi
  115. echo "${1} ${2}" >>$CONF_FILE
  116. }
  117. get_option() {
  118. echo $(grep -E "^${1}.*" $CONF_FILE|sed -e "s|${1}||")
  119. }
  120. # ISO-639 language names for locales
  121. iso639_language() {
  122. case "$1" in
  123. aa) echo "Afar" ;;
  124. af) echo "Afrikaans" ;;
  125. an) echo "Aragonese" ;;
  126. ar) echo "Arabic" ;;
  127. ast) echo "Asturian" ;;
  128. be) echo "Belgian" ;;
  129. bg) echo "Bulgarian" ;;
  130. bhb) echo "Bhili" ;;
  131. br) echo "Breton" ;;
  132. bs) echo "Bosnian" ;;
  133. ca) echo "Catalan" ;;
  134. cs) echo "Czech" ;;
  135. cy) echo "Welsh" ;;
  136. da) echo "Danish" ;;
  137. de) echo "German" ;;
  138. el) echo "Greek" ;;
  139. en) echo "English" ;;
  140. es) echo "Spanish" ;;
  141. et) echo "Estonian" ;;
  142. eu) echo "Basque" ;;
  143. fi) echo "Finnish" ;;
  144. fo) echo "Faroese" ;;
  145. fr) echo "French" ;;
  146. ga) echo "Irish" ;;
  147. gd) echo "Scottish Gaelic" ;;
  148. gl) echo "Galician" ;;
  149. gv) echo "Manx" ;;
  150. he) echo "Hebrew" ;;
  151. hr) echo "Croatian" ;;
  152. hsb) echo "Upper Sorbian" ;;
  153. hu) echo "Hungarian" ;;
  154. id) echo "Indonesian" ;;
  155. is) echo "Icelandic" ;;
  156. it) echo "Italian" ;;
  157. iw) echo "Hebrew" ;;
  158. ja) echo "Japanese" ;;
  159. ka) echo "Georgian" ;;
  160. kk) echo "Kazakh" ;;
  161. kl) echo "Kalaallisut" ;;
  162. ko) echo "Korean" ;;
  163. ku) echo "Kurdish" ;;
  164. kw) echo "Cornish" ;;
  165. lg) echo "Ganda" ;;
  166. lt) echo "Lithuanian" ;;
  167. lv) echo "Latvian" ;;
  168. mg) echo "Malagasy" ;;
  169. mi) echo "Maori" ;;
  170. mk) echo "Macedonian" ;;
  171. ms) echo "Malay" ;;
  172. mt) echo "Maltese" ;;
  173. nb) echo "Norwegian Bokmål" ;;
  174. nl) echo "Dutch" ;;
  175. nn) echo "Norwegian Nynorsk" ;;
  176. oc) echo "Occitan" ;;
  177. om) echo "Oromo" ;;
  178. pl) echo "Polish" ;;
  179. pt) echo "Portugese" ;;
  180. ro) echo "Romanian" ;;
  181. ru) echo "Russian" ;;
  182. sk) echo "Slovak" ;;
  183. sl) echo "Slovenian" ;;
  184. so) echo "Somali" ;;
  185. sq) echo "Albanian" ;;
  186. st) echo "Southern Sotho" ;;
  187. sv) echo "Swedish" ;;
  188. tcy) echo "Tulu" ;;
  189. tg) echo "Tajik" ;;
  190. th) echo "Thai" ;;
  191. tl) echo "Tagalog" ;;
  192. tr) echo "Turkish" ;;
  193. uk) echo "Ukrainian" ;;
  194. uz) echo "Uzbek" ;;
  195. wa) echo "Walloon" ;;
  196. xh) echo "Xhosa" ;;
  197. yi) echo "Yiddish" ;;
  198. zh) echo "Chinese" ;;
  199. zu) echo "Zulu" ;;
  200. *) echo "$1" ;;
  201. esac
  202. }
  203. # ISO-3166 country codes for locales
  204. iso3166_country() {
  205. case "$1" in
  206. AD) echo "Andorra" ;;
  207. AE) echo "United Arab Emirates" ;;
  208. AL) echo "Albania" ;;
  209. AR) echo "Argentina" ;;
  210. AT) echo "Austria" ;;
  211. AU) echo "Australia" ;;
  212. BA) echo "Bonsia and Herzegovina" ;;
  213. BE) echo "Belgium" ;;
  214. BG) echo "Bulgaria" ;;
  215. BH) echo "Bahrain" ;;
  216. BO) echo "Bolivia" ;;
  217. BR) echo "Brazil" ;;
  218. BW) echo "Botswana" ;;
  219. BY) echo "Belarus" ;;
  220. CA) echo "Canada" ;;
  221. CH) echo "Switzerland" ;;
  222. CL) echo "Chile" ;;
  223. CN) echo "China" ;;
  224. CO) echo "Colombia" ;;
  225. CR) echo "Costa Rica" ;;
  226. CY) echo "Cyprus" ;;
  227. CZ) echo "Czech Republic" ;;
  228. DE) echo "Germany" ;;
  229. DJ) echo "Djibouti" ;;
  230. DK) echo "Denmark" ;;
  231. DO) echo "Dominican Republic" ;;
  232. DZ) echo "Algeria" ;;
  233. EC) echo "Ecuador" ;;
  234. EE) echo "Estonia" ;;
  235. EG) echo "Egypt" ;;
  236. ES) echo "Spain" ;;
  237. FI) echo "Finland" ;;
  238. FO) echo "Faroe Islands" ;;
  239. FR) echo "France" ;;
  240. GB) echo "Great Britain" ;;
  241. GE) echo "Georgia" ;;
  242. GL) echo "Greenland" ;;
  243. GR) echo "Greece" ;;
  244. GT) echo "Guatemala" ;;
  245. HK) echo "Hong Kong" ;;
  246. HN) echo "Honduras" ;;
  247. HR) echo "Croatia" ;;
  248. HU) echo "Hungary" ;;
  249. ID) echo "Indonesia" ;;
  250. IE) echo "Ireland" ;;
  251. IL) echo "Israel" ;;
  252. IN) echo "India" ;;
  253. IQ) echo "Iraq" ;;
  254. IS) echo "Iceland" ;;
  255. IT) echo "Italy" ;;
  256. JO) echo "Jordan" ;;
  257. JP) echo "Japan" ;;
  258. KE) echo "Kenya" ;;
  259. KR) echo "Korea, Republic of" ;;
  260. KW) echo "Kuwait" ;;
  261. KZ) echo "Kazakhstan" ;;
  262. LB) echo "Lebanon" ;;
  263. LT) echo "Lithuania" ;;
  264. LU) echo "Luxembourg" ;;
  265. LV) echo "Latvia" ;;
  266. LY) echo "Libya" ;;
  267. MA) echo "Morocco" ;;
  268. MG) echo "Madagascar" ;;
  269. MK) echo "Macedonia" ;;
  270. MT) echo "Malta" ;;
  271. MX) echo "Mexico" ;;
  272. MY) echo "Malaysia" ;;
  273. NI) echo "Nicaragua" ;;
  274. NL) echo "Netherlands" ;;
  275. NO) echo "Norway" ;;
  276. NZ) echo "New Zealand" ;;
  277. OM) echo "Oman" ;;
  278. PA) echo "Panama" ;;
  279. PE) echo "Peru" ;;
  280. PH) echo "Philippines" ;;
  281. PL) echo "Poland" ;;
  282. PR) echo "Puerto Rico" ;;
  283. PT) echo "Portugal" ;;
  284. PY) echo "Paraguay" ;;
  285. QA) echo "Qatar" ;;
  286. RO) echo "Romania" ;;
  287. RU) echo "Russian Federation" ;;
  288. SA) echo "Saudi Arabia" ;;
  289. SD) echo "Sudan" ;;
  290. SE) echo "Sweden" ;;
  291. SG) echo "Singapore" ;;
  292. SI) echo "Slovenia" ;;
  293. SK) echo "Slovakia" ;;
  294. SO) echo "Somalia" ;;
  295. SV) echo "El Salvador" ;;
  296. SY) echo "Syria" ;;
  297. TH) echo "Thailand" ;;
  298. TJ) echo "Tajikistan" ;;
  299. TN) echo "Tunisia" ;;
  300. TR) echo "Turkey" ;;
  301. TW) echo "Taiwan" ;;
  302. UA) echo "Ukraine" ;;
  303. UG) echo "Uganda" ;;
  304. US) echo "United States of America" ;;
  305. UY) echo "Uruguay" ;;
  306. UZ) echo "Uzbekistan" ;;
  307. VE) echo "Venezuela" ;;
  308. YE) echo "Yemen" ;;
  309. ZA) echo "South Africa" ;;
  310. ZW) echo "Zimbabwe" ;;
  311. *) echo "$1" ;;
  312. esac
  313. }
  314. show_disks() {
  315. local dev size sectorsize gbytes
  316. # IDE
  317. for dev in $(ls /sys/block|grep -E '^hd'); do
  318. if [ "$(cat /sys/block/$dev/device/media)" = "disk" ]; then
  319. # Find out nr sectors and bytes per sector;
  320. echo "/dev/$dev"
  321. size=$(cat /sys/block/$dev/size)
  322. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  323. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  324. echo "size:${gbytes}GB;sector_size:$sectorsize"
  325. fi
  326. done
  327. # SATA/SCSI and Virtual disks (virtio)
  328. for dev in $(ls /sys/block|grep -E '^([sv]|xv)d|mmcblk|nvme'); do
  329. echo "/dev/$dev"
  330. size=$(cat /sys/block/$dev/size)
  331. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  332. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  333. echo "size:${gbytes}GB;sector_size:$sectorsize"
  334. done
  335. # cciss(4) devices
  336. for dev in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]$'); do
  337. echo "/dev/cciss/$dev"
  338. size=$(cat /sys/block/cciss\!$dev/size)
  339. sectorsize=$(cat /sys/block/cciss\!$dev/queue/hw_sector_size)
  340. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  341. echo "size:${gbytes}GB;sector_size:$sectorsize"
  342. done
  343. }
  344. show_partitions() {
  345. local dev fstype fssize p part
  346. set -- $(show_disks)
  347. while [ $# -ne 0 ]; do
  348. disk=$(basename $1)
  349. shift 2
  350. # ATA/SCSI/SATA
  351. for p in /sys/block/$disk/$disk*; do
  352. if [ -d $p ]; then
  353. part=$(basename $p)
  354. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}'|head -1)
  355. [ "$fstype" = "iso9660" ] && continue
  356. [ "$fstype" = "crypto_LUKS" ] && continue
  357. [ "$fstype" = "LVM2_member" ] && continue
  358. fssize=$(lsblk -nr /dev/$part|awk '{print $4}'|head -1)
  359. echo "/dev/$part"
  360. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  361. fi
  362. done
  363. done
  364. # 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 "Modify Partition Table on $device" --msgbox "\n
  465. ${BOLD}cfdisk will be executed in disk $device.${RESET}\n\n
  466. For BIOS systems, MBR or GPT partition tables are supported.\n
  467. To use GPT on PC BIOS systems an empty partition of 1MB must be added\n
  468. at the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n
  469. ${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n
  470. For EFI systems GPT is mandatory and a FAT32 partition with at least\n
  471. 100MB must be created with the TOGGLE \`boot', this will be used as\n
  472. EFI System Partition. This partition must have mountpoint as \`/boot/efi'.\n\n
  473. At least 1 partition is required for the rootfs (/).\n
  474. For swap, RAM*2 must be really enough. For / 600MB are required.\n\n
  475. ${BOLD}WARNING: /usr is not supported as a separate partition.${RESET}\n
  476. ${RESET}\n" 18 80
  477. if [ $? -eq 0 ]; then
  478. while true; do
  479. clear; cfdisk $device; PARTITIONS_DONE=1
  480. break
  481. done
  482. else
  483. return
  484. fi
  485. fi
  486. }
  487. menu_keymap() {
  488. local _keymaps="$(find /usr/share/kbd/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sort)"
  489. local _KEYMAPS=
  490. for f in ${_keymaps}; do
  491. _KEYMAPS="${_KEYMAPS} ${f} -"
  492. done
  493. while true; do
  494. DIALOG --title " Select your keymap " --menu "$MENULABEL" 14 70 14 ${_KEYMAPS}
  495. if [ $? -eq 0 ]; then
  496. set_option KEYMAP "$(cat $ANSWER)"
  497. loadkeys "$(cat $ANSWER)"
  498. KEYBOARD_DONE=1
  499. break
  500. else
  501. return
  502. fi
  503. done
  504. }
  505. set_keymap() {
  506. local KEYMAP=$(get_option KEYMAP)
  507. if [ -f /etc/vconsole.conf ]; then
  508. sed -i -e "s|KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/vconsole.conf
  509. else
  510. sed -i -e "s|#\?KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/rc.conf
  511. fi
  512. }
  513. menu_locale() {
  514. local _locales="$(grep -E '\.UTF-8' /etc/default/libc-locales|awk '{print $1}'|sed -e 's/^#//')"
  515. local LOCALES ISO639 ISO3166
  516. local TMPFILE=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  517. INFOBOX "Scanning locales ..." 4 60
  518. for f in ${_locales}; do
  519. eval $(echo $f | awk 'BEGIN { FS="." } \
  520. { FS="_"; split($1, a); printf "ISO639=%s ISO3166=%s\n", a[1], a[2] }')
  521. echo "$f|$(iso639_language $ISO639) ($(iso3166_country $ISO3166))|" >> $TMPFILE
  522. done
  523. clear
  524. # Sort by ISO-639 language names
  525. LOCALES=$(sort -t '|' -k 2 < $TMPFILE | xargs | sed -e's/| /|/g')
  526. rm -f $TMPFILE
  527. while true; do
  528. (IFS="|"; DIALOG --title " Select your locale " --menu "$MENULABEL" 18 70 18 ${LOCALES})
  529. if [ $? -eq 0 ]; then
  530. set_option LOCALE "$(cat $ANSWER)"
  531. LOCALE_DONE=1
  532. break
  533. else
  534. return
  535. fi
  536. done
  537. }
  538. set_locale() {
  539. if [ -f $TARGETDIR/etc/default/libc-locales ]; then
  540. local LOCALE=$(get_option LOCALE)
  541. sed -i -e "s|LANG=.*|LANG=$LOCALE|g" $TARGETDIR/etc/locale.conf
  542. # Uncomment locale from /etc/default/libc-locales and regenerate it.
  543. sed -e "/${LOCALE}/s/^\#//" -i $TARGETDIR/etc/default/libc-locales
  544. echo "Running xbps-reconfigure -f glibc-locales ..." >$LOG
  545. chroot $TARGETDIR xbps-reconfigure -f glibc-locales >$LOG 2>&1
  546. fi
  547. }
  548. menu_timezone() {
  549. local _tzones="$(cd /usr/share/zoneinfo; find Africa/ America/ Antarctica/ Arctic/ Asia/ Atlantic/ Australia/ Europe/ Indian/ Pacific/ posix/ -type f | sort)"
  550. local _TIMEZONES=
  551. for f in ${_tzones}; do
  552. _TIMEZONES="${_TIMEZONES} ${f} -"
  553. done
  554. while true; do
  555. DIALOG --title " Select your timezone " --menu "$MENULABEL" 14 70 14 ${_TIMEZONES}
  556. if [ $? -eq 0 ]; then
  557. set_option TIMEZONE "$(cat $ANSWER)"
  558. TIMEZONE_DONE=1
  559. break
  560. else
  561. return
  562. fi
  563. done
  564. }
  565. set_timezone() {
  566. local TIMEZONE="$(get_option TIMEZONE)"
  567. sed -i -e "s|#TIMEZONE=.*|TIMEZONE=$TIMEZONE|g" $TARGETDIR/etc/rc.conf
  568. }
  569. menu_hostname() {
  570. while true; do
  571. DIALOG --inputbox "Set the machine hostname:" ${INPUTSIZE}
  572. if [ $? -eq 0 ]; then
  573. set_option HOSTNAME "$(cat $ANSWER)"
  574. HOSTNAME_DONE=1
  575. break
  576. else
  577. return
  578. fi
  579. done
  580. }
  581. set_hostname() {
  582. echo $(get_option HOSTNAME) > $TARGETDIR/etc/hostname
  583. }
  584. menu_rootpassword() {
  585. local _firstpass _secondpass _desc
  586. while true; do
  587. if [ -z "${_firstpass}" ]; then
  588. _desc="Enter the root password"
  589. else
  590. _desc="$_desc again"
  591. fi
  592. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  593. if [ $? -eq 0 ]; then
  594. if [ -z "${_firstpass}" ]; then
  595. _firstpass="$(cat $ANSWER)"
  596. else
  597. _secondpass="$(cat $ANSWER)"
  598. fi
  599. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  600. if [ "${_firstpass}" != "${_secondpass}" ]; then
  601. INFOBOX "Passwords do not match! Please enter again." 6 60
  602. unset _firstpass _secondpass
  603. sleep 2 && clear && continue
  604. fi
  605. set_option ROOTPASSWORD "${_firstpass}"
  606. ROOTPASSWORD_DONE=1
  607. break
  608. fi
  609. else
  610. return
  611. fi
  612. done
  613. }
  614. set_rootpassword() {
  615. echo "root:$(get_option ROOTPASSWORD)" | chpasswd -R $TARGETDIR -c SHA512
  616. }
  617. menu_useraccount() {
  618. local _firstpass _secondpass _desc
  619. local _groups _status _group _checklist
  620. local _preset
  621. while true; do
  622. _preset=$(get_option USERLOGIN)
  623. [ -z "$_preset" ] && _preset="void"
  624. DIALOG --inputbox "Enter a primary login name:" ${INPUTSIZE} "$_preset"
  625. if [ $? -eq 0 ]; then
  626. set_option USERLOGIN "$(cat $ANSWER)"
  627. USERLOGIN_DONE=1
  628. break
  629. else
  630. return
  631. fi
  632. done
  633. while true; do
  634. _preset=$(get_option USERNAME)
  635. [ -z "$_preset" ] && _preset="Void User"
  636. DIALOG --inputbox "Enter a user name for login '$(get_option USERLOGIN)' :" \
  637. ${INPUTSIZE} "$_preset"
  638. if [ $? -eq 0 ]; then
  639. set_option USERNAME "$(cat $ANSWER)"
  640. USERNAME_DONE=1
  641. break
  642. else
  643. return
  644. fi
  645. done
  646. while true; do
  647. if [ -z "${_firstpass}" ]; then
  648. _desc="Enter the password for login '$(get_option USERLOGIN)'"
  649. else
  650. _desc="$_desc again"
  651. fi
  652. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  653. if [ $? -eq 0 ]; then
  654. if [ -z "${_firstpass}" ]; then
  655. _firstpass="$(cat $ANSWER)"
  656. else
  657. _secondpass="$(cat $ANSWER)"
  658. fi
  659. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  660. if [ "${_firstpass}" != "${_secondpass}" ]; then
  661. INFOBOX "Passwords do not match! Please enter again." 6 60
  662. unset _firstpass _secondpass
  663. sleep 2 && clear && continue
  664. fi
  665. set_option USERPASSWORD "${_firstpass}"
  666. USERPASSWORD_DONE=1
  667. break
  668. fi
  669. else
  670. return
  671. fi
  672. done
  673. _groups="wheel,audio,video,floppy,cdrom,optical,kvm,xbuilder"
  674. while true; do
  675. _desc="Select group membership for login '$(get_option USERLOGIN)':"
  676. for _group in $(cat /etc/group); do
  677. _gid="$(echo ${_group} | cut -d: -f3)"
  678. _group="$(echo ${_group} | cut -d: -f1)"
  679. _status="$(echo ${_groups} | grep -w ${_group})"
  680. if [ -z "${_status}" ]; then
  681. _status=off
  682. else
  683. _status=on
  684. fi
  685. if [ -z "${_checklist}" ]; then
  686. _checklist="${_group} ${_group}:${_gid} ${_status}"
  687. else
  688. _checklist="${_checklist} ${_group} ${_group}:${_gid} ${_status}"
  689. fi
  690. done
  691. DIALOG --no-tags --checklist "${_desc}" 20 60 18 ${_checklist}
  692. if [ $? -eq 0 ]; then
  693. set_option USERGROUPS $(cat $ANSWER | sed -e's| |,|g')
  694. USERGROUPS_DONE=1
  695. break
  696. else
  697. return
  698. fi
  699. done
  700. }
  701. set_useraccount() {
  702. [ -z "$USERLOGIN_DONE" ] && return
  703. [ -z "$USERPASSWORD_DONE" ] && return
  704. [ -z "$USERNAME_DONE" ] && return
  705. [ -z "$USERGROUPS_DONE" ] && return
  706. useradd -R $TARGETDIR -m -G $(get_option USERGROUPS) \
  707. -c "$(get_option USERNAME)" $(get_option USERLOGIN)
  708. echo "$(get_option USERLOGIN):$(get_option USERPASSWORD)" | \
  709. chpasswd -R $TARGETDIR -c SHA512
  710. }
  711. menu_bootloader() {
  712. while true; do
  713. DIALOG --title " Select the disk to install the bootloader" \
  714. --menu "$MENULABEL" ${MENUSIZE} $(show_disks) none "Manage bootloader otherwise"
  715. if [ $? -eq 0 ]; then
  716. set_option BOOTLOADER "$(cat $ANSWER)"
  717. BOOTLOADER_DONE=1
  718. break
  719. else
  720. return
  721. fi
  722. done
  723. while true; do
  724. DIALOG --yesno "Use a graphical terminal for the boot loader?" ${YESNOSIZE}
  725. if [ $? -eq 0 ]; then
  726. set_option TEXTCONSOLE 0
  727. break
  728. elif [ $? -eq 1 ]; then
  729. set_option TEXTCONSOLE 1
  730. break
  731. else
  732. return
  733. fi
  734. done
  735. }
  736. set_bootloader() {
  737. local dev=$(get_option BOOTLOADER) grub_args=
  738. if [ "$dev" = "none" ]; then return; fi
  739. # Check if it's an EFI system via efivars module.
  740. if [ -n "$EFI_SYSTEM" ]; then
  741. grub_args="--target=$EFI_TARGET --efi-directory=/boot/efi --bootloader-id=void_grub --recheck"
  742. fi
  743. echo "Running grub-install $grub_args $dev..." >$LOG
  744. chroot $TARGETDIR grub-install $grub_args $dev >$LOG 2>&1
  745. if [ $? -ne 0 ]; then
  746. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  747. failed to install GRUB to $dev!\nCheck $LOG for errors." ${MSGBOXSIZE}
  748. DIE 1
  749. fi
  750. echo "Running grub-mkconfig on $TARGETDIR..." >$LOG
  751. chroot $TARGETDIR grub-mkconfig -o /boot/grub/grub.cfg >$LOG 2>&1
  752. if [ $? -ne 0 ]; then
  753. DIALOG --msgbox "${BOLD}${RED}ERROR${RESET}: \
  754. failed to run grub-mkconfig!\nCheck $LOG for errors." ${MSGBOXSIZE}
  755. DIE 1
  756. fi
  757. }
  758. test_network() {
  759. rm -f xtraeme.asc && \
  760. xbps-uhelper fetch http://alpha.de.repo.voidlinux.org/live/xtraeme.asc >$LOG 2>&1
  761. if [ $? -eq 0 ]; then
  762. DIALOG --msgbox "Network is working properly!" ${MSGBOXSIZE}
  763. NETWORK_DONE=1
  764. return 1
  765. fi
  766. DIALOG --msgbox "Network is inaccessible, please set it up properly." ${MSGBOXSIZE}
  767. }
  768. configure_wifi() {
  769. local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
  770. DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
  771. "SSID:" 1 1 "" 1 16 30 0 \
  772. "Encryption:" 2 1 "" 2 16 4 3 \
  773. "Password:" 3 1 "" 3 16 63 0 || return 1
  774. set -- $(cat $ANSWER)
  775. ssid="$1"; enc="$2"; pass="$3";
  776. if [ -z "$ssid" ]; then
  777. DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
  778. return 1
  779. elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
  780. DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSXBOXSIZE}
  781. return 1
  782. elif [ -z "$pass" ]; then
  783. DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
  784. fi
  785. rm -f ${_wpasupconf%.conf}-${dev}.conf
  786. cp -f ${_wpasupconf} ${_wpasupconf%.conf}-${dev}.conf
  787. if [ "$enc" = "wep" ]; then
  788. echo "network={" >> ${_wpasupconf%.conf}-${dev}.conf
  789. echo " ssid=\"$ssid\"" >> ${_wpasupconf%.conf}-${dev}.conf
  790. echo " wep_key0=\"$pass\"" >> ${_wpasupconf%.conf}-${dev}.conf
  791. echo " wep_tx_keyidx=0" >> ${_wpasupconf%.conf}-${dev}.conf
  792. echo " auth_alg=SHARED" >> ${_wpasupconf%.conf}-${dev}.conf
  793. echo "}" >> ${_wpasupconf%.conf}-${dev}.conf
  794. else
  795. wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf%.conf}-${dev}.conf
  796. fi
  797. configure_net_dhcp $dev
  798. return $?
  799. }
  800. configure_net() {
  801. local dev="$1" rval
  802. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  803. rval=$?
  804. if [ $rval -eq 0 ]; then
  805. configure_net_dhcp $dev
  806. elif [ $rval -eq 1 ]; then
  807. configure_net_static $dev
  808. fi
  809. }
  810. iface_setup() {
  811. ip addr show dev $1|grep -q 'inet '
  812. return $?
  813. }
  814. configure_net_dhcp() {
  815. local dev="$1"
  816. iface_setup $dev
  817. if [ $? -eq 1 ]; then
  818. dhcpcd -t 10 -w -4 -L $dev -e "wpa_supplicant_conf=/etc/wpa_supplicant/wpa_supplicant-${dev}.conf" 2>&1 | tee $LOG | \
  819. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  820. if [ $? -ne 0 ]; then
  821. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
  822. return 1
  823. fi
  824. iface_setup $dev
  825. if [ $? -eq 1 ]; then
  826. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  827. return 1
  828. fi
  829. fi
  830. test_network
  831. if [ $? -eq 1 ]; then
  832. set_option NETWORK "${dev} dhcp"
  833. fi
  834. }
  835. configure_net_static() {
  836. local ip gw dns1 dns2 dev=$1
  837. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  838. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  839. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  840. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  841. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  842. set -- $(cat $ANSWER)
  843. ip=$1; gw=$2; dns1=$3; dns2=$4
  844. echo "running: ip link set dev $dev up" >$LOG
  845. ip link set dev $dev up >$LOG 2>&1
  846. if [ $? -ne 0 ]; then
  847. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  848. return 1
  849. fi
  850. echo "running: ip addr add $ip dev $dev"
  851. ip addr add $ip dev $dev >$LOG 2>&1
  852. if [ $? -ne 0 ]; then
  853. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  854. return 1
  855. fi
  856. ip route add $gw dev $dev >$LOG 2>&1
  857. if [ $? -ne 0 ]; then
  858. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  859. return 1
  860. fi
  861. echo "nameserver $dns1" >/etc/resolv.conf
  862. echo "nameserver $dns2" >>/etc/resolv.conf
  863. test_network
  864. if [ $? -eq 1 ]; then
  865. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  866. fi
  867. }
  868. menu_network() {
  869. local dev addr f DEVICES
  870. for f in $(ls /sys/class/net); do
  871. [ "$f" = "lo" ] && continue
  872. addr=$(cat /sys/class/net/$f/address)
  873. DEVICES="$DEVICES $f $addr"
  874. done
  875. DIALOG --title " Select the network interface to configure " \
  876. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  877. if [ $? -eq 0 ]; then
  878. dev=$(cat $ANSWER)
  879. if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
  880. configure_wifi $dev
  881. else
  882. configure_net $dev
  883. fi
  884. fi
  885. }
  886. validate_filesystems() {
  887. local mnts dev size fstype mntpt mkfs rootfound fmt
  888. local usrfound efi_system_partition
  889. unset TARGETFS
  890. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  891. set -- ${mnts}
  892. while [ $# -ne 0 ]; do
  893. fmt=""
  894. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  895. shift 6
  896. if [ "$mntpt" = "/" ]; then
  897. rootfound=1
  898. elif [ "$mntpt" = "/usr" ]; then
  899. usrfound=1
  900. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  901. efi_system_partition=1
  902. fi
  903. if [ "$mkfs" -eq 1 ]; then
  904. fmt="NEW FILESYSTEM: "
  905. fi
  906. if [ -z "$TARGETFS" ]; then
  907. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  908. else
  909. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  910. fi
  911. done
  912. if [ -z "$rootfound" ]; then
  913. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  914. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  915. return 1
  916. elif [ -n "$usrfound" ]; then
  917. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  918. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  919. return 1
  920. elif [ -n "$EFI_SYSTEM" -a -z "$efi_system_partition" ]; then
  921. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  922. The EFI System Partition has not yet been configured, please create it\n
  923. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  924. fi
  925. FILESYSTEMS_DONE=1
  926. }
  927. create_filesystems() {
  928. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  929. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  930. set -- ${mnts}
  931. while [ $# -ne 0 ]; do
  932. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  933. shift 6
  934. # swap partitions
  935. if [ "$fstype" = "swap" ]; then
  936. swapoff $dev >/dev/null 2>&1
  937. if [ "$mkfs" -eq 1 ]; then
  938. mkswap $dev >$LOG 2>&1
  939. if [ $? -ne 0 ]; then
  940. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  941. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  942. DIE 1
  943. fi
  944. fi
  945. swapon $dev >$LOG 2>&1
  946. if [ $? -ne 0 ]; then
  947. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  948. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  949. DIE 1
  950. fi
  951. # Add entry for target fstab
  952. uuid=$(blkid -o value -s UUID "$dev")
  953. echo "UUID=$uuid none swap sw 0 0" >>$TARGET_FSTAB
  954. continue
  955. fi
  956. if [ "$mkfs" -eq 1 ]; then
  957. case "$fstype" in
  958. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  959. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  960. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  961. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  962. f2fs) MKFS="mkfs.f2fs"; modprobe f2fs >$LOG 2>&1;;
  963. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  964. xfs) MKFS="mkfs.xfs -f"; modprobe xfs >$LOG 2>&1;;
  965. esac
  966. TITLE="Check $LOG for details ..."
  967. INFOBOX "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  968. echo "Running $MKFS $dev..." >$LOG
  969. $MKFS $dev >$LOG 2>&1; rv=$?
  970. if [ $rv -ne 0 ]; then
  971. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  972. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  973. DIE 1
  974. fi
  975. fi
  976. # Mount rootfs the first one.
  977. [ "$mntpt" != "/" ] && continue
  978. mkdir -p $TARGETDIR
  979. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  980. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  981. if [ $? -ne 0 ]; then
  982. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  983. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  984. DIE 1
  985. fi
  986. # Add entry to target fstab
  987. uuid=$(blkid -o value -s UUID "$dev")
  988. if [ "$fstype" = "f2fs" ]; then
  989. fspassno=0
  990. else
  991. fspassno=1
  992. fi
  993. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  994. done
  995. # mount all filesystems in target rootfs
  996. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  997. set -- ${mnts}
  998. while [ $# -ne 0 ]; do
  999. dev=$2; fstype=$3; mntpt="$5"
  1000. shift 6
  1001. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  1002. mkdir -p ${TARGETDIR}${mntpt}
  1003. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  1004. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  1005. if [ $? -ne 0 ]; then
  1006. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  1007. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  1008. DIE
  1009. fi
  1010. # Add entry to target fstab
  1011. uuid=$(blkid -o value -s UUID "$dev")
  1012. echo "UUID=$uuid $mntpt $fstype defaults 0 2" >>$TARGET_FSTAB
  1013. done
  1014. }
  1015. mount_filesystems() {
  1016. for f in sys proc dev; do
  1017. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  1018. echo "Mounting $TARGETDIR/$f..." >$LOG
  1019. mount --bind /$f $TARGETDIR/$f >$LOG 2>&1
  1020. done
  1021. }
  1022. umount_filesystems() {
  1023. local f
  1024. for f in sys/fs/fuse/connections sys proc dev; do
  1025. echo "Unmounting $TARGETDIR/$f..." >$LOG
  1026. umount $TARGETDIR/$f >$LOG 2>&1
  1027. done
  1028. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  1029. set -- ${mnts}
  1030. while [ $# -ne 0 ]; do
  1031. local dev=$2; local fstype=$3; local mntpt=$5
  1032. shift 6
  1033. if [ "$fstype" = "swap" ]; then
  1034. echo "Disabling swap space on $dev..." >$LOG
  1035. swapoff $dev >$LOG 2>&1
  1036. continue
  1037. fi
  1038. if [ "$mntpt" != "/" ]; then
  1039. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  1040. umount $TARGETDIR/$mntpt >$LOG 2>&1
  1041. fi
  1042. done
  1043. echo "Unmounting $TARGETDIR..." >$LOG
  1044. umount $TARGETDIR >$LOG 2>&1
  1045. }
  1046. log_and_count() {
  1047. local progress whole tenth
  1048. while read line; do
  1049. echo "$line" >$LOG
  1050. copy_count=$((copy_count + 1))
  1051. progress=$((1000 * copy_count / copy_total))
  1052. if [ "$progress" != "$copy_progress" ]; then
  1053. whole=$((progress / 10))
  1054. tenth=$((progress % 10))
  1055. printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
  1056. copy_progress=$progress
  1057. fi
  1058. done
  1059. }
  1060. copy_rootfs() {
  1061. local tar_in="--create --one-file-system --xattrs"
  1062. TITLE="Check $LOG for details ..."
  1063. INFOBOX "Counting files, please be patient ..." 4 60
  1064. copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
  1065. export copy_total copy_count=0 copy_progress=
  1066. clear
  1067. tar ${tar_in} -f - / 2>/dev/null | \
  1068. tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
  1069. log_and_count | \
  1070. DIALOG --title "${TITLE}" \
  1071. --progressbox "Copying live image to target rootfs." 5 60
  1072. if [ $? -ne 0 ]; then
  1073. DIE 1
  1074. fi
  1075. unset copy_total copy_count copy_percent
  1076. }
  1077. install_packages() {
  1078. local _grub= _syspkg=
  1079. if [ -n "$EFI_SYSTEM" ]; then
  1080. if [ $EFI_FW_BITS -eq 32 ]; then
  1081. _grub="grub-i386-efi"
  1082. else
  1083. _grub="grub-x86_64-efi"
  1084. fi
  1085. else
  1086. _grub="grub"
  1087. fi
  1088. _syspkg="base-system"
  1089. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  1090. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  1091. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  1092. mkdir -p $TARGETDIR/boot/grub
  1093. _arch=$(xbps-uhelper arch)
  1094. stdbuf -oL env XBPS_ARCH=${_arch} \
  1095. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  1096. DIALOG --title "Installing base system packages..." \
  1097. --programbox 24 80
  1098. if [ $? -ne 0 ]; then
  1099. DIE 1
  1100. fi
  1101. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  1102. chroot $TARGETDIR xbps-reconfigure -a
  1103. }
  1104. enable_dhcpd() {
  1105. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  1106. }
  1107. menu_install() {
  1108. # Don't continue if filesystems are not ready.
  1109. validate_filesystems || return 1
  1110. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  1111. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  1112. if [ -z "$FILESYSTEMS_DONE" ]; then
  1113. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  1114. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1115. return 1
  1116. elif [ -z "$ROOTPASSWORD_DONE" ]; then
  1117. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  1118. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1119. return 1
  1120. elif [ -z "$BOOTLOADER_DONE" ]; then
  1121. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  1122. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1123. return 1
  1124. fi
  1125. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  1126. ${BOLD}${TARGETFS}${RESET}\n
  1127. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  1128. filesystems.${RESET}\n\n
  1129. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  1130. unset TARGETFS
  1131. # Create and mount filesystems
  1132. create_filesystems
  1133. # If source not set use defaults.
  1134. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  1135. copy_rootfs
  1136. . /etc/default/live.conf
  1137. rm -f $TARGETDIR/etc/motd
  1138. rm -f $TARGETDIR/etc/issue
  1139. rm -f $TARGETDIR/usr/sbin/void-installer
  1140. # Remove modified sddm.conf to let sddm use the defaults.
  1141. rm -f $TARGETDIR/etc/sddm.conf
  1142. # Remove live user.
  1143. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  1144. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  1145. sed -i -e "/$USERNAME ALL=.*/d" $TARGETDIR/etc/sudoers
  1146. TITLE="Check $LOG for details ..."
  1147. INFOBOX "Rebuilding initramfs for target ..." 4 60
  1148. echo "Rebuilding initramfs for target ..." >$LOG
  1149. # mount required fs
  1150. mount_filesystems
  1151. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  1152. INFOBOX "Removing temporary packages from target ..." 4 60
  1153. echo "Removing temporary packages from target ..." >$LOG
  1154. xbps-remove -r $TARGETDIR -Ry dialog >>$LOG 2>&1
  1155. rmdir $TARGETDIR/mnt/target
  1156. else
  1157. # mount required fs
  1158. mount_filesystems
  1159. # network install, use packages.
  1160. install_packages
  1161. fi
  1162. INFOBOX "Applying installer settings..." 4 60
  1163. # copy target fstab.
  1164. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  1165. # Mount /tmp as tmpfs.
  1166. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  1167. # set up keymap, locale, timezone, hostname, root passwd and user account.
  1168. set_keymap
  1169. set_locale
  1170. set_timezone
  1171. set_hostname
  1172. set_rootpassword
  1173. set_useraccount
  1174. # Copy /etc/skel files for root.
  1175. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  1176. # network settings for target
  1177. if [ -n "$NETWORK_DONE" ]; then
  1178. local net="$(get_option NETWORK)"
  1179. set -- ${net}
  1180. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  1181. if [ -z "$_type" ]; then
  1182. # network type empty??!!!
  1183. :
  1184. elif [ "$_type" = "dhcp" ]; then
  1185. if [ -f /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf ]; then
  1186. cp /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf $TARGETDIR/etc/wpa_supplicant
  1187. ln -sf /etc/sv/dhcpcd-${_dev} $TARGETDIR/etc/runit/runsvdir/default/dhcpcd-${_dev}
  1188. else
  1189. enable_dhcpd
  1190. fi
  1191. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  1192. # static IP through dhcpcd.
  1193. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig
  1194. echo "# Static IP configuration set by the void-installer for $_dev." \
  1195. >$TARGETDIR/etc/dhcpcd.conf
  1196. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  1197. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  1198. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  1199. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  1200. enable_dhcpd
  1201. fi
  1202. fi
  1203. if [ -f $TARGETDIR/etc/sudoers ]; then
  1204. USERLOGIN="$(get_option USERLOGIN)"
  1205. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" -a -n "$USERLOGIN" ]; then
  1206. # enable sudo for primary user USERLOGIN who is not member of wheel
  1207. echo "# Enable sudo for login '$USERLOGIN'" >> $TARGETDIR/etc/sudoers
  1208. echo "$USERLOGIN ALL=(ALL) ALL" >> $TARGETDIR/etc/sudoers
  1209. else
  1210. # enable the sudoers entry for members of group wheel
  1211. sed -i $TARGETDIR/etc/sudoers \
  1212. -e "s;#.*%wheel ALL=(ALL) ALL;%wheel ALL=(ALL) ALL;"
  1213. fi
  1214. unset USERLOGIN
  1215. fi
  1216. # enable text console for grub if chosen
  1217. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  1218. sed -i $TARGETDIR/etc/default/grub \
  1219. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  1220. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  1221. fi
  1222. # install bootloader.
  1223. set_bootloader
  1224. sync && sync && sync
  1225. # unmount all filesystems.
  1226. umount_filesystems
  1227. # installed successfully.
  1228. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  1229. Do you want to reboot the system?" ${YESNOSIZE}
  1230. if [ $? -eq 0 ]; then
  1231. shutdown -r now
  1232. else
  1233. return
  1234. fi
  1235. }
  1236. menu_source() {
  1237. local src=
  1238. DIALOG --title " Select installation source " \
  1239. --menu "$MENULABEL" 8 70 0 \
  1240. "Local" "Packages from ISO image" \
  1241. "Network" "Packages from official remote reposity"
  1242. case "$(cat $ANSWER)" in
  1243. "Local") src="local";;
  1244. "Network") src="net";
  1245. if [ -z "$NETWORK_DONE" ]; then
  1246. menu_network;
  1247. fi;;
  1248. *) return 1;;
  1249. esac
  1250. SOURCE_DONE=1
  1251. set_option SOURCE $src
  1252. }
  1253. menu() {
  1254. if [ -z "$DEFITEM" ]; then
  1255. DEFITEM="Keyboard"
  1256. fi
  1257. if xbps-uhelper arch | grep '-musl$' > /dev/null; then
  1258. DIALOG --default-item $DEFITEM \
  1259. --extra-button --extra-label "Settings" \
  1260. --title " Void Linux installation menu " \
  1261. --menu "$MENULABEL" 10 70 0 \
  1262. "Keyboard" "Set system keyboard" \
  1263. "Network" "Set up the network" \
  1264. "Source" "Set source installation" \
  1265. "Hostname" "Set system hostname" \
  1266. "Timezone" "Set system time zone" \
  1267. "RootPassword" "Set system root password" \
  1268. "UserAccount" "Set primary user name and password" \
  1269. "BootLoader" "Set disk to install bootloader" \
  1270. "Partition" "Partition disk(s)" \
  1271. "Filesystems" "Configure filesystems and mount points" \
  1272. "Install" "Start installation with saved settings" \
  1273. "Exit" "Exit installation"
  1274. else
  1275. DIALOG --default-item $DEFITEM \
  1276. --extra-button --extra-label "Settings" \
  1277. --title " Void Linux installation menu " \
  1278. --menu "$MENULABEL" 10 70 0 \
  1279. "Keyboard" "Set system keyboard" \
  1280. "Network" "Set up the network" \
  1281. "Source" "Set source installation" \
  1282. "Hostname" "Set system hostname" \
  1283. "Locale" "Set system locale" \
  1284. "Timezone" "Set system time zone" \
  1285. "RootPassword" "Set system root password" \
  1286. "UserAccount" "Set primary user name and password" \
  1287. "BootLoader" "Set disk to install bootloader" \
  1288. "Partition" "Partition disk(s)" \
  1289. "Filesystems" "Configure filesystems and mount points" \
  1290. "Install" "Start installation with saved settings" \
  1291. "Exit" "Exit installation"
  1292. fi
  1293. if [ $? -eq 3 ]; then
  1294. # Show settings
  1295. cp $CONF_FILE /tmp/conf_hidden.$$;
  1296. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1297. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1298. rm /tmp/conf_hidden.$$
  1299. return
  1300. fi
  1301. case $(cat $ANSWER) in
  1302. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1303. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1304. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1305. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="Locale";;
  1306. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1307. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1308. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1309. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1310. && DEFITEM="BootLoader";;
  1311. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1312. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1313. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1314. "Install") menu_install;;
  1315. "Exit") DIE;;
  1316. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1317. esac
  1318. }
  1319. if [ ! -x /bin/dialog ]; then
  1320. echo "ERROR: missing dialog command, exiting..."
  1321. exit 1
  1322. fi
  1323. if [ "$(id -u)" != "0" ]; then
  1324. echo "void-installer must run as root" 1>&2
  1325. exit 1
  1326. fi
  1327. #
  1328. # main()
  1329. #
  1330. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1331. Welcome to the Void Linux installation. A simple and minimal \
  1332. Linux distribution made from scratch and built from the source package tree \
  1333. available for XBPS, a new alternative binary package system.\n\n
  1334. The installation should be pretty straightforward. If you are in trouble \
  1335. please join us at ${BOLD}#voidlinux${RESET} on ${BOLD}irc.freenode.org${RESET}.\n\n
  1336. ${BOLD}http://www.voidlinux.eu${RESET}\n\n" 16 80
  1337. while true; do
  1338. menu
  1339. done
  1340. exit 0
  1341. # vim: set ts=4 sw=4 et: