Add mirror country selection and cleanup a few places

This commit is contained in:
natemaia 2020-05-17 11:05:57 -07:00
parent c30b103b82
commit 1a49d67c4c

170
installer
View File

@ -1,12 +1,11 @@
#!/bin/bash #!/bin/bash
# This program is free software, provided under the GNU GPL # 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 # Some ideas and code reworked from other resources
# AIF, Calamares, and the Arch Wiki.. Credit where credit is due # AIF, Calamares, and the Arch Wiki.. Credit where credit is due
# shellcheck disable=SC2086,SC2046,SC2254,SC2164 # shellcheck disable=SC2086,SC2046,SC2254,SC2164
VER=2.1.50 VER=2.1.50
# default values { # default values {
@ -627,26 +626,22 @@ select_keymap()
{ {
if [[ ! -f /tmp/xkeys ]]; then if [[ ! -f /tmp/xkeys ]]; then
dlg KEYMAP menu "Keyboard" "$_keymap" \ dlg KEYMAP menu "Keyboard" "$_keymap" \
us English cm English gb English au English gh English \ af Afghani al Albanian am Armenian ara Arabic at German au English \
za English ng English ca French 'cd' French gn French \ az Azerbaijani ba Bosnian bd Bangla be Belgian 'bg' Bulgarian br Portuguese \
tg French fr French de German at German ch German \ bt Dzongkha bw Tswana by Belarusian ca French 'cd' French ch German \
es Spanish latam Spanish br Portuguese pt Portuguese ma Arabic \ cm English cn Chinese cz Czech de German dk Danish dz Berber \
sy Arabic ara Arabic ua Ukrainian cz Czech ru Russian \ ee Estonian epo Esperanto es Spanish et Amharic 'fi' Finnish fo Faroese \
sk Slovak nl Dutch it Italian hu Hungarian cn Chinese \ fr French gb English ge Georgian gh English gn French gr Greek \
tw Taiwanese vn Vietnamese kr Korean jp Japanese th Thai \ hr Croatian hu Hungarian id Indonesian ie Irish il Hebrew 'in' Indian \
la Lao pl Polish se Swedish is Icelandic 'fi' Finnish \ iq Iraqi ir Persian is Icelandic it Italian jp Japanese ke Swahili \
dk Danish be Belgian in Indian al Albanian am Armenian \ kg Kyrgyz kh Khmer kr Korean kz Kazakh la Lao latam Spanish \
bd Bangla ba Bosnian 'bg' Bulgarian dz Berber mm Burmese \ lk Sinhala lt Lithuanian lv Latvian ma Arabic mao Maori md Moldavian \
hr Croatian gr Greek il Hebrew ir Persian iq Iraqi \ me Montenegrin mk Macedonian ml Bambara mm Burmese mn Mongolian mt Maltese \
af Afghani fo Faroese ge Georgian ee Estonian kg Kyrgyz \ 'mv' Dhivehi my Malay ng English nl Dutch no Norwegian np Nepali \
kz Kazakh lt Lithuanian mt Maltese mn Mongolian ro Romanian \ ph Filipino pk Urdu pl Polish pt Portuguese ro Romanian rs Serbian \
no Norwegian rs Serbian si Slovenian tj Tajik lk Sinhala \ ru Russian se Swedish si Slovenian sk Slovak sn Wolof sy Arabic \
tr Turkish uz Uzbek ie Irish pk Urdu 'mv' Dhivehi \ tg French th Thai tj Tajik tm Turkmen tr Turkish tw Taiwanese \
np Nepali et Amharic sn Wolof ml Bambara tz Swahili \ tz Swahili ua Ukrainian us English uz Uzbek vn Vietnamese za English || return 1
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
echo "$KEYMAP" > /tmp/xkeys echo "$KEYMAP" > /tmp/xkeys
else 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- " txt="\nWARNING: ALL data on $device will be destroyed and the following partitions will be created\n\n- "
if [[ $SYS == 'BIOS' ]]; then if [[ $SYS == 'BIOS' ]]; then
label="msdos" boot_fs="ext4" boot_type="primary" 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 else
label="gpt" boot_fs="fat32" boot_type="ESP" 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 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" yesno "Auto Partition" "$txt" && part_auto "$device" "$label" "$boot_fs" "$root_size" "$boot_type"
else else
clear clear
@ -1043,18 +1038,17 @@ part_mount()
mkdir -p "$mntp" mkdir -p "$mntp"
if [[ $BTRFS -ne 2 && $fs && ${FS_OPTS[$fs]} && $part != "$BOOT" && $part != "$AUTO_ROOT" ]] && select_mntopts "$part" "$fs"; then 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 errshow 0 "mount -o $MNT_OPTS $part $mntp" || return 1
else else
mount "$part" "$mntp" > /dev/null 2> "$ERR" || mount "$part" "$mntp" > /dev/null 2> "$ERR"
errshow 0 "mount $part $mntp" || return 1
MNT_OPTS='' MNT_OPTS=''
mount "$part" "$mntp" > /dev/null 2> "$ERR"
errshow 0 "mount $part $mntp" || return 1
fi fi
msg "Mount Complete" "\nMounted $part at $mntp\n" 1 msg "Mount Complete" "\nMounted $part at $mntp\n" 1
part_countdec "$part" part_countdec "$part"
part_cryptlv "$part" part_cryptlv "$part"
return 0 return 0
} }
@ -1086,8 +1080,12 @@ part_pretty()
[[ $size_t == 'K' || ($size_t == 'M' && $isize -lt 80) ]] || printf "%s\n" "$dev ${size}__$model" [[ $size_t == 'K' || ($size_t == 'M' && $isize -lt 80) ]] || printf "%s\n" "$dev ${size}__$model"
done < <(lsblk -lno TYPE,PATH,SIZE,FSTYPE,LABEL $part | done < <(lsblk -lno TYPE,PATH,SIZE,FSTYPE,LABEL $part |
awk "/$regexp/"' && !'"/${IGNORE_DEV:-NONEXX}/"' { awk "/$regexp/"' && !'"/${IGNORE_DEV:-NONEXX}/"' {
if ($4 == "") { $4 = "unformatted" } if ($4 == "") {
if ($5 == "") { $5 = "unlabeled" } $4 = "unformatted"
}
if ($5 == "") {
$5 = "unlabeled"
}
print $2, $3 "__" $4 "__" $5 print $2, $3 "__" $4 "__" $5
}') }')
} }
@ -1461,8 +1459,7 @@ select_mntopts()
opts+="$i - off " opts+="$i - off "
done done
until [[ $MNT_OPTS ]]; do until [[ $MNT_OPTS ]]; do
dlg MNT_OPTS check "$title" "$_mount" $opts dlg MNT_OPTS check "$title" "$_mount" $opts || return 1 # no options is auto mount
[[ $MNT_OPTS ]] || return 1 # no options is auto mount
MNT_OPTS="${MNT_OPTS// /,}" MNT_OPTS="${MNT_OPTS// /,}"
yesno "$title" "\nConfirm mount options: $MNT_OPTS\n" || MNT_OPTS='' yesno "$title" "\nConfirm mount options: $MNT_OPTS\n" || MNT_OPTS=''
done done
@ -2037,47 +2034,35 @@ install_mkinitcpio()
install_mirrorlist() install_mirrorlist()
{ {
if hash reflector > /dev/null 2>&1; then if [[ $AUTO_MIR ]]; then
timedatectl set-ntp 1 && timedatectl > /dev/null 2>&1 timedatectl set-ntp 1 && timedatectl > /dev/null 2>&1
reflector --verbose --score 80 -l 40 -f 5 --sort rate --save "$1" reflector --verbose --score 80 -l 40 -f 5 --sort rate --save /etc/pacman.d/mirrorlist
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 else
mirror="https://www.archlinux.org/mirrorlist/?country=${country}&use_mirror_status=on" echo "ranking mirrorlist, this may take a while..."
fi cp -f /etc/pacman.d/mirrorlist /tmp/mirrors
else # no country code so just grab all mirrors, will be a very slow sort but we don't have other options rankmirrors -n 6 /tmp/mirrors > /etc/pacman.d/mirrorlist
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"
fi fi
} }
install_background() install_background()
{ {
local luks net="networkmanager" local luks='' net="networkmanager"
[[ ! -d /etc/NetworkManager/system-connections ]] && net="netctl" [[ ! -d /etc/NetworkManager/system-connections ]] && net="netctl"
[[ $LUKS ]] && luks="cryptsetup" [[ $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 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 if [[ $PACSTRAP == 1 ]]; then
pacman -Sy >> /tmp/bgout 2>&1 pacman -Sy >> /tmp/bgout 2>&1
@ -2113,6 +2098,69 @@ install_background()
trap "kill $BG_PID 2> /dev/null" EXIT 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 # display manager config
# these are called based on which DM is chosen after it is installed # 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 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 die 1
fi fi
install_mirrorlist "/etc/pacman.d/mirrorlist" install_mirrorlist
al_repo "/etc/pacman.conf" al_repo "/etc/pacman.conf"
pacman -Syyu --noconfirm || die 1 pacman -Syyu --noconfirm || die 1
rm -rf /var/cache/pacman/pkg/* rm -rf /var/cache/pacman/pkg/*