installer.sh.in 47 KB

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