Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookworm WiFi #1848

Merged
merged 15 commits into from
Feb 28, 2024
77 changes: 36 additions & 41 deletions build-image/first-boot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@ echo -e "\\n\\n$(timestamp) [openHABian] Starting the openHABian initial setup."
rm -f /opt/openHABian-install-failed
touch /opt/openHABian-install-inprogress


echo -n "$(timestamp) [openHABian] Storing configuration... "
if ! cp "/opt/openhabian/build-image/openhabian.conf" "$CONFIGFILE"; then echo "FAILED (copy)"; fail_inprogress; fi
if [[ -f /boot/firmware/openhabian.conf ]]; then confdir=/boot/firmware; else confdir=/boot; fi
if ! cp "${confdir}/openhabian.conf" "$CONFIGFILE"; then echo "FAILED (copy)"; fail_inprogress; fi
if ! sed -i 's|\r$||' "$CONFIGFILE"; then echo "FAILED (Unix line endings)"; fail_inprogress; fi
if ! source "$CONFIGFILE"; then echo "FAILED (source config)"; fail_inprogress; fi
if ! source "/opt/openhabian/functions/helpers.bash"; then echo "FAILED (source helpers)"; fail_inprogress; fi
if ! source "/opt/openhabian/functions/wifi.bash"; then echo "FAILED (source wifi)"; fail_inprogress; fi
if source "/opt/openhabian/functions/openhabian.bash"; then echo "OK"; else echo "FAILED (source openhabian)"; fail_inprogress; fi

if is_bookworm; then
webserver=/boot/firmware/webserver.bash
else
rfkill unblock wifi # Wi-Fi is blocked by Raspi OS default since bullseye(?)
webserver=/boot/webserver.bash
fi

if [[ "${debugmode:-on}" == "on" ]]; then
unset SILENT
unset DEBUGMAX
Expand All @@ -43,14 +52,7 @@ elif [[ "${debugmode:-on}" == "maximum" ]]; then
set -x
fi

rfkill unblock wifi # Wi-Fi is blocked by Raspi OS default since bullseye(?)

if is_bookworm; then
webserver=/boot/firmware/webserver.bash
else
webserver=/boot/webserver.bash
fi

echo -n "$(timestamp) [openHABian] Starting webserver with installation log... "
if [[ -x $(command -v python3) ]]; then
bash $webserver "start"
Expand Down Expand Up @@ -85,21 +87,25 @@ fi
echo "watch cat /boot/first-boot.log" > "$HOME/.bash_profile"

# shellcheck source=/etc/openhabian.conf disable=SC2154
if [[ -z $wifi_ssid ]]; then
# Actually check if ethernet is working
echo -n "$(timestamp) [openHABian] Setting up Ethernet connection... "
if grep -qs "up" /sys/class/net/eth0/operstate; then echo "OK"; else echo "FAILED"; fi

if ! running_in_docker && tryUntil "ping -c1 8.8.8.8 &> /dev/null || curl --silent --head https://www.openhab.org/docs/ |& grep -qs 'HTTP/[^ ]*[ ]200'" 5 1; then
if [[ "$hotspot" == "enable" ]] && ! [[ -x $(command -v comitup) ]]; then
echo -n "$(timestamp) [openHABian] Installing comitup hotspot (will reboot after)... "
setup_hotspot "install"
cp "${BASEDIR:-/opt/openhabian}"/includes/interfaces /etc/network/
echo "$(timestamp) [openHABian] hotspot software installed. Rebooting your system to make it take effect!"
reboot
fi
hotSpot=${hotspot:-enable}
# shellcheck source=/etc/openhabian.conf disable=SC2154
wifiSSID="$wifi_ssid"
# shellcheck source=/etc/openhabian.conf disable=SC2154
wifiPassword="$wifi_password"
if is_bookworm; then
echo -n "$(timestamp) [openHABian] Setting up NetworkManager and Wi-Fi connection... "
systemctl enable --now NetworkManager

if [[ -n $wifiSSID ]]; then
# Setup WiFi via NetworkManager
# shellcheck source=/etc/openhabian.conf disable=SC2154
nmcli -w 30 d wifi connect "${wifiSSID}" password "${wifiPassword}" ifname wlan0
fi
elif grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && ! grep -qsE "^[[:space:]]*dtoverlay=(pi3-)?disable-wifi" /boot/config.txt; 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"
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
ip link set wlan0 up
Expand All @@ -115,21 +121,11 @@ elif grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && ! grep -qs
else
echo "OK"
fi
if tryUntil "ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs 'HTTP/1.1 200 OK'" 5 1; then
if [[ "$hotspot" == "enable" ]] && ! [[ -x $(command -v comitup) ]]; then
echo -n "$(timestamp) [openHABian] Installing comitup hotspot (will reboot after)... "
setup_hotspot "install"
cp "${BASEDIR:-/opt/openhabian}"/includes/interfaces /etc/network/
echo "$(timestamp) [openHABian] hotspot software installed. Rebooting your system to make it take effect!"
reboot
fi
fi
else

echo -n "$(timestamp) [openHABian] Setting up Wi-Fi connection... "

# shellcheck source=/etc/openhabian.conf disable=SC2154
wifiCountry="$wifi_country"
wifiSSID="$wifi_ssid"
wifiPassword="$wifi_password"

# Check if the country code is valid, valid country codes are followed by spaces in /usr/share/zoneinfo/zone.tab
if grep -qs "^${wifiCountry^^}[[:space:]]" /usr/share/zoneinfo/zone.tab; then
Expand All @@ -156,12 +152,12 @@ fi
echo -n "$(timestamp) [openHABian] Ensuring network connectivity... "
if ! running_in_docker && tryUntil "ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs 'HTTP/1.1 200 OK'" 5 1; then
echo "FAILED"
if grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && iwconfig |& grep -qs "ESSID:off"; then
echo "$(timestamp) [openHABian] I was not able to connect to the configured Wi-Fi. Please check your signal quality. Reachable Wi-Fi networks are:"
iwlist wlan0 scanning | grep "ESSID" | sed 's/^\s*ESSID:/\t- /g'
echo "$(timestamp) [openHABian] Please try again with your correct SSID and password. The following Wi-Fi configuration was used:"
cat /etc/wpa_supplicant/wpa_supplicant.conf
rm -f /etc/wpa_supplicant/wpa_supplicant.conf

if [[ "$hotSpot" == "enable" ]] && ! [[ -x $(command -v comitup) ]]; then
#echo -n "$(timestamp) [openHABian] Installing comitup hotspot (will reboot after)... "
if setup_hotspot "install"; then echo "OK"; else echo "FAILED"; fi
#echo "$(timestamp) [openHABian] Hotspot software installed. Rebooting your system to make it take effect!"
#reboot
Comment on lines +157 to +160
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commented lines left here intentionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort of, yes
unsure if it works without rebooting but seems now it does

fi
echo "$(timestamp) [openHABian] The public internet is not reachable. Please check your local network environment."
echo " We have launched a publicly accessible hotspot named $(grep ap_name: /etc/comitup.conf | cut -d' ' -f2)."
Expand All @@ -170,7 +166,6 @@ if ! running_in_docker && tryUntil "ping -c1 8.8.8.8 &> /dev/null || curl --sile
echo " After about an hour, we will continue trying to get your system installed,"
echo " but without proper Internet connectivity this is not likely to be going to work."

systemctl enable --now NetworkManager
tryUntil "ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs 'HTTP/1.1 200 OK'" 100 30
else
echo "OK"
Expand Down
2 changes: 1 addition & 1 deletion build-image/offline-install-modifications.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apt-get --quiet install --download-only --yes libc6 libstdc++6 zlib1g make \
python3-cairo python3-click python3-colorama python3-flask \
python3-itsdangerous python3-jinja2 python3-markupsafe \
python3-networkmanager python3-pyinotify python3-simplejson python3-werkzeug \
openjdk-11-jre-headless
openjdk-17-jre-headless
source /opt/openhabian/functions/nodejs-apps.bash
nodejs_setup
apt-get --quiet autoremove --yes
Expand Down
2 changes: 1 addition & 1 deletion build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ destination="openhabian-${hwPlatform}-${2:-latest}-${timestamp}-crc${crc32checks
mv -v "$imageFile" "$destination"
rm -rf "$buildFolder"

echo_process "Compressing imageu $destination... "
echo_process "Compressing image $destination... "
# speedup compression, T0 will use all cores and should be supported by reasonably new versions of xz
xz --verbose --compress --keep -9 -T0 "$destination"
crc32checksum="$(crc32 "${destination}.xz")"
Expand Down
5 changes: 3 additions & 2 deletions functions/nodejs-apps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ nodejs_setup() {
else
if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" nodejs; then echo "OK"; else echo "FAILED"; return 1; fi
fi
#if [[ "$myDistro" == "bookworm" ]]; then jsscripting_npm_install; fi
if [[ "$myDistro" == "bookworm" ]]; then jsscripting_npm_install; fi
if ! command -v npm &> /dev/null; then
echo -n "$(timestamp) [openHABian] Installing npm ... "
if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" npm; then echo "OK"; else echo "FAILED (install npm)"; return 1; fi
#if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" npm; then echo "OK"; else echo "FAILED (install npm)"; return 1; fi
if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" npm; then echo "OK"; else echo "FAILED (install npm)"; fi
fi
fi
}
Expand Down
10 changes: 7 additions & 3 deletions functions/wifi.bash
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ setup_hotspot() {
if [[ $1 == "install" ]]; then
echo -n "$(timestamp) [openHABian] Installing Comitup hotspot... "
# manage networking through network manager
apt install --yes network-manager &> /dev/null
DEBIAN_FRONTEND=noninteractive apt install --yes network-manager &> /dev/null
systemctl enable --now NetworkManager
# get from source - the comitup package in Buster is 2yrs old
echo "deb http://davesteele.github.io/comitup/repo comitup main" > /etc/apt/sources.list.d/comitup.list
if ! cond_redirect apt-get --quiet update; then echo "FAILED (update apt lists)"; return 1; fi
Expand All @@ -130,10 +131,13 @@ setup_hotspot() {
# shellcheck disable=SC2154
sed -i -e "s|ap_password:.*$|ap_password: ${hotspotpw}|g" /etc/comitup.conf

if cond_redirect apt install --yes -o Dpkg::Options::=--force-confdef comitup; then echo "OK"; else echo "FAILED"; return 1; fi
DEBIAN_FRONTEND=noninteractive dpkg --configure -a &>/dev/null
DEBIAN_FRONTEND=noninteractive apt install --yes -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' comitup &>/dev/null
systemctl enable --now comitup
comitup-cli d
echo "denyinterfaces wlan0 eth0" >> /etc/dhcpcd.conf
sed -i '3 i dhcp=internal' /etc/NetworkManager/NetworkManager.conf
install -m 644 includes/generic/100-disable-wifi-mac-randomization.conf /etc/NetworkManager/conf.d/
install -m 644 /opt/openhabian/includes/generic/100-disable-wifi-mac-randomization.conf /etc/NetworkManager/conf.d/
elif [[ $1 == "disable" ]]; then
echo -n "$(timestamp) [openHABian] Uninstalling hotspot... "
if cond_redirect apt purge --yes comitup; then echo "OK"; else echo "FAILED"; return 1; fi
Expand Down
Loading