From 1a49d67c4c401a88cf8f8cfbfaf5ab346b75c15f Mon Sep 17 00:00:00 2001 From: natemaia Date: Sun, 17 May 2020 11:05:57 -0700 Subject: [PATCH] Add mirror country selection and cleanup a few places --- installer | 172 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 62 deletions(-) diff --git a/installer b/installer index cba9309..da0b282 100755 --- a/installer +++ b/installer @@ -1,12 +1,11 @@ #!/bin/bash # This program is free software, provided under the GNU GPL -# Written by Nathaniel Maia for use in Archlabs +# Written by Nathaniel Maia for Archlabs, works in most Arch based distros # Some ideas and code reworked from other resources # AIF, Calamares, and the Arch Wiki.. Credit where credit is due # shellcheck disable=SC2086,SC2046,SC2254,SC2164 - VER=2.1.50 # default values { @@ -627,26 +626,22 @@ select_keymap() { if [[ ! -f /tmp/xkeys ]]; then dlg KEYMAP menu "Keyboard" "$_keymap" \ - us English cm English gb English au English gh English \ - za English ng English ca French 'cd' French gn French \ - tg French fr French de German at German ch German \ - es Spanish latam Spanish br Portuguese pt Portuguese ma Arabic \ - sy Arabic ara Arabic ua Ukrainian cz Czech ru Russian \ - sk Slovak nl Dutch it Italian hu Hungarian cn Chinese \ - tw Taiwanese vn Vietnamese kr Korean jp Japanese th Thai \ - la Lao pl Polish se Swedish is Icelandic 'fi' Finnish \ - dk Danish be Belgian in Indian al Albanian am Armenian \ - bd Bangla ba Bosnian 'bg' Bulgarian dz Berber mm Burmese \ - hr Croatian gr Greek il Hebrew ir Persian iq Iraqi \ - af Afghani fo Faroese ge Georgian ee Estonian kg Kyrgyz \ - kz Kazakh lt Lithuanian mt Maltese mn Mongolian ro Romanian \ - no Norwegian rs Serbian si Slovenian tj Tajik lk Sinhala \ - tr Turkish uz Uzbek ie Irish pk Urdu 'mv' Dhivehi \ - np Nepali et Amharic sn Wolof ml Bambara tz Swahili \ - ke Swahili bw Tswana ph Filipino my Malay tm Turkmen \ - id Indonesian bt Dzongkha lv Latvian md Moldavian mao Maori \ - by Belarusian az Azerbaijani mk Macedonian kh Khmer epo Esperanto \ - me Montenegrin || return 1 + af Afghani al Albanian am Armenian ara Arabic at German au English \ + az Azerbaijani ba Bosnian bd Bangla be Belgian 'bg' Bulgarian br Portuguese \ + bt Dzongkha bw Tswana by Belarusian ca French 'cd' French ch German \ + cm English cn Chinese cz Czech de German dk Danish dz Berber \ + ee Estonian epo Esperanto es Spanish et Amharic 'fi' Finnish fo Faroese \ + fr French gb English ge Georgian gh English gn French gr Greek \ + hr Croatian hu Hungarian id Indonesian ie Irish il Hebrew 'in' Indian \ + iq Iraqi ir Persian is Icelandic it Italian jp Japanese ke Swahili \ + kg Kyrgyz kh Khmer kr Korean kz Kazakh la Lao latam Spanish \ + lk Sinhala lt Lithuanian lv Latvian ma Arabic mao Maori md Moldavian \ + me Montenegrin mk Macedonian ml Bambara mm Burmese mn Mongolian mt Maltese \ + 'mv' Dhivehi my Malay ng English nl Dutch no Norwegian np Nepali \ + ph Filipino pk Urdu pl Polish pt Portuguese ro Romanian rs Serbian \ + ru Russian se Swedish si Slovenian sk Slovak sn Wolof sy Arabic \ + tg French th Thai tj Tajik tm Turkmen tr Turkish tw Taiwanese \ + tz Swahili ua Ukrainian us English uz Uzbek vn Vietnamese za English || return 1 echo "$KEYMAP" > /tmp/xkeys else @@ -910,12 +905,12 @@ part_menu() txt="\nWARNING: ALL data on $device will be destroyed and the following partitions will be created\n\n- " if [[ $SYS == 'BIOS' ]]; then label="msdos" boot_fs="ext4" boot_type="primary" - txt+="An $boot_fs boot partition with the boot flag enabled (512M)\n- " + txt+="$boot_fs boot partition with the boot flag enabled (512M)\n- " else label="gpt" boot_fs="fat32" boot_type="ESP" - txt+="A $boot_fs efi boot partition (512M)\n- " + txt+="$boot_fs efi boot partition (512M)\n- " fi - txt+="An ext4 partition using all remaining space ($root_size)\n\nDo you want to continue?\n" + txt+="ext4 partition using all remaining space ($root_size)\n\nDo you want to continue?\n" yesno "Auto Partition" "$txt" && part_auto "$device" "$label" "$boot_fs" "$root_size" "$boot_type" else clear @@ -1043,18 +1038,17 @@ part_mount() mkdir -p "$mntp" if [[ $BTRFS -ne 2 && $fs && ${FS_OPTS[$fs]} && $part != "$BOOT" && $part != "$AUTO_ROOT" ]] && select_mntopts "$part" "$fs"; then - mount -o $MNT_OPTS "$part" "$mntp" > /dev/null 2> "$ERR" || mount -o $MNT_OPTS "$part" "$mntp" > /dev/null 2> "$ERR" + mount -o $MNT_OPTS "$part" "$mntp" > /dev/null 2> "$ERR" errshow 0 "mount -o $MNT_OPTS $part $mntp" || return 1 else - mount "$part" "$mntp" > /dev/null 2> "$ERR" || mount "$part" "$mntp" > /dev/null 2> "$ERR" - errshow 0 "mount $part $mntp" || return 1 MNT_OPTS='' + mount "$part" "$mntp" > /dev/null 2> "$ERR" + errshow 0 "mount $part $mntp" || return 1 fi msg "Mount Complete" "\nMounted $part at $mntp\n" 1 part_countdec "$part" part_cryptlv "$part" - return 0 } @@ -1086,8 +1080,12 @@ part_pretty() [[ $size_t == 'K' || ($size_t == 'M' && $isize -lt 80) ]] || printf "%s\n" "$dev ${size}__$model" done < <(lsblk -lno TYPE,PATH,SIZE,FSTYPE,LABEL $part | awk "/$regexp/"' && !'"/${IGNORE_DEV:-NONEXX}/"' { - if ($4 == "") { $4 = "unformatted" } - if ($5 == "") { $5 = "unlabeled" } + if ($4 == "") { + $4 = "unformatted" + } + if ($5 == "") { + $5 = "unlabeled" + } print $2, $3 "__" $4 "__" $5 }') } @@ -1461,8 +1459,7 @@ select_mntopts() opts+="$i - off " done until [[ $MNT_OPTS ]]; do - dlg MNT_OPTS check "$title" "$_mount" $opts - [[ $MNT_OPTS ]] || return 1 # no options is auto mount + dlg MNT_OPTS check "$title" "$_mount" $opts || return 1 # no options is auto mount MNT_OPTS="${MNT_OPTS// /,}" yesno "$title" "\nConfirm mount options: $MNT_OPTS\n" || MNT_OPTS='' done @@ -2037,47 +2034,35 @@ install_mkinitcpio() install_mirrorlist() { - if hash reflector > /dev/null 2>&1; then + if [[ $AUTO_MIR ]]; then timedatectl set-ntp 1 && timedatectl > /dev/null 2>&1 - reflector --verbose --score 80 -l 40 -f 5 --sort rate --save "$1" - elif hash rankmirrors > /dev/null 2>&1; then - echo "Sorting mirrorlist... This will take a while" - local key="access_key=5f29642060ab983b31fdf4c2935d8c56" - - ip_add="$(curl -fsSL "http://api.ipstack.com/check&?$key&fields=ip" | - python -c "import sys, json; print(json.load(sys.stdin)['ip'])")" - - country="$(curl -fsSL "http://api.ipstack.com/$ip_add?$key&fields=country_code" | - python -c "import sys, json; print(json.load(sys.stdin)['country_code'])")" - - if [[ "$country" ]]; then - if [[ $country =~ (CA|US) ]]; then - # use both CA and US mirrors for CA or US countries - mirror="https://www.archlinux.org/mirrorlist/?country=US&country=CA&use_mirror_status=on" - elif [[ $country =~ (AU|NZ) ]]; then - # use both AU and NZ mirrors for AU or NZ countries - mirror="https://www.archlinux.org/mirrorlist/?country=AU&country=NZ&use_mirror_status=on" - else - mirror="https://www.archlinux.org/mirrorlist/?country=${country}&use_mirror_status=on" - fi - else # no country code so just grab all mirrors, will be a very slow sort but we don't have other options - mirror="https://www.archlinux.org/mirrorlist/?country=all&use_mirror_status=on" - fi - curl -fsSL "$mirror" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 6 - > "$1" + reflector --verbose --score 80 -l 40 -f 5 --sort rate --save /etc/pacman.d/mirrorlist + else + echo "ranking mirrorlist, this may take a while..." + cp -f /etc/pacman.d/mirrorlist /tmp/mirrors + rankmirrors -n 6 /tmp/mirrors > /etc/pacman.d/mirrorlist fi } install_background() { - local luks net="networkmanager" + local luks='' net="networkmanager" [[ ! -d /etc/NetworkManager/system-connections ]] && net="netctl" [[ $LUKS ]] && luks="cryptsetup" + local txt="\nUse an automatically generated mirrorlist?\n\nNo will require selecting which countries to use" + if hash reflector > /dev/null 2>&1 && yesno "Mirrorlist" "$txt"; then + AUTO_MIR=true + else + AUTO_MIR='' + install_mirror_country + fi + yesno "Background Install" "$_bginstall" "Pacstrap" "Copy ISO" || PACSTRAP=0 ( - install_mirrorlist "/etc/pacman.d/mirrorlist" > /tmp/bgout 2>&1 + install_mirrorlist > /tmp/bgout 2>&1 if [[ $PACSTRAP == 1 ]]; then pacman -Sy >> /tmp/bgout 2>&1 @@ -2113,6 +2098,69 @@ install_background() trap "kill $BG_PID 2> /dev/null" EXIT } +install_mirror_country() +{ + local conf='' tmp='' + + until [[ $conf ]]; do + local url='' + dlg CODES check "Mirror Country" "\nSelect which countries to use for mirrors from the list below." \ + AU Australia "$(ofn AU "$CODES")" AT Austria "$(ofn AT "$CODES")" \ + BA "Bosnia Herzegovina" "$(ofn BA "$CODES")" BY Belarus "$(ofn BY "$CODES")" \ + BE Belgium "$(ofn BE "$CODES")" BR Brazil "$(ofn BR "$CODES")" \ + BG Bulgaria "$(ofn BG "$CODES")" CA Canada "$(ofn CA "$CODES")" \ + CL Chile "$(ofn CL "$CODES")" CN China "$(ofn CN "$CODES")" \ + CO Colombia "$(ofn CO "$CODES")" CZ "Czech Republic" "$(ofn CZ "$CODES")" \ + DK Denmark "$(ofn DK "$CODES")" EE Estonia "$(ofn EE "$CODES")" \ + FI Finland "$(ofn FI "$CODES")" FR France "$(ofn FR "$CODES")" \ + DE Germany "$(ofn DE "$CODES")" GB "United Kingdom" "$(ofn GB "$CODES")" \ + GR Greece "$(ofn GR "$CODES")" HU Hungary "$(ofn HU "$CODES")" \ + IN India "$(ofn IN "$CODES")" IE Ireland "$(ofn IE "$CODES")" \ + IL Israel "$(ofn IL "$CODES")" IT Italy "$(ofn IT "$CODES")" \ + JP Japan "$(ofn JP "$CODES")" KZ Kazakhstan "$(ofn KZ "$CODES")" \ + KR Korea "$(ofn KR "$CODES")" LT Lithuania "$(ofn LT "$CODES")" \ + LV Latvia "$(ofn LV "$CODES")" LU Luxembourg "$(ofn LU "$CODES")" \ + MK Macedonia "$(ofn MK "$CODES")" NL Netherlands "$(ofn NL "$CODES")" \ + NC "New Caledonia" "$(ofn NC "$CODES")" NZ "New Zealand" "$(ofn NZ "$CODES")" \ + NO Norway "$(ofn NO "$CODES")" PL Poland "$(ofn PL "$CODES")" \ + PT Portugal "$(ofn PT "$CODES")" RO Romania "$(ofn RO "$CODES")" \ + RU Russia "$(ofn RU "$CODES")" RS Serbia "$(ofn RS "$CODES")" \ + SG Singapore "$(ofn SG "$CODES")" SK Slovakia "$(ofn SK "$CODES")" \ + ZA "South Africa" "$(ofn ZA "$CODES")" ES Spain "$(ofn ES "$CODES")" \ + LK "Sri Lanka" "$(ofn LK "$CODES")" SE Sweden "$(ofn SE "$CODES")" \ + CH Switzerland "$(ofn CH "$CODES")" TW Taiwan "$(ofn TW "$CODES")" \ + TR Turkey "$(ofn TR "$CODES")" UA Ukraine "$(ofn UA "$CODES")" \ + US "United States" "$(ofn US "$CODES")" UZ Uzbekistan "$(ofn UZ "$CODES")" \ + VN Vietnam "$(ofn VN "$CODES")" || return 1 + + # build the url to use + for i in $CODES; do + if [[ $url ]]; then + url+="&country=$i" + else + url="https://www.archlinux.org/mirrorlist/?country=$i" + fi + done + url+="&use_mirror_status=on" + + msg "Mirror Country" "\nDownloading the latest mirrorlist for the chosen countries.\n\n$url\n" 0 + tmp="$(mktemp --suffix=-mirrorlist)" + curl -fsSL $url -o $tmp 2> "$ERR" + errshow 0 "curl -fsSL $url -o $tmp" || return 1 + sed -i 's/^#Server/Server/g' "$tmp" + + # let the user edit and confirm it + $EDITOR "$tmp" + if yesno "Mirror Country" "\nUse the newly created mirrorlist for installation?\n"; then + conf=true + else + rm -f "$tmp" + fi + done + cp -f "$tmp" /etc/pacman.d/mirrorlist + chmod +r /etc/pacman.d/mirrorlist +} + ############################################################################### # display manager config # these are called based on which DM is chosen after it is installed @@ -2904,7 +2952,7 @@ live() msg "Remount Fail" "\nUnable to remount root with a larger copy-on-write space, this is needed for installing packages.\n\nExiting..\n" 2 die 1 fi - install_mirrorlist "/etc/pacman.d/mirrorlist" + install_mirrorlist al_repo "/etc/pacman.conf" pacman -Syyu --noconfirm || die 1 rm -rf /var/cache/pacman/pkg/*