1473 lines · 48.0 KB · Text
RawDownload
#!/bin/bash#-# Copyright (c) 2012-2015 Juan Romero Pardines <xtraeme@gmail.com>.#               2012 Dave Elusive <davehome@redthumb.info.tm>.# All rights reserved.## Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions# are met:# 1. Redistributions of source code must retain the above copyright#    notice, this list of conditions and the following disclaimer.# 2. Redistributions in binary form must reproduce the above copyright#    notice, this list of conditions and the following disclaimer in the#    documentation and/or other materials provided with the distribution.## THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#- # Make sure we don't inherit these from env.SOURCE_DONE=HOSTNAME_DONE=KEYBOARD_DONE=LOCALE_DONE=TIMEZONE_DONE=ROOTPASSWORD_DONE=USERLOGIN_DONE=USERPASSWORD_DONE=USERNAME_DONE=USERGROUPS_DONE=BOOTLOADER_DONE=PARTITIONS_DONE=NETWORK_DONE=FILESYSTEMS_DONE= TARGETDIR=/mnt/targetLOG=/dev/tty8CONF_FILE=/tmp/.void-installer.confif [ ! -f $CONF_FILE ]; then    touch -f $CONF_FILEfiANSWER=$(mktemp -t vinstall-XXXXXXXX || exit 1)TARGET_FSTAB=$(mktemp -t vinstall-fstab-XXXXXXXX || exit 1) trap "DIE" INT TERM QUIT # disable printkif [ -w /proc/sys/kernel/printk ]; then    echo 0 >/proc/sys/kernel/printkfi # Detect if this is an EFI system.if [ -e /sys/firmware/efi/systab ]; then    EFI_SYSTEM=1    EFI_FW_BITS=$(cat /sys/firmware/efi/fw_platform_size)    if [ $EFI_FW_BITS -eq 32 ]; then        EFI_TARGET=i386-efi    else        EFI_TARGET=x86_64-efi    fifi # dialog colorsBLACK="\Z0"RED="\Z1"GREEN="\Z2"YELLOW="\Z3"BLUE="\Z4"MAGENTA="\Z5"CYAN="\Z6"WHITE="\Z7"BOLD="\Zb"REVERSE="\Zr"UNDERLINE="\Zu"RESET="\Zn" # Properties shared per widget.MENULABEL="${BOLD}Use UP and DOWN keys to navigate \menus. Use TAB to switch between buttons and ENTER to select.${RESET}"MENUSIZE="14 60 0"INPUTSIZE="8 60"MSGBOXSIZE="8 70"YESNOSIZE="$INPUTSIZE"WIDGET_SIZE="10 70" DIALOG() {    rm -f $ANSWER    dialog --colors --keep-tite --no-shadow --no-mouse \        --backtitle "${BOLD}${WHITE}Void Linux installation -- https://www.voidlinux.org (@@MKLIVE_VERSION@@)${RESET}" \        --cancel-label "Back" --aspect 20 "$@" 2>$ANSWER    return $?} INFOBOX() {    # Note: dialog --infobox and --keep-tite don't work together    dialog --colors --no-shadow --no-mouse \        --backtitle "${BOLD}${WHITE}Void Linux installation -- https://www.voidlinux.org (@@MKLIVE_VERSION@@)${RESET}" \        --title "${TITLE}" --aspect 20 --infobox "$@"} DIE() {    rval=$1    [ -z "$rval" ] && rval=0    clear    rm -f $ANSWER $TARGET_FSTAB    # reenable printk    if [ -w /proc/sys/kernel/printk ]; then        echo 4 >/proc/sys/kernel/printk    fi    umount_filesystems    exit $rval} set_option() {    if grep -Eq "^${1}.*" $CONF_FILE; then        sed -i -e "/^${1}.*/d" $CONF_FILE    fi    echo "${1} ${2}" >>$CONF_FILE} get_option() {    echo $(grep -E "^${1}.*" $CONF_FILE|sed -e "s|${1}||")} # ISO-639 language names for localesiso639_language() {    case "$1" in    aa)  echo "Afar" ;;    af)  echo "Afrikaans" ;;    an)  echo "Aragonese" ;;    ar)  echo "Arabic" ;;    ast) echo "Asturian" ;;    be)  echo "Belgian" ;;    bg)  echo "Bulgarian" ;;    bhb) echo "Bhili" ;;    br)  echo "Breton" ;;    bs)  echo "Bosnian" ;;    ca)  echo "Catalan" ;;    cs)  echo "Czech" ;;    cy)  echo "Welsh" ;;    da)  echo "Danish" ;;    de)  echo "German" ;;    el)  echo "Greek" ;;    en)  echo "English" ;;    es)  echo "Spanish" ;;    et)  echo "Estonian" ;;    eu)  echo "Basque" ;;    fi)  echo "Finnish" ;;    fo)  echo "Faroese" ;;    fr)  echo "French" ;;    ga)  echo "Irish" ;;    gd)  echo "Scottish Gaelic" ;;    gl)  echo "Galician" ;;    gv)  echo "Manx" ;;    he)  echo "Hebrew" ;;    hr)  echo "Croatian" ;;    hsb) echo "Upper Sorbian" ;;    hu)  echo "Hungarian" ;;    id)  echo "Indonesian" ;;    is)  echo "Icelandic" ;;    it)  echo "Italian" ;;    iw)  echo "Hebrew" ;;    ja)  echo "Japanese" ;;    ka)  echo "Georgian" ;;    kk)  echo "Kazakh" ;;    kl)  echo "Kalaallisut" ;;    ko)  echo "Korean" ;;    ku)  echo "Kurdish" ;;    kw)  echo "Cornish" ;;    lg)  echo "Ganda" ;;    lt)  echo "Lithuanian" ;;    lv)  echo "Latvian" ;;    mg)  echo "Malagasy" ;;    mi)  echo "Maori" ;;    mk)  echo "Macedonian" ;;    ms)  echo "Malay" ;;    mt)  echo "Maltese" ;;    nb)  echo "Norwegian Bokmål" ;;    nl)  echo "Dutch" ;;    nn)  echo "Norwegian Nynorsk" ;;    oc)  echo "Occitan" ;;    om)  echo "Oromo" ;;    pl)  echo "Polish" ;;    pt)  echo "Portugese" ;;    ro)  echo "Romanian" ;;    ru)  echo "Russian" ;;    sk)  echo "Slovak" ;;    sl)  echo "Slovenian" ;;    so)  echo "Somali" ;;    sq)  echo "Albanian" ;;    st)  echo "Southern Sotho" ;;    sv)  echo "Swedish" ;;    tcy) echo "Tulu" ;;    tg)  echo "Tajik" ;;    th)  echo "Thai" ;;    tl)  echo "Tagalog" ;;    tr)  echo "Turkish" ;;    uk)  echo "Ukrainian" ;;    uz)  echo "Uzbek" ;;    wa)  echo "Walloon" ;;    xh)  echo "Xhosa" ;;    yi)  echo "Yiddish" ;;    zh)  echo "Chinese" ;;    zu)  echo "Zulu" ;;    *)   echo "$1" ;;    esac} # ISO-3166 country codes for localesiso3166_country() {    case "$1" in    AD) echo "Andorra" ;;    AE) echo "United Arab Emirates" ;;    AL) echo "Albania" ;;    AR) echo "Argentina" ;;    AT) echo "Austria" ;;    AU) echo "Australia" ;;    BA) echo "Bonsia and Herzegovina" ;;    BE) echo "Belgium" ;;    BG) echo "Bulgaria" ;;    BH) echo "Bahrain" ;;    BO) echo "Bolivia" ;;    BR) echo "Brazil" ;;    BW) echo "Botswana" ;;    BY) echo "Belarus" ;;    CA) echo "Canada" ;;    CH) echo "Switzerland" ;;    CL) echo "Chile" ;;    CN) echo "China" ;;    CO) echo "Colombia" ;;    CR) echo "Costa Rica" ;;    CY) echo "Cyprus" ;;    CZ) echo "Czech Republic" ;;    DE) echo "Germany" ;;    DJ) echo "Djibouti" ;;    DK) echo "Denmark" ;;    DO) echo "Dominican Republic" ;;    DZ) echo "Algeria" ;;    EC) echo "Ecuador" ;;    EE) echo "Estonia" ;;    EG) echo "Egypt" ;;    ES) echo "Spain" ;;    FI) echo "Finland" ;;    FO) echo "Faroe Islands" ;;    FR) echo "France" ;;    GB) echo "Great Britain" ;;    GE) echo "Georgia" ;;    GL) echo "Greenland" ;;    GR) echo "Greece" ;;    GT) echo "Guatemala" ;;    HK) echo "Hong Kong" ;;    HN) echo "Honduras" ;;    HR) echo "Croatia" ;;    HU) echo "Hungary" ;;    ID) echo "Indonesia" ;;    IE) echo "Ireland" ;;    IL) echo "Israel" ;;    IN) echo "India" ;;    IQ) echo "Iraq" ;;    IS) echo "Iceland" ;;    IT) echo "Italy" ;;    JO) echo "Jordan" ;;    JP) echo "Japan" ;;    KE) echo "Kenya" ;;    KR) echo "Korea, Republic of" ;;    KW) echo "Kuwait" ;;    KZ) echo "Kazakhstan" ;;    LB) echo "Lebanon" ;;    LT) echo "Lithuania" ;;    LU) echo "Luxembourg" ;;    LV) echo "Latvia" ;;    LY) echo "Libya" ;;    MA) echo "Morocco" ;;    MG) echo "Madagascar" ;;    MK) echo "Macedonia" ;;    MT) echo "Malta" ;;    MX) echo "Mexico" ;;    MY) echo "Malaysia" ;;    NI) echo "Nicaragua" ;;    NL) echo "Netherlands" ;;    NO) echo "Norway" ;;    NZ) echo "New Zealand" ;;    OM) echo "Oman" ;;    PA) echo "Panama" ;;    PE) echo "Peru" ;;    PH) echo "Philippines" ;;    PL) echo "Poland" ;;    PR) echo "Puerto Rico" ;;    PT) echo "Portugal" ;;    PY) echo "Paraguay" ;;    QA) echo "Qatar" ;;    RO) echo "Romania" ;;    RU) echo "Russian Federation" ;;    SA) echo "Saudi Arabia" ;;    SD) echo "Sudan" ;;    SE) echo "Sweden" ;;    SG) echo "Singapore" ;;    SI) echo "Slovenia" ;;    SK) echo "Slovakia" ;;    SO) echo "Somalia" ;;    SV) echo "El Salvador" ;;    SY) echo "Syria" ;;    TH) echo "Thailand" ;;    TJ) echo "Tajikistan" ;;    TN) echo "Tunisia" ;;    TR) echo "Turkey" ;;    TW) echo "Taiwan" ;;    UA) echo "Ukraine" ;;    UG) echo "Uganda" ;;    US) echo "United States of America" ;;    UY) echo "Uruguay" ;;    UZ) echo "Uzbekistan" ;;    VE) echo "Venezuela" ;;    YE) echo "Yemen" ;;    ZA) echo "South Africa" ;;    ZW) echo "Zimbabwe" ;;    *)  echo "$1" ;;    esac} show_disks() {    local dev size sectorsize gbytes     # IDE    for dev in $(ls /sys/block|grep -E '^hd'); do        if [ "$(cat /sys/block/$dev/device/media)" = "disk" ]; then            # Find out nr sectors and bytes per sector;            echo "/dev/$dev"            size=$(cat /sys/block/$dev/size)            sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)            gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"            echo "size:${gbytes}GB;sector_size:$sectorsize"        fi    done    # SATA/SCSI and Virtual disks (virtio)    for dev in $(ls /sys/block|grep -E '^([sv]|xv)d|mmcblk|nvme'); do        echo "/dev/$dev"        size=$(cat /sys/block/$dev/size)        sectorsize=$(cat /sys/block/$dev/queue/hw_sector_size)        gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"        echo "size:${gbytes}GB;sector_size:$sectorsize"    done    # cciss(4) devices    for dev in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]$'); do        echo "/dev/cciss/$dev"        size=$(cat /sys/block/cciss\!$dev/size)        sectorsize=$(cat /sys/block/cciss\!$dev/queue/hw_sector_size)        gbytes="$(($size * $sectorsize / 1024 / 1024 / 1024))"        echo "size:${gbytes}GB;sector_size:$sectorsize"    done} show_partitions() {    local dev fstype fssize p part     set -- $(show_disks)    while [ $# -ne 0 ]; do        disk=$(basename $1)        shift 2        # ATA/SCSI/SATA        for p in /sys/block/$disk/$disk*; do            if [ -d $p ]; then                part=$(basename $p)                fstype=$(lsblk -nfr /dev/$part|awk '{print $2}'|head -1)                [ "$fstype" = "iso9660" ] && continue                [ "$fstype" = "crypto_LUKS" ] && continue                [ "$fstype" = "LVM2_member" ] && continue                fssize=$(lsblk -nr /dev/$part|awk '{print $4}'|head -1)                echo "/dev/$part"                echo "size:${fssize:-unknown};fstype:${fstype:-none}"            fi        done    done    # Device Mapper    for p in /dev/mapper/*; do        part=$(basename $p)        [ "${part}" = "live-rw" ] && continue        [ "${part}" = "live-base" ] && continue        [ "${part}" = "control" ] && continue         fstype=$(lsblk -nfr $p|awk '{print $2}'|head -1)        fssize=$(lsblk -nr $p|awk '{print $4}'|head -1)        echo "${p}"        echo "size:${fssize:-unknown};fstype:${fstype:-none}"    done    # Software raid (md)    for p in $(ls -d /dev/md* 2>/dev/null|grep '[0-9]'); do        part=$(basename $p)        if cat /proc/mdstat|grep -qw $part; then            fstype=$(lsblk -nfr /dev/$part|awk '{print $2}')            [ "$fstype" = "crypto_LUKS" ] && continue            [ "$fstype" = "LVM2_member" ] && continue            fssize=$(lsblk -nr /dev/$part|awk '{print $4}')            echo "$p"            echo "size:${fssize:-unknown};fstype:${fstype:-none}"        fi    done    # cciss(4) devices    for part in $(ls /dev/cciss 2>/dev/null|grep -E 'c[0-9]d[0-9]p[0-9]+'); do        fstype=$(lsblk -nfr /dev/cciss/$part|awk '{print $2}')        [ "$fstype" = "crypto_LUKS" ] && continue        [ "$fstype" = "LVM2_member" ] && continue        fssize=$(lsblk -nr /dev/cciss/$part|awk '{print $4}')        echo "/dev/cciss/$part"        echo "size:${fssize:-unknown};fstype:${fstype:-none}"    done    if [ -e /sbin/lvs ]; then        # LVM        lvs --noheadings|while read lvname vgname perms size; do            echo "/dev/mapper/${vgname}-${lvname}"            echo "size:${size};fstype:lvm"        done    fi} menu_filesystems() {    local dev fstype fssize mntpoint reformat     while true; do        DIALOG --ok-label "Change" --cancel-label "Done" \            --title " Select the partition to edit " --menu "$MENULABEL" \            ${MENUSIZE} $(show_partitions)        [ $? -ne 0 ] && return         dev=$(cat $ANSWER)        DIALOG --title " Select the filesystem type for $dev " \            --menu "$MENULABEL" ${MENUSIZE} \            "btrfs" "Oracle's Btrfs" \            "ext2" "Linux ext2 (no journaling)" \            "ext3" "Linux ext3 (journal)" \            "ext4" "Linux ext4 (journal)" \            "f2fs" "Flash-Friendly Filesystem" \            "swap" "Linux swap" \            "vfat" "FAT32" \            "xfs" "SGI's XFS"        if [ $? -eq 0 ]; then            fstype=$(cat $ANSWER)        else            continue        fi        if [ "$fstype" != "swap" ]; then            DIALOG --inputbox "Please specify the mount point for $dev:" ${INPUTSIZE}            if [ $? -eq 0 ]; then                mntpoint=$(cat $ANSWER)            elif [ $? -eq 1 ]; then                continue            fi        else            mntpoint=swap        fi        DIALOG --yesno "Do you want to create a new filesystem on $dev?" ${YESNOSIZE}        if [ $? -eq 0 ]; then            reformat=1        elif [ $? -eq 1 ]; then            reformat=0        else            continue        fi        fssize=$(lsblk -nr $dev|awk '{print $4}')        set -- "$fstype" "$fssize" "$mntpoint" "$reformat"        if [ -n "$1" -a -n "$2" -a -n "$3" -a -n "$4" ]; then            local bdev=$(basename $dev)            local ddev=$(basename $(dirname $dev))            if [ "$ddev" != "dev" ]; then                sed -i -e "/^MOUNTPOINT \/dev\/${ddev}\/${bdev}.*/d" $CONF_FILE            else                sed -i -e "/^MOUNTPOINT \/dev\/${bdev}.*/d" $CONF_FILE            fi            echo "MOUNTPOINT $dev $1 $2 $3 $4" >>$CONF_FILE        fi    done} menu_partitions() {    DIALOG --title " Select the disk to partition " \        --menu "$MENULABEL" ${MENUSIZE} $(show_disks)    if [ $? -eq 0 ]; then        local device=$(cat $ANSWER)         DIALOG --title " Select the software for partitioning " \            --menu "$MENULABEL" ${MENUSIZE} \            "cfdisk" "Easy to use" \            "fdisk" "More advanced"        if [ $? -eq 0 ]; then            local software=$(cat $ANSWER)             DIALOG --title "Modify Partition Table on $device" --msgbox "\n${BOLD}${software} will be executed in disk $device.${RESET}\n\nFor BIOS systems, MBR or GPT partition tables are supported.\nTo use GPT on PC BIOS systems an empty partition of 1MB must be added\nat the first 2GB of the disk with the TOGGLE \`bios_grub' enabled.\n${BOLD}NOTE: you don't need this on EFI systems.${RESET}\n\n

Lines 1–500 of 1473.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t