Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 56 additions & 41 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ Available commands:
done
}

# Total physical system RAM: Used to calculate percentage based value for software cache limits, e.g.: OPcache/APCu
# Total physical system RAM: Used to calculate percentage based value for software cache limits, like OPcache/APCu.
readonly RAM_PHYS=$(free -m | mawk '/^Mem:/{print $2;exit}')
# Total RAM + swap space: Used to estimate whether the swap file size needs to be increased.
readonly RAM_TOTAL=$(free -tm | mawk '/^Total:/{print $2;exit}')
RAM_TOTAL=$(free -tm | mawk '/^Total:/{print $2;exit}')
# Swap space
RAM_SWAP=$(( $RAM_TOTAL - $RAM_PHYS ))

# Whether to restart Deluge web UI once, required on fresh installs for auto-connection to work, more precisely a little delay between daemon and web UI is required
RESTART_DELUGE_WEB=0
Expand Down Expand Up @@ -2560,10 +2562,11 @@ sudo sysctl -p /etc/sysctl.d/dietpi-$1.conf"
# Can piwheels be used? The Python version needs to match the Debian version, else dynamically linked shared libraries may not match!
if (( $G_HW_ARCH < 3 ))
then
if (( ( $G_DISTRO == 7 && $python_version == 311 ) || ( $G_DISTRO > 7 && $python_version == 313 ) ))
then
piwheels=1
fi
case $G_DISTRO in
7) (( $python_version == 311 )) && piwheels=1;;
8) (( $python_version == 313 )) && piwheels=1;;
*) (( $python_version == 314 )) && piwheels=1;;
esac
fi

# Process arguments
Expand Down Expand Up @@ -2675,6 +2678,29 @@ sudo sysctl -p /etc/sysctl.d/dietpi-$1.conf"
G_EXEC rm -R "$1"
}

# Raise swap space to assure min $1 MiB total memory
RAM_SWAP_OLD=$RAM_SWAP
Min_Total_Memory()
{
# Assure input is an integer >= 512, treat anything below that as typo
G_CHECK_VALIDINT "$1" 512

# Check whether requirement is met already
(( $1 > $RAM_TOTAL )) || return 0

# Avoid very small swap files, assume a margin of 10%
(( $1 > $RAM_PHYS*11/10 )) || return 0

G_DIETPI-NOTIFY 2 "Raising swap size to meet requirement of $1 MiB memory for ${aSOFTWARE_NAME[$software_id]}"

# Apply swap size
/boot/dietpi/func/dietpi-set_swapfile $(( $1 - $RAM_PHYS ))

RAM_TOTAL=$1
RAM_SWAP_OLD=$RAM_SWAP
RAM_SWAP=$(( $RAM_TOTAL - $RAM_PHYS ))
}

To_Install()
{
(( ${aSOFTWARE_INSTALL_STATE[$1]} == 1 )) || return 1
Expand Down Expand Up @@ -4874,8 +4900,8 @@ The install script will now exit. After applying one of the above, rerun dietpi-
occ db:add-missing-indices
occ db:add-missing-primary-keys

# On <1 GiB devices assure at least 512 MiB swap space are available to stand 512 MiB file uploads + increased PHP cache and session file usage: https://github.com/MichaIng/DietPi/issues/2293
(( $RAM_PHYS < 924 && $(free -m | mawk '/^Swap:/{print $2;exit}') < 512 )) && /boot/dietpi/func/dietpi-set_swapfile 512
# Assure 1.5 GiB RAM to stand 512 MiB file uploads + increased PHP cache and session file usage: https://github.com/MichaIng/DietPi/issues/2293
Min_Total_Memory 1536

G_EXEC occ maintenance:mode --off

Expand Down Expand Up @@ -5920,12 +5946,8 @@ _EOF_
G_EXEC curl -sSfLo install.sh 'https://raw.githubusercontent.com/pi-hole/pi-hole/master/automated%20install/basic-install.sh'
G_EXEC chmod +x install.sh

# Check free available memory. Increase swap size to prevent gravity running out of memory.
if (( $(free -m | mawk '/^Mem:/{print $7;exit}') < 512 && $(free -m | mawk '/^Swap:/{print $2;exit}') < 512 ))
then
G_DIETPI-NOTIFY 2 'Increasing swap size to 512 MiB for running gravity.sh, please wait...\n'
/boot/dietpi/func/dietpi-set_swapfile 512
fi
# Assure 1 GiB memory to prevent gravity running out of memory
Min_Total_Memory 1024

# Unbound: Switch port to 5335 if it was installed before, else it got just configured within its install step above
if (( ${aSOFTWARE_INSTALL_STATE[182]} == 2 )) && grep -q '^[[:blank:]]*port:[[:blank:]][[:blank:]]*53$' /etc/unbound/unbound.conf.d/dietpi.conf
Expand Down Expand Up @@ -11157,7 +11179,7 @@ _EOF_'
G_EXEC chown "$ha_user:$ha_user" "$ha_home"

# Dependencies
PYTHON_VERSION=$ha_python_version Python_Deps -u "$ha_user" av bcrypt cryptography numpy pillow pycares pyenv pymicro-vad tiktoken
PYTHON_VERSION=$ha_python_version Python_Deps -P -u "$ha_user" av bcrypt cryptography numpy pillow pycares pyenv pymicro-vad tiktoken
# - Custom dependencies, e.g. MariaDB support: G_AGI libmariadb-dev; pip3 install mysqlclient|PyMySQL
local custom_apt_deps=$(sed -n '/^[[:blank:]]*SOFTWARE_HOMEASSISTANT_APT_DEPS=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
mapfile -t -d' ' -O "${#aDEPS[@]}" aDEPS < <(echo -n "$custom_apt_deps")
Expand Down Expand Up @@ -11194,8 +11216,6 @@ _EOF_'
# - Disable cache
G_EXEC mkdir -p "$ha_home/.pip"
G_EXEC eval "echo -e '[global]\nno-cache-dir=true' > '$ha_home/.pip/pip.conf'"
# - ARMv6/7 Trixie/Forky: Add piwheels: The Python version needs to match the Debian version, else dynamically linked shared libraries may not match
(( $G_HW_ARCH < 3 && $G_DISTRO > 7 )) && G_CONFIG_INJECT 'extra-index-url[[:blank:]]*=' 'extra-index-url=https://www.piwheels.org/simple/' "$ha_home/.pip/pip.conf" '\[global\]'

# Generate script to activate pyenv: This must be sourced from the originating shell, hence it does not require execute permissions.
echo "#!/bin/dash
Expand All @@ -11217,6 +11237,7 @@ eval \"\$(pyenv init -)\"
G_EXEC_OUTPUT=1 G_EXEC runuser -u "$ha_user" -- dash -c "$ha_pyenv_activation; exec pip3 install -U pip setuptools wheel"
G_EXEC_DESC="Installing additional dependencies: $custom_pip_deps"
G_EXEC_OUTPUT=1 G_EXEC runuser -u "$ha_user" -- dash -c "$ha_pyenv_activation; exec pip3 install $custom_pip_deps"
find /tmp -mindepth 1 -maxdepth 1 -user "$ha_user" -exec rm -R {} +
G_EXEC_DESC='Installing Home Assistant core module'
G_EXEC_OUTPUT=1 G_EXEC runuser -u "$ha_user" -- dash -c "$ha_pyenv_activation; exec pip3 install homeassistant"

Expand Down Expand Up @@ -11305,21 +11326,13 @@ _EOF_
# Permissions
G_EXEC chown -R papermc:papermc /mnt/dietpi_userdata/papermc

# Assure 512 MiB heap size and 1.5 GiB overall memory (-100 MiB to avoid tiny swap space)
# Adjust heap size: min 1 GiB on >=2 GB physical RAM devices, else 512 MiB
local memory_limit=$JAVA_MAX_HEAP_SIZE
if (( $memory_limit < 1024 ))
(( $memory_limit < 1024 )) && memory_limit=1024
if (( $RAM_PHYS < 1849 ))
then
memory_limit=512
if (( $RAM_TOTAL < 1436 ))
then
G_DIETPI-NOTIFY 2 'Stable PaperMC operation requires at least 1.5 GiB system memory. We will now increase your swap size to satisfy this requirement.'
/boot/dietpi/func/dietpi-set_swapfile $(( 1536 - $RAM_PHYS ))

# Apply 1 GiB heap size on 2 GiB+ physical RAM devices
elif (( $RAM_PHYS > 1848 ))
then
memory_limit=1024
fi
Min_Total_Memory 1536
fi

# Service
Expand Down Expand Up @@ -12003,13 +12016,8 @@ _EOF_
G_EXEC pnpm c set --location=project cacheDir "$immich_src/.pnpmCache"
G_EXEC pnpm c set --location=project stateDir "$immich_src/.pnpmState"

# Assure at least 6 GiB total memory (RAM + swap) for the build, saving original swap size first
if (( $RAM_TOTAL < 6*1024 ))
then
local orig_swap_size=$(( $RAM_TOTAL - $RAM_PHYS ))
G_DIETPI-NOTIFY 2 'Immich build requires at least 6 GiB of total memory. We will temporarily increase the swap size to satisfy this requirement.'
/boot/dietpi/func/dietpi-set_swapfile $(( 6*1024 - $RAM_PHYS ))
fi
# Assure at least 5 GiB total memory (RAM + swap) for the build
Min_Total_Memory 5120

# Prevent JavaScript OOM during build
export NODE_OPTIONS='--max-old-space-size=4096'
Expand Down Expand Up @@ -12038,12 +12046,11 @@ _EOF_
G_EXEC cd "$G_WORKING_DIR"
(( ${aSOFTWARE_INSTALL_STATE[216]} == 1 )) || G_EXEC rm -R "$immich_src"

# Restore original swap size, ensuring a minimum of 2 GiB total memory (RAM + swap) for smaller SBCs
if (( $RAM_TOTAL < 6*1024 ))
# If Immich Machine Learning is not installed, restore original swap size, but ensuring a minimum of 2 GiB total memory (RAM + swap) for smaller SBCs
if (( ${aSOFTWARE_INSTALL_STATE[216]} < 1 && $RAM_SWAP_OLD < $RAM_SWAP ))
then
(( $RAM_TOTAL < 2048 )) && orig_swap_size=1 # dietpi-set_swapfile internally translates "1" to assure 2 GiB total memory
/boot/dietpi/func/dietpi-set_swapfile "$orig_swap_size"
unset -v orig_swap_size
(( $RAM_SWAP_OLD + $RAM_PHYS < 2048 )) && RAM_SWAP_OLD=1 # "1" => 2 GiB total memory
/boot/dietpi/func/dietpi-set_swapfile "$RAM_SWAP_OLD"
fi

# Install GeoNames data for reverse geocoding
Expand Down Expand Up @@ -12175,6 +12182,14 @@ _EOF_
immich_src="immich-${version#v}"
fi

# Assure at least 3 GiB total memory (RAM + swap), and 5 GiB if co-installed with Immich core
if (( ${aSOFTWARE_INSTALL_STATE[215]} > 0 ))
then
Min_Total_Memory 5120
else
Min_Total_Memory 3072
fi

# Install the immich_ml Python package and its dependencies into a virtual environment at /opt/immich-ml
Remove_old_venv /opt/immich-ml
G_EXEC python3 -m venv --upgrade-deps /opt/immich-ml
Expand Down
2 changes: 1 addition & 1 deletion dietpi/func/dietpi-set_swapfile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
if (( $SWAP_SIZE == 1 )); then

SWAP_SIZE=$(( 2048 - $(free -m | mawk '/^Mem:/{print $2;exit}') ))
if (( $SWAP_SIZE > 1 && $SWAP_SIZE < 100 )); then
if (( $SWAP_SIZE > 0 && $SWAP_SIZE < 100 )); then

G_DIETPI-NOTIFY 0 "Skipping the auto-creation of a tiny $SWAP_SIZE MiB swap file"
G_DIETPI-NOTIFY 0 'Set < 100 MiB values manually to create such small swap files'
Expand Down