2023-07-17 09:28:52 +02:00
#!/usr/bin/env bash
2023-08-11 17:19:18 +02:00
# SPDX-License-Identifier: GPL-3.0-or-later
2023-07-17 09:28:52 +02:00
# created by Tobias Powalowski <tpowa@archlinux.org>
2023-09-03 22:02:48 +02:00
. /usr/lib/archboot/common.sh
2024-03-20 16:48:05 +01:00
_TITLE = " archboot.com | ${ _RUNNING_ARCH } | ${ _RUNNING_KERNEL } | Basic Setup | Pacman Configuration "
2023-07-17 09:28:52 +02:00
2023-08-31 10:28:44 +02:00
_task_download_mirror( ) {
2023-09-04 15:23:29 +02:00
${ _DLPROG } -o /tmp/pacman_mirrorlist.txt " https://www.archlinux.org/mirrorlist/?country= ${ _COUNTRY } &protocol=https&ip_version=4&ip_version=6&use_mirror_status=on "
2023-08-31 10:28:44 +02:00
rm /.archboot
}
_download_mirror( ) {
: > /.archboot
_task_download_mirror &
_progress_wait "0" "99" " ${ _DOWNLOAD } " "0.01"
2023-08-02 08:17:59 +02:00
_progress "100" " ${ _DOWNLOAD } "
sleep 2
}
2023-07-17 09:28:52 +02:00
_select_mirror( ) {
2023-07-22 10:44:56 +02:00
# Download updated mirrorlist, if possible (only on x86_64)
2023-07-17 09:28:52 +02:00
if [ [ " ${ _RUNNING_ARCH } " = = "x86_64" ] ] ; then
2023-09-04 14:58:39 +02:00
_COUNTRY = " $( ${ _DLPROG } "http://ip-api.com/csv/?fields=countryCode" ) "
2023-08-02 08:19:39 +02:00
_DOWNLOAD = " Downloading latest mirrorlist for Region ${ _COUNTRY } ... "
2023-08-03 16:02:14 +02:00
_download_mirror | _dialog --title " Pacman Configuration " --no-mouse --gauge " ${ _DOWNLOAD } " 6 70 0
2024-06-26 21:49:04 +02:00
if rg -q '#Server = https:' /tmp/pacman_mirrorlist.txt; then
2023-09-06 10:28:59 +02:00
mv " ${ _PACMAN_MIRROR } " " ${ _PACMAN_MIRROR } .bak "
cp /tmp/pacman_mirrorlist.txt " ${ _PACMAN_MIRROR } "
2023-07-17 09:28:52 +02:00
fi
fi
2023-07-22 10:44:56 +02:00
# This regex doesn't honor commenting
2024-06-27 09:57:02 +02:00
_MIRRORS = " $( rg -o '(https://[^/]*)' -r '$1 _' ${ _PACMAN_MIRROR } ) "
2024-07-17 21:43:50 +02:00
[ [ -z ${ _MIRRORS } ] ] && _MIRRORS = " $( rg -o '(http://[^/]*)' -r '$1 _' ${ _PACMAN_MIRROR } ) "
2023-11-15 16:52:55 +01:00
#shellcheck disable=SC2086
_dialog --cancel-label " ${ _LABEL } " --title " Package Mirror " --menu "" 13 55 7 \
"Custom Mirror" "_" ${ _MIRRORS } 2>${ _ANSWER } || return 1
#shellcheck disable=SC2155
local _SERVER = $( cat " ${ _ANSWER } " )
if [ [ " ${ _SERVER } " = = "Custom Mirror" ] ] ; then
_dialog --inputbox "Enter the full URL to repositories." 8 65 \
"" 2>" ${ _ANSWER } " || _SYNC_URL = ""
_SYNC_URL = $( cat " ${ _ANSWER } " )
else
2024-07-30 21:18:44 +02:00
# get URL from _PACMAN_MIRROR and only show 1 result
2024-07-30 15:51:58 +02:00
_SYNC_URL = $( rg -m1 -o " ${ _SERVER } .* " " ${ _PACMAN_MIRROR } " )
2023-11-15 16:52:55 +01:00
fi
2023-07-17 09:28:52 +02:00
echo " Using mirror: ${ _SYNC_URL } " >" ${ _LOG } "
2023-07-22 19:41:52 +02:00
# comment already existing entries
2024-06-27 07:36:04 +02:00
sd '^Server' '#Server' " ${ _PACMAN_MIRROR } "
2023-07-17 09:28:52 +02:00
#shellcheck disable=SC2027,SC2086
2024-02-25 16:41:49 +01:00
echo "Server = " ${ _SYNC_URL } "" >> " ${ _PACMAN_MIRROR } "
2023-11-15 17:05:08 +01:00
if ! pacman -Sy & >${ _LOG } ; then
2023-11-15 17:03:38 +01:00
_dialog --title " ERROR " --no-mouse --infobox "Your selected mirror is not working correctly, please configure again!" 3 75
2023-11-15 17:02:28 +01:00
sleep 3
2023-11-15 16:59:57 +01:00
_SYNC_URL = ""
fi
2023-07-17 09:28:52 +02:00
}
2024-07-25 07:48:17 +02:00
#shellcheck disable=SC2120
2023-07-17 09:28:52 +02:00
_enable_testing( ) {
2024-07-25 07:48:17 +02:00
_DOTESTING = ""
2024-06-26 21:49:04 +02:00
if ! rg -q "^\[.*testing\]" /etc/pacman.conf; then
2024-07-25 07:48:17 +02:00
if _dialog --title " Testing Repositories " --defaultno --yesno "Do you want to enable testing repositories?\n\nOnly enable this if you need latest\navailable packages for testing purposes!" 8 50; then
2024-07-10 21:40:20 +02:00
#shellcheck disable=SC2016
2024-06-27 07:36:04 +02:00
sd '^#(\[[c,e].*-testing\]\n)#' '$1' " ${ 1 } /etc/pacman.conf "
2024-07-25 07:48:17 +02:00
_DOTESTING = 1
2023-07-17 09:28:52 +02:00
fi
2023-08-01 20:49:02 +02:00
else
_DOTESTING = 1
2023-07-17 09:28:52 +02:00
fi
}
2023-08-31 14:50:10 +02:00
_task_pacman_keyring_install( ) {
2024-06-11 12:31:10 +02:00
_pacman_keyring
2024-09-08 15:44:33 +02:00
#shellcheck disable=SC2068
2024-09-08 14:34:33 +02:00
pacman -Sy --noconfirm --noprogressbar ${ _KEYRING [@] } & >" ${ _LOG } "
2023-08-31 14:29:14 +02:00
rm /.archboot
}
_prepare_pacman( ) {
: > /.archboot
_task_pacman_keyring_install &
2023-09-02 08:35:23 +02:00
_progress_wait "0" "99" "Updating Arch Linux keyring..." "0.15"
2023-08-31 14:29:14 +02:00
_progress "100" "Arch Linux keyring is ready."
sleep 2
2023-07-17 12:06:01 +02:00
}
2023-08-31 14:39:08 +02:00
_task_update_environment( ) {
2023-07-17 10:52:11 +02:00
_UPDATE_ENVIRONMENT = ""
_LOCAL_KERNEL = ""
_ONLINE_KERNEL = ""
2023-08-01 21:22:23 +02:00
pacman -Sy & >" ${ _LOG } "
#shellcheck disable=SC2086
2024-06-26 21:49:04 +02:00
_LOCAL_KERNEL = " $( pacman -Qi ${ _KERNELPKG } | rg 'Version.*: (.*)' -r '$1' ) "
2023-08-01 21:22:23 +02:00
if [ [ " ${ _RUNNING_ARCH } " = = "aarch64" ] ] ; then
#shellcheck disable=SC2086
2024-06-26 21:49:04 +02:00
_ONLINE_KERNEL = " $( pacman -Si ${ _KERNELPKG } -${ _RUNNING_ARCH } | rg 'Version.*: (.*)' -r '$1' ) "
2023-08-01 21:22:23 +02:00
else
if [ [ -n " ${ _DOTESTING } " ] ] ; then
#shellcheck disable=SC2086
2024-06-26 21:49:04 +02:00
_ONLINE_KERNEL = " $( pacman -Si core-testing/${ _KERNELPKG } 2>${ _NO_LOG } | rg 'Version.*: (.*)' -r '$1' ) "
2023-08-01 21:22:23 +02:00
fi
if [ [ -z " ${ _ONLINE_KERNEL } " ] ] ; then
2023-08-01 21:03:13 +02:00
#shellcheck disable=SC2086
2024-06-26 21:49:04 +02:00
_ONLINE_KERNEL = " $( pacman -Si ${ _KERNELPKG } | rg 'Version.*: (.*)' -r '$1' ) "
2023-07-17 09:28:52 +02:00
fi
fi
2023-10-07 22:01:11 +02:00
echo " ${ _LOCAL_KERNEL } local kernel version and ${ _ONLINE_KERNEL } online kernel version. " >" ${ _LOG } "
if ! [ [ " ${ _LOCAL_KERNEL } " = = " ${ _ONLINE_KERNEL } " ] ] ; then
echo " ${ _ONLINE_KERNEL } " > /.new_kernel
fi
2023-08-31 14:39:08 +02:00
rm /.archboot
}
_update_environment( ) {
: > /.archboot
_task_update_environment &
2023-08-31 18:14:35 +02:00
_progress_wait "0" " 97" "Checking on new online kernel version..." "0.025"
2023-10-07 22:01:11 +02:00
if ! [ [ -f "/.new_kernel" ] ] ; then
2023-08-01 21:22:23 +02:00
_progress "98" "No new kernel online available. Skipping update environment."
2023-08-31 10:39:09 +02:00
sleep 1
2023-08-03 15:58:29 +02:00
_progress "100" "Pacman configuration completed successfully."
sleep 2
2023-08-03 15:53:56 +02:00
else
2023-08-03 15:58:29 +02:00
_progress "100" "New kernel online available. Asking for update..."
2023-08-03 15:56:23 +02:00
sleep 2
2023-08-01 21:22:23 +02:00
fi
2023-07-17 09:28:52 +02:00
}
_check
2023-07-20 08:58:10 +02:00
if [ [ ! -e "/var/cache/pacman/pkg/archboot.db" ] ] ; then
2023-08-25 12:19:47 +02:00
if ! ping -c1 www.google.com & >" ${ _NO_LOG } " ; then
2023-07-28 17:06:26 +02:00
_dialog --title " ERROR " --no-mouse --infobox "Your network is not working. Please reconfigure it." 3 60
2023-07-20 08:58:10 +02:00
sleep 5
_abort
fi
2023-07-19 07:48:29 +02:00
fi
2023-07-17 09:28:52 +02:00
while true; do
2023-07-20 08:55:10 +02:00
if [ [ -e "/var/cache/pacman/pkg/archboot.db" ] ] ; then
2023-08-03 16:02:14 +02:00
_dialog --title " Pacman Configuration " --no-mouse --infobox "Setting local mirror..." 3 40
2023-07-20 09:03:00 +02:00
_PACMAN_CONF = "/etc/pacman.conf"
2023-07-21 15:44:34 +02:00
cat << EOF > " ${ _PACMAN_CONF } "
[ options]
Architecture = auto
SigLevel = Required DatabaseOptional
LocalFileSigLevel = Optional
[ archboot]
Server = file:///var/cache/pacman/pkg
EOF
2023-07-20 09:06:43 +02:00
pacman -Sy >>" ${ _LOG } "
2023-07-22 07:14:16 +02:00
sleep 2
2023-07-20 08:55:10 +02:00
break
2023-08-01 21:46:44 +02:00
else
if [ [ " ${ _RUNNING_ARCH } " = = "x86_64" ] ] ; then
2024-07-10 21:42:44 +02:00
#shellcheck disable=SC2119
2023-08-01 21:46:44 +02:00
_enable_testing
fi
2023-11-15 16:52:55 +01:00
_SYNC_URL = ""
while [ [ -z " ${ _SYNC_URL } " ] ] ; do
_select_mirror || _abort
done
2023-07-20 08:55:10 +02:00
fi
2023-08-31 14:51:51 +02:00
if _prepare_pacman | _dialog --title " Pacman Configuration " --no-mouse --gauge "Update Arch Linux keyring..." 6 70 0; then
2023-07-17 12:31:55 +02:00
break
else
2023-07-28 17:06:26 +02:00
_dialog --title " ERROR " --no-mouse --infobox "Please reconfigure pacman." 3 40
2023-08-01 20:53:53 +02:00
sleep 3
2023-07-17 12:31:55 +02:00
fi
2023-07-17 09:28:52 +02:00
done
2023-08-01 21:22:23 +02:00
if [ [ ! -e "/var/cache/pacman/pkg/archboot.db" ] ] && \
2024-06-26 21:49:04 +02:00
update | rg -q '\-latest' && \
[ [ " $( rg -o 'MemTotal.* (\d+)' -r '$1' /proc/meminfo) " -gt "2571000" ] ] && \
2023-08-01 21:22:23 +02:00
! [ [ " ${ _RUNNING_ARCH } " = = "riscv64" ] ] ; then
2023-08-31 14:39:08 +02:00
_update_environment | _dialog --title " Pacman Configuration " --no-mouse --gauge "Checking on new online kernel version..." 6 70 0
2023-08-03 15:53:56 +02:00
if [ [ -e /.new_kernel ] ] ; then
2023-08-03 15:56:23 +02:00
_dialog --title " New Kernel Available " --defaultno --yesno " Do you want to update the Archboot Environment to $( cat /.new_kernel) ?\n\nATTENTION:\nThis will reboot the system using kexec! " 9 60 && _UPDATE_ENVIRONMENT = 1
2023-08-03 15:53:56 +02:00
if [ [ -n " ${ _UPDATE_ENVIRONMENT } " ] ] ; then
_run_update_environment
fi
2023-09-20 20:08:59 +02:00
_dialog --title " Success " --no-mouse --infobox "Pacman configuration completed successfully." 3 60
2023-08-03 16:04:32 +02:00
sleep 2
2023-08-03 15:53:56 +02:00
rm /.new_kernel
2023-08-03 15:42:29 +02:00
fi
2023-08-01 21:22:23 +02:00
_cleanup
2023-07-20 08:55:10 +02:00
fi
2023-09-20 20:08:59 +02:00
_dialog --title " Success " --no-mouse --infobox "Pacman configuration completed successfully." 3 60
2023-07-22 07:14:16 +02:00
sleep 2
2023-07-17 09:28:52 +02:00
_cleanup