installer.sh.in 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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. fi
  59. # dialog colors
  60. BLACK="\Z0"
  61. RED="\Z1"
  62. GREEN="\Z2"
  63. YELLOW="\Z3"
  64. BLUE="\Z4"
  65. MAGENTA="\Z5"
  66. CYAN="\Z6"
  67. WHITE="\Z7"
  68. BOLD="\Zb"
  69. REVERSE="\Zr"
  70. UNDERLINE="\Zu"
  71. RESET="\Zn"
  72. # Properties shared per widget.
  73. MENULABEL="${BOLD}Use UP and DOWN keys to navigate \
  74. menus. Use TAB to switch between buttons and ENTER to select.${RESET}"
  75. MENUSIZE="14 60 0"
  76. INPUTSIZE="8 60"
  77. MSGBOXSIZE="8 70"
  78. YESNOSIZE="$INPUTSIZE"
  79. WIDGET_SIZE="10 70"
  80. DIALOG() {
  81. rm -f $ANSWER
  82. dialog --colors --keep-tite --no-shadow --no-mouse \
  83. --backtitle "${BOLD}${WHITE}Void Linux installation -- http://www.voidlinux.eu/ (@@MKLIVE_VERSION@@)${RESET}" \
  84. --cancel-label "Back" --aspect 20 "$@" 2>$ANSWER
  85. return $?
  86. }
  87. DIE() {
  88. rval=$1
  89. [ -z "$rval" ] && rval=0
  90. clear
  91. rm -f $ANSWER $TARGET_FSTAB
  92. # reenable printk
  93. if [ -w /proc/sys/kernel/printk ]; then
  94. echo 4 >/proc/sys/kernel/printk
  95. fi
  96. umount_filesystems
  97. exit $rval
  98. }
  99. set_option() {
  100. if grep -Eq "^${1}.*" $CONF_FILE; then
  101. sed -i -e "/^${1}.*/d" $CONF_FILE
  102. fi
  103. echo "${1} ${2}" >>$CONF_FILE
  104. }
  105. get_option() {
  106. echo $(grep -E "^${1}.*" $CONF_FILE|sed -e "s|${1}||")
  107. }
  108. show_disks() {
  109. local dev size sectorsize gbytes
  110. # IDE
  111. for dev in $(ls /sys/block|grep -E '^hd'); do
  112. if [ "$(cat /sys/block/$dev/device/media)" = "disk" ]; then
  113. # Find out nr sectors and bytes per sector;
  114. echo "/dev/$dev"
  115. size=$(cat /sys/block/$dev/size)
  116. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  117. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  118. echo "size:${gbytes}GB;sector_size:$sectorsize"
  119. fi
  120. done
  121. # SATA/SCSI and Virtual disks (virtio)
  122. for dev in $(ls /sys/block|grep -E '^([sv]|xv)d|mmcblk'); do
  123. echo "/dev/$dev"
  124. size=$(cat /sys/block/$dev/size)
  125. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  126. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  127. echo "size:${gbytes}GB;sector_size:$sectorsize"
  128. done
  129. # cciss(4) devices
  130. for dev in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]$'); do
  131. echo "/dev/cciss/$dev"
  132. size=$(cat /sys/block/cciss\!$dev/size)
  133. sectorsize=$(cat /sys/block/cciss\!$dev/queue/hw_sector_size)
  134. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  135. echo "size:${gbytes}GB;sector_size:$sectorsize"
  136. done
  137. }
  138. show_partitions() {
  139. local dev fstype fssize p part
  140. set -- $(show_disks)
  141. while [ $# -ne 0 ]; do
  142. disk=$(basename $1)
  143. shift 2
  144. # ATA/SCSI/SATA
  145. for p in /sys/block/$disk/$disk*; do
  146. if [ -d $p ]; then
  147. part=$(basename $p)
  148. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}'|head -1)
  149. [ "$fstype" = "iso9660" ] && continue
  150. [ "$fstype" = "crypto_LUKS" ] && continue
  151. [ "$fstype" = "LVM2_member" ] && continue
  152. fssize=$(lsblk -nr /dev/$part|awk '{print $4}'|head -1)
  153. echo "/dev/$part"
  154. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  155. fi
  156. done
  157. done
  158. # Software raid (md)
  159. for p in $(ls -d /dev/md* 2>/dev/null|grep '[0-9]'); do
  160. part=$(basename $p)
  161. if cat /proc/mdstat|grep -qw $part; then
  162. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  163. [ "$fstype" = "crypto_LUKS" ] && continue
  164. [ "$fstype" = "LVM2_member" ] && continue
  165. fssize=$(lsblk -nr /dev/$part|awk '{print $4}')
  166. echo "$p"
  167. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  168. fi
  169. done
  170. # cciss(4) devices
  171. for part in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]p[0-9]+'); do
  172. fstype=$(lsblk -nfr /dev/cciss/$part|awk '{print $2}')
  173. [ "$fstype" = "crypto_LUKS" ] && continue
  174. [ "$fstype" = "LVM2_member" ] && continue
  175. fssize=$(lsblk -nr /dev/cciss/$part|awk '{print $4}')
  176. echo "/dev/cciss/$part"
  177. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  178. done
  179. if [ -e /sbin/lvs ]; then
  180. # LVM
  181. lvs --noheadings|while read lvname vgname perms size; do
  182. echo "/dev/mapper/${vgname}-${lvname}"
  183. echo "size:${size};fstype:lvm"
  184. done
  185. fi
  186. }
  187. menu_filesystems() {
  188. local dev fstype fssize mntpoint reformat
  189. while true; do
  190. DIALOG --title " Select the partition to edit " --menu "$MENULABEL" \
  191. ${MENUSIZE} $(show_partitions)
  192. [ $? -ne 0 ] && return
  193. dev=$(cat $ANSWER)
  194. DIALOG --title " Select the filesystem type for $dev " \
  195. --menu "$MENULABEL" ${MENUSIZE} \
  196. "btrfs" "Oracle's Btrfs" \
  197. "ext2" "Linux ext2 (no journaling)" \
  198. "ext3" "Linux ext3 (journal)" \
  199. "ext4" "Linux ext4 (journal)" \
  200. "f2fs" "Flash-Friendly Filesystem" \
  201. "swap" "Linux swap" \
  202. "vfat" "FAT32" \
  203. "xfs" "SGI's XFS"
  204. if [ $? -eq 0 ]; then
  205. fstype=$(cat $ANSWER)
  206. else
  207. continue
  208. fi
  209. if [ "$fstype" != "swap" ]; then
  210. DIALOG --inputbox "Please specify the mount point for $dev:" ${INPUTSIZE}
  211. if [ $? -eq 0 ]; then
  212. mntpoint=$(cat $ANSWER)
  213. elif [ $? -eq 1 ]; then
  214. continue
  215. fi
  216. else
  217. mntpoint=swap
  218. fi
  219. DIALOG --yesno "Do you want to create a new filesystem on $dev?" ${YESNOSIZE}
  220. if [ $? -eq 0 ]; then
  221. reformat=1
  222. elif [ $? -eq 1 ]; then
  223. reformat=0
  224. else
  225. continue
  226. fi
  227. fssize=$(lsblk -nr $dev|awk '{print $4}')
  228. set -- "$fstype" "$fssize" "$mntpoint" "$reformat"
  229. if [ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ]; then
  230. local bdev=$(basename $dev)
  231. local ddev=$(basename $(dirname $dev))
  232. if [ "$ddev" != "dev" ]; then
  233. sed -i -e "/^MOUNTPOINT \/dev\/${ddev}\/${bdev}.*/d" $CONF_FILE
  234. else
  235. sed -i -e "/^MOUNTPOINT \/dev\/${bdev}.*/d" $CONF_FILE
  236. fi
  237. echo "MOUNTPOINT $dev $1 $2 $3 $4" >>$CONF_FILE
  238. fi
  239. done
  240. }
  241. menu_partitions() {
  242. DIALOG --title " Select the disk to partition " \
  243. --menu "$MENULABEL" ${MENUSIZE} $(show_disks)
  244. if [ $? -eq 0 ]; then
  245. local device=$(cat $ANSWER)
  246. DIALOG --title "Modify Partition Table on $device" --msgbox "\n
  247. ${BOLD}cfdisk will be executed in disk $device.${RESET}\n\n
  248. For BIOS systems, MBR or GPT partition tables are supported.\n
  249. To use GPT on PC BIOS systems an empty partition of 1MB must be added\n
  250. at the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n
  251. ${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n
  252. For EFI systems GPT is mandatory and a FAT32 partition with at least\n
  253. 100MB must be created with the TOGGLE \`boot', this will be used as\n
  254. EFI System Partition. This partition must have mountpoint as \`/boot/efi'.\n\n
  255. At least 1 partitions is required for the rootfs (/).\n
  256. For swap, RAM*2 must be really enough. For / 600MB are required.\n\n
  257. ${BOLD}WARNING: /usr is not supported as a separate partition.${RESET}\n
  258. ${RESET}\n" 18 80
  259. if [ $? -eq 0 ]; then
  260. while true; do
  261. clear; cfdisk $device; PARTITIONS_DONE=1
  262. break
  263. done
  264. else
  265. return
  266. fi
  267. fi
  268. }
  269. menu_keymap() {
  270. local _keymaps="$(find /usr/share/kbd/keymaps/ -type f -iname "*.map.gz" -printf "%f\n" | sed 's|.map.gz||g' | sort)"
  271. local _KEYMAPS=
  272. for f in ${_keymaps}; do
  273. _KEYMAPS="${_KEYMAPS} ${f} -"
  274. done
  275. while true; do
  276. DIALOG --title " Select your keymap " --menu "$MENULABEL" 14 70 14 ${_KEYMAPS}
  277. if [ $? -eq 0 ]; then
  278. set_option KEYMAP "$(cat $ANSWER)"
  279. loadkeys "$(cat $ANSWER)"
  280. KEYBOARD_DONE=1
  281. break
  282. else
  283. return
  284. fi
  285. done
  286. }
  287. set_keymap() {
  288. local KEYMAP=$(get_option KEYMAP)
  289. if [ -f /etc/vconsole.conf ]; then
  290. sed -i -e "s|KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/vconsole.conf
  291. else
  292. sed -i -e "s|#\?KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/rc.conf
  293. fi
  294. }
  295. menu_locale() {
  296. local _locales="$(grep -E '\.UTF-8' /etc/default/libc-locales|awk '{print $1}'|sed -e 's/^#//')"
  297. local _LOCALES=
  298. for f in ${_locales}; do
  299. _LOCALES="${_LOCALES} ${f} -"
  300. done
  301. while true; do
  302. DIALOG --title " Select your locale " --menu "$MENULABEL" 14 70 14 ${_LOCALES}
  303. if [ $? -eq 0 ]; then
  304. set_option LOCALE "$(cat $ANSWER)"
  305. LOCALE_DONE=1
  306. break
  307. else
  308. return
  309. fi
  310. done
  311. }
  312. set_locale() {
  313. if [ -f $TARGETDIR/etc/default/libc-locales ]; then
  314. local LOCALE=$(get_option LOCALE)
  315. sed -i -e "s|LANG=.*|LANG=$LOCALE|g" $TARGETDIR/etc/locale.conf
  316. # Uncomment locale from /etc/default/libc-locales and regenerate it.
  317. sed -e "/${LOCALE}/s/^\#//" -i $TARGETDIR/etc/default/libc-locales
  318. echo "Running xbps-reconfigure -f glibc-locales ..." >$LOG
  319. chroot $TARGETDIR xbps-reconfigure -f glibc-locales >$LOG 2>&1
  320. fi
  321. }
  322. menu_timezone() {
  323. local _tzones="$(cd /usr/share/zoneinfo; find Africa/ America/ Antarctica/ Arctic/ Asia/ Atlantic/ Australia/ Europe/ Indian/ Pacific/ posix/ -type f | sort)"
  324. local _TIMEZONES=
  325. for f in ${_tzones}; do
  326. _TIMEZONES="${_TIMEZONES} ${f} -"
  327. done
  328. while true; do
  329. DIALOG --title " Select your timezone " --menu "$MENULABEL" 14 70 14 ${_TIMEZONES}
  330. if [ $? -eq 0 ]; then
  331. set_option TIMEZONE "$(cat $ANSWER)"
  332. TIMEZONE_DONE=1
  333. break
  334. else
  335. return
  336. fi
  337. done
  338. }
  339. set_timezone() {
  340. local TIMEZONE="$(get_option TIMEZONE)"
  341. sed -i -e "s|#TIMEZONE=.*|TIMEZONE=$TIMEZONE|g" $TARGETDIR/etc/rc.conf
  342. }
  343. menu_hostname() {
  344. while true; do
  345. DIALOG --inputbox "Set the machine hostname:" ${INPUTSIZE}
  346. if [ $? -eq 0 ]; then
  347. set_option HOSTNAME "$(cat $ANSWER)"
  348. HOSTNAME_DONE=1
  349. break
  350. else
  351. return
  352. fi
  353. done
  354. }
  355. set_hostname() {
  356. echo $(get_option HOSTNAME) > $TARGETDIR/etc/hostname
  357. }
  358. menu_rootpassword() {
  359. local _firstpass _secondpass _desc
  360. while true; do
  361. if [ -n "${_firstpass}" ]; then
  362. _desc="Enter the root password again"
  363. else
  364. _desc="Enter the root password"
  365. fi
  366. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  367. if [ $? -eq 0 ]; then
  368. if [ -z "${_firstpass}" ]; then
  369. _firstpass="$(cat $ANSWER)"
  370. else
  371. _secondpass="$(cat $ANSWER)"
  372. fi
  373. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  374. if [ "${_firstpass}" != "${_secondpass}" ]; then
  375. DIALOG --infobox "Passwords do not match! Please enter again." 6 80
  376. unset _firstpass _secondpass
  377. sleep 2 && continue
  378. fi
  379. set_option ROOTPASSWORD "${_firstpass}"
  380. ROOTPASSWORD_DONE=1
  381. break
  382. fi
  383. else
  384. return
  385. fi
  386. done
  387. }
  388. set_rootpassword() {
  389. echo "root:$(get_option ROOTPASSWORD)" | chpasswd -R $TARGETDIR -c SHA512
  390. }
  391. menu_useraccount() {
  392. local _firstpass _secondpass _desc
  393. local _groups _status _group _checklist
  394. while true; do
  395. DIALOG --inputbox "Enter a primary login name:" ${INPUTSIZE} "void"
  396. if [ $? -eq 0 ]; then
  397. set_option USERLOGIN "$(cat $ANSWER)"
  398. USERLOGIN_DONE=1
  399. break
  400. else
  401. return
  402. fi
  403. done
  404. while true; do
  405. DIALOG --inputbox "Enter a user name for login '$(get_option USERLOGIN)' :" \
  406. ${INPUTSIZE} "$(get_option USERLOGIN)"
  407. if [ $? -eq 0 ]; then
  408. set_option USERNAME "$(cat $ANSWER)"
  409. USERNAME_DONE=1
  410. break
  411. else
  412. return
  413. fi
  414. done
  415. while true; do
  416. if [ -n "${_firstpass}" ]; then
  417. _desc="Enter the password for login '$(get_option USERLOGIN)' again"
  418. else
  419. _desc="Enter the password for login '$(get_option USERLOGIN)'"
  420. fi
  421. DIALOG --insecure --passwordbox "${_desc}" ${INPUTSIZE}
  422. if [ $? -eq 0 ]; then
  423. if [ -z "${_firstpass}" ]; then
  424. _firstpass="$(cat $ANSWER)"
  425. else
  426. _secondpass="$(cat $ANSWER)"
  427. fi
  428. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  429. if [ "${_firstpass}" != "${_secondpass}" ]; then
  430. DIALOG --infobox "Passwords do not match! Please enter again." 6 80
  431. unset _firstpass _secondpass
  432. sleep 2 && continue
  433. fi
  434. set_option USERPASSWORD "${_firstpass}"
  435. USERPASSWORD_DONE=1
  436. break
  437. fi
  438. else
  439. return
  440. fi
  441. done
  442. _groups="wheel,audio,video,floppy,cdrom,optical,kvm,xbuilder"
  443. while true; do
  444. _desc="Select group membership for login '$(get_option USERLOGIN)':"
  445. for _group in $(cat /etc/group); do
  446. _gid="$(echo ${_group} | cut -d: -f3)"
  447. _group="$(echo ${_group} | cut -d: -f1)"
  448. _status="$(echo ${_groups} | grep -w ${_group})"
  449. if [ -z "${_status}" ]; then
  450. _status=off
  451. else
  452. _status=on
  453. fi
  454. if [ -z "${_checklist}" ]; then
  455. _checklist="${_group} ${_group}:${_gid} ${_status}"
  456. else
  457. _checklist="${_checklist} ${_group} ${_group}:${_gid} ${_status}"
  458. fi
  459. done
  460. DIALOG --no-tags --checklist "${_desc}" 20 60 18 ${_checklist}
  461. if [ $? -eq 0 ]; then
  462. set_option USERGROUPS $(cat $ANSWER | sed -e's| |,|g')
  463. USERGROUPS_DONE=1
  464. break
  465. else
  466. return
  467. fi
  468. done
  469. }
  470. set_useraccount() {
  471. [ -z "$USERLOGIN_DONE" ] && return
  472. [ -z "$USERPASSWORD_DONE" ] && return
  473. [ -z "$USERNAME_DONE" ] && return
  474. [ -z "$USERGROUPS_DONE" ] && return
  475. useradd -R $TARGETDIR -m -G $(get_option USERGROUPS) \
  476. -c "$(get_option USERNAME)" $(get_option USERLOGIN)
  477. echo "$(get_option USERLOGIN):$(get_option USERPASSWORD)" | \
  478. chpasswd -R $TARGETDIR -c SHA512
  479. }
  480. menu_bootloader() {
  481. while true; do
  482. DIALOG --title " Select the disk to install the bootloader" \
  483. --menu "$MENULABEL" ${MENUSIZE} $(show_disks) none "Manage bootloader otherwise"
  484. if [ $? -eq 0 ]; then
  485. set_option BOOTLOADER "$(cat $ANSWER)"
  486. BOOTLOADER_DONE=1
  487. break
  488. else
  489. return
  490. fi
  491. done
  492. while true; do
  493. DIALOG --yesno "Use a graphical terminal for the boot loader?" ${YESNOSIZE}
  494. if [ $? -eq 0 ]; then
  495. set_option TEXTCONSOLE 0
  496. break
  497. elif [ $? -eq 1 ]; then
  498. set_option TEXTCONSOLE 1
  499. break
  500. else
  501. return
  502. fi
  503. done
  504. }
  505. set_bootloader() {
  506. local dev=$(get_option BOOTLOADER) grub_args=
  507. if [ "$dev" = "none" ]; then return; fi
  508. # Check if it's an EFI system via efivars module.
  509. if [ -n "$EFI_SYSTEM" ]; then
  510. grub_args="--target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=void_grub --recheck"
  511. fi
  512. echo "Running grub-install $grub_args $dev..." >$LOG
  513. chroot $TARGETDIR grub-install $grub_args $dev >$LOG 2>&1
  514. if [ $? -ne 0 ]; then
  515. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  516. failed to install GRUB to $dev!\nCheck $LOG for errors." ${MSGBOXSIZE}
  517. DIE 1
  518. fi
  519. echo "Running grub-mkconfig on $TARGETDIR..." >$LOG
  520. chroot $TARGETDIR grub-mkconfig -o /boot/grub/grub.cfg >$LOG 2>&1
  521. if [ $? -ne 0 ]; then
  522. DIALOG --msgbox "${BOLD}${RED}ERROR${RESET}: \
  523. failed to run grub-mkconfig!\nCheck $LOG for errors." ${MSGBOXSIZE}
  524. DIE 1
  525. fi
  526. }
  527. test_network() {
  528. rm -f xtraeme.asc && \
  529. xbps-uhelper fetch http://repo.voidlinux.eu/live/xtraeme.asc >$LOG 2>&1
  530. if [ $? -eq 0 ]; then
  531. DIALOG --msgbox "Network is working properly!" ${MSGBOXSIZE}
  532. NETWORK_DONE=1
  533. return 1
  534. fi
  535. DIALOG --msgbox "Network is unaccessible, please setup it properly." ${MSGBOXSIZE}
  536. }
  537. configure_wifi() {
  538. local dev="$1" ssid enc pass _wpasupconf=/etc/wpa_supplicant/wpa_supplicant.conf
  539. DIALOG --form "Wireless configuration for ${dev}\n(encryption type: wep or wpa)" 0 0 0 \
  540. "SSID:" 1 1 "" 1 16 30 0 \
  541. "Encryption:" 2 1 "" 2 16 4 3 \
  542. "Password:" 3 1 "" 3 16 50 0 || return 1
  543. set -- $(cat $ANSWER)
  544. ssid="$1"; enc="$2"; pass="$3";
  545. if [ -z "$ssid" ]; then
  546. DIALOG --msgbox "Invalid SSID." ${MSGBOXSIZE}
  547. return 1
  548. elif [ -z "$enc" -o "$enc" != "wep" -a "$enc" != "wpa" ]; then
  549. DIALOG --msgbox "Invalid encryption type (possible values: wep or wpa)." ${MSXBOXSIZE}
  550. return 1
  551. elif [ -z "$pass" ]; then
  552. DIALOG --msgbox "Invalid AP password." ${MSGBOXSIZE}
  553. fi
  554. rm -f ${_wpasupconf%.conf}-${dev}.conf
  555. cp -f ${_wpasupconf} ${_wpasupconf%.conf}-${dev}.conf
  556. if [ "$enc" = "wep" ]; then
  557. echo "network={" >> ${_wpasupconf%.conf}-${dev}.conf
  558. echo " ssid=\"$ssid\"" >> ${_wpasupconf%.conf}-${dev}.conf
  559. echo " wep_key0=\"$pass\"" >> ${_wpasupconf%.conf}-${dev}.conf
  560. echo " wep_tx_keyidx=0" >> ${_wpasupconf%.conf}-${dev}.conf
  561. echo " auth_alg=SHARED" >> ${_wpasupconf%.conf}-${dev}.conf
  562. echo "}" >> ${_wpasupconf%.conf}-${dev}.conf
  563. else
  564. wpa_passphrase "$ssid" "$pass" >> ${_wpasupconf%.conf}-${dev}.conf
  565. fi
  566. configure_net_dhcp $dev
  567. return $?
  568. }
  569. configure_net() {
  570. local dev="$1" rval
  571. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  572. rval=$?
  573. if [ $rval -eq 0 ]; then
  574. configure_net_dhcp $dev
  575. elif [ $rval -eq 1 ]; then
  576. configure_net_static $dev
  577. fi
  578. }
  579. iface_setup() {
  580. ip addr show dev $1|grep -q 'inet '
  581. return $?
  582. }
  583. configure_net_dhcp() {
  584. local dev="$1"
  585. iface_setup $dev
  586. if [ $? -eq 1 ]; then
  587. dhcpcd -t 10 -w -4 -L $dev -e "wpa_supplicant_conf=/etc/wpa_supplicant/wpa_supplicant-${dev}.conf" 2>&1 | tee $LOG | \
  588. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  589. if [ $? -ne 0 ]; then
  590. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run dhcpcd. See $LOG for details." ${MSGBOXSIZE}
  591. return 1
  592. fi
  593. iface_setup $dev
  594. if [ $? -eq 1 ]; then
  595. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  596. return 1
  597. fi
  598. fi
  599. test_network
  600. if [ $? -eq 1 ]; then
  601. set_option NETWORK "${dev} dhcp"
  602. fi
  603. }
  604. configure_net_static() {
  605. local ip gw dns1 dns2 dev=$1
  606. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  607. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  608. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  609. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  610. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  611. set -- $(cat $ANSWER)
  612. ip=$1; gw=$2; dns1=$3; dns2=$4
  613. echo "running: ip link set dev $dev up" >$LOG
  614. ip link set dev $dev up >$LOG 2>&1
  615. if [ $? -ne 0 ]; then
  616. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  617. return 1
  618. fi
  619. echo "running: ip addr add $ip dev $dev"
  620. ip addr add $ip dev $dev >$LOG 2>&1
  621. if [ $? -ne 0 ]; then
  622. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  623. return 1
  624. fi
  625. ip route add $gw dev $dev >$LOG 2>&1
  626. if [ $? -ne 0 ]; then
  627. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  628. return 1
  629. fi
  630. echo "nameserver $dns1" >/etc/resolv.conf
  631. echo "nameserver $dns2" >>/etc/resolv.conf
  632. test_network
  633. if [ $? -eq 1 ]; then
  634. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  635. fi
  636. }
  637. menu_network() {
  638. local dev addr f DEVICES
  639. for f in $(ls /sys/class/net); do
  640. [ "$f" = "lo" ] && continue
  641. addr=$(cat /sys/class/net/$f/address)
  642. DEVICES="$DEVICES $f $addr"
  643. done
  644. DIALOG --title " Select the network interface to configure " \
  645. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  646. if [ $? -eq 0 ]; then
  647. dev=$(cat $ANSWER)
  648. if $(echo $dev|egrep -q "^wl.*" 2>/dev/null); then
  649. configure_wifi $dev
  650. else
  651. configure_net $dev
  652. fi
  653. fi
  654. }
  655. validate_filesystems() {
  656. local mnts dev size fstype mntpt mkfs rootfound fmt
  657. local usrfound efi_system_partition
  658. unset TARGETFS
  659. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  660. set -- ${mnts}
  661. while [ $# -ne 0 ]; do
  662. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  663. shift 6
  664. if [ "$mntpt" = "/" ]; then
  665. rootfound=1
  666. elif [ "$mntpt" = "/usr" ]; then
  667. usrfound=1
  668. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  669. efi_system_partition=1
  670. fi
  671. if [ "$mkfs" -eq 1 ]; then
  672. fmt="NEW FILESYSTEM: "
  673. fi
  674. if [ -z "$TARGETFS" ]; then
  675. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  676. else
  677. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  678. fi
  679. done
  680. if [ -z "$rootfound" ]; then
  681. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  682. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  683. return 1
  684. elif [ -n "$usrfound" ]; then
  685. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  686. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  687. return 1
  688. elif [ -n "$EFI_SYSTEM" -a -z "$efi_system_partition" ]; then
  689. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  690. The EFI System Partition has not yet been configured, please create it\n
  691. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  692. fi
  693. FILESYSTEMS_DONE=1
  694. }
  695. create_filesystems() {
  696. local mnts dev mntpt fstype fspassno mkfs size rv uuid
  697. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  698. set -- ${mnts}
  699. while [ $# -ne 0 ]; do
  700. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  701. shift 6
  702. # swap partitions
  703. if [ "$fstype" = "swap" ]; then
  704. swapoff $dev >/dev/null 2>&1
  705. if [ "$mkfs" -eq 1 ]; then
  706. mkswap $dev >$LOG 2>&1
  707. if [ $? -ne 0 ]; then
  708. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  709. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  710. DIE 1
  711. fi
  712. fi
  713. swapon $dev >$LOG 2>&1
  714. if [ $? -ne 0 ]; then
  715. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  716. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  717. DIE 1
  718. fi
  719. # Add entry for target fstab
  720. uuid=$(blkid -o value -s UUID "$dev")
  721. echo "UUID=$uuid none swap sw 0 0" >>$TARGET_FSTAB
  722. continue
  723. fi
  724. if [ "$mkfs" -eq 1 ]; then
  725. case "$fstype" in
  726. btrfs) MKFS="mkfs.btrfs -f"; modprobe btrfs >$LOG 2>&1;;
  727. ext2) MKFS="mke2fs -F"; modprobe ext2 >$LOG 2>&1;;
  728. ext3) MKFS="mke2fs -F -j"; modprobe ext3 >$LOG 2>&1;;
  729. ext4) MKFS="mke2fs -F -t ext4"; modprobe ext4 >$LOG 2>&1;;
  730. f2fs) MKFS="mkfs.f2fs"; modprobe f2fs >$LOG 2>&1;;
  731. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  732. xfs) MKFS="mkfs.xfs -f"; modprobe xfs >$LOG 2>&1;;
  733. esac
  734. DIALOG --infobox "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  735. echo "Running $MKFS $dev..." >$LOG
  736. $MKFS $dev >$LOG 2>&1; rv=$?
  737. if [ $rv -ne 0 ]; then
  738. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  739. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  740. DIE 1
  741. fi
  742. fi
  743. # Mount rootfs the first one.
  744. [ "$mntpt" != "/" ] && continue
  745. mkdir -p $TARGETDIR
  746. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  747. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  748. if [ $? -ne 0 ]; then
  749. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  750. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  751. DIE 1
  752. fi
  753. # Add entry to target fstab
  754. uuid=$(blkid -o value -s UUID "$dev")
  755. if [ "$fstype" = "f2fs" ]; then
  756. fspassno=0
  757. else
  758. fspassno=1
  759. fi
  760. echo "UUID=$uuid $mntpt $fstype defaults 0 $fspassno" >>$TARGET_FSTAB
  761. done
  762. # mount all filesystems in target rootfs
  763. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  764. set -- ${mnts}
  765. while [ $# -ne 0 ]; do
  766. dev=$2; fstype=$3; mntpt="$5"
  767. shift 6
  768. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  769. mkdir -p ${TARGETDIR}${mntpt}
  770. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  771. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  772. if [ $? -ne 0 ]; then
  773. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  774. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  775. DIE
  776. fi
  777. # Add entry to target fstab
  778. uuid=$(blkid -o value -s UUID "$dev")
  779. echo "UUID=$uuid $mntpt $fstype defaults 0 2" >>$TARGET_FSTAB
  780. done
  781. }
  782. mount_filesystems() {
  783. for f in sys proc dev; do
  784. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  785. echo "Mounting $TARGETDIR/$f..." >$LOG
  786. mount --bind /$f $TARGETDIR/$f >$LOG 2>&1
  787. done
  788. }
  789. umount_filesystems() {
  790. local f
  791. for f in sys/fs/fuse/connections sys proc dev; do
  792. echo "Unmounting $TARGETDIR/$f..." >$LOG
  793. umount $TARGETDIR/$f >$LOG 2>&1
  794. done
  795. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  796. set -- ${mnts}
  797. while [ $# -ne 0 ]; do
  798. local dev=$2; local fstype=$3; local mntpt=$5
  799. shift 6
  800. if [ "$fstype" = "swap" ]; then
  801. echo "Disabling swap space on $dev..." >$LOG
  802. swapoff $dev >$LOG 2>&1
  803. continue
  804. fi
  805. if [ "$mntpt" != "/" ]; then
  806. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  807. umount $TARGETDIR/$mntpt >$LOG 2>&1
  808. fi
  809. done
  810. echo "Unmounting $TARGETDIR..." >$LOG
  811. umount $TARGETDIR >$LOG 2>&1
  812. }
  813. copy_rootfs() {
  814. DIALOG --title "Check $LOG for details" \
  815. --infobox "Copying live image to target rootfs, please wait ..." 4 60
  816. LANG=C cp -axvnu / $TARGETDIR >$LOG 2>&1
  817. if [ $? -ne 0 ]; then
  818. DIE 1
  819. fi
  820. }
  821. install_packages() {
  822. local _grub= _syspkg=
  823. if [ -n "$EFI_SYSTEM" ]; then
  824. _grub="grub-x86_64-efi"
  825. else
  826. _grub="grub"
  827. fi
  828. _syspkg="base-system"
  829. mkdir -p $TARGETDIR/var/db/xbps/keys $TARGETDIR/usr/share
  830. cp -a /usr/share/xbps.d $TARGETDIR/usr/share/
  831. cp /var/db/xbps/keys/*.plist $TARGETDIR/var/db/xbps/keys
  832. mkdir -p $TARGETDIR/boot/grub
  833. _arch=$(xbps-uhelper arch)
  834. stdbuf -oL env XBPS_ARCH=${_arch} \
  835. xbps-install -r $TARGETDIR -SyU ${_syspkg} ${_grub} 2>&1 | \
  836. DIALOG --title "Installing base system packages..." \
  837. --programbox 24 80
  838. if [ $? -ne 0 ]; then
  839. DIE 1
  840. fi
  841. xbps-reconfigure -r $TARGETDIR -f base-files >/dev/null 2>&1
  842. chroot $TARGETDIR xbps-reconfigure -a
  843. }
  844. enable_dhcpd() {
  845. ln -sf /etc/sv/dhcpcd $TARGETDIR/etc/runit/runsvdir/default/dhcpcd
  846. }
  847. menu_install() {
  848. # Don't continue if filesystems are not ready.
  849. validate_filesystems || return 1
  850. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  851. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  852. if [ -z "$FILESYSTEMS_DONE" ]; then
  853. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  854. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  855. return 1
  856. elif [ -z "$ROOTPASSWORD_DONE" ]; then
  857. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  858. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  859. return 1
  860. elif [ -z "$BOOTLOADER_DONE" ]; then
  861. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  862. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  863. return 1
  864. fi
  865. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  866. ${BOLD}${TARGETFS}${RESET}\n
  867. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  868. filesystems.${RESET}\n\n
  869. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  870. unset TARGETFS
  871. # Create and mount filesystems
  872. create_filesystems
  873. # If source not set use defaults.
  874. if [ "$(get_option SOURCE)" = "local" -o -z "$SOURCE_DONE" ]; then
  875. copy_rootfs
  876. . /etc/default/live.conf
  877. rm -f $TARGETDIR/etc/motd
  878. rm -f $TARGETDIR/etc/issue
  879. rm -f $TARGETDIR/usr/sbin/void-installer
  880. # Remove live user.
  881. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  882. chroot $TARGETDIR userdel -r $USERNAME >$LOG 2>&1
  883. sed -i -e "/$USERNAME ALL=.*/d" $TARGETDIR/etc/sudoers
  884. DIALOG --title "Check $LOG for details" \
  885. --infobox "Rebuilding initramfs for target ..." 4 60
  886. echo "Rebuilding initramfs for target ..." >$LOG
  887. # mount required fs
  888. mount_filesystems
  889. chroot $TARGETDIR dracut --no-hostonly --add-drivers "ahci" --force >>$LOG 2>&1
  890. DIALOG --title "Check $LOG for details" \
  891. --infobox "Removing temporary packages from target ..." 4 60
  892. echo "Removing temporary packages from target ..." >$LOG
  893. xbps-remove -r $TARGETDIR -Ry dialog >>$LOG 2>&1
  894. rmdir $TARGETDIR/mnt/target
  895. else
  896. # mount required fs
  897. mount_filesystems
  898. # network install, use packages.
  899. install_packages
  900. fi
  901. DIALOG --infobox "Applying installer settings..." 4 60
  902. # copy target fstab.
  903. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  904. # Mount /tmp as tmpfs.
  905. echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TARGETDIR/etc/fstab
  906. # set up keymap, locale, timezone, hostname, root passwd and user account.
  907. set_keymap
  908. set_locale
  909. set_timezone
  910. set_hostname
  911. set_rootpassword
  912. set_useraccount
  913. # Copy /etc/skel files for root.
  914. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  915. # network settings for target
  916. if [ -n "$NETWORK_DONE" ]; then
  917. local net="$(get_option NETWORK)"
  918. set -- ${net}
  919. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  920. if [ -z "$_type" ]; then
  921. # network type empty??!!!
  922. :
  923. elif [ "$_type" = "dhcp" ]; then
  924. if [ -f /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf ]; then
  925. cp /etc/wpa_supplicant/wpa_supplicant-${_dev}.conf $TARGETDIR/etc/wpa_supplicant
  926. ln -sf /etc/sv/dhcpcd-${_dev} $TARGETDIR/etc/runit/runsvdir/default/dhcpcd-${_dev}
  927. else
  928. enable_dhcpd
  929. fi
  930. elif [ -n "$_dev" -a "$_type" = "static" ]; then
  931. # static IP through dhcpcd.
  932. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig
  933. echo "# Static IP configuration set by the void-installer for $_dev." \
  934. >$TARGETDIR/etc/dhcpcd.conf
  935. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  936. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  937. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  938. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  939. enable_dhcpd
  940. fi
  941. fi
  942. if [ -f $TARGETDIR/etc/sudoers ]; then
  943. if [ -z "$(echo $(get_option USERGROUPS) | grep -w wheel)" ]; then
  944. # enable sudo for primary user USERLOGIN
  945. echo "# Enable sudo for login '$(get_option USERLOGIN)'" >> $TARGETDIR/etc/sudoers
  946. echo "$(get_option USERLOGIN) ALL=(ALL) ALL" >> $TARGETDIR/etc/sudoers
  947. else
  948. # enable sudoers entry for members of group wheel for primary user
  949. sed -i $TARGETDIR/etc/sudoers \
  950. -e "s;#.*%wheel ALL=(ALL) ALL;%wheel ALL=(ALL) ALL;"
  951. fi
  952. fi
  953. # enable text console for grub if chosen
  954. if [ "$(get_option TEXTCONSOLE)" = "1" ]; then
  955. sed -i $TARGETDIR/etc/default/grub \
  956. -e 's|#\(GRUB_TERMINAL_INPUT\).*|\1=console|' \
  957. -e 's|#\(GRUB_TERMINAL_OUTPUT\).*|\1=console|'
  958. fi
  959. # install bootloader.
  960. set_bootloader
  961. sync && sync && sync
  962. # unmount all filesystems.
  963. umount_filesystems
  964. # installed successfully.
  965. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  966. Do you want to reboot the system?" ${YESNOSIZE}
  967. if [ $? -eq 0 ]; then
  968. shutdown -r now
  969. else
  970. return
  971. fi
  972. }
  973. menu_source() {
  974. local src=
  975. DIALOG --title " Select installation source " \
  976. --menu "$MENULABEL" 8 70 0 \
  977. "Local" "Packages from ISO image" \
  978. "Network" "Packages from official remote reposity"
  979. case "$(cat $ANSWER)" in
  980. "Local") src="local";;
  981. "Network") src="net";
  982. if [ -z "$NETWORK_DONE" ]; then
  983. menu_network;
  984. fi;;
  985. *) return 1;;
  986. esac
  987. SOURCE_DONE=1
  988. set_option SOURCE $src
  989. }
  990. menu() {
  991. if [ -z "$DEFITEM" ]; then
  992. DEFITEM="Keyboard"
  993. fi
  994. DIALOG --default-item $DEFITEM \
  995. --extra-button --extra-label "Settings" \
  996. --title " Void Linux installation menu " \
  997. --menu "$MENULABEL" 10 70 0 \
  998. "Keyboard" "Set system keyboard" \
  999. "Network" "Set up the network" \
  1000. "Source" "Set source installation" \
  1001. "Hostname" "Set system hostname" \
  1002. "Locale" "Set system locale" \
  1003. "Timezone" "Set system time zone" \
  1004. "RootPassword" "Set system root password" \
  1005. "UserAccount" "Set primary user name and password" \
  1006. "BootLoader" "Set disk to install bootloader" \
  1007. "Partition" "Partition disk(s)" \
  1008. "Filesystems" "Configure filesystems and mount points" \
  1009. "Install" "Start installation with saved settings" \
  1010. "Exit" "Exit installation"
  1011. if [ $? -eq 3 ]; then
  1012. # Show settings
  1013. cp $CONF_FILE /tmp/conf_hidden.$$;
  1014. sed -i "s/^ROOTPASSWORD.*/ROOTPASSWORD <-hidden->/" /tmp/conf_hidden.$$
  1015. DIALOG --title "Saved settings for installation" --textbox /tmp/conf_hidden.$$ 14 60
  1016. rm /tmp/conf_hidden.$$
  1017. return
  1018. fi
  1019. case $(cat $ANSWER) in
  1020. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Network";;
  1021. "Network") menu_network && [ -n "$NETWORK_DONE" ] && DEFITEM="Source";;
  1022. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  1023. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="Locale";;
  1024. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  1025. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  1026. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="UserAccount";;
  1027. "UserAccount") menu_useraccount && [ -n "$USERNAME_DONE" ] && [ -n "$USERPASSWORD_DONE" ] \
  1028. && DEFITEM="BootLoader";;
  1029. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  1030. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  1031. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  1032. "Install") menu_install;;
  1033. "Exit") DIE;;
  1034. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  1035. esac
  1036. }
  1037. if [ ! -x /bin/dialog ]; then
  1038. echo "ERROR: missing dialog command, exiting..."
  1039. exit 1
  1040. fi
  1041. #
  1042. # main()
  1043. #
  1044. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  1045. Welcome to the Void Linux installation. A simple and minimal \
  1046. Linux distribution made from scratch and built from the source package tree \
  1047. available for XBPS, a new alternative binary package system.\n\n
  1048. The installation should be pretty straightforward. If you are in trouble \
  1049. please join us at ${BOLD}#xbps${RESET} on ${BOLD}irc.freenode.org${RESET}.\n\n
  1050. ${BOLD}http://www.voidlinux.eu${RESET}\n\n" 16 80
  1051. while true; do
  1052. menu
  1053. done
  1054. exit 0
  1055. # vim: set ts=4 sw=4 et: