installer.sh.in 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. #!/bin/sh
  2. #-
  3. # Copyright (c) 2012-2013 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. BOOTLOADER_DONE=
  35. PARTITIONS_DONE=
  36. NETWORK_DONE=
  37. FILESYSTEMS_DONE=
  38. TARGETDIR=/mnt/target
  39. LOG=/dev/tty7
  40. CONF_FILE=/tmp/.void-installer.conf
  41. if [ ! -f $CONF_FILE ]; then
  42. touch -f $CONF_FILE
  43. fi
  44. ANSWER=$(mktemp -t vinstall-XXXXXXXX || exit 1)
  45. TARGET_FSTAB=$(mktemp -t vinstall-fstab-XXXXXXXX || exit 1)
  46. trap "DIE" INT TERM QUIT
  47. # disable printk
  48. if [ -w /proc/sys/kernel/printk ]; then
  49. echo 0 >/proc/sys/kernel/printk
  50. fi
  51. # Detect if this is an EFI system.
  52. if [ -e /sys/firmware/efi/systab ]; then
  53. EFI_SYSTEM=1
  54. fi
  55. # dialog colors
  56. BLACK="\Z0"
  57. RED="\Z1"
  58. GREEN="\Z2"
  59. YELLOW="\Z3"
  60. BLUE="\Z4"
  61. MAGENTA="\Z5"
  62. CYAN="\Z6"
  63. WHITE="\Z7"
  64. BOLD="\Zb"
  65. REVERSE="\Zr"
  66. UNDERLINE="\Zu"
  67. RESET="\Zn"
  68. # Properties shared per widget.
  69. MENULABEL="${BOLD}Use UP and DOWN keys to navigate \
  70. menus. Use TAB to switch between buttons and ENTER to select.${RESET}"
  71. MENUSIZE="14 60 0"
  72. INPUTSIZE="8 60"
  73. MSGBOXSIZE="8 70"
  74. YESNOSIZE="$INPUTSIZE"
  75. WIDGET_SIZE="10 70"
  76. DIALOG() {
  77. rm -f $ANSWER
  78. dialog --colors --keep-tite --no-shadow --no-mouse \
  79. --backtitle "${BOLD}${WHITE}Void Linux installation -- http://www.voidlinux.eu/ (@@MKLIVE_VERSION@@)${RESET}" \
  80. --cancel-label "Back" --aspect 20 "$@" 2>$ANSWER
  81. return $?
  82. }
  83. DIE() {
  84. rval=$1
  85. [ -z "$rval" ] && rval=0
  86. clear
  87. rm -f $ANSWER $TARGET_FSTAB
  88. # reenable printk
  89. if [ -w /proc/sys/kernel/printk ]; then
  90. echo 4 >/proc/sys/kernel/printk
  91. fi
  92. umount_filesystems
  93. exit $rval
  94. }
  95. set_option() {
  96. if grep -Eq "^${1}.*" $CONF_FILE; then
  97. sed -i -e "/^${1}.*/d" $CONF_FILE
  98. fi
  99. echo "${1} ${2}" >>$CONF_FILE
  100. }
  101. get_option() {
  102. echo $(grep -E "^${1}.*" $CONF_FILE|sed -e "s|${1}||")
  103. }
  104. show_disks() {
  105. local dev size sectorsize gbytes
  106. # IDE
  107. for dev in $(ls /sys/block|grep -E '^hd'); do
  108. if [ "$(cat /sys/block/$dev/device/media)" = "disk" ]; then
  109. # Find out nr sectors and bytes per sector;
  110. echo "/dev/$dev"
  111. size=$(cat /sys/block/$dev/size)
  112. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  113. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  114. echo "size:${gbytes}GB;sector_size:$sectorsize"
  115. fi
  116. done
  117. # SATA/SCSI and Virtual disks (virtio)
  118. for dev in $(ls /sys/block|grep -E '^([sv]|xv)d'); do
  119. echo "/dev/$dev"
  120. size=$(cat /sys/block/$dev/size)
  121. sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)
  122. gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"
  123. echo "size:${gbytes}GB;sector_size:$sectorsize"
  124. done
  125. }
  126. show_partitions() {
  127. local dev fstype fssize p part
  128. set -- $(show_disks)
  129. while [ $# -ne 0 ]; do
  130. disk=$(basename $1)
  131. shift 2
  132. # ATA/SCSI/SATA
  133. for p in /sys/block/$disk/$disk*; do
  134. if [ -d $p ]; then
  135. part=$(basename $p)
  136. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  137. [ "$fstype" = "iso9660" ] && continue
  138. fssize=$(lsblk -nr /dev/$part|awk '{print $4}')
  139. echo "/dev/$part"
  140. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  141. fi
  142. done
  143. # LVM
  144. for p in $(ls /dev/mapper 2>/dev/null|grep -v control); do
  145. [ "$p" = "live-rw" ] && continue
  146. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  147. fssize=$(lsblk -nr /dev/mapper/$p|awk '{print $4}')
  148. echo "/dev/mapper/$p"
  149. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  150. done
  151. # Software raid (md)
  152. for p in $(ls -d /dev/md* 2>/dev/null|grep '[0-9]'); do
  153. if cat /proc/mdstat|grep -qw $(echo $p|sed -e 's|/dev/||g'); then
  154. fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')
  155. fssize=$(lsblk -nr /dev/$p|awk '{print $4}')
  156. echo "$p"
  157. echo "size:${fssize:-unknown};fstype:${fstype:-none}"
  158. fi
  159. done
  160. done
  161. }
  162. menu_filesystems() {
  163. local dev fstype fssize mntpoint reformat
  164. while true; do
  165. DIALOG --title " Select the partition to edit " --menu "$MENULABEL" \
  166. ${MENUSIZE} $(show_partitions)
  167. [ $? -ne 0 ] && return
  168. dev=$(cat $ANSWER)
  169. DIALOG --title " Select the filesystem type for $dev " \
  170. --menu "$MENULABEL" ${MENUSIZE} \
  171. "btrfs" "Oracle's Btrfs" \
  172. "ext2" "Linux ext2 (no journaling)" \
  173. "ext3" "Linux ext3 (journal)" \
  174. "ext4" "Linux ext4 (journal)" \
  175. "f2fs" "Flash-Friendly Filesystem" \
  176. "swap" "Linux swap" \
  177. "vfat" "FAT32" \
  178. "xfs" "SGI's XFS"
  179. if [ $? -eq 0 ]; then
  180. fstype=$(cat $ANSWER)
  181. else
  182. continue
  183. fi
  184. if [ "$fstype" != "swap" ]; then
  185. DIALOG --inputbox "Please specify the mount point for $dev:" ${INPUTSIZE}
  186. if [ $? -eq 0 ]; then
  187. mntpoint=$(cat $ANSWER)
  188. elif [ $? -eq 1 ]; then
  189. continue
  190. fi
  191. else
  192. mntpoint=swap
  193. fi
  194. DIALOG --yesno "Do you want to create a new filesystem on $dev?" ${YESNOSIZE}
  195. if [ $? -eq 0 ]; then
  196. reformat=1
  197. elif [ $? -eq 1 ]; then
  198. reformat=0
  199. else
  200. continue
  201. fi
  202. fssize=$(lsblk -nr $dev|awk '{print $4}')
  203. set -- "$fstype" "$fssize" "$mntpoint" "$reformat"
  204. if [ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ]; then
  205. local bdev=$(basename $dev)
  206. if grep -Eq "^MOUNTPOINT \/dev\/${bdev}.*" $CONF_FILE; then
  207. sed -i -e "/^MOUNTPOINT \/dev\/${bdev}.*/d" $CONF_FILE
  208. fi
  209. echo "MOUNTPOINT $dev $1 $2 $3 $4" >>$CONF_FILE
  210. fi
  211. done
  212. }
  213. menu_partitions() {
  214. DIALOG --title " Select the disk to partition " \
  215. --menu "$MENULABEL" ${MENUSIZE} $(show_disks)
  216. if [ $? -eq 0 ]; then
  217. local device=$(cat $ANSWER)
  218. DIALOG --title "Modify Partition Table on $device" --msgbox "\n
  219. ${BOLD}GNU parted will be executed in disk $device.${RESET}\n\n
  220. For BIOS systems, MBR or GPT partition tables are supported.\n
  221. To use GPT on PC BIOS systems an empty partition of 1MB must be added\n
  222. at the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n
  223. ${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n
  224. For EFI systems GPT is mandatory and a FAT32 partition with at least\n
  225. 100MB must be created with the TOGGLE \`boot', this will be used as\n
  226. EFI System Partition. This partition must have mountpoint as \`/boot/efi'.\n\n
  227. At least 2 partitions are required: swap and rootfs (/).\n
  228. For swap, RAM*2 must be really enough. For / 600MB are required.\n\n
  229. ${BOLD}WARNING: /usr is not supported as a separate partition.${RESET}\n
  230. ${BOLD}WARNING: changes made by parted are destructive, you've been warned.
  231. ${RESET}\n" 18 80
  232. if [ $? -eq 0 ]; then
  233. while true; do
  234. clear; parted $device; PARTITIONS_DONE=1; partprobe $device
  235. break
  236. done
  237. else
  238. return
  239. fi
  240. fi
  241. }
  242. menu_keymap() {
  243. local _keymaps="$(localectl --no-pager list-keymaps)"
  244. local _KEYMAPS=
  245. for f in ${_keymaps}; do
  246. _KEYMAPS="${_KEYMAPS} ${f} -"
  247. done
  248. while true; do
  249. DIALOG --title " Select your keymap " --menu "$MENULABEL" 14 70 14 ${_KEYMAPS}
  250. if [ $? -eq 0 ]; then
  251. set_option KEYMAP "$(cat $ANSWER)"
  252. loadkeys "$(cat $ANSWER)"
  253. KEYBOARD_DONE=1
  254. break
  255. else
  256. return
  257. fi
  258. done
  259. }
  260. set_keymap() {
  261. local KEYMAP=$(get_option KEYMAP)
  262. sed -i -e "s|KEYMAP=.*|KEYMAP=$KEYMAP|g" $TARGETDIR/etc/vconsole.conf
  263. }
  264. menu_locale() {
  265. local _locales="$(grep -E '\.UTF-8' /etc/default/libc-locales|awk '{print $1}'|sed -e 's/^#//')"
  266. local _LOCALES=
  267. for f in ${_locales}; do
  268. _LOCALES="${_LOCALES} ${f} -"
  269. done
  270. while true; do
  271. DIALOG --title " Select your locale " --menu "$MENULABEL" 14 70 14 ${_LOCALES}
  272. if [ $? -eq 0 ]; then
  273. set_option LOCALE "$(cat $ANSWER)"
  274. LOCALE_DONE=1
  275. break
  276. else
  277. return
  278. fi
  279. done
  280. }
  281. set_locale() {
  282. local LOCALE=$(get_option LOCALE)
  283. sed -i -e "s|LANG=.*|LANG=$LOCALE|g" $TARGETDIR/etc/locale.conf
  284. # Uncomment locale from /etc/default/libc-locales and regenerate it.
  285. sed -e "/${LOCALE}/s/^\#//" -i $TARGETDIR/etc/default/libc-locales
  286. echo "Running xbps-reconfigure -f glibc-locales ..." >$LOG
  287. chroot $TARGETDIR xbps-reconfigure -f glibc-locales >$LOG 2>&1
  288. }
  289. menu_timezone() {
  290. local _tzones="$(timedatectl --no-pager list-timezones)"
  291. local _TIMEZONES=
  292. for f in ${_tzones}; do
  293. _TIMEZONES="${_TIMEZONES} ${f} -"
  294. done
  295. while true; do
  296. DIALOG --title " Select your timezone " --menu "$MENULABEL" 14 70 14 ${_TIMEZONES}
  297. if [ $? -eq 0 ]; then
  298. set_option TIMEZONE "$(cat $ANSWER)"
  299. TIMEZONE_DONE=1
  300. break
  301. else
  302. return
  303. fi
  304. done
  305. }
  306. set_timezone() {
  307. local TIMEZONE="$(get_option TIMEZONE)"
  308. ln -sf /usr/share/zoneinfo/${TIMEZONE} $TARGETDIR/etc/localtime
  309. }
  310. menu_hostname() {
  311. while true; do
  312. DIALOG --inputbox "Set the machine hostname:" ${INPUTSIZE}
  313. if [ $? -eq 0 ]; then
  314. set_option HOSTNAME "$(cat $ANSWER)"
  315. HOSTNAME_DONE=1
  316. break
  317. else
  318. return
  319. fi
  320. done
  321. }
  322. set_hostname() {
  323. echo $(get_option HOSTNAME) > $TARGETDIR/etc/hostname
  324. }
  325. menu_rootpassword() {
  326. local _firstpass= _secondpass= _desc=
  327. while true; do
  328. if [ -n "${_firstpass}" ]; then
  329. _desc="Enter the root password again (password won't be displayed)"
  330. else
  331. _desc="Enter the root password (password won't be displayed)"
  332. fi
  333. DIALOG --passwordbox "${_desc}" ${MSGBOXSIZE}
  334. if [ $? -eq 0 ]; then
  335. if [ -z "${_firstpass}" ]; then
  336. _firstpass="$(cat $ANSWER)"
  337. else
  338. _secondpass="$(cat $ANSWER)"
  339. fi
  340. if [ -n "${_firstpass}" -a -n "${_secondpass}" ]; then
  341. if [ "${_firstpass}" != "${_secondpass}" ]; then
  342. DIALOG --infobox "Passwords do not match! please reenter it again" 6 80
  343. unset _firstpass _secondpass
  344. sleep 2 && continue
  345. fi
  346. set_option ROOTPASSWORD "${_firstpass}"
  347. ROOTPASSWORD_DONE=1
  348. break
  349. fi
  350. else
  351. return
  352. fi
  353. done
  354. }
  355. set_rootpassword() {
  356. echo "root:$(get_option ROOTPASSWORD)" | chpasswd -R $TARGETDIR -c SHA512
  357. }
  358. menu_bootloader() {
  359. while true; do
  360. DIALOG --title " Select the disk to install the bootloader" \
  361. --menu "$MENULABEL" ${MENUSIZE} $(show_disks)
  362. if [ $? -eq 0 ]; then
  363. set_option BOOTLOADER "$(cat $ANSWER)"
  364. BOOTLOADER_DONE=1
  365. break
  366. else
  367. return
  368. fi
  369. done
  370. }
  371. set_bootloader() {
  372. local dev=$(get_option BOOTLOADER) grub_args=
  373. # Check if it's an EFI system via efivars module.
  374. if [ -n "$EFI_SYSTEM" ]; then
  375. grub_args="--target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=void_grub --recheck"
  376. fi
  377. echo "Running grub-install $grub_args $dev..." >$LOG
  378. chroot $TARGETDIR grub-install $grub_args $dev >$LOG 2>&1
  379. if [ $? -ne 0 ]; then
  380. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  381. failed to install GRUB to $dev!\nCheck $LOG for errors." ${MSGBOXSIZE}
  382. DIE 1
  383. fi
  384. echo "Running grub-mkconfig on $TARGETDIR..." >$LOG
  385. chroot $TARGETDIR grub-mkconfig -o /boot/grub/grub.cfg >$LOG 2>&1
  386. if [ $? -ne 0 ]; then
  387. DIALOG --msgbox "${BOLD}${RED}ERROR${RESET}: \
  388. failed to run grub-mkconfig!\nCheck $LOG for errors." ${MSGBOXSIZE}
  389. DIE 1
  390. fi
  391. }
  392. test_network() {
  393. rm -f xtraeme.asc && \
  394. xbps-uhelper fetch http://xbps.nopcode.org/live/xtraeme.asc >$LOG 2>&1
  395. if [ $? -eq 0 ]; then
  396. DIALOG --msgbox "Network is working properly!" ${MSGBOXSIZE}
  397. NETWORK_DONE=1
  398. return 1
  399. fi
  400. DIALOG --msgbox "Network is unaccessible, please setup it properly." ${MSGBOXSIZE}
  401. }
  402. configure_wifi() {
  403. local dev="$1"
  404. DIALOG --form "Wireless configuration for $dev:" 0 0 0 \
  405. "SSID:" 1 1 "add your AP name here" 1 21 20 0 \
  406. "Encryption:" 2 1 "Only supported: WEP or WPA-PSK" 2 21 20 0 \
  407. "Passphrase:" 3 1 "Enter the AP passphrase here" 3 21 20 0 || return 1
  408. }
  409. configure_eth() {
  410. local dev="$1" rval
  411. DIALOG --yesno "Do you want to use DHCP for $dev?" ${YESNOSIZE}
  412. rval=$?
  413. if [ $rval -eq 0 ]; then
  414. configure_net_dhcp $dev
  415. elif [ $rval -eq 1 ]; then
  416. configure_net_static $dev
  417. fi
  418. }
  419. iface_setup() {
  420. ip addr show dev $1|grep -q 'inet '
  421. return $?
  422. }
  423. configure_net_dhcp() {
  424. local dev="$1"
  425. iface_setup $dev
  426. if [ $? -eq 1 ]; then
  427. dhcpcd -t 10 -w -4 -L $dev 2>&1 | tee $LOG | \
  428. DIALOG --progressbox "Initializing $dev via DHCP..." ${WIDGET_SIZE}
  429. if [ $? -ne 0 ]; then
  430. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to run udhcpc. See $LOG for details." ${MSGBOXSIZE}
  431. return 1
  432. fi
  433. iface_setup $dev
  434. if [ $? -eq 1 ]; then
  435. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} DHCP request failed for $dev. Check $LOG for errors." ${MSGBOXSIZE}
  436. return 1
  437. fi
  438. fi
  439. test_network
  440. if [ $? -eq 1 ]; then
  441. set_option NETWORK "${dev} dhcp"
  442. fi
  443. }
  444. configure_net_static() {
  445. local ip gw dns1 dns2 dev=$1
  446. DIALOG --form "Static IP configuration for $dev:" 0 0 0 \
  447. "IP address:" 1 1 "192.168.0.2" 1 21 20 0 \
  448. "Gateway:" 2 1 "192.168.0.1" 2 21 20 0 \
  449. "DNS Primary" 3 1 "8.8.8.8" 3 21 20 0 \
  450. "DNS Secondary" 4 1 "8.8.4.4" 4 21 20 0 || return 1
  451. set -- $(cat $ANSWER)
  452. ip=$1; gw=$2; dns1=$3; dns2=$4
  453. echo "running: ip link set dev $dev up" >$LOG
  454. ip link set dev $dev up >$LOG 2>&1
  455. if [ $? -ne 0 ]; then
  456. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to bring $dev interface." ${MSGBOXSIZE}
  457. return 1
  458. fi
  459. echo "running: ip addr add $ip dev $dev"
  460. ip addr add $ip dev $dev >$LOG 2>&1
  461. if [ $? -ne 0 ]; then
  462. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} Failed to set ip to the $dev interface." ${MSGBOXSIZE}
  463. return 1
  464. fi
  465. ip route add $gw dev $dev >$LOG 2>&1
  466. if [ $? -ne 0 ]; then
  467. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} failed to setup your gateway." ${MSGBOXSIZE}
  468. return 1
  469. fi
  470. echo "nameserver $dns1" >/etc/resolv.conf
  471. echo "nameserver $dns2" >>/etc/resolv.conf
  472. test_network
  473. if [ $? -eq 1 ]; then
  474. set_option NETWORK "${dev} static $ip $gw $dns1 $dns2"
  475. fi
  476. }
  477. menu_network() {
  478. local dev addr f DEVICES
  479. for f in $(ls /sys/class/net); do
  480. [ "$f" = "lo" ] && continue
  481. addr=$(cat /sys/class/net/$f/address)
  482. DEVICES="$DEVICES $f $addr"
  483. done
  484. DIALOG --title " Select the network interface to configure " \
  485. --menu "$MENULABEL" ${MENUSIZE} ${DEVICES}
  486. if [ $? -eq 0 ]; then
  487. dev=$(cat $ANSWER)
  488. if $(echo $dev|grep -q "wlan[0-9]" 2>/dev/null); then
  489. configure_wifi $dev
  490. else
  491. configure_eth $dev
  492. fi
  493. fi
  494. }
  495. validate_filesystems() {
  496. local mnts dev size fstype mntpt mkfs rootfound swapfound fmt
  497. local usrfound efi_system_partition
  498. unset TARGETFS
  499. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  500. set -- ${mnts}
  501. while [ $# -ne 0 ]; do
  502. dev=$2; fstype=$3; size=$4; mntpt="$5"; mkfs=$6
  503. shift 6
  504. if [ "$mntpt" = "/" ]; then
  505. rootfound=1
  506. elif [ "$mntpt" = "/usr" ]; then
  507. usrfound=1
  508. elif [ "$fstype" = "vfat" -a "$mntpt" = "/boot/efi" ]; then
  509. efi_system_partition=1
  510. fi
  511. if [ "$mkfs" -eq 1 ]; then
  512. fmt="NEW FILESYSTEM: "
  513. fi
  514. if [ -z "$TARGETFS" ]; then
  515. TARGETFS="${fmt}$dev ($size) mounted on $mntpt as ${fstype}\n"
  516. else
  517. TARGETFS="${TARGETFS}${fmt}${dev} ($size) mounted on $mntpt as ${fstype}\n"
  518. fi
  519. done
  520. if [ -z "$rootfound" ]; then
  521. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  522. the mount point for the root filesystem (/) has not yet been configured." ${MSGBOXSIZE}
  523. return 1
  524. elif [ -n "$usrfound" ]; then
  525. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  526. /usr mount point has been configured but is not supported, please remove it to continue." ${MSGBOXSIZE}
  527. return 1
  528. elif [ -n "$EFI_SYSTEM" -a -z "$efi_system_partition" ]; then
  529. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  530. The EFI System Partition has not yet been configured, please create it\n
  531. as FAT32, mountpoint /boot/efi and at least with 100MB of size." ${MSGBOXSIZE}
  532. fi
  533. FILESYSTEMS_DONE=1
  534. }
  535. create_filesystems() {
  536. local mnts dev mntpt fstype mkfs size rv uuid
  537. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  538. set -- ${mnts}
  539. while [ $# -ne 0 ]; do
  540. dev=$2; fstype=$3; mntpt="$5"; mkfs=$6
  541. shift 6
  542. # swap partitions
  543. if [ "$fstype" = "swap" ]; then
  544. swapoff $dev >/dev/null 2>&1
  545. if [ "$mkfs" -eq 1 ]; then
  546. mkswap $dev >$LOG 2>&1
  547. if [ $? -ne 0 ]; then
  548. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  549. failed to create swap on ${dev}!\ncheck $LOG for errors." ${MSGBOXSIZE}
  550. DIE 1
  551. fi
  552. fi
  553. swapon $dev >$LOG 2>&1
  554. if [ $? -ne 0 ]; then
  555. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  556. failed to activate swap on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  557. DIE 1
  558. fi
  559. # Add entry for target fstab
  560. uuid=$(blkid -o value -s UUID "$dev")
  561. echo "UUID=$uuid none swap sw 0 0" >>$TARGET_FSTAB
  562. continue
  563. fi
  564. if [ "$mkfs" -eq 1 ]; then
  565. case "$fstype" in
  566. btrfs) MKFS="mkfs.btrfs"; modprobe btrfs >$LOG 2>&1;;
  567. ext2) MKFS="mke2fs"; modprobe ext2 >$LOG 2>&1;;
  568. ext3) MKFS="mke2fs -j"; modprobe ext3 >$LOG 2>&1;;
  569. ext4) MKFS="mke2fs -t ext4"; modprobe ext4 >$LOG 2>&1;;
  570. f2fs) MKFS="mkfs.f2fs"; modprobe f2fs >$LOG 2>&1;;
  571. vfat) MKFS="mkfs.vfat -F32"; modprobe vfat >$LOG 2>&1;;
  572. xfs) MKFS="mkfs.xfs -f"; modprobe xfs >$LOG 2>&1;;
  573. esac
  574. DIALOG --infobox "Creating filesystem $fstype on $dev for $mntpt ..." 8 60
  575. echo "Running $MKFS $dev..." >$LOG
  576. $MKFS $dev >$LOG 2>&1; rv=$?
  577. if [ $rv -ne 0 ]; then
  578. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  579. failed to create filesystem $fstype on $dev!\ncheck $LOG for errors." ${MSGBOXSIZE}
  580. DIE 1
  581. fi
  582. fi
  583. # Mount rootfs the first one.
  584. [ "$mntpt" != "/" ] && continue
  585. mkdir -p $TARGETDIR
  586. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  587. mount -t $fstype $dev $TARGETDIR >$LOG 2>&1
  588. if [ $? -ne 0 ]; then
  589. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  590. failed to mount $dev on ${mntpt}! check $LOG for errors." ${MSGBOXSIZE}
  591. DIE 1
  592. fi
  593. # Add entry to target fstab
  594. uuid=$(blkid -o value -s UUID "$dev")
  595. echo "UUID=$uuid $mntpt $fstype defaults 0 1" >>$TARGET_FSTAB
  596. done
  597. # mount all filesystems in target rootfs
  598. mnts=$(grep -E '^MOUNTPOINT.*' $CONF_FILE)
  599. set -- ${mnts}
  600. while [ $# -ne 0 ]; do
  601. dev=$2; fstype=$3; mntpt="$5"
  602. shift 6
  603. [ "$mntpt" = "/" -o "$fstype" = "swap" ] && continue
  604. mkdir -p ${TARGETDIR}${mntpt}
  605. echo "Mounting $dev on $mntpt ($fstype)..." >$LOG
  606. mount -t $fstype $dev ${TARGETDIR}${mntpt} >$LOG 2>&1
  607. if [ $? -ne 0 ]; then
  608. DIALOG --msgbox "${BOLD}${RED}ERROR:${RESET} \
  609. failed to mount $dev on $mntpt! check $LOG for errors." ${MSGBOXSIZE}
  610. DIE
  611. fi
  612. # Add entry to target fstab
  613. uuid=$(blkid -o value -s UUID "$dev")
  614. echo "UUID=$uuid $mntpt $fstype defaults 0 1" >>$TARGET_FSTAB
  615. done
  616. }
  617. mount_filesystems() {
  618. for f in sys proc dev; do
  619. [ ! -d $TARGETDIR/$f ] && mkdir $TARGETDIR/$f
  620. echo "Mounting $TARGETDIR/$f..." >$LOG
  621. mount --bind /$f $TARGETDIR/$f >$LOG 2>&1
  622. done
  623. }
  624. umount_filesystems() {
  625. local f
  626. for f in sys/fs/fuse/connections sys proc dev; do
  627. echo "Unmounting $TARGETDIR/$f..." >$LOG
  628. umount $TARGETDIR/$f >$LOG 2>&1
  629. done
  630. local mnts="$(grep -E '^MOUNTPOINT.*$' $CONF_FILE)"
  631. set -- ${mnts}
  632. while [ $# -ne 0 ]; do
  633. local dev=$2; local fstype=$3; local mntpt=$5
  634. shift 6
  635. if [ "$fstype" = "swap" ]; then
  636. echo "Disabling swap space on $dev..." >$LOG
  637. swapoff $dev >$LOG 2>&1
  638. continue
  639. fi
  640. if [ "$mntpt" != "/" ]; then
  641. echo "Unmounting $TARGETDIR/$mntpt..." >$LOG
  642. umount $TARGETDIR/$mntpt >$LOG 2>&1
  643. fi
  644. done
  645. echo "Unmounting $TARGETDIR..." >$LOG
  646. umount $TARGETDIR >$LOG 2>&1
  647. }
  648. copy_rootfs() {
  649. LANG=C cp -axvn / $TARGETDIR 2>&1 | \
  650. DIALOG --title "Copyring live image to target rootfs ..." \
  651. --programbox 24 80
  652. if [ $? -ne 0 ]; then
  653. DIE 1
  654. fi
  655. }
  656. menu_install() {
  657. # Don't continue if filesystems are not ready.
  658. validate_filesystems || return 1
  659. ROOTPASSWORD_DONE="$(get_option ROOTPASSWORD)"
  660. BOOTLOADER_DONE="$(get_option BOOTLOADER)"
  661. if [ -z "$FILESYSTEMS_DONE" ]; then
  662. DIALOG --msgbox "${BOLD}Required filesystems were not configured, \
  663. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  664. return 1
  665. elif [ -z "$ROOTPASSWORD_DONE" ]; then
  666. DIALOG --msgbox "${BOLD}The root password has not been configured, \
  667. please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  668. return 1
  669. elif [ -z "$BOOTLOADER_DONE" ]; then
  670. DIALOG --msgbox "${BOLD}The disk to install the bootloader has not been \
  671. configured, please do so before starting the installation.${RESET}" ${MSGBOXSIZE}
  672. return 1
  673. fi
  674. DIALOG --yesno "${BOLD}The following operations will be executed:${RESET}\n\n
  675. ${BOLD}${TARGETFS}${RESET}\n
  676. ${BOLD}${RED}WARNING: data on partitions will be COMPLETELY DESTROYED for new \
  677. filesystems.${RESET}\n\n
  678. ${BOLD}Do you want to continue?${RESET}" 20 80 || return
  679. unset TARGETFS
  680. # Create and mount filesystems
  681. create_filesystems
  682. # mount required fs
  683. mount_filesystems
  684. # If source not set use defaults.
  685. if [ -z "$SOURCE_DONE" ]; then
  686. enable_localsrc
  687. fi
  688. # Install required packages.
  689. copy_rootfs
  690. # Disable autologin and remove motd from live image.
  691. rm -f $TARGETDIR/etc/motd $TARGETDIR/etc/systemd/system/[email protected]
  692. # Remove live user.
  693. . /etc/default/live.conf
  694. echo "Removing $USERNAME live user from targetdir ..." >$LOG
  695. chroot $TARGETDIR userdel -r $USERNAME >>$LOG 2>&1
  696. DIALOG --infobox "Applying installer settings..." 4 60
  697. # copy target fstab.
  698. install -Dm644 $TARGET_FSTAB $TARGETDIR/etc/fstab
  699. # set up keymap, locale, timezone, hostname and root passwd.
  700. set_keymap
  701. set_locale
  702. set_timezone
  703. set_hostname
  704. set_rootpassword
  705. # Copy /etc/skel files for root.
  706. cp $TARGETDIR/etc/skel/.[bix]* $TARGETDIR/root
  707. # network settings for target
  708. if [ -n "$NETWORK_DONE" ]; then
  709. local net="$(get_option NETWORK)"
  710. set -- ${net}
  711. local _dev="$1" _type="$2" _ip="$3" _gw="$4" _dns1="$5" _dns2="$6"
  712. if [ -z "$_type" ]; then
  713. # network type empty??!!!
  714. :
  715. elif [ "$_type" = "dhcp" ]; then
  716. # if user had dhcp enabled, enable dhcpcd service for that device.
  717. chroot $TARGETDIR systemctl enable dhcpcd.service >$LOG 2>&1
  718. elif [ -n "$dev" -a -n "$type" = "static" ]; then
  719. # static IP through dhcpcd.
  720. mv $TARGETDIR/etc/dhcpcd.conf $TARGETDIR/etc/dhdpcd.conf.orig
  721. echo "# Static IP configuration set by the void-installer for $_dev." \
  722. >$TARGETDIR/etc/dhcpcd.conf
  723. echo "interface $_dev" >>$TARGETDIR/etc/dhcpcd.conf
  724. echo "static ip_address=$_ip" >>$TARGETDIR/etc/dhcpcd.conf
  725. echo "static routers=$_gw" >>$TARGETDIR/etc/dhcpcd.conf
  726. echo "static domain_name_servers=$_dns1 $_dns2" >>$TARGETDIR/etc/dhcpcd.conf
  727. chroot $TARGETDIR systemctl enable dhcpcd.service >$LOG 2>&1
  728. fi
  729. fi
  730. # install bootloader.
  731. set_bootloader
  732. sync && sync && sync
  733. # unmount all filesystems.
  734. umount_filesystems
  735. # installed successfully.
  736. DIALOG --yesno "${BOLD}Void Linux has been installed successfully!${RESET}\n
  737. Do you want to reboot the system?" ${YESNOSIZE}
  738. if [ $? -eq 0 ]; then
  739. shutdown -r now
  740. else
  741. return
  742. fi
  743. }
  744. enable_localsrc() {
  745. # local and fallback to official remote.
  746. echo "repositories = { /packages, http://xbps.nopcode.org/repos/current }" >/tmp/xbps.conf
  747. }
  748. enable_netsrc() {
  749. # only remote.
  750. echo "repositories = { http://xbps.nopcode.org/repos/current }" > /tmp/xbps.conf
  751. }
  752. menu_source() {
  753. local src=
  754. DIALOG --title " Select installation source " \
  755. --menu "$MENULABEL" 8 70 0 \
  756. "Local" "Packages from ISO image" \
  757. "Network" "Packages from official remote reposity"
  758. case "$(cat $ANSWER)" in
  759. "Local") src="local"; enable_localsrc;;
  760. "Network") src="net"; enable_netsrc; menu_network;;
  761. *) return 1;;
  762. esac
  763. SOURCE_DONE=1
  764. set_option SOURCE $src
  765. }
  766. menu() {
  767. if [ -z "$DEFITEM" ]; then
  768. DEFITEM="Keyboard"
  769. fi
  770. DIALOG --default-item $DEFITEM \
  771. --extra-button --extra-label "Settings" \
  772. --title " Void Linux installation menu " \
  773. --menu "$MENULABEL" 10 70 0 \
  774. "Keyboard" "Set system keyboard" \
  775. "Source" "Set source installation" \
  776. "Hostname" "Set system hostname" \
  777. "Locale" "Set system locale" \
  778. "Timezone" "Set system time zone" \
  779. "RootPassword" "Set system root password" \
  780. "BootLoader" "Set disk to install bootloader" \
  781. "Partition" "Partition disk(s)" \
  782. "Filesystems" "Configure filesystems and mount points" \
  783. "Install" "Start installation with saved settings" \
  784. "Exit" "Exit installation"
  785. if [ $? -eq 3 ]; then
  786. # Show settings
  787. DIALOG --title "Saved settings for installation" --textbox $CONF_FILE 14 60
  788. return
  789. fi
  790. case $(cat $ANSWER) in
  791. "Keyboard") menu_keymap && [ -n "$KEYBOARD_DONE" ] && DEFITEM="Source";;
  792. "Source") menu_source && [ -n "$SOURCE_DONE" ] && DEFITEM="Hostname";;
  793. "Hostname") menu_hostname && [ -n "$HOSTNAME_DONE" ] && DEFITEM="Locale";;
  794. "Locale") menu_locale && [ -n "$LOCALE_DONE" ] && DEFITEM="Timezone";;
  795. "Timezone") menu_timezone && [ -n "$TIMEZONE_DONE" ] && DEFITEM="RootPassword";;
  796. "RootPassword") menu_rootpassword && [ -n "$ROOTPASSWORD_DONE" ] && DEFITEM="BootLoader";;
  797. "BootLoader") menu_bootloader && [ -n "$BOOTLOADER_DONE" ] && DEFITEM="Partition";;
  798. "Partition") menu_partitions && [ -n "$PARTITIONS_DONE" ] && DEFITEM="Filesystems";;
  799. "Filesystems") menu_filesystems && [ -n "$FILESYSTEMS_DONE" ] && DEFITEM="Install";;
  800. "Install") menu_install;;
  801. "Exit") DIE;;
  802. *) DIALOG --yesno "Abort Installation?" ${YESNOSIZE} && DIE
  803. esac
  804. }
  805. #
  806. # main()
  807. #
  808. DIALOG --title "${BOLD}${RED} Enter the void ... ${RESET}" --msgbox "\n
  809. Welcome to the Void Linux installation. A simple and minimal \
  810. Linux distribution made from scratch and built from the source package tree \
  811. available for XBPS, a new alternative binary package system.\n\n
  812. The installation should be pretty straightforward, if you are in trouble \
  813. please join us at ${BOLD}#xbps on irc.freenode.org${RESET}.\n\n
  814. ${BOLD}http://www.voidlinux.eu${RESET}\n\n" 16 80
  815. while true; do
  816. menu
  817. done
  818. exit 0
  819. # vim: set ts=4 sw=4 et: