edge: fix HDMI/X11 startup race + stage updates (env, mqtt, ui, wifi, itscreen)
This commit is contained in:
parent
ac0c1ec683
commit
8e908bb752
|
|
@ -0,0 +1,305 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_PATH="${SCRIPT_DIR}/$(basename "${BASH_SOURCE[0]}")"
|
||||
|
||||
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
exec sudo -E /bin/bash "$SCRIPT_PATH" "$@"
|
||||
fi
|
||||
echo "ERROR: root privileges are required. Run: sudo bash ./compact_installer.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
export DEBIAN_FRONTEND="${DEBIAN_FRONTEND:-noninteractive}"
|
||||
|
||||
LOG_FILE="${SCRIPT_DIR}/compact_installer.log"
|
||||
STATE_FILE="${SCRIPT_DIR}/compact_installer.state"
|
||||
|
||||
STAGE_ORDER=(
|
||||
"stage_mqtt"
|
||||
"stage_wifi"
|
||||
"stage_ui"
|
||||
"stage_z2m"
|
||||
"stage_itscreen"
|
||||
"stage_reverse_tunnels"
|
||||
)
|
||||
|
||||
CURRENT_STAGE=""
|
||||
CURRENT_INSTALLER=""
|
||||
RESET_STATE=0
|
||||
FROM_STAGE=""
|
||||
START_FROM_STAGE=""
|
||||
|
||||
mkdir -p "$SCRIPT_DIR"
|
||||
touch "$LOG_FILE"
|
||||
touch "$STATE_FILE"
|
||||
chmod 0644 "$LOG_FILE" "$STATE_FILE" 2>/dev/null || true
|
||||
exec > >(tee -a "$LOG_FILE") 2>&1
|
||||
|
||||
log() {
|
||||
printf '[%s] %s\n' "$(date -u +'%F %T UTC')" "$*"
|
||||
}
|
||||
|
||||
warn() {
|
||||
log "WARN: $*"
|
||||
}
|
||||
|
||||
die() {
|
||||
log "ERROR: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
on_err() {
|
||||
local rc="$1"
|
||||
local line="$2"
|
||||
if [[ -n "$CURRENT_STAGE" ]]; then
|
||||
log "ERROR: unexpected failure in ${CURRENT_STAGE} at line ${line} (rc=${rc})"
|
||||
else
|
||||
log "ERROR: unexpected failure at line ${line} (rc=${rc})"
|
||||
fi
|
||||
}
|
||||
trap 'on_err "$?" "$LINENO"' ERR
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
sudo bash ./compact_installer.sh
|
||||
sudo bash ./compact_installer.sh --from stage_ui
|
||||
sudo bash ./compact_installer.sh --reset-state
|
||||
|
||||
Behavior:
|
||||
- runs stages in this exact order:
|
||||
stage_mqtt -> stage_wifi -> stage_ui -> stage_z2m -> stage_itscreen -> stage_reverse_tunnels
|
||||
- after stage_reverse_tunnels, prints reminder about manual VPS bootstrap and reboot
|
||||
- stops on first failure
|
||||
EOF
|
||||
}
|
||||
|
||||
set_state_value() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local tmp
|
||||
tmp="$(mktemp "${STATE_FILE}.tmp.XXXXXX")"
|
||||
if [[ -f "$STATE_FILE" ]]; then
|
||||
awk -F= -v k="$key" '$1 != k { print $0 }' "$STATE_FILE" >"$tmp"
|
||||
fi
|
||||
printf '%s=%s\n' "$key" "$value" >>"$tmp"
|
||||
mv -f "$tmp" "$STATE_FILE"
|
||||
}
|
||||
|
||||
get_state_value() {
|
||||
local key="$1"
|
||||
[[ -f "$STATE_FILE" ]] || return 0
|
||||
awk -F= -v k="$key" '$1 == k { print substr($0, index($0, "=") + 1) }' "$STATE_FILE" | tail -n1
|
||||
}
|
||||
|
||||
set_stage_status() {
|
||||
local stage="$1"
|
||||
local status="$2"
|
||||
set_state_value "STATUS_${stage}" "$status"
|
||||
}
|
||||
|
||||
get_stage_status() {
|
||||
local stage="$1"
|
||||
get_state_value "STATUS_${stage}"
|
||||
}
|
||||
|
||||
reset_state() {
|
||||
: >"$STATE_FILE"
|
||||
log "State reset: $STATE_FILE"
|
||||
}
|
||||
|
||||
is_known_stage() {
|
||||
local wanted="$1"
|
||||
local stage
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
[[ "$stage" == "$wanted" ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
next_stage_after() {
|
||||
local current="$1"
|
||||
local seen=0
|
||||
local stage
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
if [[ "$seen" -eq 0 ]]; then
|
||||
[[ "$stage" == "$current" ]] && seen=1
|
||||
continue
|
||||
fi
|
||||
printf '%s\n' "$stage"
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
stage_candidates() {
|
||||
local stage="$1"
|
||||
case "$stage" in
|
||||
stage_mqtt)
|
||||
printf '%s\n' "stage_mqtt_install.sh"
|
||||
;;
|
||||
stage_wifi)
|
||||
printf '%s\n' "stage_wifi_install.sh"
|
||||
;;
|
||||
stage_ui)
|
||||
printf '%s\n' "ui_installer.sh"
|
||||
printf '%s\n' "stage_ui_install.sh"
|
||||
;;
|
||||
stage_z2m)
|
||||
printf '%s\n' "stage_z2m_install"
|
||||
printf '%s\n' "stage_z2m.sh"
|
||||
;;
|
||||
stage_itscreen)
|
||||
printf '%s\n' "stage_itscreen_install.sh"
|
||||
;;
|
||||
stage_reverse_tunnels)
|
||||
printf '%s\n' "stage_reverse_tunnels_install.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
find_stage_installer() {
|
||||
local stage="$1"
|
||||
local stage_dir="${SCRIPT_DIR}/${stage}"
|
||||
local candidate
|
||||
[[ -d "$stage_dir" ]] || return 1
|
||||
while IFS= read -r candidate; do
|
||||
[[ -n "$candidate" ]] || continue
|
||||
[[ -f "${stage_dir}/${candidate}" ]] && {
|
||||
printf '%s\n' "${stage_dir}/${candidate}"
|
||||
return 0
|
||||
}
|
||||
done < <(stage_candidates "$stage")
|
||||
return 1
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo "IOMATEX COMPACT INSTALLER"
|
||||
echo "============================================================"
|
||||
echo "Project root : ${SCRIPT_DIR}"
|
||||
echo "Start from : ${START_FROM_STAGE:-stage_mqtt}"
|
||||
echo "Log file : ${LOG_FILE}"
|
||||
echo "State file : ${STATE_FILE}"
|
||||
echo "Stage order : ${STAGE_ORDER[*]}"
|
||||
echo "============================================================"
|
||||
echo
|
||||
}
|
||||
|
||||
run_stage() {
|
||||
local stage="$1"
|
||||
local installer=""
|
||||
local stage_dir="${SCRIPT_DIR}/${stage}"
|
||||
local rc=0
|
||||
|
||||
installer="$(find_stage_installer "$stage")" || die "Installer not found for ${stage}"
|
||||
|
||||
CURRENT_STAGE="$stage"
|
||||
CURRENT_INSTALLER="$(basename "$installer")"
|
||||
log "START: ${stage} -> ${CURRENT_INSTALLER}"
|
||||
set_state_value "LAST_STAGE" "$stage"
|
||||
set_state_value "LAST_INSTALLER" "$CURRENT_INSTALLER"
|
||||
set_state_value "LAST_RESULT" "running"
|
||||
|
||||
set +e
|
||||
(
|
||||
cd "$stage_dir"
|
||||
export UCF_FORCE_CONFFOLD=1
|
||||
/bin/bash "./${CURRENT_INSTALLER}"
|
||||
)
|
||||
rc=$?
|
||||
set -e
|
||||
|
||||
if [[ "$rc" -ne 0 ]]; then
|
||||
set_stage_status "$stage" "failed"
|
||||
set_state_value "LAST_RESULT" "failed"
|
||||
die "Stage ${stage} failed with rc=${rc}"
|
||||
fi
|
||||
|
||||
set_stage_status "$stage" "success"
|
||||
set_state_value "LAST_RESULT" "success"
|
||||
log "OK: ${stage}"
|
||||
CURRENT_STAGE=""
|
||||
CURRENT_INSTALLER=""
|
||||
}
|
||||
|
||||
print_final_summary() {
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo "COMPACT INSTALLER SUMMARY"
|
||||
echo "============================================================"
|
||||
echo "Successful stages:"
|
||||
local stage
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
if [[ "$(get_stage_status "$stage")" == "success" ]]; then
|
||||
echo " - ${stage}"
|
||||
fi
|
||||
done
|
||||
echo
|
||||
echo "After stage_reverse_tunnels:"
|
||||
echo " - run the VPS bootstrap command printed by stage_reverse_tunnels"
|
||||
echo " - reboot Edge so enabled reverse tunnel services actually start"
|
||||
echo "============================================================"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--reset-state)
|
||||
RESET_STATE=1
|
||||
shift
|
||||
;;
|
||||
--from)
|
||||
[[ $# -ge 2 ]] || die "--from requires a stage name"
|
||||
FROM_STAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "Unknown argument: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -n "$FROM_STAGE" ]] && is_known_stage "$FROM_STAGE" || [[ -z "$FROM_STAGE" ]] || die "Unknown stage: ${FROM_STAGE}"
|
||||
|
||||
if [[ "$RESET_STATE" -eq 1 ]]; then
|
||||
reset_state
|
||||
fi
|
||||
|
||||
log "=== COMPACT INSTALLER START ==="
|
||||
log "Log file: ${LOG_FILE}"
|
||||
log "State file: ${STATE_FILE}"
|
||||
START_FROM_STAGE="${FROM_STAGE:-stage_mqtt}"
|
||||
|
||||
print_header
|
||||
|
||||
started=0
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
if [[ "$started" -eq 0 ]]; then
|
||||
if [[ "$stage" == "$START_FROM_STAGE" ]]; then
|
||||
started=1
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$FROM_STAGE" && "$(get_stage_status "$stage")" == "success" ]]; then
|
||||
log "RESUME: ${stage} already successful, skipping"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo
|
||||
echo ">>> RUNNING ${stage}"
|
||||
run_stage "$stage"
|
||||
done
|
||||
|
||||
print_final_summary
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,328 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_PATH="${SCRIPT_DIR}/$(basename "${BASH_SOURCE[0]}")"
|
||||
|
||||
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
exec sudo -E /bin/bash "$SCRIPT_PATH" "$@"
|
||||
fi
|
||||
echo "ERROR: root privileges are required. Run: sudo bash ./compact_installer_no_z2m.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
export DEBIAN_FRONTEND="${DEBIAN_FRONTEND:-noninteractive}"
|
||||
|
||||
LOG_FILE="${SCRIPT_DIR}/compact_installer_no_z2m.log"
|
||||
STATE_FILE="${SCRIPT_DIR}/compact_installer_no_z2m.state"
|
||||
|
||||
STAGE_ORDER=(
|
||||
"stage_mqtt"
|
||||
"stage_wifi"
|
||||
"stage_ui"
|
||||
"stage_itscreen"
|
||||
"stage_reverse_tunnels"
|
||||
)
|
||||
|
||||
CURRENT_STAGE=""
|
||||
CURRENT_INSTALLER=""
|
||||
RESET_STATE=0
|
||||
FROM_STAGE=""
|
||||
START_FROM_STAGE=""
|
||||
|
||||
mkdir -p "$SCRIPT_DIR"
|
||||
touch "$LOG_FILE"
|
||||
touch "$STATE_FILE"
|
||||
chmod 0644 "$LOG_FILE" "$STATE_FILE" 2>/dev/null || true
|
||||
exec > >(tee -a "$LOG_FILE") 2>&1
|
||||
|
||||
log() {
|
||||
printf '[%s] %s\n' "$(date -u +'%F %T UTC')" "$*"
|
||||
}
|
||||
|
||||
die() {
|
||||
log "ERROR: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
on_err() {
|
||||
local rc="$1"
|
||||
local line="$2"
|
||||
if [[ -n "$CURRENT_STAGE" ]]; then
|
||||
log "ERROR: unexpected failure in ${CURRENT_STAGE} at line ${line} (rc=${rc})"
|
||||
else
|
||||
log "ERROR: unexpected failure at line ${line} (rc=${rc})"
|
||||
fi
|
||||
}
|
||||
trap 'on_err "$?" "$LINENO"' ERR
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
sudo bash ./compact_installer_no_z2m.sh
|
||||
sudo bash ./compact_installer_no_z2m.sh --from stage_ui
|
||||
sudo bash ./compact_installer_no_z2m.sh --reset-state
|
||||
|
||||
Behavior:
|
||||
- first force-cleans known Zigbee2MQTT leftovers from previous attempts
|
||||
- then runs stages in this exact order:
|
||||
stage_mqtt -> stage_wifi -> stage_ui -> stage_itscreen -> stage_reverse_tunnels
|
||||
- after stage_reverse_tunnels, prints reminder about manual VPS bootstrap and reboot
|
||||
- stops on first failure
|
||||
EOF
|
||||
}
|
||||
|
||||
set_state_value() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local tmp
|
||||
tmp="$(mktemp "${STATE_FILE}.tmp.XXXXXX")"
|
||||
if [[ -f "$STATE_FILE" ]]; then
|
||||
awk -F= -v k="$key" '$1 != k { print $0 }' "$STATE_FILE" >"$tmp"
|
||||
fi
|
||||
printf '%s=%s\n' "$key" "$value" >>"$tmp"
|
||||
mv -f "$tmp" "$STATE_FILE"
|
||||
}
|
||||
|
||||
get_state_value() {
|
||||
local key="$1"
|
||||
[[ -f "$STATE_FILE" ]] || return 0
|
||||
awk -F= -v k="$key" '$1 == k { print substr($0, index($0, "=") + 1) }' "$STATE_FILE" | tail -n1
|
||||
}
|
||||
|
||||
set_stage_status() {
|
||||
local stage="$1"
|
||||
local status="$2"
|
||||
set_state_value "STATUS_${stage}" "$status"
|
||||
}
|
||||
|
||||
get_stage_status() {
|
||||
local stage="$1"
|
||||
get_state_value "STATUS_${stage}"
|
||||
}
|
||||
|
||||
reset_state() {
|
||||
: >"$STATE_FILE"
|
||||
log "State reset: $STATE_FILE"
|
||||
}
|
||||
|
||||
is_known_stage() {
|
||||
local wanted="$1"
|
||||
local stage
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
[[ "$stage" == "$wanted" ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
stage_candidates() {
|
||||
local stage="$1"
|
||||
case "$stage" in
|
||||
stage_mqtt)
|
||||
printf '%s\n' "stage_mqtt_install.sh"
|
||||
;;
|
||||
stage_wifi)
|
||||
printf '%s\n' "stage_wifi_install.sh"
|
||||
;;
|
||||
stage_ui)
|
||||
printf '%s\n' "ui_installer.sh"
|
||||
printf '%s\n' "stage_ui_install.sh"
|
||||
;;
|
||||
stage_itscreen)
|
||||
printf '%s\n' "stage_itscreen_install.sh"
|
||||
;;
|
||||
stage_reverse_tunnels)
|
||||
printf '%s\n' "stage_reverse_tunnels_install.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
find_stage_installer() {
|
||||
local stage="$1"
|
||||
local stage_dir="${SCRIPT_DIR}/${stage}"
|
||||
local candidate
|
||||
[[ -d "$stage_dir" ]] || return 1
|
||||
while IFS= read -r candidate; do
|
||||
[[ -n "$candidate" ]] || continue
|
||||
[[ -f "${stage_dir}/${candidate}" ]] && {
|
||||
printf '%s\n' "${stage_dir}/${candidate}"
|
||||
return 0
|
||||
}
|
||||
done < <(stage_candidates "$stage")
|
||||
return 1
|
||||
}
|
||||
|
||||
cleanup_z2m_leftovers() {
|
||||
local unit
|
||||
local path
|
||||
|
||||
log "Cleanup: removing possible Zigbee2MQTT leftovers from previous attempts"
|
||||
|
||||
for unit in zigbee2mqtt.service zigbee2mqtt; do
|
||||
systemctl stop "$unit" >/dev/null 2>&1 || true
|
||||
systemctl disable "$unit" >/dev/null 2>&1 || true
|
||||
systemctl reset-failed "$unit" >/dev/null 2>&1 || true
|
||||
done
|
||||
|
||||
rm -f /etc/systemd/system/zigbee2mqtt.service
|
||||
rm -f /lib/systemd/system/zigbee2mqtt.service
|
||||
rm -f /etc/systemd/system/multi-user.target.wants/zigbee2mqtt.service
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
|
||||
for path in \
|
||||
/opt/zigbee2mqtt \
|
||||
/var/lib/zigbee2mqtt \
|
||||
/var/log/zigbee2mqtt \
|
||||
/etc/zigbee2mqtt \
|
||||
/etc/default/zigbee2mqtt \
|
||||
/etc/init.d/zigbee2mqtt \
|
||||
/var/log/zigbee2mqtt.log \
|
||||
/run/zigbee2mqtt \
|
||||
/tmp/zigbee2mqtt; do
|
||||
rm -rf "$path" >/dev/null 2>&1 || true
|
||||
done
|
||||
|
||||
if id -u zigbee2mqtt >/dev/null 2>&1; then
|
||||
userdel -r zigbee2mqtt >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if getent group zigbee2mqtt >/dev/null 2>&1; then
|
||||
groupdel zigbee2mqtt >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
log "Cleanup: Zigbee2MQTT leftovers removal completed"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo "IOMATEX COMPACT INSTALLER (NO Z2M)"
|
||||
echo "============================================================"
|
||||
echo "Project root : ${SCRIPT_DIR}"
|
||||
echo "Start from : ${START_FROM_STAGE:-stage_mqtt}"
|
||||
echo "Log file : ${LOG_FILE}"
|
||||
echo "State file : ${STATE_FILE}"
|
||||
echo "Stage order : ${STAGE_ORDER[*]}"
|
||||
echo "============================================================"
|
||||
echo
|
||||
}
|
||||
|
||||
run_stage() {
|
||||
local stage="$1"
|
||||
local installer=""
|
||||
local stage_dir="${SCRIPT_DIR}/${stage}"
|
||||
local rc=0
|
||||
|
||||
installer="$(find_stage_installer "$stage")" || die "Installer not found for ${stage}"
|
||||
|
||||
CURRENT_STAGE="$stage"
|
||||
CURRENT_INSTALLER="$(basename "$installer")"
|
||||
log "START: ${stage} -> ${CURRENT_INSTALLER}"
|
||||
set_state_value "LAST_STAGE" "$stage"
|
||||
set_state_value "LAST_INSTALLER" "$CURRENT_INSTALLER"
|
||||
set_state_value "LAST_RESULT" "running"
|
||||
|
||||
set +e
|
||||
(
|
||||
cd "$stage_dir"
|
||||
export UCF_FORCE_CONFFOLD=1
|
||||
/bin/bash "./${CURRENT_INSTALLER}"
|
||||
)
|
||||
rc=$?
|
||||
set -e
|
||||
|
||||
if [[ "$rc" -ne 0 ]]; then
|
||||
set_stage_status "$stage" "failed"
|
||||
set_state_value "LAST_RESULT" "failed"
|
||||
die "Stage ${stage} failed with rc=${rc}"
|
||||
fi
|
||||
|
||||
set_stage_status "$stage" "success"
|
||||
set_state_value "LAST_RESULT" "success"
|
||||
log "OK: ${stage}"
|
||||
CURRENT_STAGE=""
|
||||
CURRENT_INSTALLER=""
|
||||
}
|
||||
|
||||
print_final_summary() {
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo "COMPACT INSTALLER NO Z2M SUMMARY"
|
||||
echo "============================================================"
|
||||
echo "Successful stages:"
|
||||
local stage
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
if [[ "$(get_stage_status "$stage")" == "success" ]]; then
|
||||
echo " - ${stage}"
|
||||
fi
|
||||
done
|
||||
echo
|
||||
echo "Cleanup performed before install:"
|
||||
echo " - possible Zigbee2MQTT service/files/user/data were force-removed"
|
||||
echo
|
||||
echo "After stage_reverse_tunnels:"
|
||||
echo " - run the VPS bootstrap command printed by stage_reverse_tunnels"
|
||||
echo " - reboot Edge so enabled reverse tunnel services actually start"
|
||||
echo "============================================================"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--reset-state)
|
||||
RESET_STATE=1
|
||||
shift
|
||||
;;
|
||||
--from)
|
||||
[[ $# -ge 2 ]] || die "--from requires a stage name"
|
||||
FROM_STAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "Unknown argument: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -n "$FROM_STAGE" ]] && is_known_stage "$FROM_STAGE" || [[ -z "$FROM_STAGE" ]] || die "Unknown stage: ${FROM_STAGE}"
|
||||
|
||||
if [[ "$RESET_STATE" -eq 1 ]]; then
|
||||
reset_state
|
||||
fi
|
||||
|
||||
log "=== COMPACT INSTALLER NO Z2M START ==="
|
||||
log "Log file: ${LOG_FILE}"
|
||||
log "State file: ${STATE_FILE}"
|
||||
|
||||
cleanup_z2m_leftovers
|
||||
START_FROM_STAGE="${FROM_STAGE:-stage_mqtt}"
|
||||
|
||||
print_header
|
||||
|
||||
started=0
|
||||
for stage in "${STAGE_ORDER[@]}"; do
|
||||
if [[ "$started" -eq 0 ]]; then
|
||||
if [[ "$stage" == "$START_FROM_STAGE" ]]; then
|
||||
started=1
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$FROM_STAGE" && "$(get_stage_status "$stage")" == "success" ]]; then
|
||||
log "RESUME: ${stage} already successful, skipping"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo
|
||||
echo ">>> RUNNING ${stage}"
|
||||
run_stage "$stage"
|
||||
done
|
||||
|
||||
print_final_summary
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# Compact installer
|
||||
|
||||
`compact_installer.sh` запускает стадии в фиксированном порядке:
|
||||
|
||||
```text
|
||||
stage_mqtt -> stage_wifi -> stage_ui -> stage_z2m -> stage_itscreen -> stage_reverse_tunnels
|
||||
```
|
||||
|
||||
Запуск:
|
||||
|
||||
```bash
|
||||
sudo bash ./compact_installer.sh
|
||||
```
|
||||
|
||||
Особенности:
|
||||
|
||||
- `stage_env` ставится отдельно и в `compact_installer.sh` не входит;
|
||||
- после `stage_reverse_tunnels` нужно выполнить команду для VPS, которую выведет инсталлер `stage_reverse_tunnels`, и затем перезагрузить Edge.
|
||||
|
||||
Дополнительно:
|
||||
|
||||
```bash
|
||||
sudo bash ./compact_installer.sh --from stage_ui
|
||||
sudo bash ./compact_installer.sh --reset-state
|
||||
```
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
# Compact installer without Z2M
|
||||
|
||||
`compact_installer_no_z2m.sh` сначала вычищает возможные хвосты от прошлых попыток установки Zigbee2MQTT, а потом запускает стадии:
|
||||
|
||||
```text
|
||||
stage_mqtt -> stage_wifi -> stage_ui -> stage_itscreen -> stage_reverse_tunnels
|
||||
```
|
||||
|
||||
Запуск:
|
||||
|
||||
```bash
|
||||
sudo bash ./compact_installer_no_z2m.sh
|
||||
```
|
||||
|
||||
Что чистится перед установкой:
|
||||
|
||||
- `zigbee2mqtt.service`;
|
||||
- пользователь и группа `zigbee2mqtt`;
|
||||
- каталоги `/opt/zigbee2mqtt`, `/var/lib/zigbee2mqtt`, `/var/log/zigbee2mqtt`;
|
||||
- типовые systemd/init/default-файлы Zigbee2MQTT.
|
||||
|
||||
Дополнительно:
|
||||
|
||||
```bash
|
||||
sudo bash ./compact_installer_no_z2m.sh --from stage_ui
|
||||
sudo bash ./compact_installer_no_z2m.sh --reset-state
|
||||
```
|
||||
|
|
@ -37,7 +37,27 @@ sudo reboot
|
|||
|
||||
Подожди, пока Edge снова поднимется по сети.
|
||||
|
||||
## 5. Теперь скопируй остальные папки на Edge
|
||||
## 5. После перезагрузки используй пользователя `iomatex`
|
||||
|
||||
После выполнения `stage_env` вход нужно делать уже под новым пользователем:
|
||||
|
||||
```text
|
||||
username: iomatex
|
||||
password: iomatex
|
||||
```
|
||||
|
||||
Подключение по SSH:
|
||||
|
||||
```bash
|
||||
ssh iomatex@192.168.1.50
|
||||
```
|
||||
|
||||
## 6. Важно: LightDM попросит сменить пароль
|
||||
|
||||
После `stage_env` и входа в графическую сессию `LightDM` потребует сменить пароль пользователя `iomatex`.
|
||||
Это ожидаемое поведение.
|
||||
|
||||
## 7. Теперь скопируй остальные папки на Edge
|
||||
|
||||
Скопируй `stage_mqtt`, `stage_itscreen`, `stage_ui` на устройство. Пример:
|
||||
|
||||
|
|
@ -45,37 +65,37 @@ sudo reboot
|
|||
scp -r stage_mqtt stage_itscreen stage_ui iomatex@192.168.1.50:/home/iomatex/
|
||||
```
|
||||
|
||||
## 6. Подключись к Edge по SSH под `iomatex`
|
||||
## 8. Подключись к Edge по SSH под `iomatex`
|
||||
|
||||
```bash
|
||||
ssh iomatex@192.168.1.50
|
||||
```
|
||||
|
||||
## 7. Перейди в папку пользователя
|
||||
## 9. Перейди в папку пользователя
|
||||
|
||||
```bash
|
||||
cd /home/iomatex
|
||||
```
|
||||
|
||||
## 8. Установи `stage_mqtt`
|
||||
## 10. Установи `stage_mqtt`
|
||||
|
||||
```bash
|
||||
sudo bash stage_mqtt/stage_mqtt_install.sh
|
||||
```
|
||||
|
||||
## 9. Установи `stage_itscreen`
|
||||
## 11. Установи `stage_itscreen`
|
||||
|
||||
```bash
|
||||
sudo bash stage_itscreen/stage_itscreen_install.sh
|
||||
```
|
||||
|
||||
## 10. Установи `stage_ui`
|
||||
## 12. Установи `stage_ui`
|
||||
|
||||
```bash
|
||||
sudo bash stage_ui/ui_installer.sh
|
||||
```
|
||||
|
||||
## 11. Полный порядок команд
|
||||
## 13. Полный порядок команд
|
||||
|
||||
```bash
|
||||
sudo bash stage_mqtt/stage_mqtt_install.sh
|
||||
|
|
@ -83,7 +103,7 @@ sudo bash stage_itscreen/stage_itscreen_install.sh
|
|||
sudo bash stage_ui/ui_installer.sh
|
||||
```
|
||||
|
||||
## 12. Проверка после установки
|
||||
## 14. Проверка после установки
|
||||
|
||||
```bash
|
||||
systemctl status itscreen-x11.service --no-pager
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -200,6 +200,81 @@ apt_remove_if_installed() {
|
|||
run_long "Remove packages" 900 /usr/bin/apt-get remove -y "${installed[@]}"
|
||||
}
|
||||
|
||||
install_mbpoll() {
|
||||
local build_dir="/tmp/mbpoll-build.$$"
|
||||
|
||||
if command -v mbpoll >/dev/null 2>&1; then
|
||||
log "mbpoll already installed: $(command -v mbpoll)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "[INFO] Installing mbpoll..."
|
||||
apt_update_if_needed
|
||||
|
||||
if /usr/bin/apt-cache show mbpoll >>"$LOG" 2>&1; then
|
||||
if apt_install_missing mbpoll; then
|
||||
if command -v mbpoll >/dev/null 2>&1; then
|
||||
log "mbpoll installed from apt: $(command -v mbpoll)"
|
||||
return 0
|
||||
fi
|
||||
log "ERROR: mbpoll package install completed but command not found"
|
||||
else
|
||||
log "mbpoll apt install failed; falling back to source build"
|
||||
fi
|
||||
else
|
||||
log "mbpoll package not found in apt repositories; falling back to source build"
|
||||
fi
|
||||
|
||||
apt_install_missing build-essential autoconf automake libtool pkg-config git libmodbus-dev
|
||||
|
||||
rm -rf "$build_dir"
|
||||
if ! run_long "Clone mbpoll source" 900 \
|
||||
/usr/bin/git clone --depth 1 https://github.com/epsilonrt/mbpoll "$build_dir"; then
|
||||
log "ERROR: failed to clone mbpoll source"
|
||||
rm -rf "$build_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! run_long "Bootstrap mbpoll" 900 \
|
||||
/bin/bash -lc 'cd "$1" && ./bootstrap' _ "$build_dir"; then
|
||||
log "ERROR: failed to bootstrap mbpoll"
|
||||
rm -rf "$build_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! run_long "Configure mbpoll" 900 \
|
||||
/bin/bash -lc 'cd "$1" && ./configure' _ "$build_dir"; then
|
||||
log "ERROR: failed to configure mbpoll"
|
||||
rm -rf "$build_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! run_long "Build mbpoll" 1800 \
|
||||
/bin/bash -lc 'cd "$1" && make -j"$(nproc)"' _ "$build_dir"; then
|
||||
log "ERROR: failed to build mbpoll"
|
||||
rm -rf "$build_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! run_long "Install mbpoll" 900 \
|
||||
/bin/bash -lc 'cd "$1" && make install' _ "$build_dir"; then
|
||||
log "ERROR: failed to install mbpoll"
|
||||
rm -rf "$build_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -rf "$build_dir"
|
||||
hash -r 2>/dev/null || true
|
||||
|
||||
if command -v mbpoll >/dev/null 2>&1; then
|
||||
log "mbpoll installed from source: $(command -v mbpoll)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "ERROR: mbpoll install finished but command is still unavailable"
|
||||
return 1
|
||||
}
|
||||
|
||||
systemctl_try() {
|
||||
/bin/systemctl "$@" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
|
@ -246,12 +321,19 @@ ensure_group_membership() {
|
|||
return "$changed"
|
||||
}
|
||||
|
||||
TOTAL_STEPS=15
|
||||
step_n=0
|
||||
step() {
|
||||
local filled empty bar percent
|
||||
step_n=$((step_n+1))
|
||||
percent=$(( step_n * 100 / TOTAL_STEPS ))
|
||||
filled=$(( step_n * 20 / TOTAL_STEPS ))
|
||||
empty=$(( 20 - filled ))
|
||||
bar="$(printf '%*s' "$filled" '' | tr ' ' '#')$(printf '%*s' "$empty" '' | tr ' ' '-')"
|
||||
echo
|
||||
echo "[${bar}] ${step_n}/${TOTAL_STEPS} (${percent}%)"
|
||||
echo "=== Step ${step_n}: $* ==="
|
||||
log "STEP ${step_n}: $*"
|
||||
log "STEP ${step_n}/${TOTAL_STEPS} (${percent}%): $*"
|
||||
}
|
||||
|
||||
spinner() {
|
||||
|
|
@ -335,7 +417,7 @@ if grep -q $'\r' "$0"; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
log "=== IOMATEX STAGE0_1 v3.2 START (Debian 11) ==="
|
||||
log "=== IOMATEX EDGE :: STAGE_ENV START (Debian 11) ==="
|
||||
log "LOG: $LOG"
|
||||
|
||||
# -------------------------
|
||||
|
|
@ -351,15 +433,25 @@ EOF
|
|||
# -------------------------
|
||||
step "APT sources normalize (official Debian 11 bullseye + non-free; remove vendor lists)"
|
||||
backup_if_exists /etc/apt/sources.list
|
||||
backup_if_exists /etc/apt/apt.conf.d/99no-translations
|
||||
|
||||
write_if_changed /etc/apt/apt.conf.d/99no-translations 0644 <<'EOF'
|
||||
Acquire::Languages "none";
|
||||
EOF
|
||||
log "APT translations policy ensured: Acquire::Languages none"
|
||||
|
||||
write_if_changed /etc/apt/sources.list 0644 <<'EOF'
|
||||
deb http://deb.debian.org/debian bullseye main contrib non-free
|
||||
deb http://deb.debian.org/debian bullseye-updates main contrib non-free
|
||||
deb http://security.debian.org/debian-security bullseye-security main contrib non-free
|
||||
deb http://deb.debian.org/debian-security bullseye-security main contrib non-free
|
||||
EOF
|
||||
|
||||
rm -f /etc/apt/sources.list.d/*.list 2>/dev/null || true
|
||||
log "APT sources normalized to official Debian 11 (no backports)"
|
||||
rm -f /etc/apt/sources.list.d/*.sources 2>/dev/null || true
|
||||
log "APT sources normalized to official Debian 11 policy"
|
||||
log "APT policy: deb-src disabled by omission"
|
||||
log "APT policy: bullseye-backports disabled by omission"
|
||||
log "APT policy: vendor list and deb822 sources removed"
|
||||
|
||||
# -------------------------
|
||||
# Step 3: APT repair + update
|
||||
|
|
@ -392,10 +484,12 @@ apt_install_missing \
|
|||
dos2unix \
|
||||
logrotate \
|
||||
rsyslog \
|
||||
lxterminal \
|
||||
network-manager \
|
||||
policykit-1
|
||||
|
||||
step "Install mbpoll"
|
||||
install_mbpoll
|
||||
|
||||
# -------------------------
|
||||
# Step 5: Timezone Asia/Dubai
|
||||
# -------------------------
|
||||
|
|
@ -424,7 +518,6 @@ IOM_USER="iomatex"
|
|||
IOM_PASS="iomatex" # default (must be changed on first login)
|
||||
ITS_USER="itscreen"
|
||||
Z2M_USER="zigbee2mqtt"
|
||||
GUI_MIGRATION_CHANGED=0
|
||||
|
||||
ensure_user() {
|
||||
local u="$1"
|
||||
|
|
@ -480,33 +573,7 @@ ensure_gui_home_state() {
|
|||
done
|
||||
}
|
||||
|
||||
configure_lightdm_autologin() {
|
||||
[ -d /etc/lightdm ] || { log "LightDM not installed; skip GUI autologin migration"; return 0; }
|
||||
|
||||
mkdir -p /etc/lightdm/lightdm.conf.d
|
||||
|
||||
write_if_changed /etc/lightdm/lightdm.conf.d/90-iomatex-autologin.conf 0644 root root <<'EOF'
|
||||
[Seat:*]
|
||||
autologin-user=iomatex
|
||||
autologin-user-timeout=0
|
||||
EOF
|
||||
if [ "$WRITE_CHANGED" -eq 1 ]; then
|
||||
GUI_MIGRATION_CHANGED=1
|
||||
fi
|
||||
|
||||
for lightdm_cfg in /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.d/*.conf; do
|
||||
[ -f "$lightdm_cfg" ] || continue
|
||||
if grep -qE '^[[:space:]]*autologin-user[[:space:]]*=[[:space:]]*youngfeel[[:space:]]*$' "$lightdm_cfg"; then
|
||||
sed -i -E 's/^[[:space:]]*autologin-user[[:space:]]*=.*/autologin-user=iomatex/' "$lightdm_cfg"
|
||||
GUI_MIGRATION_CHANGED=1
|
||||
log "Updated LightDM autologin user in ${lightdm_cfg}: youngfeel -> iomatex"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ensure_gui_home_state "$IOM_USER"
|
||||
configure_lightdm_autologin
|
||||
|
||||
if id youngfeel >/dev/null 2>&1; then
|
||||
log "Harden vendor user: youngfeel (lock password, disable shell, remove sudo)"
|
||||
soft_run "Lock password youngfeel" 10 /usr/bin/passwd -l youngfeel
|
||||
|
|
@ -873,7 +940,7 @@ soft_run "Run userdata bootstrap now (best-effort)" 30 /bin/systemctl start ioma
|
|||
# Finish summary
|
||||
# -------------------------
|
||||
step "Finish (health summary)"
|
||||
log "=== IOMATEX STAGE0_1 v3.2 COMPLETE ==="
|
||||
log "=== IOMATEX EDGE :: STAGE_ENV COMPLETE ==="
|
||||
log "Hostname preserved: $(hostname)"
|
||||
log "User: iomatex (password MUST be changed on first login)"
|
||||
log "Cockpit: https://${IP_MAIN}:9090"
|
||||
|
|
@ -883,10 +950,10 @@ REG_NOW="$(iw reg get 2>/dev/null | awk '/^country /{print $2; exit}' | sed 's/:
|
|||
|
||||
echo
|
||||
echo "======================================================"
|
||||
echo " IOMATEX EDGE :: STAGE0_1 COMPLETE"
|
||||
echo " IOMATEX EDGE :: STAGE_ENV COMPLETE"
|
||||
echo "======================================================"
|
||||
echo
|
||||
echo " Hostname : $(hostname) (preserved; not set by stage_env)"
|
||||
echo " Hostname : $(hostname)"
|
||||
echo
|
||||
echo " Users:"
|
||||
echo " - iomatex (admin, sudo) -> password MUST be changed on first login"
|
||||
|
|
@ -898,10 +965,6 @@ echo " - youngfeel (hardened/disabled if existed)"
|
|||
echo
|
||||
echo " Password policy : minlen=8 (NO dictionary), pam_unix obscure OFF"
|
||||
echo
|
||||
if [ "$GUI_MIGRATION_CHANGED" -eq 1 ]; then
|
||||
echo " GUI session : LightDM autologin switched to iomatex (reboot or lightdm restart required)"
|
||||
echo
|
||||
fi
|
||||
echo " Userdata usage (cold-boot safe):"
|
||||
echo " - swap on /userdata via systemd oneshot (no fstab)"
|
||||
echo " - generic userdata log root at /userdata/logs/iomatex"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ ITS_GROUP="itscreen"
|
|||
ITS_BINARY="/opt/itscreen/bin/itscreen"
|
||||
ITS_WRAPPER="/usr/local/bin/itscreen-run"
|
||||
ITS_SESSION_SCRIPT="/usr/local/bin/itscreen-session"
|
||||
ITS_SESSION_LAUNCH="/usr/local/bin/itscreen-session-launch"
|
||||
ITS_X11_LAUNCHER="/usr/local/bin/itscreen-x11-launch"
|
||||
ITS_X11_CLEANUP="/usr/local/bin/itscreen-x11-cleanup"
|
||||
ITS_SERVICE="itscreen-x11.service"
|
||||
|
|
@ -24,10 +25,13 @@ ITS_UNIT_FILE="/etc/systemd/system/${ITS_SERVICE}"
|
|||
ITS_RUN_DIR="/run/itscreen"
|
||||
LOCK_DIR="/var/lib/itscreen"
|
||||
LOCK_FILE="${LOCK_DIR}/itscreen.lock"
|
||||
ITS_CONFIG_DIR="/var/lib/itscreen/config/it-screen"
|
||||
ITS_CONFIG_FILE="${ITS_CONFIG_DIR}/it-screen.conf"
|
||||
DEVICE_ID_FILE="/userdata/device-id"
|
||||
DEVICE_ID_RE='^g-box-[a-f0-9]{8}$'
|
||||
|
||||
step_n=0
|
||||
TOTAL_STEPS=13
|
||||
|
||||
log() {
|
||||
local line="[$(date -u +'%F %T UTC')] $*"
|
||||
|
|
@ -45,10 +49,16 @@ die() {
|
|||
}
|
||||
|
||||
step() {
|
||||
local filled empty bar percent
|
||||
step_n=$((step_n + 1))
|
||||
percent=$(( step_n * 100 / TOTAL_STEPS ))
|
||||
filled=$(( step_n * 20 / TOTAL_STEPS ))
|
||||
empty=$(( 20 - filled ))
|
||||
bar="$(printf '%*s' "$filled" '' | tr ' ' '#')$(printf '%*s' "$empty" '' | tr ' ' '-')"
|
||||
echo
|
||||
echo "[${bar}] ${step_n}/${TOTAL_STEPS} (${percent}%)"
|
||||
echo "=== Step ${step_n}: $* ==="
|
||||
log "STEP ${step_n}: $*"
|
||||
log "STEP ${step_n}/${TOTAL_STEPS} (${percent}%): $*"
|
||||
}
|
||||
|
||||
require_root() {
|
||||
|
|
@ -314,6 +324,7 @@ ensure_runtime_directories() {
|
|||
ensure_dir /opt/itscreen/logs 0755 "$ITS_USER" "$ITS_GROUP"
|
||||
ensure_dir /var/lib/itscreen 0755 "$ITS_USER" "$ITS_GROUP"
|
||||
ensure_dir /var/lib/itscreen/config 0770 "$ITS_USER" "$ITS_GROUP"
|
||||
ensure_dir "$ITS_CONFIG_DIR" 0770 "$ITS_USER" "$ITS_GROUP"
|
||||
ensure_dir /var/lib/itscreen/data 0770 "$ITS_USER" "$ITS_GROUP"
|
||||
ensure_dir /var/lib/itscreen/logs 0770 "$ITS_USER" "$ITS_GROUP"
|
||||
ensure_dir /var/log/itscreen 0755 "$ITS_USER" "$ITS_GROUP"
|
||||
|
|
@ -325,10 +336,21 @@ ensure_runtime_directories() {
|
|||
ensure_dir "$ITS_RUN_DIR" 0755 root root
|
||||
}
|
||||
|
||||
install_itscreen_config() {
|
||||
step "Force fullscreen in it-screen config"
|
||||
write_file "$ITS_CONFIG_FILE" 0660 "$ITS_USER" "$ITS_GROUP" <<'EOF'
|
||||
[WidgetPosition]
|
||||
fullscreen=1
|
||||
minimizeButtonHint=0
|
||||
minimizeFrame=0
|
||||
EOF
|
||||
}
|
||||
|
||||
install_qt_packages() {
|
||||
step "Install Qt runtime (exact list)"
|
||||
install_packages_best_effort "Install Qt runtime" 1800 \
|
||||
libgl1 libegl1 libgbm1 libdrm2 libinput10 \
|
||||
libqt5gui5-gles libqt5quick5-gles \
|
||||
libx11-6 libxcb1 libxkbcommon0 libxkbcommon-x11-0 \
|
||||
libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0 \
|
||||
libxcb-xinerama0 libxcb-xkb1 libxcb-randr0 libxcb-shape0 libxcb-shm0 \
|
||||
|
|
@ -339,16 +361,14 @@ install_qt_packages() {
|
|||
libqt5serialbus5
|
||||
|
||||
install_packages_best_effort "Install Qt extras" 1800 \
|
||||
gedit lxterminal clang qtcreator openbox \
|
||||
gedit lxterminal clang qtcreator openbox wmctrl xdotool \
|
||||
libqt5serialbus5-bin \
|
||||
qtpositioning5-dev qml-module-qtpositioning \
|
||||
libqt5texttospeech5-dev \
|
||||
qml-module-qtpositioning \
|
||||
qml-module-qtquick-virtualkeyboard qtvirtualkeyboard-plugin \
|
||||
libqt5webview5-dev qml-module-qtwebview \
|
||||
qml-module-qtwebview \
|
||||
qml-module-qt-labs-settings qml-module-qtquick-xmllistmodel \
|
||||
libqt5serialbus5-dev \
|
||||
qml-module-qtquick-controls2 \
|
||||
qml-module-qt-websockets libqt5websockets5-dev \
|
||||
qml-module-qt-websockets \
|
||||
qml-module-qt-labs-platform
|
||||
|
||||
ldconfig
|
||||
|
|
@ -413,6 +433,135 @@ EOF
|
|||
install_x11_session_scripts() {
|
||||
step "Install dedicated X11 session helpers"
|
||||
|
||||
write_file "$ITS_SESSION_LAUNCH" 0755 root root <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ITS_LOG_DIR="${ITSCREEN_LOG_DIR:-/var/lib/itscreen/logs}"
|
||||
DISPLAY_VALUE="${DISPLAY:-:0}"
|
||||
XAUTHORITY_VALUE="${XAUTHORITY:-/run/itscreen/Xauthority}"
|
||||
OPENBOX_LOG="${ITS_LOG_DIR}/openbox.log"
|
||||
APP_LOG="${ITS_LOG_DIR}/itscreen.log"
|
||||
LAUNCH_LOG="${ITS_LOG_DIR}/session-launch.log"
|
||||
APP_PID=""
|
||||
|
||||
mkdir -p "$ITS_LOG_DIR"
|
||||
touch "$OPENBOX_LOG" "$APP_LOG" "$LAUNCH_LOG"
|
||||
|
||||
log() {
|
||||
local line="[$(date -u +'%F %T UTC')] $*"
|
||||
echo "$line"
|
||||
echo "$line" >>"$LAUNCH_LOG" 2>/dev/null || true
|
||||
}
|
||||
|
||||
have() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
wait_for_x_ready() {
|
||||
local attempt
|
||||
for attempt in $(seq 1 20); do
|
||||
if have xset && DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" xset q >/dev/null 2>&1; then
|
||||
log "X11 display is ready on ${DISPLAY_VALUE}"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
log "WARN: X11 readiness probe timed out on ${DISPLAY_VALUE}; continuing"
|
||||
return 0
|
||||
}
|
||||
|
||||
ensure_openbox() {
|
||||
if ! have openbox; then
|
||||
log "ERROR: openbox is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if pgrep -u itscreen -x openbox >/dev/null 2>&1; then
|
||||
log "openbox already running"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "Starting openbox window manager"
|
||||
DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" openbox >>"$OPENBOX_LOG" 2>&1 &
|
||||
sleep 1
|
||||
if pgrep -u itscreen -x openbox >/dev/null 2>&1; then
|
||||
log "openbox started successfully"
|
||||
else
|
||||
log "WARN: openbox start could not be confirmed"
|
||||
fi
|
||||
}
|
||||
|
||||
find_window_id_for_pid() {
|
||||
local pid="$1"
|
||||
local win_id=""
|
||||
|
||||
if have wmctrl; then
|
||||
win_id="$(DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" wmctrl -lp 2>/dev/null | awk -v pid="$pid" '$3 == pid { print $1; exit }' || true)"
|
||||
if [[ -n "$win_id" ]]; then
|
||||
printf '%s\n' "$win_id"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if have xdotool; then
|
||||
win_id="$(DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" xdotool search --onlyvisible --pid "$pid" 2>/dev/null | head -n 1 || true)"
|
||||
if [[ -n "$win_id" ]]; then
|
||||
printf '%s\n' "$win_id"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
apply_fullscreen() {
|
||||
local pid="$1"
|
||||
local attempt
|
||||
local win_id=""
|
||||
|
||||
for attempt in $(seq 1 15); do
|
||||
if ! kill -0 "$pid" >/dev/null 2>&1; then
|
||||
log "WARN: itscreen exited before fullscreen could be applied"
|
||||
return 1
|
||||
fi
|
||||
|
||||
win_id="$(find_window_id_for_pid "$pid" || true)"
|
||||
if [[ -n "$win_id" ]]; then
|
||||
log "Found it-screen window ${win_id} on attempt ${attempt}"
|
||||
if have wmctrl && DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" wmctrl -i -r "$win_id" -b add,fullscreen >/dev/null 2>&1; then
|
||||
DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" wmctrl -i -a "$win_id" >/dev/null 2>&1 || true
|
||||
log "Fullscreen applied via wmctrl"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "WARN: wmctrl fullscreen failed for window ${win_id}"
|
||||
if have xdotool && DISPLAY="$DISPLAY_VALUE" XAUTHORITY="$XAUTHORITY_VALUE" xdotool windowactivate --sync "$win_id" key F11 >/dev/null 2>&1; then
|
||||
log "Fullscreen applied via xdotool fallback"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "WARN: xdotool fullscreen fallback failed for window ${win_id}"
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
log "WARN: failed to find or fullscreen it-screen window after retries"
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_x_ready
|
||||
ensure_openbox
|
||||
|
||||
log "Launching it-screen"
|
||||
/usr/local/bin/itscreen-run "$@" >>"$APP_LOG" 2>&1 &
|
||||
APP_PID=$!
|
||||
log "it-screen started with pid ${APP_PID}"
|
||||
|
||||
apply_fullscreen "$APP_PID" || true
|
||||
wait "$APP_PID"
|
||||
EOF
|
||||
|
||||
write_file "$ITS_SESSION_SCRIPT" 0755 root root <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
|
@ -426,12 +575,6 @@ export XDG_DATA_HOME=/var/lib/itscreen/data
|
|||
export XDG_RUNTIME_DIR=/run/itscreen/xdg
|
||||
export ITSCREEN_LOG_DIR=/var/lib/itscreen/logs
|
||||
|
||||
session_cmd='openbox & exec /usr/local/bin/itscreen-run'
|
||||
if ! command -v openbox >/dev/null 2>&1; then
|
||||
echo "openbox is required for dedicated X11 fullscreen mode" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec /usr/bin/setpriv --reuid itscreen --regid itscreen --init-groups \
|
||||
/usr/bin/env \
|
||||
HOME="$HOME" \
|
||||
|
|
@ -444,7 +587,7 @@ exec /usr/bin/setpriv --reuid itscreen --regid itscreen --init-groups \
|
|||
XDG_CONFIG_HOME="$XDG_CONFIG_HOME" \
|
||||
XDG_DATA_HOME="$XDG_DATA_HOME" \
|
||||
ITSCREEN_LOG_DIR="$ITSCREEN_LOG_DIR" \
|
||||
/usr/bin/dbus-run-session -- /bin/sh -lc "$session_cmd"
|
||||
/usr/bin/dbus-run-session -- /usr/local/bin/itscreen-session-launch
|
||||
EOF
|
||||
|
||||
write_file "$ITS_X11_CLEANUP" 0755 root root <<'EOF'
|
||||
|
|
@ -452,7 +595,9 @@ EOF
|
|||
set -euo pipefail
|
||||
|
||||
/usr/bin/pkill -u itscreen -x itscreen >/dev/null 2>&1 || true
|
||||
/usr/bin/pkill -u itscreen -f '/usr/local/bin/itscreen-session-launch' >/dev/null 2>&1 || true
|
||||
/usr/bin/pkill -u itscreen -f '/usr/local/bin/itscreen-run' >/dev/null 2>&1 || true
|
||||
/usr/bin/pkill -u itscreen -x openbox >/dev/null 2>&1 || true
|
||||
/usr/bin/pkill -f '(^|/)(Xorg|X)([[:space:]].*)?[[:space:]]:0([[:space:]]|$)' >/dev/null 2>&1 || true
|
||||
/usr/bin/pkill -f '/usr/bin/xinit /usr/local/bin/itscreen-session' >/dev/null 2>&1 || true
|
||||
/usr/bin/fuser -k /tmp/.X11-unix/X0 >/dev/null 2>&1 || true
|
||||
|
|
@ -565,6 +710,7 @@ print_summary() {
|
|||
echo " ${SUDOERS_FILE}"
|
||||
echo " ${ITS_WRAPPER}"
|
||||
echo " ${ITS_SESSION_SCRIPT}"
|
||||
echo " ${ITS_SESSION_LAUNCH}"
|
||||
echo " ${ITS_X11_LAUNCHER}"
|
||||
echo " ${ITS_X11_CLEANUP}"
|
||||
echo " ${ITS_UNIT_FILE}"
|
||||
|
|
@ -600,6 +746,7 @@ main() {
|
|||
cleanup_legacy_lightdm_boot_path
|
||||
cleanup_legacy_x11_hacks
|
||||
install_itscreen_binary
|
||||
install_itscreen_config
|
||||
install_sudoers
|
||||
install_wrapper
|
||||
install_x11_session_scripts
|
||||
|
|
|
|||
|
|
@ -44,11 +44,18 @@ remove_if_exists() {
|
|||
}
|
||||
|
||||
step_n=0
|
||||
TOTAL_STEPS=13
|
||||
step() {
|
||||
local filled empty bar percent
|
||||
step_n=$((step_n+1))
|
||||
percent=$(( step_n * 100 / TOTAL_STEPS ))
|
||||
filled=$(( step_n * 20 / TOTAL_STEPS ))
|
||||
empty=$(( 20 - filled ))
|
||||
bar="$(printf '%*s' "$filled" '' | tr ' ' '#')$(printf '%*s' "$empty" '' | tr ' ' '-')"
|
||||
echo
|
||||
echo "[${bar}] ${step_n}/${TOTAL_STEPS} (${percent}%)"
|
||||
echo "=== Step ${step_n}: $* ==="
|
||||
log "STEP ${step_n}: $*"
|
||||
log "STEP ${step_n}/${TOTAL_STEPS} (${percent}%): $*"
|
||||
}
|
||||
|
||||
spinner() {
|
||||
|
|
|
|||
|
|
@ -2133,6 +2133,9 @@ class Handler(BaseHTTPRequestHandler):
|
|||
if parsed.path == "/console.css":
|
||||
self.send_file(os.path.join(PUBLIC_DIR, "console.css"), "text/css; charset=utf-8")
|
||||
return
|
||||
if parsed.path == "/console.i18n.js":
|
||||
self.send_file(os.path.join(PUBLIC_DIR, "console.i18n.js"), "application/javascript; charset=utf-8")
|
||||
return
|
||||
if parsed.path == "/console.js":
|
||||
self.send_file(os.path.join(PUBLIC_DIR, "console.js"), "application/javascript; charset=utf-8")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -61,6 +61,20 @@ body{
|
|||
linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
|
||||
color:var(--ink);
|
||||
}
|
||||
html[dir="rtl"] body{direction:rtl}
|
||||
html[dir="rtl"] .panel,
|
||||
html[dir="rtl"] .cardTop,
|
||||
html[dir="rtl"] .meta,
|
||||
html[dir="rtl"] .compactMeta,
|
||||
html[dir="rtl"] .splitMeta,
|
||||
html[dir="rtl"] .identityPanel,
|
||||
html[dir="rtl"] .identityItem,
|
||||
html[dir="rtl"] .list,
|
||||
html[dir="rtl"] .empty,
|
||||
html[dir="rtl"] .emptyInline,
|
||||
html[dir="rtl"] .banner{
|
||||
text-align:right;
|
||||
}
|
||||
.shell{max-width:1180px;margin:0 auto;padding:28px 18px 40px}
|
||||
.hero{
|
||||
display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:16px;align-items:center;
|
||||
|
|
@ -202,6 +216,31 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e
|
|||
.menuActionLabel{
|
||||
flex:1 1 auto;
|
||||
}
|
||||
.menuSelectGroup{
|
||||
display:grid;
|
||||
gap:6px;
|
||||
padding:8px 4px 2px;
|
||||
}
|
||||
.menuSelectLabel{
|
||||
color:var(--muted);
|
||||
font-size:12px;
|
||||
font-weight:700;
|
||||
letter-spacing:.06em;
|
||||
text-transform:uppercase;
|
||||
}
|
||||
.menuSelect{
|
||||
width:100%;
|
||||
border:1px solid var(--line);
|
||||
border-radius:12px;
|
||||
background:var(--surface-soft);
|
||||
color:var(--ink);
|
||||
padding:10px 12px;
|
||||
font:inherit;
|
||||
}
|
||||
.menuSelect:focus-visible{
|
||||
outline:none;
|
||||
box-shadow:0 0 0 3px rgba(14,122,83,.18);
|
||||
}
|
||||
.menuBackdrop{
|
||||
position:fixed;
|
||||
inset:0;
|
||||
|
|
@ -346,10 +385,13 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e
|
|||
.reverseTunnelCard{gap:0}
|
||||
.tunnelSummaryGrid{
|
||||
display:grid;
|
||||
grid-template-columns:repeat(4,minmax(0,1fr));
|
||||
grid-template-columns:repeat(3,minmax(0,1fr));
|
||||
gap:10px;
|
||||
margin-top:16px;
|
||||
}
|
||||
.tunnelSummaryWide{
|
||||
margin-top:10px;
|
||||
}
|
||||
.tunnelSummaryItem{
|
||||
border:1px solid var(--line);
|
||||
border-radius:12px;
|
||||
|
|
@ -358,6 +400,9 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e
|
|||
display:grid;
|
||||
gap:4px;
|
||||
}
|
||||
.tunnelSummaryItemWide{
|
||||
width:100%;
|
||||
}
|
||||
.tunnelSummaryLabel{
|
||||
font-size:11px;
|
||||
text-transform:uppercase;
|
||||
|
|
@ -457,6 +502,31 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e
|
|||
font-size:13px;
|
||||
padding-top:10px;
|
||||
}
|
||||
.reverseTunnelCommand{
|
||||
margin-top:10px;
|
||||
}
|
||||
html[dir="rtl"] .menuToggleBtn{left:18px;right:auto}
|
||||
html[dir="rtl"] .actionMenu{left:18px;right:auto}
|
||||
html[dir="rtl"] .menuActionBtn,
|
||||
html[dir="rtl"] .tunnelAccordionToggle,
|
||||
html[dir="rtl"] .scanRow,
|
||||
html[dir="rtl"] .scanHeader,
|
||||
html[dir="rtl"] .networkInterfaceHead,
|
||||
html[dir="rtl"] .audioDeviceHead,
|
||||
html[dir="rtl"] .connectorHead,
|
||||
html[dir="rtl"] .displayHero,
|
||||
html[dir="rtl"] .apHero,
|
||||
html[dir="rtl"] .specTable,
|
||||
html[dir="rtl"] .field,
|
||||
html[dir="rtl"] .itscreenLogsToolbar{
|
||||
text-align:right;
|
||||
}
|
||||
html[dir="rtl"] .passwordField,
|
||||
html[dir="rtl"] .actionRow,
|
||||
html[dir="rtl"] .audioActionRow,
|
||||
html[dir="rtl"] .itscreenLogsActions{
|
||||
flex-direction:row-reverse;
|
||||
}
|
||||
@keyframes tunnelAccordionIn{
|
||||
from{opacity:0;transform:translateY(-4px)}
|
||||
to{opacity:1;transform:translateY(0)}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -12,6 +12,14 @@
|
|||
if (theme === "dark" || theme === "light") {
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
}
|
||||
var language = localStorage.getItem("consoleLanguage");
|
||||
if (language === "ar") {
|
||||
document.documentElement.setAttribute("dir", "rtl");
|
||||
document.documentElement.setAttribute("lang", "ar");
|
||||
} else if (language === "ru" || language === "pl" || language === "hi" || language === "en") {
|
||||
document.documentElement.setAttribute("dir", "ltr");
|
||||
document.documentElement.setAttribute("lang", language);
|
||||
}
|
||||
} catch (error) {}
|
||||
})();
|
||||
</script>
|
||||
|
|
@ -23,23 +31,23 @@
|
|||
<div class="brand">
|
||||
<img class="brandDevice" src="/g-box.png" alt="IOMATEX G-Box" onerror="this.onerror=null;this.src='/logo.png';">
|
||||
<div class="brandCopy">
|
||||
<div class="eyebrow">IOMATEX G-Box</div>
|
||||
<h1>Edge Automation Gateway</h1>
|
||||
<div class="capabilityBadge">Digital DNA ready</div>
|
||||
<div class="eyebrow" id="brandEyebrow">IOMATEX G-Box</div>
|
||||
<h1 id="heroTitle">Edge Automation Gateway</h1>
|
||||
<div class="capabilityBadge" id="capabilityBadge">Digital DNA ready</div>
|
||||
<p class="sub brandSupport" id="osLabel">Unified diagnostics, network operations and gateway commissioning.</p>
|
||||
</div>
|
||||
</div>
|
||||
<section class="panel identityPanel">
|
||||
<div class="identityItem">
|
||||
<span class="label">Edge Serial Number</span>
|
||||
<span class="label" id="edgeSerialLabel">Edge Serial Number</span>
|
||||
<strong id="edgeId">-</strong>
|
||||
</div>
|
||||
<div class="identityItem">
|
||||
<span class="label">Host / IP</span>
|
||||
<span class="label" id="hostIpLabel">Host / IP</span>
|
||||
<strong id="hostName">-</strong>
|
||||
</div>
|
||||
<div class="identityItem identityItemWide">
|
||||
<span class="label">Updated</span>
|
||||
<span class="label" id="updatedLabel">Updated</span>
|
||||
<strong id="updatedAt">-</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -48,33 +56,44 @@
|
|||
<span></span><span></span><span></span>
|
||||
</button>
|
||||
<div id="actionMenu" class="actionMenu" hidden>
|
||||
<label class="menuSelectGroup" for="languageSelect">
|
||||
<span class="menuSelectLabel" id="languageMenuLabel">Language</span>
|
||||
<select id="languageSelect" class="menuSelect">
|
||||
<option value="en">English</option>
|
||||
<option value="ru">Русский</option>
|
||||
<option value="pl">Polski</option>
|
||||
<option value="ar">العربية</option>
|
||||
<option value="hi">हिन्दी</option>
|
||||
</select>
|
||||
</label>
|
||||
<button id="themeToggleBtn" class="menuActionBtn" type="button" aria-label="Switch theme" title="Switch theme">
|
||||
<span class="menuActionIcon" id="themeToggleIcon" aria-hidden="true"></span>
|
||||
<span class="menuActionLabel">Theme</span>
|
||||
<span class="menuActionLabel" id="themeMenuLabel">Theme</span>
|
||||
</button>
|
||||
<button id="refreshBtn" class="menuActionBtn" type="button">
|
||||
<span class="menuActionIcon" aria-hidden="true">↻</span>
|
||||
<span class="menuActionLabel">Refresh</span>
|
||||
<span class="menuActionLabel" id="refreshMenuLabel">Refresh</span>
|
||||
</button>
|
||||
<button id="rebootBtn" class="menuActionBtn is-danger" type="button">
|
||||
<span class="menuActionIcon" aria-hidden="true">⏻</span>
|
||||
<span class="menuActionLabel">Reboot</span>
|
||||
<span class="menuActionLabel" id="rebootMenuLabel">Reboot</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav class="tabs" aria-label="Primary navigation">
|
||||
<button class="tabBtn is-active" type="button" data-tab="health">Health</button>
|
||||
<button class="tabBtn" type="button" data-tab="network">Network</button>
|
||||
<button class="tabBtn" type="button" data-tab="tscreen">It-Screen</button>
|
||||
<button class="tabBtn" type="button" data-tab="gbox">G-Box Instructions and Manual</button>
|
||||
<button class="tabBtn is-active" type="button" data-tab="health" id="tabHealth">Health</button>
|
||||
<button class="tabBtn" type="button" data-tab="network" id="tabNetwork">Network</button>
|
||||
<button class="tabBtn" type="button" data-tab="tscreen" id="tabTscreen">It-Screen</button>
|
||||
<button class="tabBtn" type="button" data-tab="gbox" id="tabGbox">G-Box Instructions and Manual</button>
|
||||
</nav>
|
||||
|
||||
<section id="tabContent" class="tabContent" aria-live="polite"></section>
|
||||
</main>
|
||||
<div id="menuBackdrop" class="menuBackdrop" hidden></div>
|
||||
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
|
||||
<script src="/console.i18n.js"></script>
|
||||
<script src="/console.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import glob
|
|||
import math
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
|
||||
|
||||
DRM_ROOT = "/sys/class/drm"
|
||||
|
|
@ -695,6 +696,80 @@ def _reverse_tunnel_item_state(installed, configured, unit):
|
|||
return "inactive", "Inactive", active
|
||||
|
||||
|
||||
def _reverse_tunnel_bootstrap_command(ctx):
|
||||
hostname = _read_trimmed(ctx, "/etc/hostname").split(".", 1)[0]
|
||||
if not hostname:
|
||||
return ""
|
||||
|
||||
public_key_line = ""
|
||||
for path in _reverse_tunnel_key_paths(ctx):
|
||||
if not path.endswith(".pub"):
|
||||
continue
|
||||
candidate = (ctx["read_text"](path) or "").strip()
|
||||
if candidate:
|
||||
public_key_line = candidate
|
||||
break
|
||||
if not public_key_line:
|
||||
return ""
|
||||
|
||||
wrappers = {}
|
||||
for name in ("cockpit", "z2m", "webui"):
|
||||
raw = ctx["read_text"](f"/usr/local/sbin/iomatex-rt-{name}.sh") or ""
|
||||
if raw:
|
||||
wrappers[name] = raw
|
||||
if len(wrappers) < 3:
|
||||
return ""
|
||||
|
||||
def parse_wrapper(raw):
|
||||
port_match = re.search(r"-R\s+127\.0\.0\.1:(\d+):127\.0\.0\.1:(\d+)", raw)
|
||||
target_match = re.search(r'"([^"@\s]+)@([^"\s]+)"', raw)
|
||||
ssh_port_match = re.search(r"-p\s+\"?(\d+)\"?", raw)
|
||||
if not port_match or not target_match:
|
||||
return None
|
||||
return {
|
||||
"remote_port": port_match.group(1),
|
||||
"local_port": port_match.group(2),
|
||||
"vps_user": target_match.group(1),
|
||||
"vps_host": target_match.group(2),
|
||||
"vps_port": ssh_port_match.group(1) if ssh_port_match else "22",
|
||||
}
|
||||
|
||||
parsed = {name: parse_wrapper(raw) for name, raw in wrappers.items()}
|
||||
if any(item is None for item in parsed.values()):
|
||||
return ""
|
||||
|
||||
cockpit = parsed["cockpit"]
|
||||
z2m = parsed["z2m"]
|
||||
webui = parsed["webui"]
|
||||
vps_user = cockpit["vps_user"]
|
||||
edge_ip = ""
|
||||
|
||||
rc, stdout, _ = ctx["run"](["/usr/bin/curl", "-fsS", "--max-time", "5", "https://api.ipify.org"], timeout=8)
|
||||
if rc == 0:
|
||||
edge_ip = (stdout or "").strip()
|
||||
|
||||
return (
|
||||
f"EDGE_HOSTNAME={shlex.quote(hostname)}; "
|
||||
f"EDGE_IP={shlex.quote(edge_ip)}; "
|
||||
f"EDGE_PUBKEY_LINE={shlex.quote(public_key_line)}; "
|
||||
f"COCKPIT_REMOTE_PORT={shlex.quote(cockpit['remote_port'])}; "
|
||||
f"Z2M_REMOTE_PORT={shlex.quote(z2m['remote_port'])}; "
|
||||
f"WEBUI_REMOTE_PORT={shlex.quote(webui['remote_port'])}; "
|
||||
f"VPS_USER={shlex.quote(vps_user)}; "
|
||||
f"sudo useradd -m -s /usr/sbin/nologin \"$VPS_USER\" 2>/dev/null || true; "
|
||||
f"sudo install -d -m 700 -o \"$VPS_USER\" -g \"$VPS_USER\" \"/home/$VPS_USER/.ssh\"; "
|
||||
f"printf 'no-pty,no-agent-forwarding,no-X11-forwarding,permitopen=\"127.0.0.1:9090\",permitopen=\"127.0.0.1:8081\",permitopen=\"127.0.0.1:80\",permitlisten=\"127.0.0.1:%s\",permitlisten=\"127.0.0.1:%s\",permitlisten=\"127.0.0.1:%s\" %s\\n' "
|
||||
f"\"$COCKPIT_REMOTE_PORT\" \"$Z2M_REMOTE_PORT\" \"$WEBUI_REMOTE_PORT\" \"$EDGE_PUBKEY_LINE\" | sudo tee \"/home/$VPS_USER/.ssh/authorized_keys\" >/dev/null; "
|
||||
f"sudo chown -R \"$VPS_USER:$VPS_USER\" \"/home/$VPS_USER/.ssh\"; "
|
||||
f"sudo chmod 600 \"/home/$VPS_USER/.ssh/authorized_keys\"; "
|
||||
f"sudo fail2ban-client set sshd unbanip \"$EDGE_IP\" 2>/dev/null || true; "
|
||||
f"(sudo grep -q '^ignoreip' /etc/fail2ban/jail.local && sudo sed -i \"s/^ignoreip.*/& $EDGE_IP/\" /etc/fail2ban/jail.local) || "
|
||||
f"echo -e \"[DEFAULT]\\nignoreip = 127.0.0.1/8 $EDGE_IP\" | sudo tee /etc/fail2ban/jail.local >/dev/null; "
|
||||
f"sudo systemctl restart fail2ban; "
|
||||
f"echo \"OK: $VPS_USER ready\""
|
||||
)
|
||||
|
||||
|
||||
def reverse_tunnel_card(ctx):
|
||||
service_states = []
|
||||
installed_checks = []
|
||||
|
|
@ -789,6 +864,7 @@ def reverse_tunnel_card(ctx):
|
|||
warnings[:3],
|
||||
details=details,
|
||||
tunnels=service_states,
|
||||
bootstrap_command=_reverse_tunnel_bootstrap_command(ctx),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -115,11 +115,28 @@ remove_if_exists() {
|
|||
return 0
|
||||
}
|
||||
|
||||
echo "[0/8] Validate source tree"
|
||||
step_n=0
|
||||
TOTAL_STEPS=10
|
||||
|
||||
step() {
|
||||
local label="$1"
|
||||
local filled empty bar percent
|
||||
step_n=$((step_n + 1))
|
||||
percent=$(( step_n * 100 / TOTAL_STEPS ))
|
||||
filled=$(( step_n * 20 / TOTAL_STEPS ))
|
||||
empty=$(( 20 - filled ))
|
||||
bar="$(printf '%*s' "$filled" '' | tr ' ' '#')$(printf '%*s' "$empty" '' | tr ' ' '-')"
|
||||
echo
|
||||
echo "[${bar}] ${step_n}/${TOTAL_STEPS} (${percent}%)"
|
||||
echo "=== Step ${step_n}: ${label} ==="
|
||||
}
|
||||
|
||||
step "Validate source tree"
|
||||
for path in \
|
||||
"$SRC_ROOT/backend/app.py" \
|
||||
"$SRC_ROOT/backend/itscreen_registration.py" \
|
||||
"$SRC_ROOT/frontend/index.html" \
|
||||
"$SRC_ROOT/frontend/console.i18n.js" \
|
||||
"$SRC_ROOT/frontend/console.js" \
|
||||
"$SRC_ROOT/frontend/console.css" \
|
||||
"$SRC_ROOT/providers/00_core_services.py"; do
|
||||
|
|
@ -129,17 +146,17 @@ for path in \
|
|||
}
|
||||
done
|
||||
|
||||
echo "[1/8] Ensure runtime packages exist"
|
||||
step "Ensure runtime packages exist"
|
||||
apt-get update
|
||||
apt-get install -y python3 python3-pil python3-paho-mqtt network-manager iw
|
||||
python3 --version
|
||||
echo "[1/8] Skip setcap: service runs as root and can bind port 80 without extra capabilities"
|
||||
echo "Skip setcap: service runs as root and can bind port 80 without extra capabilities"
|
||||
|
||||
echo "[2/8] Stop previous service"
|
||||
step "Stop previous service"
|
||||
stop_disable_reset_unit "${SERVICE_NAME}"
|
||||
stop_disable_reset_unit "${LEGACY_SERVICE_NAME}"
|
||||
|
||||
echo "[3/8] Prepare directories and preserve previous install"
|
||||
step "Prepare directories and preserve previous install"
|
||||
mkdir -p /etc/iomatex
|
||||
if [ -d "$LEGACY_APP_DIR" ]; then
|
||||
rm -rf "$LEGACY_PREV_DIR"
|
||||
|
|
@ -156,10 +173,11 @@ cat > "$CFG_PATH" <<JSON
|
|||
}
|
||||
JSON
|
||||
|
||||
echo "[4/8] Install console core files"
|
||||
step "Install console core files"
|
||||
copy_tree "$SRC_ROOT/backend" "$STAGE_BACKEND_DIR"
|
||||
copy_tree "$SRC_ROOT/frontend" "$STAGE_FRONTEND_DIR"
|
||||
install -m 0644 "$SRC_ROOT/frontend/index.html" "$STAGE_PUBLIC_DIR/index.html"
|
||||
install -m 0644 "$SRC_ROOT/frontend/console.i18n.js" "$STAGE_PUBLIC_DIR/console.i18n.js"
|
||||
install -m 0644 "$SRC_ROOT/frontend/console.js" "$STAGE_PUBLIC_DIR/console.js"
|
||||
install -m 0644 "$SRC_ROOT/frontend/console.css" "$STAGE_PUBLIC_DIR/console.css"
|
||||
copy_tree "$SRC_ROOT/providers" "$STAGE_PROVIDERS_DIR"
|
||||
|
|
@ -167,12 +185,13 @@ rm -rf "$STAGE_PROVIDERS_DIR/__pycache__" "$STAGE_BACKEND_DIR/__pycache__"
|
|||
require_file "$STAGE_BACKEND_DIR/app.py"
|
||||
require_file "$STAGE_BACKEND_DIR/itscreen_registration.py"
|
||||
require_file "$STAGE_FRONTEND_DIR/index.html"
|
||||
require_file "$STAGE_FRONTEND_DIR/console.i18n.js"
|
||||
require_file "$STAGE_FRONTEND_DIR/console.js"
|
||||
require_file "$STAGE_FRONTEND_DIR/console.css"
|
||||
require_file "$STAGE_PROVIDERS_DIR/00_core_services.py"
|
||||
require_file "$SRC_GBOX"
|
||||
|
||||
echo "[6/8] Generate logo and favicon"
|
||||
step "Generate logo and favicon"
|
||||
if [ ! -f "$SRC_LOGO" ]; then
|
||||
echo "ERROR: logo source image not found: $SRC_LOGO" >&2
|
||||
exit 1
|
||||
|
|
@ -195,7 +214,7 @@ fav.thumbnail((64, 64))
|
|||
fav.save(fav_out, format="PNG")
|
||||
PY
|
||||
|
||||
echo "[7/8] Install systemd service"
|
||||
step "Install systemd service"
|
||||
cat > "/etc/systemd/system/${SERVICE_NAME}" <<UNIT
|
||||
[Unit]
|
||||
Description=IOMATEX Console Core
|
||||
|
|
@ -220,7 +239,7 @@ remove_if_exists /etc/avahi/services/iomatex-console.service
|
|||
remove_if_exists /usr/local/sbin/iomatex-mdns-alias
|
||||
remove_if_exists /etc/systemd/system/iomatex-mdns-alias.service
|
||||
|
||||
echo "[9/9] Validate and restart"
|
||||
step "Validate and restart"
|
||||
python3 -m py_compile "$STAGE_BACKEND_DIR/app.py" "$STAGE_BACKEND_DIR/itscreen_registration.py" "$STAGE_PROVIDERS_DIR/00_core_services.py"
|
||||
require_file "$STAGE_PUBLIC_DIR/index.html"
|
||||
require_file "$STAGE_PUBLIC_DIR/console.js"
|
||||
|
|
@ -255,7 +274,7 @@ if ! wait_for_local_http; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
echo "[10/10] Summary"
|
||||
step "Summary"
|
||||
echo "Web UI: http://<EDGE-IP>"
|
||||
echo "Status API: curl -s http://127.0.0.1/api/status | cat"
|
||||
echo "Health API: curl -s http://127.0.0.1/api/health/summary | cat"
|
||||
|
|
|
|||
|
|
@ -54,11 +54,18 @@ log() {
|
|||
}
|
||||
|
||||
step_n=0
|
||||
TOTAL_STEPS=11
|
||||
step() {
|
||||
local filled empty bar percent
|
||||
step_n=$((step_n + 1))
|
||||
percent=$(( step_n * 100 / TOTAL_STEPS ))
|
||||
filled=$(( step_n * 20 / TOTAL_STEPS ))
|
||||
empty=$(( 20 - filled ))
|
||||
bar="$(printf '%*s' "$filled" '' | tr ' ' '#')$(printf '%*s' "$empty" '' | tr ' ' '-')"
|
||||
echo
|
||||
echo "[${bar}] ${step_n}/${TOTAL_STEPS} (${percent}%)"
|
||||
echo "=== Step ${step_n}: $* ==="
|
||||
log "STEP ${step_n}: $*"
|
||||
log "STEP ${step_n}/${TOTAL_STEPS} (${percent}%): $*"
|
||||
}
|
||||
|
||||
need_root() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue