move _MEM_TOTAL to common.sh and replace grep calls with rg

This commit is contained in:
Tobias Powalowski 2024-06-22 22:31:32 +02:00
parent 71f91fe849
commit 01676f0f3d
4 changed files with 20 additions and 19 deletions

View file

@ -14,6 +14,7 @@ _LABEL="Exit"
_DLPROG="curl -L -s" _DLPROG="curl -L -s"
_KERNELPKG="linux" _KERNELPKG="linux"
_KEYRING="archlinux-keyring" _KEYRING="archlinux-keyring"
_MEM_TOTAL="$(rg -w MemTotal /proc/meminfo | rg -o '\d+')"
if echo "${_BASENAME}" | grep -qw aarch64; then if echo "${_BASENAME}" | grep -qw aarch64; then
_ARCHBOOT="archboot-arm" _ARCHBOOT="archboot-arm"
_KEYRING="${_KEYRING} archlinuxarm-keyring" _KEYRING="${_KEYRING} archlinuxarm-keyring"

View file

@ -2,8 +2,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
# created by Tobias Powalowski <tpowa@archlinux.org> # created by Tobias Powalowski <tpowa@archlinux.org>
. /usr/lib/archboot/common.sh . /usr/lib/archboot/common.sh
[[ -z $TTY ]] && TTY=$(tty) [[ -z $_TTY ]] && _TTY=$(tty)
TTY=${TTY#/dev/} _TTY=${_TTY#/dev/}
_welcome () { _welcome () {
echo -e "\e[1mWelcome to \e[36mArchboot\e[m\e[1m - Arch Linux ${_RUNNING_ARCH^^}\e[m" echo -e "\e[1mWelcome to \e[36mArchboot\e[m\e[1m - Arch Linux ${_RUNNING_ARCH^^}\e[m"
@ -47,7 +47,7 @@ _copy_root() {
# fstrim <mountpoint> for manual action # fstrim <mountpoint> for manual action
# it needs some seconds to get RAM free on delete! # it needs some seconds to get RAM free on delete!
_switch_root_zram() { _switch_root_zram() {
if [[ "${TTY}" = "tty1" ]]; then if [[ "${_TTY}" = "tty1" ]]; then
clear clear
[[ -d /run/nextroot ]] || mkdir /run/nextroot [[ -d /run/nextroot ]] || mkdir /run/nextroot
: > /.archboot : > /.archboot
@ -72,7 +72,7 @@ fi
_enter_shell() { _enter_shell() {
# dbus sources profiles again # dbus sources profiles again
if ! echo "${TTY}" | grep -q pts; then if ! echo "${_TTY}" | grep -q pts; then
echo "" echo ""
echo -e "Hit \e[1m\e[92mENTER\e[m for \e[1mlogin\e[m routine or \e[1m\e[92mCTRL-C\e[m for \e[1mbash\e[m prompt." echo -e "Hit \e[1m\e[92mENTER\e[m for \e[1mlogin\e[m routine or \e[1m\e[92mCTRL-C\e[m for \e[1mbash\e[m prompt."
cd / cd /
@ -91,8 +91,8 @@ _run_latest_install() {
_run_update_installer() { _run_update_installer() {
cd / cd /
if [[ "${TTY}" == "tty1" ]]; then if [[ "${_TTY}" == "tty1" ]]; then
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -lt 2971000 ]]; then if [[ "$()" -lt 2971000 ]]; then
_run_latest _run_latest
else else
# local image # local image
@ -110,7 +110,7 @@ _run_update_installer() {
fi fi
} }
if [[ "${TTY}" = "tty1" ]] ; then if [[ "${_TTY}" = "tty1" ]] ; then
if ! mount | grep -q zram0; then if ! mount | grep -q zram0; then
_TITLE="archboot.com | ${_RUNNING_ARCH} | ${_RUNNING_KERNEL} | Basic Setup | ZRAM" _TITLE="archboot.com | ${_RUNNING_ARCH} | ${_RUNNING_KERNEL} | Basic Setup | ZRAM"
_switch_root_zram | _dialog --title " Initializing System " --gauge "Creating btrfs on /dev/zram0..." 6 75 0 | tee -a /dev/ttyS0 /dev/ttyAMA0 /dev/ttyUSB0 /dev/pts/0 2>"${_NO_LOG}" _switch_root_zram | _dialog --title " Initializing System " --gauge "Creating btrfs on /dev/zram0..." 6 75 0 | tee -a /dev/ttyS0 /dev/ttyAMA0 /dev/ttyUSB0 /dev/pts/0 2>"${_NO_LOG}"
@ -150,12 +150,12 @@ if [[ -e /usr/bin/setup ]]; then
launcher launcher
fi fi
# latest image, fail if less than 2.3GB RAM available # latest image, fail if less than 2.3GB RAM available
elif [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -lt 2270000 ]]; then elif [[ "${_MEM_TOTAL}" -lt 2270000 ]]; then
_welcome _welcome
_memory_error "2.3GB" _memory_error "2.3GB"
_enter_shell _enter_shell
# local image, fail if less than 3.0GB RAM available # local image, fail if less than 3.0GB RAM available
elif [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -lt 2971000 &&\ elif [[ "${_MEM_TOTAL}" -lt 2971000 &&\
-e "${_LOCAL_DB}" ]]; then -e "${_LOCAL_DB}" ]]; then
_welcome _welcome
_memory_error "2.9GB" _memory_error "2.9GB"

View file

@ -5,7 +5,7 @@
_ram_check() { _ram_check() {
while true; do while true; do
# continue when 1 GB RAM is free # continue when 1 GB RAM is free
[[ "$(grep -w MemAvailable /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt "1000000" ]] && break [[ "$(rg -w MemAvailable /proc/meminfo | rg -o '\d+')" -gt "1000000" ]] && break
done done
} }
@ -283,7 +283,7 @@ _new_environment() {
_progress "97" "Waiting for kernel to free RAM..." _progress "97" "Waiting for kernel to free RAM..."
# wait until enough memory is available! # wait until enough memory is available!
while true; do while true; do
[[ "$(($(stat -c %s "${_RAM}/${_INITRD}")*200/100000))" -lt "$(grep -w MemAvailable /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" ]] && break [[ "$(($(stat -c %s "${_RAM}/${_INITRD}")*200/100000))" -lt "$(rg -w MemAvailable /proc/meminfo | rg -o '\d+')" ]] && break
sleep 1 sleep 1
done done
_progress "100" "Restarting with KEXEC_LOAD..." _progress "100" "Restarting with KEXEC_LOAD..."

View file

@ -35,41 +35,41 @@ usage () {
echo -e " \e[1m-update\e[m Update scripts: setup, quickinst, network, clock and helpers." echo -e " \e[1m-update\e[m Update scripts: setup, quickinst, network, clock and helpers."
fi fi
# latest image # latest image
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 2000000 && ! -e "/.full_system" && ! -e "${_LOCAL_DB}" ]]; then if [[ "${_MEM_TOTAL}" -gt 2000000 && ! -e "/.full_system" && ! -e "${_LOCAL_DB}" ]]; then
echo -e " \e[1m-full-system\e[m Switch to full Arch Linux system." echo -e " \e[1m-full-system\e[m Switch to full Arch Linux system."
# local image # local image
elif [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 2571000 && ! -e "/.full_system" && -e "${_LOCAL_DB}" && -e "/usr/bin/setup" ]]; then elif [[ "${_MEM_TOTAL}" -gt 2571000 && ! -e "/.full_system" && -e "${_LOCAL_DB}" && -e "/usr/bin/setup" ]]; then
echo -e " \e[1m-full-system\e[m Switch to full Arch Linux system." echo -e " \e[1m-full-system\e[m Switch to full Arch Linux system."
fi fi
echo -e "" echo -e ""
if [[ -e "/usr/bin/setup" ]]; then if [[ -e "/usr/bin/setup" ]]; then
# works only on latest image # works only on latest image
if ! [[ -e "${_LOCAL_DB}" ]]; then if ! [[ -e "${_LOCAL_DB}" ]]; then
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 2400000 ]] ; then if [[ "${_MEM_TOTAL}" -gt 2400000 ]] ; then
_graphic_options _graphic_options
fi fi
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 1500000 ]]; then if [[ "${_MEM_TOTAL}" -gt 1500000 ]]; then
echo -e " \e[1m-sway\e[m Launch Sway desktop with VNC sharing enabled." echo -e " \e[1m-sway\e[m Launch Sway desktop with VNC sharing enabled."
echo -e " \e[1m-xfce\e[m Launch Xfce desktop with VNC sharing enabled." echo -e " \e[1m-xfce\e[m Launch Xfce desktop with VNC sharing enabled."
echo -e " \e[1m-custom-xorg\e[m Install custom X environment." echo -e " \e[1m-custom-xorg\e[m Install custom X environment."
[[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 2400000 ]] && echo -e " \e[1m-custom-wayland\e[m Install custom Wayland environment." [[ "${_MEM_TOTAL}" -gt 2400000 ]] && echo -e " \e[1m-custom-wayland\e[m Install custom Wayland environment."
echo "" echo ""
fi fi
fi fi
fi fi
if ! [[ -e "${_LOCAL_DB}" ]] || [[ -e "${_LOCAL_DB}" && ! -e "/usr/bin/setup" ]]; then if ! [[ -e "${_LOCAL_DB}" ]] || [[ -e "${_LOCAL_DB}" && ! -e "/usr/bin/setup" ]]; then
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 2270000 ]]; then if [[ "${_MEM_TOTAL}" -gt 2270000 ]]; then
if ! [[ "${_RUNNING_ARCH}" == "riscv64" ]]; then if ! [[ "${_RUNNING_ARCH}" == "riscv64" ]]; then
echo -e " \e[1m-latest\e[m Launch latest archboot environment (using kexec)." echo -e " \e[1m-latest\e[m Launch latest archboot environment (using kexec)."
fi fi
fi fi
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 4061000 ]]; then if [[ "${_MEM_TOTAL}" -gt 4061000 ]]; then
if ! [[ "${_RUNNING_ARCH}" == "riscv64" ]]; then if ! [[ "${_RUNNING_ARCH}" == "riscv64" ]]; then
echo -e " \e[1m-latest-install\e[m Launch latest archboot environment with" echo -e " \e[1m-latest-install\e[m Launch latest archboot environment with"
echo -e " package cache (using kexec)." echo -e " package cache (using kexec)."
fi fi
fi fi
if [[ "$(grep -w MemTotal /proc/meminfo | cut -d ':' -f2 | sed -e 's# ##g' -e 's#kB$##g')" -gt 4216000 ]]; then if [[ "${_MEM_TOTAL}" -gt 4216000 ]]; then
echo -e " \e[1m-latest-image\e[m Generate latest image files in /archboot directory." echo -e " \e[1m-latest-image\e[m Generate latest image files in /archboot directory."
fi fi
fi fi