installer.sh.in 49 KB

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