installer.sh.in 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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 -- http://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 -- http://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. # Software raid (md)
  365. for p in $(ls -d /dev/md* 2>/dev/null|grep '[0-9]'); do
  366. part=$(basename $p)
  367. if cat /proc/mdstat|grep -qw $part; then
  368. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  369. [ "$fstype" = "crypto_LUKS" ] && continue
  370. [ "$fstype" = "LVM2_member" ] && continue
  371. fssize=$(lsblk -nr /dev/$part|awk '{print $4}')
  372. echo "$p"
  373. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  374. fi
  375. done
  376. # cciss(4) devices
  377. for part in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]p[0-9]+'); do
  378. fstype=$(lsblk -nfr /dev/cciss/$part|awk '{print $2}')
  379. [ "$fstype" = "crypto_LUKS" ] && continue
  380. [ "$fstype" = "LVM2_member" ] && continue
  381. fssize=$(lsblk -nr /dev/cciss/$part|awk '{print $4}')
  382. echo "/dev/cciss/$part"
  383. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  384. done
  385. if [ -e /sbin/lvs ]; then
  386. # LVM
  387. lvs --noheadings|while read lvname vgname perms size; do
  388. echo "/dev/mapper/${vgname}-${lvname}"
  389. echo "size:${size};fstype:lvm"
  390. done
  391. fi
  392. }
  393. menu_filesystems() {
  394. local dev fstype fssize mntpoint reformat
  395. while true; do
  396. DIALOG --title " Select the partition to edit " --menu "$MENULABEL" \
  397. ${MENUSIZE} $(show_partitions)
  398. [ $? -ne 0 ] && return
  399. dev=$(cat $ANSWER)
  400. DIALOG --title " Select the filesystem type for $dev " \
  401. --menu "$MENULABEL" ${MENUSIZE} \
  402. "btrfs" "Oracle's Btrfs" \
  403. "ext2" "Linux ext2 (no journaling)" \
  404. "ext3" "Linux ext3 (journal)" \
  405. "ext4" "Linux ext4 (journal)" \
  406. "f2fs" "Flash-Friendly Filesystem" \
  407. "swap" "Linux swap" \
  408. "vfat" "FAT32" \
  409. "xfs" "SGI's XFS"
  410. if [ $? -eq 0 ]; then
  411. fstype=$(cat $ANSWER)
  412. else
  413. continue
  414. fi
  415. if [ "$fstype" != "swap" ]; then
  416. DIALOG --inputbox "Please specify the mount point for $dev:" ${INPUTSIZE}
  417. if [ $? -eq 0 ]; then
  418. mntpoint=$(cat $ANSWER)
  419. elif [ $? -eq 1 ]; then
  420. continue
  421. fi
  422. else
  423. mntpoint=swap
  424. fi
  425. DIALOG --yesno "Do you want to create a new filesystem on $dev?" ${YESNOSIZE}
  426. if [ $? -eq 0 ]; then
  427. reformat=1
  428. elif [ $? -eq 1 ]; then
  429. reformat=0
  430. else
  431. continue
  432. fi
  433. fssize=$(lsblk -nr $dev|awk '{print $4}')
  434. set -- "$fstype" "$fssize" "$mntpoint" "$reformat"
  435. if [ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ]; then
  436. local bdev=$(basename $dev)
  437. local ddev=$(basename $(dirname $dev))
  438. if [ "$ddev" != "dev" ]; then
  439. sed -i -e "/^MOUNTPOINT \/dev\/${ddev}\/${bdev}.*/d" $CONF_FILE
  440. else
  441. sed -i -e "/^MOUNTPOINT \/dev\/${bdev}.*/d" $CONF_FILE
  442. fi
  443. echo "MOUNTPOINT $dev $1 $2 $3 $4" >>$CONF_FILE
  444. fi
  445. done
  446. }
  447. menu_partitions() {
  448. DIALOG --title " Select the disk to partition " \
  449. --menu "$MENULABEL" ${MENUSIZE} $(show_disks)
  450. if [ $? -eq 0 ]; then
  451. local device=$(cat $ANSWER)
  452. DIALOG --title "Modify Partition Table on $device" --msgbox "\n
  453. ${BOLD}cfdisk will be executed in disk $device.${RESET}\n\n
  454. For BIOS systems, MBR or GPT partition tables are supported.\n
  455. To use GPT on PC BIOS systems an empty partition of 1MB must be added\n
  456. at the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n
  457. ${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n
  458. For EFI systems GPT is mandatory and a FAT32 partition with at least\n
  459. 100MB must be created with the TOGGLE \`boot', this will be used as\n
  460. EFI System Partition. This partition must have mountpoint as \`/boot/efi'.\n\n
  461. At least 1 partitions is required for the rootfs (/).\n
  462. For swap, RAM*2 must be really enough. For / 600MB are required.\n\n
  463. ${BOLD}WARNING: /usr is not supported as a separate partition.${RESET}\n
  464. ${RESET}\n" 18 80
  465. if [ $? -eq 0 ]; then
  466. while true; do
  467. clear; cfdisk $device; PARTITIONS_DONE=1
  468. break
  469. done
  470. else
  471. return
  472. fi
  473. fi
  474. }
  475. menu_keymap() {
  476. local _keymaps="$(find /usr/share/kbd/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sort)"
  477. local _KEYMAPS=
  478. for f in ${_keymaps}; do
  479. _KEYMAPS="${_KEYMAPS} ${f} -"
  480. done
  481. while true; do
  482. DIALOG --title " Select your keymap " --menu "$MENULABEL" 14 70 14 ${_KEYMAPS}
  483. if [ $? -eq 0 ]; then
  484. set_option KEYMAP "$(cat $ANSWER)"
  485. loadkeys "$(cat $ANSWER)"
  486. KEYBOARD_DONE=1
  487. break
  488. else
  489. return
  490. fi
  491. done
  492. }
  493. set_keymap() {
  494. local KEYMAP=$(get_option KEYMAP)
  495. if [ -f /etc/vconsole.conf ]; then
  496. sed -i -e "s|KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/vconsole.conf
  497. else
  498. sed -i -e "s|#\?KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/rc.conf
  499. fi
  500. }
  501. menu_locale() {
  502. local _locales="$(grep -E '\.UTF-8' /etc/default/libc-locales|awk '{print $1}'|sed -e 's/^#//')"
  503. local LOCALES ISO639 ISO3166
  504. local TMPFILE=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  505. INFOBOX "Scanning locales ..." 4 60
  506. for f in ${_locales}; do
  507. eval $(echo $f | awk 'BEGIN { FS="." } \
  508. { FS="_"; split($1, a); printf "ISO639=%s ISO3166=%s\n", a[1], a[2] }')
  509. echo "$f|$(iso639_language $ISO639) ($(iso3166_country $ISO3166))|" >> $TMPFILE
  510. done
  511. clear
  512. # Sort by ISO-639 language names
  513. LOCALES=$(sort -t '|' -k 2 < $TMPFILE | xargs | sed -e's/| /|/g')
  514. rm -f $TMPFILE
  515. while true; do
  516. (IFS="|"; DIALOG --title " Select your locale " --menu "$MENULABEL" 18 70 18 ${LOCALES})
  517. if [ $? -eq 0 ]; then
  518. set_option LOCALE "$(cat $ANSWER)"
  519. LOCALE_DONE=1
  520. break
  521. else
  522. return
  523. fi
  524. done
  525. }
  526. set_locale() {
  527. if [ -f $TARGETDIR/etc/default/libc-locales ]; then
  528. local LOCALE=$(get_option LOCALE)
  529. sed -i -e "s|LANG=.*|LANG=$LOCALE|g" $TARGETDIR/etc/locale.conf
  530. # Uncomment locale from /etc/default/libc-locales and regenerate it.
  531. sed -e "/${LOCALE}/s/^\#//" -i $TARGETDIR/etc/default/libc-locales
  532. echo "Running xbps-reconfigure -f glibc-locales ..." >$LOG
  533. chroot $TARGETDIR xbps-reconfigure -f glibc-locales >$LOG 2>&1
  534. fi
  535. }
  536. menu_timezone() {
  537. local _tzones="$(cd /usr/share/zoneinfo; find Africa/ America/ Antarctica/ Arctic/ Asia/ Atlantic/ Australia/ Europe/ Indian/ Pacific/ posix/ -type f | sort)"
  538. local _TIMEZONES=
  539. for f in ${_tzones}; do
  540. _TIMEZONES="${_TIMEZONES} ${f} -"
  541. done
  542. while true; do
  543. DIALOG --title " Select your timezone " --menu "$MENULABEL" 14 70 14 ${_TIMEZONES}
  544. if [ $? -eq 0 ]; then
  545. set_option TIMEZONE "$(cat $ANSWER)"
  546. TIMEZONE_DONE=1
  547. break
  548. else
  549. return
  550. fi
  551. done
  552. }
  553. set_timezone() {
  554. local TIMEZONE="$(get_option TIMEZONE)"
  555. sed -i -e "s|#TIMEZONE=.*|TIMEZONE=$TIMEZONE|g" $TARGETDIR/etc/rc.conf
  556. }
  557. menu_hostname() {
  558. while true; do
  559. DIALOG --inputbox "Set the machine hostname:" ${INPUTSIZE}
  560. if [ $? -eq 0 ]; then
  561. set_option HOSTNAME "$(cat $ANSWER)"
  562. HOSTNAME_DONE=1
  563. break
  564. else
  565. return
  566. fi
  567. done
  568. }
  569. set_hostname() {
  570. echo $(get_option HOSTNAME) > $TARGETDIR/etc/hostname
  571. }
  572. menu_rootpassword() {
  573. local _firstpass _secondpass _desc
  574. while true; do
  575. if [ -z "${_firstpass}" ]; then
  576. _desc="Enter the root password"
  577. else
  578. _desc="$_desc again"
  579. fi
  580. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  581. if [ $? -eq 0 ]; then
  582. if [ -z "${_firstpass}" ]; then
  583. _firstpass="$(cat $ANSWER)"
  584. else
  585. _secondpass="$(cat $ANSWER)"
  586. fi
  587. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  588. if [ "${_firstpass}" != "${_secondpass}" ]; then
  589. INFOBOX "Passwords do not match! Please enter again." 6 60
  590. unset _firstpass _secondpass
  591. sleep 2 && clear && continue
  592. fi
  593. set_option ROOTPASSWORD "${_firstpass}"
  594. ROOTPASSWORD_DONE=1
  595. break
  596. fi
  597. else
  598. return
  599. fi
  600. done
  601. }
  602. set_rootpassword() {
  603. echo "root:$(get_option ROOTPASSWORD)" | chpasswd -R $TARGETDIR -c SHA512
  604. }
  605. menu_useraccount() {
  606. local _firstpass _secondpass _desc
  607. local _groups _status _group _checklist
  608. local _preset
  609. while true; do
  610. _preset=$(get_option USERLOGIN)
  611. [ -z "$_preset" ] && _preset="void"
  612. DIALOG --inputbox "Enter a primary login name:" ${INPUTSIZE} "$_preset"
  613. if [ $? -eq 0 ]; then
  614. set_option USERLOGIN "$(cat $ANSWER)"
  615. USERLOGIN_DONE=1
  616. break
  617. else
  618. return
  619. fi
  620. done
  621. while true; do
  622. _preset=$(get_option USERNAME)
  623. [ -z "$_preset" ] && _preset="Void User"
  624. DIALOG --inputbox "Enter a user name for login '$(get_option USERLOGIN)' :" \
  625. ${INPUTSIZE} "$_preset"
  626. if [ $? -eq 0 ]; then
  627. set_option USERNAME "$(cat $ANSWER)"
  628. USERNAME_DONE=1
  629. break
  630. else
  631. return
  632. fi
  633. done
  634. while true; do
  635. if [ -z "${_firstpass}" ]; then
  636. _desc="Enter the password for login '$(get_option USERLOGIN)'"
  637. else
  638. _desc="$_desc again"
  639. fi
  640. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  641. if [ $? -eq 0 ]; then
  642. if [ -z "${_firstpass}" ]; then
  643. _firstpass="$(cat $ANSWER)"
  644. else
  645. _secondpass="$(cat $ANSWER)"
  646. fi
  647. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  648. if [ "${_firstpass}" != "${_secondpass}" ]; then
  649. INFOBOX "Passwords do not match! Please enter again." 6 60
  650. unset _firstpass _secondpass
  651. sleep 2 && clear && continue
  652. fi
  653. set_option USERPASSWORD "${_firstpass}"
  654. USERPASSWORD_DONE=1
  655. break
  656. fi
  657. else
  658. return
  659. fi
  660. done
  661. _groups="wheel,audio,video,floppy,cdrom,optical,kvm,xbuilder"
  662. while true; do
  663. _desc="Select group membership for login '$(get_option USERLOGIN)':"
  664. for _group in $(cat /etc/group); do
  665. _gid="$(echo ${_group} | cut -d: -f3)"
  666. _group="$(echo ${_group} | cut -d: -f1)"
  667. _status="$(echo ${_groups} | grep -w ${_group})"
  668. if [ -z "${_status}" ]; then
  669. _status=off
  670. else
  671. _status=on
  672. fi
  673. if [ -z "${_checklist}" ]; then
  674. _checklist="${_group} ${_group}:${_gid} ${_status}"
  675. else
  676. _checklist="${_checklist} ${_group} ${_group}:${_gid} ${_status}"
  677. fi
  678. done
  679. DIALOG --no-tags --checklist "${_desc}" 20 60 18 ${_checklist}
  680. if [ $? -eq 0 ]; then
  681. set_option USERGROUPS $(cat $ANSWER | sed -e's| |,|g')
  682. USERGROUPS_DONE=1
  683. break
  684. else
  685. return
  686. fi
  687. done
  688. }
  689. set_useraccount() {
  690. [ -z "$USERLOGIN_DONE" ] && return
  691. [ -z "$USERPASSWORD_DONE" ] && return
  692. [ -z "$USERNAME_DONE" ] && return
  693. [ -z "$USERGROUPS_DONE" ] && return
  694. useradd -R $TARGETDIR -m -G $(get_option USERGROUPS) \
  695. -c "$(get_option USERNAME)" $(get_option USERLOGIN)
  696. echo "$(get_option USERLOGIN):$(get_option USERPASSWORD)" | \
  697. chpasswd -R $TARGETDIR -c SHA512
  698. }
  699. menu_bootloader() {
  700. while true; do
  701. DIALOG --title " Select the disk to install the bootloader" \
  702. --menu "$MENULABEL" ${MENUSIZE} $(show_disks) none "Manage bootloader otherwise"
  703. if [ $? -eq 0 ]; then
  704. set_option BOOTLOADER "$(cat $ANSWER)"
  705. BOOTLOADER_DONE=1
  706. break
  707. else
  708. return
  709. fi
  710. done
  711. while true; do
  712. DIALOG --yesno "Use a graphical terminal for the boot loader?" ${YESNOSIZE}
  713. if [ $? -eq 0 ]; then
  714. set_option TEXTCONSOLE 0
  715. break
  716. elif [ $? -eq 1 ]; then
  717. set_option TEXTCONSOLE 1
  718. break
  719. else
  720. return
  721. fi
  722. done
  723. }
  724. set_bootloader() {
  725. local dev=$(get_option BOOTLOADER) grub_args=
  726. if [ "$dev" = "none" ]; then return; fi
  727. # Check if it's an EFI system via efivars module.
  728. if [ -n "$EFI_SYSTEM" ]; then
  729. grub_args="--target=$EFI_TARGET --efi-directory=/boot/efi --bootloader-id=void_grub --recheck"
  730. fi
  731. echo "Running grub-install $grub_args $dev..." >$LOG
  732. chroot $TARGETDIR grub-install $grub_args $dev >$LOG 2>&1
  733. if [ $? -ne 0 ]; then
  734. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  735. failed to install GRUB to $dev!\nCheck $LOG for errors." ${MSGBOXSIZE}
  736. DIE 1
  737. fi
  738. echo "Running grub-mkconfig on $TARGETDIR..." >$LOG
  739. chroot $TARGETDIR grub-mkconfig -o /boot/grub/grub.cfg >$LOG 2>&1
  740. if [ $? -ne 0 ]; then
  741. DIALOG --msgbox "${BOLD}${RED}ERROR${RESET}: \
  742. failed to run grub-mkconfig!\nCheck $LOG for errors." ${MSGBOXSIZE}
  743. DIE 1
  744. fi
  745. }
  746. test_network() {
  747. rm -f xtraeme.asc && \
  748. xbps-uhelper fetch http://repo.voidlinux.eu/live/xtraeme.asc >$LOG 2>&1
  749. if [ $? -eq 0 ]; then
  750. DIALOG --msgbox "Network is working properly!" ${MSGBOXSIZE}
  751. NETWORK_DONE=1
  752. return 1
  753. fi
  754. DIALOG --msgbox "Network is inaccessible, please set it up properly." ${MSGBOXSIZE}
  755. }
  756. configure_wifi() {
  757. local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
  758. DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
  759. "SSID:" 1 1 "" 1 16 30 0 \
  760. "Encryption:" 2 1 "" 2 16 4 3 \
  761. "Password:" 3 1 "" 3 16 63 0 || return 1
  762. set -- $(cat $ANSWER)
  763. ssid="$1"; enc="$2"; pass="$3";
  764. if [ -z "$ssid" ]; then
  765. DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
  766. return 1
  767. elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
  768. DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSXBOXSIZE}
  769. return 1
  770. elif [ -z "$pass" ]; then
  771. DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
  772. fi
  773. rm -f ${_wpasupconf%.conf}-${dev}.conf
  774. cp -f ${_wpasupconf} ${_wpasupconf%.conf}-${dev}.conf
  775. if [ "$enc" = "wep" ]; then
  776. echo "network={" >> ${_wpasupconf%.conf}-${dev}.conf
  777. echo " ssid=\"$ssid\"" >> ${_wpasupconf%.conf}-${dev}.conf
  778. echo " wep_key0=\"$pass\"" >> ${_wpasupconf%.conf}-${dev}.conf
  779. echo " wep_tx_keyidx=0" >> ${_wpasupconf%.conf}-${dev}.conf
  780. echo " auth_alg=SHARED" >> ${_wpasupconf%.conf}-${dev}.conf
  781. echo "}" >> ${_wpasupconf%.conf}-${dev}.conf
  782. else
  783. wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf%.conf}-${dev}.conf
  784. fi
  785. configure_net_dhcp $dev
  786. return $?
  787. }
  788. configure_net() {
  789. local dev="$1" rval
  790. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  791. rval=$?
  792. if [ $rval -eq 0 ]; then
  793. configure_net_dhcp $dev
  794. elif [ $rval -eq 1 ]; then
  795. configure_net_static $dev
  796. fi
  797. }
  798. iface_setup() {
  799. ip addr show dev $1|grep -q 'inet '
  800. return $?
  801. }
  802. configure_net_dhcp() {
  803. local dev="$1"
  804. iface_setup $dev
  805. if [ $? -eq 1 ]; then
  806. dhcpcd -t 10 -w -4 -L $dev -e "wpa_supplicant_conf=/etc/wpa_supplicant/wpa_supplicant-${dev}.conf" 2>&1 | tee $LOG | \
  807. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  808. if [ $? -ne 0 ]; then
  809. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
  810. return 1
  811. fi
  812. iface_setup $dev
  813. if [ $? -eq 1 ]; then
  814. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  815. return 1
  816. fi
  817. fi
  818. test_network
  819. if [ $? -eq 1 ]; then
  820. set_option NETWORK "${dev} dhcp"
  821. fi
  822. }
  823. configure_net_static() {
  824. local ip gw dns1 dns2 dev=$1
  825. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  826. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  827. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  828. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  829. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  830. set -- $(cat $ANSWER)
  831. ip=$1; gw=$2; dns1=$3; dns2=$4
  832. echo "running: ip link set dev $dev up" >$LOG
  833. ip link set dev $dev up >$LOG 2>&1
  834. if [ $? -ne 0 ]; then
  835. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  836. return 1
  837. fi
  838. echo "running: ip addr add $ip dev $dev"
  839. ip addr add $ip dev $dev >$LOG 2>&1
  840. if [ $? -ne 0 ]; then
  841. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  842. return 1
  843. fi
  844. ip route add $gw dev $dev >$LOG 2>&1
  845. if [ $? -ne 0 ]; then
  846. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  847. return 1
  848. fi
  849. echo "nameserver $dns1" >/etc/resolv.conf
  850. echo "nameserver $dns2" >>/etc/resolv.conf
  851. test_network
  852. if [ $? -eq 1 ]; then
  853. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  854. fi
  855. }
  856. menu_network() {
  857. local dev addr f DEVICES
  858. for f in $(ls /sys/class/net); do
  859. [ "$f" = "lo" ] && continue
  860. addr=$(cat /sys/class/net/$f/address)
  861. DEVICES="$DEVICES $f $addr"
  862. done
  863. DIALOG --title " Select the network interface to configure " \
  864. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  865. if [ $? -eq 0 ]; then
  866. dev=$(cat $ANSWER)
  867. if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
  868. configure_wifi $dev
  869. else
  870. configure_net $dev
  871. fi
  872. fi
  873. }
  874. validate_filesystems() {
  875. local mnts dev size fstype mntpt mkfs rootfound fmt
  876. local usrfound efi_system_partition
  877. unset TARGETFS
  878. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  879. set -- ${mnts}
  880. while [ $# -ne 0 ]; do
  881. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  882. shift 6
  883. if [ "$mntpt" = "/" ]; then
  884. rootfound=1
  885. elif [ "$mntpt" = "/usr" ]; then
  886. usrfound=1
  887. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  888. efi_system_partition=1
  889. fi
  890. if [ "$mkfs" -eq 1 ]; then
  891. fmt="NEW FILESYSTEM: "
  892. fi
  893. if [ -z "$TARGETFS" ]; then
  894. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  895. else
  896. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  897. fi
  898. done
  899. if [ -z "$rootfound" ]; then
  900. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  901. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  902. return 1
  903. elif [ -n "$usrfound" ]; then
  904. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  905. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  906. return 1
  907. elif [ -n "$EFI_SYSTEM" -a -z "$efi_system_partition" ]; then
  908. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  909. The EFI System Partition has not yet been configured, please create it\n
  910. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  911. fi
  912. FILESYSTEMS_DONE=1
  913. }
  914. create_filesystems() {
  915. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  916. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  917. set -- ${mnts}
  918. while [ $# -ne 0 ]; do
  919. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  920. shift 6
  921. # swap partitions
  922. if [ "$fstype" = "swap" ]; then
  923. swapoff $dev >/dev/null 2>&1
  924. if [ "$mkfs" -eq 1 ]; then
  925. mkswap $dev >$LOG 2>&1
  926. if [ $? -ne 0 ]; then
  927. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  928. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  929. DIE 1
  930. fi
  931. fi
  932. swapon $dev >$LOG 2>&1
  933. if [ $? -ne 0 ]; then
  934. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  935. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  936. DIE 1
  937. fi
  938. # Add entry for target fstab
  939. uuid=$(blkid -o value -s UUID "$dev")
  940. echo "UUID=$uuid none swap sw 0 0" >>$TARGET_FSTAB
  941. continue
  942. fi
  943. if [ "$mkfs" -eq 1 ]; then
  944. case "$fstype" in
  945. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  946. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  947. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  948. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  949. f2fs) MKFS="mkfs.f2fs"; modprobe f2fs >$LOG 2>&1;;
  950. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  951. xfs) MKFS="mkfs.xfs -f"; modprobe xfs >$LOG 2>&1;;
  952. esac
  953. TITLE="Check $LOG for details ..."
  954. INFOBOX "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  955. echo "Running $MKFS $dev..." >$LOG
  956. $MKFS $dev >$LOG 2>&1; rv=$?
  957. if [ $rv -ne 0 ]; then
  958. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  959. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  960. DIE 1
  961. fi
  962. fi
  963. # Mount rootfs the first one.
  964. [ "$mntpt" != "/" ] && continue
  965. mkdir -p $TARGETDIR
  966. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  967. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  968. if [ $? -ne 0 ]; then
  969. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  970. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  971. DIE 1
  972. fi
  973. # Add entry to target fstab
  974. uuid=$(blkid -o value -s UUID "$dev")
  975. if [ "$fstype" = "f2fs" ]; then
  976. fspassno=0
  977. else
  978. fspassno=1
  979. fi
  980. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  981. done
  982. # mount all filesystems in target rootfs
  983. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  984. set -- ${mnts}
  985. while [ $# -ne 0 ]; do
  986. dev=$2; fstype=$3; mntpt="$5"
  987. shift 6
  988. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  989. mkdir -p ${TARGETDIR}${mntpt}
  990. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  991. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  992. if [ $? -ne 0 ]; then
  993. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  994. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  995. DIE
  996. fi
  997. # Add entry to target fstab
  998. uuid=$(blkid -o value -s UUID "$dev")
  999. echo "UUID=$uuid $mntpt $fstype defaults 0 2" >>$TARGET_FSTAB
  1000. done
  1001. }
  1002. mount_filesystems() {
  1003. for f in sys proc dev; do
  1004. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  1005. echo "Mounting $TARGETDIR/$f..." >$LOG
  1006. mount --bind /$f $TARGETDIR/$f >$LOG 2>&1
  1007. done
  1008. }
  1009. umount_filesystems() {
  1010. local f
  1011. for f in sys/fs/fuse/connections sys proc dev; do
  1012. echo "Unmounting $TARGETDIR/$f..." >$LOG
  1013. umount $TARGETDIR/$f >$LOG 2>&1
  1014. done
  1015. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  1016. set -- ${mnts}
  1017. while [ $# -ne 0 ]; do
  1018. local dev=$2; local fstype=$3; local mntpt=$5
  1019. shift 6
  1020. if [ "$fstype" = "swap" ]; then
  1021. echo "Disabling swap space on $dev..." >$LOG
  1022. swapoff $dev >$LOG 2>&1
  1023. continue
  1024. fi
  1025. if [ "$mntpt" != "/" ]; then
  1026. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  1027. umount $TARGETDIR/$mntpt >$LOG 2>&1
  1028. fi
  1029. done
  1030. echo "Unmounting $TARGETDIR..." >$LOG
  1031. umount $TARGETDIR >$LOG 2>&1
  1032. }
  1033. log_and_count() {
  1034. local progress whole tenth
  1035. while read line; do
  1036. echo "$line" >$LOG
  1037. copy_count=$((copy_count + 1))
  1038. progress=$((1000 * copy_count / copy_total))
  1039. if [ "$progress" != "$copy_progress" ]; then
  1040. whole=$((progress / 10))
  1041. tenth=$((progress % 10))
  1042. printf "Progress: %d.%d%% (%d of %d files)\n" $whole $tenth $copy_count $copy_total
  1043. copy_progress=$progress
  1044. fi
  1045. done
  1046. }
  1047. copy_rootfs() {
  1048. local tar_in="--create --one-file-system --xattrs"
  1049. TITLE="Check $LOG for details ..."
  1050. INFOBOX "Counting files, please be patient ..." 4 60
  1051. copy_total=$(tar ${tar_in} -v -f /dev/null / 2>/dev/null | wc -l)
  1052. export copy_total copy_count=0 copy_progress=
  1053. clear
  1054. tar ${tar_in} -f - / 2>/dev/null | \
  1055. tar --extract --xattrs --xattrs-include='*' --preserve-permissions -v -f - -C $TARGETDIR | \
  1056. log_and_count | \
  1057. DIALOG --title "${TITLE}" \
  1058. --progressbox "Copying live image to target rootfs." 5 60
  1059. if [ $? -ne 0 ]; then
  1060. DIE 1
  1061. fi
  1062. unset copy_total copy_count copy_percent
  1063. }
  1064. install_packages() {
  1065. local _grub= _syspkg=
  1066. if [ -n "$EFI_SYSTEM" ]; then
  1067. if [ $EFI_FW_BITS -eq 32 ]; then
  1068. _grub="grub-i386-efi"
  1069. else
  1070. _grub="grub-x86_64-efi"
  1071. fi
  1072. else
  1073. _grub="grub"
  1074. fi
  1075. _syspkg="base-system"
  1076. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  1077. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  1078. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  1079. mkdir -p $TARGETDIR/boot/grub
  1080. _arch=$(xbps-uhelper arch)
  1081. stdbuf -oL env XBPS_ARCH=${_arch} \
  1082. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  1083. DIALOG --title "Installing base system packages..." \
  1084. --programbox 24 80
  1085. if [ $? -ne 0 ]; then
  1086. DIE 1
  1087. fi
  1088. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  1089. chroot $TARGETDIR xbps-reconfigure -a
  1090. }
  1091. enable_dhcpd() {
  1092. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  1093. }
  1094. menu_install() {
  1095. # Don't continue if filesystems are not ready.
  1096. validate_filesystems || return 1
  1097. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  1098. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  1099. if [ -z "$FILESYSTEMS_DONE" ]; then
  1100. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  1101. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1102. return 1
  1103. elif [ -z "$ROOTPASSWORD_DONE" ]; then
  1104. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  1105. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1106. return 1
  1107. elif [ -z "$BOOTLOADER_DONE" ]; then
  1108. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  1109. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  1110. return 1
  1111. fi
  1112. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  1113. ${BOLD}${TARGETFS}${RESET}\n
  1114. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  1115. filesystems.${RESET}\n\n
  1116. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  1117. unset TARGETFS
  1118. # Create and mount filesystems
  1119. create_filesystems
  1120. # If source not set use defaults.
  1121. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  1122. copy_rootfs
  1123. . /etc/default/live.conf
  1124. rm -f $TARGETDIR/etc/motd
  1125. rm -f $TARGETDIR/etc/issue
  1126. rm -f $TARGETDIR/usr/sbin/void-installer
  1127. # Remove live user.
  1128. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  1129. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  1130. sed -i -e "/$USERNAME ALL=.*/d" $TARGETDIR/etc/sudoers
  1131. TITLE="Check $LOG for details ..."
  1132. INFOBOX "Rebuilding initramfs for target ..." 4 60
  1133. echo "Rebuilding initramfs for target ..." >$LOG
  1134. # mount required fs
  1135. mount_filesystems
  1136. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  1137. INFOBOX "Removing temporary packages from target ..." 4 60
  1138. echo "Removing temporary packages from target ..." >$LOG
  1139. xbps-remove -r $TARGETDIR -Ry dialog >>$LOG 2>&1
  1140. rmdir $TARGETDIR/mnt/target
  1141. else
  1142. # mount required fs
  1143. mount_filesystems
  1144. # network install, use packages.
  1145. install_packages
  1146. fi
  1147. INFOBOX "Applying installer settings..." 4 60
  1148. # copy target fstab.
  1149. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  1150. # Mount /tmp as tmpfs.
  1151. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  1152. # set up keymap, locale, timezone, hostname, root passwd and user account.
  1153. set_keymap
  1154. set_locale
  1155. set_timezone
  1156. set_hostname
  1157. set_rootpassword
  1158. set_useraccount
  1159. # Copy /etc/skel files for root.
  1160. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  1161. # network settings for target
  1162. if [ -n "$NETWORK_DONE" ]; then
  1163. local net="$(get_option NETWORK)"
  1164. set -- ${net}
  1165. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  1166. if [ -z "$_type" ]; then
  1167. # network type empty??!!!
  1168. :
  1169. elif [ "$_type" = "dhcp" ]; then
  1170. if [ -f /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf ]; then
  1171. cp /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf $TARGETDIR/etc/wpa_supplicant
  1172. ln -sf /etc/sv/dhcpcd-${_dev} $TARGETDIR/etc/runit/runsvdir/default/dhcpcd-${_dev}
  1173. else
  1174. enable_dhcpd
  1175. fi
  1176. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  1177. # static IP through dhcpcd.
  1178. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig
  1179. echo "# Static IP configuration set by the void-installer for $_dev." \
  1180. >$TARGETDIR/etc/dhcpcd.conf
  1181. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  1182. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  1183. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  1184. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  1185. enable_dhcpd
  1186. fi
  1187. fi
  1188. if [ -f $TARGETDIR/etc/sudoers ]; then
  1189. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" ]; then
  1190. # enable sudo for primary user USERLOGIN
  1191. echo "# Enable sudo for login '$(get_option USERLOGIN)'" >> $TARGETDIR/etc/sudoers
  1192. echo "$(get_option USERLOGIN) ALL=(ALL) ALL" >> $TARGETDIR/etc/sudoers
  1193. else
  1194. # enable sudoers entry for members of group wheel for primary user
  1195. sed -i $TARGETDIR/etc/sudoers \
  1196. -e "s;#.*%wheel ALL=(ALL) ALL;%wheel ALL=(ALL) ALL;"
  1197. fi
  1198. fi
  1199. # enable text console for grub if chosen
  1200. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  1201. sed -i $TARGETDIR/etc/default/grub \
  1202. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  1203. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  1204. fi
  1205. # install bootloader.
  1206. set_bootloader
  1207. sync && sync && sync
  1208. # unmount all filesystems.
  1209. umount_filesystems
  1210. # installed successfully.
  1211. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  1212. Do you want to reboot the system?" ${YESNOSIZE}
  1213. if [ $? -eq 0 ]; then
  1214. shutdown -r now
  1215. else
  1216. return
  1217. fi
  1218. }
  1219. menu_source() {
  1220. local src=
  1221. DIALOG --title " Select installation source " \
  1222. --menu "$MENULABEL" 8 70 0 \
  1223. "Local" "Packages from ISO image" \
  1224. "Network" "Packages from official remote reposity"
  1225. case "$(cat $ANSWER)" in
  1226. "Local") src="local";;
  1227. "Network") src="net";
  1228. if [ -z "$NETWORK_DONE" ]; then
  1229. menu_network;
  1230. fi;;
  1231. *) return 1;;
  1232. esac
  1233. SOURCE_DONE=1
  1234. set_option SOURCE $src
  1235. }
  1236. menu() {
  1237. if [ -z "$DEFITEM" ]; then
  1238. DEFITEM="Keyboard"
  1239. fi
  1240. DIALOG --default-item $DEFITEM \
  1241. --extra-button --extra-label "Settings" \
  1242. --title " Void Linux installation menu " \
  1243. --menu "$MENULABEL" 10 70 0 \
  1244. "Keyboard" "Set system keyboard" \
  1245. "Network" "Set up the network" \
  1246. "Source" "Set source installation" \
  1247. "Hostname" "Set system hostname" \
  1248. "Locale" "Set system locale" \
  1249. "Timezone" "Set system time zone" \
  1250. "RootPassword" "Set system root password" \
  1251. "UserAccount" "Set primary user name and password" \
  1252. "BootLoader" "Set disk to install bootloader" \
  1253. "Partition" "Partition disk(s)" \
  1254. "Filesystems" "Configure filesystems and mount points" \
  1255. "Install" "Start installation with saved settings" \
  1256. "Exit" "Exit installation"
  1257. if [ $? -eq 3 ]; then
  1258. # Show settings
  1259. cp $CONF_FILE /tmp/conf_hidden.$$;
  1260. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1261. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1262. rm /tmp/conf_hidden.$$
  1263. return
  1264. fi
  1265. case $(cat $ANSWER) in
  1266. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1267. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1268. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1269. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="Locale";;
  1270. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1271. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1272. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1273. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1274. && DEFITEM="BootLoader";;
  1275. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1276. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1277. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1278. "Install") menu_install;;
  1279. "Exit") DIE;;
  1280. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1281. esac
  1282. }
  1283. if [ ! -x /bin/dialog ]; then
  1284. echo "ERROR: missing dialog command, exiting..."
  1285. exit 1
  1286. fi
  1287. if [ "$(id -u)" != "0" ]; then
  1288. echo "void-installer must run as root" 1>&2
  1289. exit 1
  1290. fi
  1291. #
  1292. # main()
  1293. #
  1294. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1295. Welcome to the Void Linux installation. A simple and minimal \
  1296. Linux distribution made from scratch and built from the source package tree \
  1297. available for XBPS, a new alternative binary package system.\n\n
  1298. The installation should be pretty straightforward. If you are in trouble \
  1299. please join us at ${BOLD}#voidlinux${RESET} on ${BOLD}irc.freenode.org${RESET}.\n\n
  1300. ${BOLD}http://www.voidlinux.eu${RESET}\n\n" 16 80
  1301. while true; do
  1302. menu
  1303. done
  1304. exit 0
  1305. # vim: set ts=4 sw=4 et: