From a80a18faa60ab832065e034ff32fabff7b33c01d Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Sun, 12 Jan 2025 21:26:42 -0700 Subject: [PATCH] Fix random docker errors Signed-off-by: Ethan Dye --- build-image/first-boot.bash | 6 +++--- functions/java-jre.bash | 28 +++++++++++++++++----------- functions/nodejs-apps.bash | 6 +++--- functions/openhabian.bash | 2 ++ functions/system.bash | 3 +-- tests/Dockerfile.amd64-installation | 1 + tests/Dockerfile.rpi3-installation | 1 + tests/Dockerfile.rpi5-installation | 1 + 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/build-image/first-boot.bash b/build-image/first-boot.bash index 664db933b..b3a45d785 100755 --- a/build-image/first-boot.bash +++ b/build-image/first-boot.bash @@ -42,7 +42,7 @@ if ! is_bookworm; then rfkill unblock wifi # Wi-Fi is blocked by Raspi OS default since bullseye(?) fi webserver=/boot/webserver.bash -[[ -L $webserver ]] || ln -s /boot/firmware/webserver.bash "$webserver" +ln -sfn /boot/firmware/webserver.bash "$webserver" if [[ "${debugmode:-on}" == "on" ]]; then unset SILENT @@ -93,7 +93,7 @@ hotSpot=${hotspot:-enable} wifiSSID="$wifi_ssid" # shellcheck source=/etc/openhabian.conf disable=SC2154 wifiPassword="$wifi_password" -if is_bookworm; then +if ! running_in_docker && is_bookworm; then echo -n "$(timestamp) [openHABian] Setting up NetworkManager and Wi-Fi connection... " systemctl enable --now NetworkManager @@ -105,7 +105,7 @@ if is_bookworm; then #elif [[ -z $wifiSSID ]]; then elif grep -qs "up" /sys/class/net/eth0/operstate; then # Actually check if ethernet is working - echo -n "$(timestamp) [openHABian] Setting up Ethernet connection... OK" + echo "$(timestamp) [openHABian] Setting up Ethernet connection... OK" elif [[ -n $wifiSSID ]] && grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && ! grep -qsE "^[[:space:]]*dtoverlay=(pi3-)?disable-wifi" /boot/config.txt; then echo -n "$(timestamp) [openHABian] Checking if WiFi is working... " if iwlist wlan0 scan |& grep -qs "Interface doesn't support scanning"; then diff --git a/functions/java-jre.bash b/functions/java-jre.bash index 4fb9868b7..d6814b832 100644 --- a/functions/java-jre.bash +++ b/functions/java-jre.bash @@ -72,17 +72,19 @@ openjdk_fetch_apt() { local keyName="debian-bookworm" echo -n "$(timestamp) [openHABian] Fetching OpenJDK ${1}... " - if ! cond_redirect add_keys "https://ftp-master.debian.org/keys/archive-key-12.asc" "$keyName"; then echo "FAILED (add keys)"; return 1; fi # Add keys for older systems that need them - echo "deb [signed-by=/usr/share/keyrings/${keyName}.gpg] http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/java.list + if [[ $1 == "21" ]]; then + if ! cond_redirect add_keys "https://ftp-master.debian.org/keys/archive-key-12.asc" "$keyName"; then echo "FAILED (add keys)"; return 1; fi # Add keys for older systems that need them + echo "deb [signed-by=/usr/share/keyrings/${keyName}.gpg] http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/java.list + # Avoid release mixing: prevent RPi from using the Debian distro for normal Raspbian packages + echo -e "Package: *\\nPin: release a=unstable\\nPin-Priority: 90\\n" > /etc/apt/preferences.d/limit-unstable + if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi - if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi - if ! cond_redirect dpkg --configure -a; then echo "FAILED (dpkg)"; return 1; fi - if cond_redirect apt-get install --download-only --yes "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED (download)"; return 1; fi - - # Avoid release mixing: prevent RPi from using the Debian distro for normal Raspbian packages - # But wait until the package is actually installed to avoid breaking the system - echo -e "Package: *\\nPin: release a=unstable\\nPin-Priority: 90\\n" > /etc/apt/preferences.d/limit-unstable - cond_redirect apt-get update + if ! cond_redirect dpkg --configure -a; then echo "FAILED (dpkg)"; return 1; fi + if cond_redirect apt-get install --download-only --yes -t unstable "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED (download)"; return 1; fi + else + if ! cond_redirect dpkg --configure -a; then echo "FAILED (dpkg)"; return 1; fi + if cond_redirect apt-get install --download-only --yes "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED (download)"; return 1; fi + fi } ## Install OpenJDK using APT repository. @@ -94,7 +96,11 @@ openjdk_install_apt() { openjdk_fetch_apt "$1" echo -n "$(timestamp) [openHABian] Installing OpenJDK ${1}... " cond_redirect java_alternatives_reset - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" -t unstable "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi + if [[ $1 == "21" ]]; then + if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" -t unstable "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi + else + if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi + fi else echo -n "$(timestamp) [openHABian] Reconfiguring OpenJDK ${1}... " cond_redirect java_alternatives_reset diff --git a/functions/nodejs-apps.bash b/functions/nodejs-apps.bash index 540d52bb8..f7d1e93f9 100644 --- a/functions/nodejs-apps.bash +++ b/functions/nodejs-apps.bash @@ -14,9 +14,9 @@ nodejs_setup() { local temp - myDistro="$(lsb_release -sc)" - if [[ "$myDistro" == "n/a" ]]; then - myDistro=${osrelease:-bullseye} + myDistro="$(lsb_release -sc | head -1)" + if [[ "$myDistro" == "n/a" ]] || running_in_docker; then + myDistro=${osrelease:-bookworm} fi temp="$(mktemp "${TMPDIR:-/tmp}"/openhabian.XXXXX)" diff --git a/functions/openhabian.bash b/functions/openhabian.bash index 5cf5477b8..db17c968b 100644 --- a/functions/openhabian.bash +++ b/functions/openhabian.bash @@ -318,6 +318,8 @@ system_check_default_password() { ## config_ipv6() ## config_ipv6() { + if running_in_docker; then echo "$(timestamp) [openHABian] Making sure router advertisements are available... SKIPPED"; return 0; fi + local aptConf="/etc/apt/apt.conf.d/S90force-ipv4" local sysctlConf="/etc/sysctl.d/99-sysctl.conf" diff --git a/functions/system.bash b/functions/system.bash index 742ae91ae..d29ea6231 100644 --- a/functions/system.bash +++ b/functions/system.bash @@ -36,7 +36,7 @@ system_upgrade() { # bad packages may require interactive input despite of this setting so do not mask output (no cond_redirect) if ! apt-get upgrade --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"; then echo "FAILED"; return 1; fi if ! cond_redirect java -version &> /dev/null; then - update_config_java "11" && java_install "11" + update_config_java "17" && java_install "17" fi unset DEBIAN_FRONTEND } @@ -69,7 +69,6 @@ needed_packages() { moreutils python3 python3-pip python3-wheel python3-setuptools sysstat \ fontconfig; \ then echo "OK"; else echo "FAILED"; return 1; fi - echo -n "$(timestamp) [openHABian] Installing additional Python packages... " if is_pi_wlan && [[ -z $PREOFFLINE ]]; then echo -n "$(timestamp) [openHABian] Installing python3 serial package... " if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" python3-smbus python3-serial; then echo "OK"; else echo "FAILED"; return 1; fi diff --git a/tests/Dockerfile.amd64-installation b/tests/Dockerfile.amd64-installation index 874aefcec..7bcf2337c 100644 --- a/tests/Dockerfile.amd64-installation +++ b/tests/Dockerfile.amd64-installation @@ -29,5 +29,6 @@ ENTRYPOINT ["./tests/entry.sh"] # Setup openHABian environment COPY . /opt/openhabian/ +COPY ./build-image/webserver.bash /boot/firmware/webserver.bash WORKDIR /opt/openhabian/ RUN install -m 755 ./tests/runlevel /sbin/runlevel diff --git a/tests/Dockerfile.rpi3-installation b/tests/Dockerfile.rpi3-installation index e3af99787..1b24b85d9 100644 --- a/tests/Dockerfile.rpi3-installation +++ b/tests/Dockerfile.rpi3-installation @@ -30,5 +30,6 @@ ENTRYPOINT ["./tests/entry.sh"] # Setup openHABian environment COPY . /opt/openhabian/ +COPY ./build-image/webserver.bash /boot/firmware/webserver.bash WORKDIR /opt/openhabian/ RUN install -m 755 ./tests/runlevel /sbin/runlevel diff --git a/tests/Dockerfile.rpi5-installation b/tests/Dockerfile.rpi5-installation index abe64ee97..950d8008f 100644 --- a/tests/Dockerfile.rpi5-installation +++ b/tests/Dockerfile.rpi5-installation @@ -29,5 +29,6 @@ ENTRYPOINT ["./tests/entry.sh"] # Setup openHABian environment COPY . /opt/openhabian/ +COPY ./build-image/webserver.bash /boot/firmware/webserver.bash WORKDIR /opt/openhabian/ RUN install -m 755 ./tests/runlevel /sbin/runlevel