#!/bin/sh set -eu if [ -d /run/systemd/system ]; then if [ -S /run/mission-core-sensors/driver.sock ]; then if ! /usr/bin/python3 -I -c 'import http.client,json,socket; c=http.client.HTTPConnection("driver",timeout=5); c.sock=socket.socket(socket.AF_UNIX); c.sock.settimeout(5); c.sock.connect("/run/mission-core-sensors/driver.sock"); c.request("GET","/prepare-safe"); r=c.getresponse(); assert r.status==200 and json.load(r).get("safe") is True'; then echo "Mission Core Node: остановите захват или просмотр записи перед обновлением или удалением." >&2 exit 1 fi fi if [ -S /run/mission-core-k1/driver.sock ]; then if ! /usr/bin/python3 -I -c 'import http.client,json,socket; c=http.client.HTTPConnection("k1",timeout=5); c.sock=socket.socket(socket.AF_UNIX); c.sock.settimeout(5); c.sock.connect("/run/mission-core-k1/driver.sock"); c.request("GET","/prepare-safe"); r=c.getresponse(); assert r.status==200 and json.load(r).get("safe") is True'; then echo "Mission Core Node: завершите подключение или запись K1 перед обновлением." >&2 exit 1 fi fi mc_node_usb_job=$(systemctl show --property=ActiveState --value mission-core-node-usb-startup.service 2>/dev/null || true) case "$mc_node_usb_job" in activating|deactivating) echo "Mission Core Node: дождитесь завершения обнаружения USB при загрузке." >&2; exit 1 ;; esac if [ -f /run/mission-core-usb-startup/pending.json ]; then echo "Mission Core Node: восстановление USB ещё не завершило включение порта; пакет сохранён." >&2 exit 1 fi mc_node_x4_job=$(systemctl show --property=ActiveState --value mission-core-node-insta360-x4-profile.service 2>/dev/null || true) case "$mc_node_x4_job" in active|activating) echo "Mission Core Node: дождитесь завершения подготовки X4." >&2; exit 1 ;; esac mc_node_vesc_job=$(systemctl show --property=ActiveState --value mission-core-node-vesc-prepare.service 2>/dev/null || true) case "$mc_node_vesc_job" in active|activating) echo "Mission Core Node: дождитесь завершения подготовки VESC." >&2; exit 1 ;; esac mc_node_device_job=$(systemctl show --property=ActiveState --value mission-core-node-realsense-prepare.service 2>/dev/null || true) case "$mc_node_device_job" in active|activating) echo "Mission Core Node: дождитесь завершения подготовки устройства." >&2; exit 1 ;; esac mc_node_environment_state=$(systemctl show --property=ActiveState --value mission-core-node-environment.service 2>/dev/null || true) case "$mc_node_environment_state" in active|activating) echo "Mission Core Node: дождитесь завершения настройки окружения в приложении." >&2 exit 1 ;; esac fi retire_startup_settings() { for mc_node_owned in /etc/xdg/autostart/org.nodedc.MissionCoreNode.desktop /etc/mission-core-node/usb-startup.json; do case "$mc_node_owned" in *.desktop) mc_node_template=/usr/share/mission-core-node/mission-core-node-autostart.desktop ;; *.json) mc_node_template=/usr/share/mission-core-node/usb-startup.json ;; esac if [ ! -L "$mc_node_owned" ] && cmp -s "$mc_node_template" "$mc_node_owned"; then rm "$mc_node_owned" fi done if [ -d /run/systemd/system ]; then systemctl disable --now mission-core-node-usb-startup.service fi } # A downgrade removes helpers introduced in 0.8.37. Retire their owned # configuration first; do not leave an enabled unit or XDG entry dangling. if [ "$1" = upgrade ] && [ -n "${2:-}" ] && dpkg --compare-versions "$2" lt 0.8.37-1; then retire_startup_settings fi case "$1" in upgrade|remove|deconfigure) if [ -d /run/systemd/system ] && [ -f /usr/lib/systemd/system/mission-core-vesc.service ]; then systemctl disable --now mission-core-vesc.service fi ;; esac case "$1" in remove|deconfigure) if cmp -s /usr/share/mission-core-node/profiles/vesc/70-mission-core-vesc.rules /etc/udev/rules.d/70-mission-core-vesc.rules; then rm /etc/udev/rules.d/70-mission-core-vesc.rules if [ -d /run/systemd/system ]; then udevadm control --reload-rules; fi fi retire_startup_settings mc_node_ssh_snippet=/etc/ssh/sshd_config.d/60-mission-core-node.conf if [ -e "$mc_node_ssh_snippet" ]; then if cmp -s /usr/share/mission-core-node/60-mission-core-node.conf "$mc_node_ssh_snippet"; then rm "$mc_node_ssh_snippet" else mc_node_saved_snippet=$(mktemp /etc/ssh/sshd_config.d/mission-core-node-removed.XXXXXX) mv "$mc_node_ssh_snippet" "$mc_node_saved_snippet" fi fi mc_node_environment_snippet=/etc/systemd/system/mission-core-node.service.d/60-environment.conf if [ ! -L "$mc_node_environment_snippet" ] && cmp -s /usr/share/mission-core-node/60-environment.conf "$mc_node_environment_snippet"; then rm "$mc_node_environment_snippet" fi if [ -d /run/systemd/system ]; then if [ -x /usr/sbin/sshd ]; then /usr/sbin/sshd -t systemctl try-reload-or-restart ssh.service fi systemctl stop mission-core-k1.service systemctl disable mission-core-k1.service || true systemctl stop mission-core-realsense.service systemctl disable mission-core-realsense.service || true systemctl stop mission-core-node.service systemctl disable mission-core-node.service systemctl stop mission-core-node-monitor.service systemctl disable mission-core-node-monitor.service systemctl stop postgresql@16-ndcmonitor.service systemctl disable postgresql@16-ndcmonitor.service fi ;; esac