Cockpit вынесен из env

This commit is contained in:
Andrei Smaliak 2026-06-10 11:19:53 +04:00
parent a4d5497e5d
commit 53dd4ce64b
10 changed files with 1049 additions and 18 deletions

View File

@ -40,6 +40,8 @@ stage_env
stage_wifi
stage_mqtt
stage_ui
stage_avahi
stage_cockpit
stage_itscreen
stage_reverse_tunnels
```
@ -47,6 +49,8 @@ stage_reverse_tunnels
Важно:
- `stage_z2m` по умолчанию в этот набор не входит;
- если нужен Zigbee2MQTT, его надо добавлять отдельно через `--with-z2m`.
- `stage_avahi` и `stage_cockpit` не ломают основную установку: если они не установились, installer продолжит и покажет отдельный report.
- Cockpit на текущем vendor image может падать из-за kernel `Oops`; его можно повторить отдельно через `sudo bash stage_cockpit/stage_cockpit_install.sh`.
## 1. Узнай IP-адрес Edge

View File

@ -79,7 +79,38 @@ Git password or token: iomatex123
Нежелательно ставить поверх:
- хоста, где порты `80` или `8099` заняты критичными сторонними сервисами.
6. `stage_itscreen`
6. `stage_avahi`
Для чего нужна:
- добавляет mDNS/Avahi discovery;
- позволяет открывать основной Web UI по имени вроде `http://g-box-023.local/`;
- не меняет IP, MQTT, Zigbee2MQTT или основной web service.
Можно ставить поверх:
- после `stage_ui`;
- на уже установленный Edge для добавления `.local` discovery.
Если не установилась:
- основная установка продолжается;
- повторить отдельно: `sudo bash stage_avahi/stage_avahi_install.sh`.
7. `stage_cockpit`
Для чего нужна:
- опционально устанавливает Cockpit на `https://<edge-ip>:9090`;
- не требуется для основной работы Edge.
Можно ставить поверх:
- после `stage_env`;
- лучше после полного install/reboot, если vendor kernel стабилен.
Если не установилась:
- основная установка продолжается;
- повторить отдельно: `sudo bash stage_cockpit/stage_cockpit_install.sh`.
Важно:
- на текущем vendor image установка `cockpit` может провоцировать kernel `Oops`;
- это проблема kernel/vendor image, не обычная ошибка `apt`.
8. `stage_itscreen`
Для чего нужна:
- устанавливает и настраивает `itscreen`;
- поднимает X11/lightdm/autologin flow;
@ -92,7 +123,7 @@ Git password or token: iomatex123
Нежелательно ставить поверх:
- систем с кастомным display-manager flow, который нельзя менять.
7. `stage_reverse_tunnels`
9. `stage_reverse_tunnels`
Для чего нужна:
- настраивает reverse SSH tunnels с Edge на VPS;
- создает 3 systemd-сервиса для туннелей:
@ -147,7 +178,8 @@ Git password or token: iomatex123
## Что можно ставить поверх, а что нет
Короткое правило:
- безопаснее всего переустанавливать поверх: `stage_wifi`, `stage_mqtt`, `stage_z2m`, `stage_ui`, `stage_itscreen`, `stage_dashboard_bridge`, `stage_dashboards`;
- безопаснее всего переустанавливать поверх: `stage_wifi`, `stage_mqtt`, `stage_z2m`, `stage_ui`, `stage_avahi`, `stage_itscreen`, `stage_dashboard_bridge`, `stage_dashboards`;
- `stage_cockpit` опциональный и может падать на нестабильном vendor kernel; его failure не должен ломать основной install;
- нежелательно без необходимости накатывать поверх: `stage_env`;
- обязательно оставлять последней: `stage_reverse_tunnels`.
@ -158,6 +190,8 @@ stage_env
stage_wifi
stage_mqtt
stage_ui
stage_avahi
stage_cockpit
stage_itscreen
stage_reverse_tunnels
```
@ -170,6 +204,8 @@ stage_wifi
stage_mqtt
stage_z2m
stage_ui
stage_avahi
stage_cockpit
stage_itscreen
stage_reverse_tunnels
```

View File

@ -16,7 +16,7 @@ APT_UPDATED=0
ASKPASS_SCRIPT=""
GIT_USERNAME="${IOMATEX_GIT_USERNAME:-}"
GIT_PASSWORD="${IOMATEX_GIT_PASSWORD:-}"
DEFAULT_PIPELINE_STAGES="stage_env,stage_wifi,stage_mqtt,stage_ui,stage_itscreen,stage_reverse_tunnels"
DEFAULT_PIPELINE_STAGES="stage_env,stage_wifi,stage_mqtt,stage_ui,stage_avahi,stage_cockpit,stage_itscreen,stage_reverse_tunnels"
log() {
printf '[%s] %s\n' "$(date -u +'%F %T UTC')" "$*"
@ -156,12 +156,12 @@ while [[ $# -gt 0 ]]; do
case "$1" in
--default-only)
USE_ALL_STAGES=0
SELECTED_STAGES="stage_env,stage_mqtt,stage_ui,stage_itscreen"
SELECTED_STAGES="stage_env,stage_mqtt,stage_ui,stage_avahi,stage_cockpit,stage_itscreen"
shift
;;
--with-z2m)
USE_ALL_STAGES=0
SELECTED_STAGES="stage_env,stage_wifi,stage_mqtt,stage_z2m,stage_ui,stage_itscreen,stage_reverse_tunnels"
SELECTED_STAGES="stage_env,stage_wifi,stage_mqtt,stage_z2m,stage_ui,stage_avahi,stage_cockpit,stage_itscreen,stage_reverse_tunnels"
shift
;;
--only)

View File

@ -74,6 +74,7 @@ SKIPPED_STAGES=()
SKIPPED_BY_SELECTION_STAGES=()
SKIPPED_MISSING_STAGES=()
FAILED_STAGES=()
SOFT_FAILED_STAGES=()
SELECTED_STAGES=()
STAGE_ORDER=(
@ -82,6 +83,8 @@ STAGE_ORDER=(
"stage_mqtt"
"stage_z2m"
"stage_ui"
"stage_avahi"
"stage_cockpit"
"stage_itscreen"
"stage_reverse_tunnels"
)
@ -96,9 +99,16 @@ MUST_HAVE_STAGES=(
OPTIONAL_STAGES=(
"stage_wifi"
"stage_z2m"
"stage_avahi"
"stage_cockpit"
"stage_reverse_tunnels"
)
SOFT_FAIL_STAGES=(
"stage_avahi"
"stage_cockpit"
)
is_known_stage() {
local wanted="$1"
local stage
@ -558,8 +568,10 @@ stage_number_to_name() {
3) echo "stage_mqtt" ;;
4) echo "stage_z2m" ;;
5) echo "stage_ui" ;;
6) echo "stage_itscreen" ;;
7) echo "stage_reverse_tunnels" ;;
6) echo "stage_avahi" ;;
7) echo "stage_cockpit" ;;
8) echo "stage_itscreen" ;;
9) echo "stage_reverse_tunnels" ;;
*) return 1 ;;
esac
}
@ -798,6 +810,12 @@ stage_candidates() {
printf '%s\n' "ui_installer.sh"
printf '%s\n' "stage_ui_install.sh"
;;
stage_avahi)
printf '%s\n' "stage_avahi_install.sh"
;;
stage_cockpit)
printf '%s\n' "stage_cockpit_install.sh"
;;
stage_itscreen)
printf '%s\n' "stage_itscreen_install.sh"
;;
@ -1129,6 +1147,7 @@ record_summary_from_state() {
SKIPPED_BY_SELECTION_STAGES=()
SKIPPED_MISSING_STAGES=()
FAILED_STAGES=()
SOFT_FAILED_STAGES=()
for stage in "${STAGE_ORDER[@]}"; do
status="$(get_stage_status "$stage")"
@ -1147,6 +1166,9 @@ record_summary_from_state() {
failed)
FAILED_STAGES+=("$stage")
;;
soft_failed)
SOFT_FAILED_STAGES+=("$stage")
;;
esac
done
}
@ -1194,12 +1216,23 @@ run_stage() {
set -e
if [[ "$rc" -ne 0 ]]; then
if in_array "$stage" "${SOFT_FAIL_STAGES[@]}"; then
set_stage_status "$stage" "soft_failed"
set_state_value "LAST_RESULT" "soft_failed"
SOFT_FAILED_STAGES+=("$stage")
log "SOFT-FAIL: ${stage} (installer=${CURRENT_INSTALLER_BASENAME}, rc=${rc}); continuing"
CURRENT_STAGE=""
CURRENT_INSTALLER=""
CURRENT_INSTALLER_BASENAME=""
return 0
else
set_stage_status "$stage" "failed"
set_state_value "LAST_RESULT" "failed"
FAILED_STAGES+=("$stage")
log "FAIL: ${stage} (installer=${CURRENT_INSTALLER_BASENAME}, rc=${rc})"
return "$rc"
fi
fi
set_stage_status "$stage" "success"
set_state_value "LAST_RESULT" "success"
@ -1312,11 +1345,38 @@ print_summary() {
done
fi
echo
echo "Non-blocking failed optional stages:"
if [[ "${#SOFT_FAILED_STAGES[@]}" -eq 0 ]]; then
echo " - none"
else
for stage in "${SOFT_FAILED_STAGES[@]}"; do
case "$stage" in
stage_cockpit)
echo " - stage_cockpit (Cockpit is not installed; core Edge install continued)"
echo " Retry separately after reboot:"
echo " cd ${PROJECT_DIR}"
echo " sudo bash stage_cockpit/stage_cockpit_install.sh"
;;
stage_avahi)
echo " - stage_avahi (mDNS discovery is not installed; core Edge install continued)"
echo " Retry separately after network is stable:"
echo " cd ${PROJECT_DIR}"
echo " sudo bash stage_avahi/stage_avahi_install.sh"
;;
*)
echo " - ${stage}"
;;
esac
done
fi
echo
echo "Post-install note:"
echo " - stage_env is followed by an automatic reboot only when it is selected and succeeds"
echo " - after reboot the installer resumes via systemd and opens lxterminal on DISPLAY=:0"
echo " - final reboot is recommended after the full run"
echo " - stage_avahi and stage_cockpit are optional and do not block the main Edge install"
echo " - stage_reverse_tunnels is intentionally last because it requires manual completion"
echo " - engineer-facing entrypoints are install_iomatex_edge.sh and install_iomatex_z2m.sh"
echo "============================================================"

161
stage_avahi/README.md Normal file
View File

@ -0,0 +1,161 @@
# stage_avahi
`stage_avahi` adds mDNS/Avahi discovery for IOMATEX Edge.
After installation, an engineer can open the Web UI by hostname instead of finding the DHCP IP manually:
```text
http://<hostname>.local/
```
Example:
```text
http://g-box-023.local/
```
## What It Installs
- `avahi-daemon`
- `avahi-utils`
- `libnss-mdns`
It enables `avahi-daemon.service` and advertises the IOMATEX Web UI as an HTTP service on port `80`.
The Avahi service file is:
```text
/etc/avahi/services/iomatex-web.service
```
## Hostname
The installer uses the current system hostname.
Expected Edge hostname format:
```text
g-box-a6559955
```
If the hostname is empty or `localhost`, the installer generates:
```text
g-box-<last6_of_machine_id>
```
Then it applies it with:
```bash
hostnamectl set-hostname
```
## mDNS Name
By default this stage publishes the short Avahi/mDNS name:
```text
g-box-023.local
```
This is configured as Avahi `host-name`, so it does not require changing the system hostname used by the rest of the Edge.
To override it during install:
```bash
sudo IOMATEX_MDNS_HOSTNAME=g-box-024 bash stage_avahi/stage_avahi_install.sh
```
## Install
Run on the Edge:
```bash
sudo bash stage_avahi/stage_avahi_install.sh
```
Expected Web UI URL:
```text
http://g-box-023.local/
```
## Engineer Connection Flow
1. Connect the engineer laptop or phone to the same network as the Edge.
2. Check the Edge hostname:
```bash
hostname
```
3. Open:
```text
http://<hostname>.local/
```
Example:
```text
http://g-box-023.local/
```
## Verification
On the Edge:
```bash
systemctl status avahi-daemon.service --no-pager
avahi-browse -art | grep -i iomatex
cat /etc/avahi/services/iomatex-web.service
```
From Linux or macOS on the same network:
```bash
ping <hostname>.local
avahi-browse -art | grep IOMATEX
```
From Windows:
```cmd
ping <hostname>.local
```
Then open:
```text
http://<hostname>.local/
```
## If `.local` Does Not Open
Check these points:
- The Edge and the engineer device must be on the same L2 network/VLAN.
- Some routers or Wi-Fi guest networks block multicast traffic.
- `avahi-daemon.service` must be active on the Edge.
- `/etc/nsswitch.conf` should contain:
```text
hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname
```
- On Windows, mDNS support depends on the OS/network policy. Try browser access first, then `ping <hostname>.local`.
- As a fallback, use the DHCP IP address directly:
```text
http://<edge-ip>/
```
## Uninstall Advertisement
To remove only the IOMATEX Web UI advertisement:
```bash
sudo bash stage_avahi/stage_avahi_uninstall.sh
```
The uninstall script does not remove Avahi packages and does not change hostname.

View File

@ -0,0 +1,428 @@
#!/usr/bin/env bash
set -euo pipefail
# IOMATEX Avahi/mDNS discovery stage
# Debian 11 / bullseye compatible
if head -c 3 "$0" 2>/dev/null | grep -q $'^\xEF\xBB\xBF'; then
echo "ERROR: UTF-8 BOM detected. Save as UTF-8 without BOM." >&2
exit 1
fi
if grep -q $'\r' "$0" 2>/dev/null; then
echo "ERROR: CRLF detected. Convert file to UNIX (LF)." >&2
exit 1
fi
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export DEBIAN_FRONTEND=noninteractive
LOG="/var/log/iomatex-stage-avahi.log"
SERVICE_FILE="/etc/avahi/services/iomatex-web.service"
AVAHI_CONF="/etc/avahi/avahi-daemon.conf"
NSSWITCH="/etc/nsswitch.conf"
WEB_PORT="80"
MDNS_HOSTNAME="${IOMATEX_MDNS_HOSTNAME:-g-box-023}"
REQUIRED_PACKAGES=(avahi-daemon avahi-utils libnss-mdns)
mkdir -p /var/log >/dev/null 2>&1 || true
touch "$LOG" >/dev/null 2>&1 || true
log() {
local line="[$(date -u +'%F %T UTC')] $*"
echo "$line"
echo "$line" >>"$LOG" 2>/dev/null || true
}
need_root() {
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
echo "ERROR: Run as root: sudo bash $0" >&2
exit 1
fi
}
package_installed() {
dpkg-query -W -f='${Status}\n' "$1" 2>/dev/null | grep -qx 'install ok installed'
}
apt_noninteractive() {
apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
"$@"
}
apt_install_missing() {
local missing=()
local pkg
for pkg in "$@"; do
if ! package_installed "$pkg"; then
missing+=("$pkg")
fi
done
if [[ "${#missing[@]}" -eq 0 ]]; then
log "Packages already installed: $*"
return 0
fi
log "Missing packages: ${missing[*]}"
log "RUN: dpkg --configure -a || true"
dpkg --configure -a >>"$LOG" 2>&1 || true
log "RUN: apt-get install -f"
apt_noninteractive install -f >>"$LOG" 2>&1 || true
log "RUN: apt-get update"
apt-get update >>"$LOG" 2>&1
log "RUN: apt-get install ${missing[*]}"
apt_noninteractive install "${missing[@]}" >>"$LOG" 2>&1
}
trim_text() {
printf '%s' "$1" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//'
}
machine_id_suffix() {
local machine_id=""
machine_id="$(cat /etc/machine-id 2>/dev/null || true)"
machine_id="$(printf '%s' "$machine_id" | tr -cd 'a-fA-F0-9' | tr '[:upper:]' '[:lower:]')"
if [[ "${#machine_id}" -lt 6 ]]; then
machine_id="$(cat /proc/sys/kernel/random/uuid | tr -d '-' | tail -c 6)"
else
machine_id="$(printf '%s' "$machine_id" | tail -c 6)"
fi
printf '%s\n' "$machine_id"
}
current_short_hostname() {
local host=""
host="$(hostname -s 2>/dev/null || hostname 2>/dev/null || true)"
host="${host%%.*}"
host="$(trim_text "$host")"
printf '%s\n' "$host"
}
ensure_hostname() {
local host
host="$(current_short_hostname)"
if [[ -z "$host" || "$host" == "localhost" || "$host" == "localhost.localdomain" ]]; then
host="g-box-$(machine_id_suffix)"
log "Hostname is empty/localhost; generated hostname: $host" >&2
if command -v hostnamectl >/dev/null 2>&1; then
hostnamectl set-hostname "$host"
else
hostname "$host"
printf '%s\n' "$host" >/etc/hostname
fi
else
log "Using existing hostname: $host" >&2
fi
printf '%s\n' "$host"
}
write_if_changed() {
local path="$1"
local mode="$2"
local owner="${3:-root}"
local group="${4:-root}"
local tmp
tmp="$(mktemp)"
cat >"$tmp"
if [[ -f "$path" ]] && cmp -s "$tmp" "$path"; then
rm -f "$tmp"
chown "$owner:$group" "$path" 2>/dev/null || true
chmod "$mode" "$path" 2>/dev/null || true
return 1
fi
if [[ -e "$path" ]]; then
cp -a "$path" "${path}.bak.$(date -u +%Y%m%d%H%M%S)" || true
fi
install -D -o "$owner" -g "$group" -m "$mode" "$tmp" "$path"
rm -f "$tmp"
return 0
}
write_avahi_service() {
mkdir -p /etc/avahi/services
if write_if_changed "$SERVICE_FILE" 0644 <<EOF
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">IOMATEX Web UI on %h</name>
<service>
<type>_http._tcp</type>
<port>${WEB_PORT}</port>
<txt-record>path=/</txt-record>
<txt-record>product=IOMATEX Edge</txt-record>
</service>
</service-group>
EOF
then
log "Updated Avahi service advertisement: $SERVICE_FILE"
else
log "Avahi service advertisement already current: $SERVICE_FILE"
fi
}
normalize_hosts_line() {
local tmp
[[ -f "$NSSWITCH" ]] || {
log "WARN: $NSSWITCH is missing; creating minimal nsswitch hosts line"
printf 'hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname\n' >"$NSSWITCH"
return 0
}
tmp="$(mktemp)"
awk '
BEGIN { done=0 }
/^[[:space:]]*hosts[[:space:]]*:/ {
print "hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname"
done=1
next
}
{ print }
END {
if (!done) {
print "hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname"
}
}
' "$NSSWITCH" >"$tmp"
if cmp -s "$tmp" "$NSSWITCH"; then
rm -f "$tmp"
log "nsswitch hosts line already current"
return 0
fi
cp -a "$NSSWITCH" "${NSSWITCH}.bak.$(date -u +%Y%m%d%H%M%S)" || true
install -m 0644 -o root -g root "$tmp" "$NSSWITCH"
rm -f "$tmp"
log "Updated nsswitch hosts line for mdns4_minimal before dns"
}
ensure_avahi_ipv4_only() {
local tmp
if [[ ! -f "$AVAHI_CONF" ]]; then
cat >"$AVAHI_CONF" <<'EOF'
[server]
use-ipv4=yes
use-ipv6=no
[publish]
publish-a-on-ipv6=no
publish-aaaa-on-ipv4=no
EOF
chmod 0644 "$AVAHI_CONF"
log "Created IPv4-only Avahi config: $AVAHI_CONF"
return 0
fi
tmp="$(mktemp)"
awk '
BEGIN {
section = ""
seen_server = 0
seen_publish = 0
server_use4 = 0
server_use6 = 0
publish_a_on_v6 = 0
publish_aaaa_on_v4 = 0
}
/^\[[^]]+\][[:space:]]*$/ {
if (section == "server") {
if (!server_use4) print "use-ipv4=yes"
if (!server_use6) print "use-ipv6=no"
}
if (section == "publish") {
if (!publish_a_on_v6) print "publish-a-on-ipv6=no"
if (!publish_aaaa_on_v4) print "publish-aaaa-on-ipv4=no"
}
section = $0
gsub(/^\[/, "", section)
gsub(/\][[:space:]]*$/, "", section)
if (section == "server") seen_server = 1
if (section == "publish") seen_publish = 1
print
next
}
section == "server" && /^[[:space:]]*#?[[:space:]]*use-ipv4[[:space:]]*=/ {
print "use-ipv4=yes"
server_use4 = 1
next
}
section == "server" && /^[[:space:]]*#?[[:space:]]*use-ipv6[[:space:]]*=/ {
print "use-ipv6=no"
server_use6 = 1
next
}
section == "publish" && /^[[:space:]]*#?[[:space:]]*publish-a-on-ipv6[[:space:]]*=/ {
print "publish-a-on-ipv6=no"
publish_a_on_v6 = 1
next
}
section == "publish" && /^[[:space:]]*#?[[:space:]]*publish-aaaa-on-ipv4[[:space:]]*=/ {
print "publish-aaaa-on-ipv4=no"
publish_aaaa_on_v4 = 1
next
}
{ print }
END {
if (section == "server") {
if (!server_use4) print "use-ipv4=yes"
if (!server_use6) print "use-ipv6=no"
}
if (section == "publish") {
if (!publish_a_on_v6) print "publish-a-on-ipv6=no"
if (!publish_aaaa_on_v4) print "publish-aaaa-on-ipv4=no"
}
if (!seen_server) {
print ""
print "[server]"
print "use-ipv4=yes"
print "use-ipv6=no"
}
if (!seen_publish) {
print ""
print "[publish]"
print "publish-a-on-ipv6=no"
print "publish-aaaa-on-ipv4=no"
}
}
' "$AVAHI_CONF" >"$tmp"
if cmp -s "$tmp" "$AVAHI_CONF"; then
rm -f "$tmp"
log "Avahi daemon config already IPv4-only"
return 0
fi
cp -a "$AVAHI_CONF" "${AVAHI_CONF}.bak.$(date -u +%Y%m%d%H%M%S)" || true
install -m 0644 -o root -g root "$tmp" "$AVAHI_CONF"
rm -f "$tmp"
log "Updated Avahi daemon config to publish IPv4 only"
}
ensure_avahi_host_name() {
local tmp
if [[ ! "$MDNS_HOSTNAME" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{0,62}$ ]]; then
echo "ERROR: invalid IOMATEX_MDNS_HOSTNAME: $MDNS_HOSTNAME" >&2
exit 1
fi
tmp="$(mktemp)"
awk -v desired="$MDNS_HOSTNAME" '
BEGIN {
section = ""
seen_server = 0
seen_hostname = 0
}
/^\[[^]]+\][[:space:]]*$/ {
if (section == "server" && !seen_hostname) {
print "host-name=" desired
}
section = $0
gsub(/^\[/, "", section)
gsub(/\][[:space:]]*$/, "", section)
if (section == "server") seen_server = 1
print
next
}
section == "server" && /^[[:space:]]*#?[[:space:]]*host-name[[:space:]]*=/ {
print "host-name=" desired
seen_hostname = 1
next
}
{ print }
END {
if (section == "server" && !seen_hostname) {
print "host-name=" desired
}
if (!seen_server) {
print ""
print "[server]"
print "host-name=" desired
}
}
' "$AVAHI_CONF" >"$tmp"
if cmp -s "$tmp" "$AVAHI_CONF"; then
rm -f "$tmp"
log "Avahi host-name already current: $MDNS_HOSTNAME"
return 0
fi
cp -a "$AVAHI_CONF" "${AVAHI_CONF}.bak.$(date -u +%Y%m%d%H%M%S)" || true
install -m 0644 -o root -g root "$tmp" "$AVAHI_CONF"
rm -f "$tmp"
log "Updated Avahi host-name: $MDNS_HOSTNAME"
}
service_status() {
systemctl is-active avahi-daemon.service 2>/dev/null || echo "unknown"
}
main() {
local host mdns status
need_root
log "=== IOMATEX AVAHI DISCOVERY INSTALL START ==="
apt_install_missing "${REQUIRED_PACKAGES[@]}"
host="$(ensure_hostname)"
normalize_hosts_line
ensure_avahi_ipv4_only
ensure_avahi_host_name
write_avahi_service
systemctl daemon-reload >/dev/null 2>&1 || true
systemctl enable --now avahi-daemon.service >/dev/null
systemctl restart avahi-daemon.service >/dev/null || true
mdns="${MDNS_HOSTNAME}.local"
status="$(service_status)"
echo
echo "IOMATEX Avahi discovery installed."
echo
echo "Hostname:"
echo "$host"
echo
echo "Avahi host-name:"
echo "$MDNS_HOSTNAME"
echo
echo "mDNS:"
echo "$mdns"
echo
echo "Web UI:"
echo "http://${mdns}/"
echo
echo "Avahi daemon:"
echo "$status"
echo
echo "Check from another Linux/Mac device:"
echo "ping ${mdns}"
echo "avahi-browse -art | grep IOMATEX"
echo
echo "Check from Windows:"
echo "ping ${mdns}"
echo "Open in browser:"
echo "http://${mdns}/"
echo
echo "Local diagnostics:"
echo "systemctl status avahi-daemon.service --no-pager"
echo "avahi-browse -art | grep -i iomatex"
echo "cat ${SERVICE_FILE}"
echo
log "=== IOMATEX AVAHI DISCOVERY INSTALL COMPLETE ==="
}
main "$@"

View File

@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
if head -c 3 "$0" 2>/dev/null | grep -q $'^\xEF\xBB\xBF'; then
echo "ERROR: UTF-8 BOM detected. Save as UTF-8 without BOM." >&2
exit 1
fi
if grep -q $'\r' "$0" 2>/dev/null; then
echo "ERROR: CRLF detected. Convert file to UNIX (LF)." >&2
exit 1
fi
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
SERVICE_FILE="/etc/avahi/services/iomatex-web.service"
need_root() {
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
echo "ERROR: Run as root: sudo bash $0" >&2
exit 1
fi
}
need_root
rm -f "$SERVICE_FILE"
if systemctl list-unit-files avahi-daemon.service >/dev/null 2>&1; then
systemctl restart avahi-daemon.service >/dev/null 2>&1 || true
fi
echo "IOMATEX Avahi advertisement removed."
echo
echo "Removed:"
echo "$SERVICE_FILE"
echo
echo "Kept unchanged:"
echo "- avahi-daemon, avahi-utils, libnss-mdns packages"
echo "- hostname"
echo "- /etc/nsswitch.conf"

61
stage_cockpit/README.md Normal file
View File

@ -0,0 +1,61 @@
# stage_cockpit
`stage_cockpit` installs Cockpit as an optional diagnostics UI for IOMATEX Edge.
Cockpit is not required for the main Edge runtime. The primary interface remains the IOMATEX Web UI:
```text
http://<edge-host-or-ip>/
```
## Why Cockpit Is Separate
On the current vendor image, installing `cockpit` has repeatedly triggered a kernel message like:
```text
kernel: Internal error: Oops - BUG: 0 [#1] SMP
```
That is a kernel/vendor-image failure, not a normal `apt` error. Because of that, Cockpit is kept in this optional stage and the main installer treats it as non-blocking.
## Install
Run after the main Edge install or as part of the non-blocking optional pipeline:
```bash
sudo bash stage_cockpit/stage_cockpit_install.sh
```
If it succeeds:
```text
https://<edge-ip>:9090
```
## If It Fails
The main Edge install can continue without Cockpit.
After reboot, retry separately:
```bash
cd /opt/iomatex/Iomatex_OS
sudo dpkg --configure -a
sudo apt-get -y -f install
sudo apt-get check
sudo bash stage_cockpit/stage_cockpit_install.sh
```
Diagnostics:
```bash
journalctl -k --no-pager -n 120 | grep -i 'oops\|bug'
cat /var/log/iomatex-stage-cockpit.log
```
## Checks
```bash
systemctl status cockpit.socket --no-pager
ss -ltnp | grep ':9090 '
```

View File

@ -0,0 +1,235 @@
#!/usr/bin/env bash
set -euo pipefail
# IOMATEX optional Cockpit stage
# Debian 11 / bullseye compatible
if head -c 3 "$0" 2>/dev/null | grep -q $'^\xEF\xBB\xBF'; then
echo "ERROR: UTF-8 BOM detected. Save as UTF-8 without BOM." >&2
exit 1
fi
if grep -q $'\r' "$0" 2>/dev/null; then
echo "ERROR: CRLF detected. Convert file to UNIX (LF)." >&2
exit 1
fi
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export DEBIAN_FRONTEND=noninteractive
LOG="/var/log/iomatex-stage-cockpit.log"
TIMEOUT_S="${IOMATEX_COCKPIT_APT_TIMEOUT:-600}"
COCKPIT_PACKAGES=(cockpit)
COCKPIT_OPTIONAL_PACKAGES=(cockpit-networkmanager cockpit-storaged)
mkdir -p /var/log >/dev/null 2>&1 || true
touch "$LOG" >/dev/null 2>&1 || true
log() {
local line="[$(date -u +'%F %T UTC')] $*"
echo "$line"
echo "$line" >>"$LOG" 2>/dev/null || true
}
need_root() {
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
echo "ERROR: Run as root: sudo bash $0" >&2
exit 1
fi
}
package_installed() {
dpkg-query -W -f='${Status}\n' "$1" 2>/dev/null | grep -qx 'install ok installed'
}
run_timed() {
local label="$1"
shift
log "RUN: ${label} :: $*"
if timeout --kill-after=10s "$TIMEOUT_S" "$@" >>"$LOG" 2>&1; then
log "OK: ${label}"
return 0
fi
local rc=$?
log "FAIL(${rc}): ${label}"
return "$rc"
}
apt_repair_state() {
local rc=0
log "APT/DPKG repair: start"
dpkg --audit >>"$LOG" 2>&1 || true
run_timed "dpkg --configure -a" dpkg --configure -a || rc=1
run_timed "apt-get -f install" apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
-f install || rc=1
run_timed "apt-get check" apt-get check || rc=1
log "APT/DPKG repair: complete rc=${rc}"
return "$rc"
}
apt_update() {
run_timed "apt-get update" apt-get update
}
install_missing_packages() {
local missing=()
local pkg
for pkg in "$@"; do
if ! package_installed "$pkg"; then
missing+=("$pkg")
fi
done
if [[ "${#missing[@]}" -eq 0 ]]; then
log "Packages already installed: $*"
return 0
fi
apt_repair_state
apt_update
run_timed "Install packages: ${missing[*]}" apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
install "${missing[@]}"
}
install_optional_packages() {
local pkg
for pkg in "$@"; do
if package_installed "$pkg"; then
log "Optional package already installed: $pkg"
continue
fi
if run_timed "Install optional package: $pkg" apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
install "$pkg"; then
continue
fi
log "WARN: optional Cockpit package failed, continuing: $pkg"
apt_repair_state || true
done
}
main_ipv4() {
local ip=""
ip="$(ip route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="src"){print $(i+1); exit}}' || true)"
[[ -n "${ip:-}" ]] && { printf '%s\n' "$ip"; return 0; }
hostname -I 2>/dev/null | awk '{print $1}' || true
}
write_cockpit_banner() {
local ip_main="${1:-<device-ip>}"
mkdir -p /etc/cockpit
cat >/etc/issue.cockpit <<EOF
======================================================
IOMATEX EDGE
======================================================
Cockpit is optional on this image.
Main IOMATEX Web UI remains the primary interface.
Cockpit: https://${ip_main}:9090
======================================================
EOF
chmod 0644 /etc/issue.cockpit
cat >/etc/cockpit/cockpit.conf <<'EOF'
[Session]
Banner=/etc/issue.cockpit
EOF
chmod 0644 /etc/cockpit/cockpit.conf
}
print_retry_report() {
cat <<EOF
IOMATEX Cockpit was not installed.
Core Edge installation can continue without Cockpit.
Reason:
- This vendor kernel has repeatedly produced "Internal error: Oops - BUG" during apt install cockpit.
- That is a kernel/vendor-image problem, not a normal apt configuration error.
Recommended action:
1. Finish the main Edge install.
2. Reboot.
3. Retry Cockpit separately:
cd /opt/iomatex/Iomatex_OS
sudo bash stage_cockpit/stage_cockpit_install.sh
Diagnostics:
sudo dpkg --configure -a
sudo apt-get -y -f install
sudo apt-get check
journalctl -k --no-pager -n 120 | grep -i 'oops\\|bug'
Log:
$LOG
EOF
}
main() {
local ip_main status
need_root
log "=== IOMATEX COCKPIT OPTIONAL INSTALL START ==="
if ! apt_repair_state; then
print_retry_report
exit 20
fi
if ! install_missing_packages "${COCKPIT_PACKAGES[@]}"; then
log "Cockpit package install failed; running fallback repair"
apt_repair_state || true
systemctl disable --now cockpit.socket >/dev/null 2>&1 || true
print_retry_report
exit 20
fi
install_optional_packages "${COCKPIT_OPTIONAL_PACKAGES[@]}"
ip_main="$(main_ipv4)"
[[ -n "${ip_main:-}" ]] || ip_main="<device-ip>"
write_cockpit_banner "$ip_main"
systemctl daemon-reload >/dev/null 2>&1 || true
if ! systemctl enable --now cockpit.socket >/dev/null 2>&1; then
log "WARN: cockpit installed but cockpit.socket did not start"
systemctl status cockpit.socket --no-pager -n 40 || true
print_retry_report
exit 20
fi
status="$(systemctl is-active cockpit.socket 2>/dev/null || echo unknown)"
echo
echo "IOMATEX Cockpit installed."
echo
echo "Cockpit socket:"
echo "$status"
echo
echo "Cockpit URL:"
echo "https://${ip_main}:9090"
echo
echo "Main IOMATEX Web UI remains primary:"
echo "http://${ip_main}/"
echo
echo "Checks:"
echo "systemctl status cockpit.socket --no-pager"
echo "ss -ltnp | grep ':9090 '"
echo
log "=== IOMATEX COCKPIT OPTIONAL INSTALL COMPLETE ==="
}
main "$@"

View File

@ -995,6 +995,8 @@ ensure_edge_name
# -------------------------
step "Install + enable Cockpit baseline + security reminder"
apt_install_missing network-manager
IOM_INSTALL_COCKPIT="${IOMATEX_INSTALL_COCKPIT:-0}"
if [[ "$IOM_INSTALL_COCKPIT" == "1" ]]; then
if apt_install_missing cockpit; then
log "cockpit package ensured"
else
@ -1002,6 +1004,10 @@ else
echo "[!] WARN: cockpit install failed; continuing without it (see $LOG)"
fi
apt_install_optional cockpit-networkmanager cockpit-storaged
else
log "Cockpit install skipped by default; set IOMATEX_INSTALL_COCKPIT=1 to opt in"
echo "[i] Cockpit install skipped by default on this image; Web UI remains available via iomatex-console"
fi
keep_pcp_logs_on_root
systemctl_enable_now_safe NetworkManager