#!/bin/sh # curl -fsSL https://lumiomac.com/install.sh | sh # Проверяем загрузку до остановки Lumio. Прежняя копия хранится до успешной замены и запуска. set -eu tmp=$(mktemp -d) # Отметку «запустилась» Lumio принимает только в своей временной папке. Открытая через open, она видит системную # (DARWIN_USER_TEMP_DIR), а не TMPDIR оболочки: со своим TMPDIR был ложный откат «did not start». user_tmp=$(getconf DARWIN_USER_TEMP_DIR 2>/dev/null || true) health=$(mktemp -d "${user_tmp:-${TMPDIR:-/tmp/}}lumio-update-health-XXXXXX") apps=/Applications # Обычная учётная запись (не администратор) в общие «Программы» писать не может — ставим в свои (~/Applications), # как и AppMover в самом приложении. Своя копия там уже есть — обновляем её, а не ставим вторую. if [ ! -e "$apps/Lumio.app" ] && { [ -e "$HOME/Applications/Lumio.app" ] || [ ! -w "$apps" ]; }; then apps="$HOME/Applications" mkdir -p "$apps" elif [ ! -w "$apps" ]; then echo "Lumio in $apps was installed by an administrator, and only an administrator can replace it." >&2 echo "Ask them to run this command, or open Lumio: it offers to move itself to your own Applications folder." >&2 rm -rf "$tmp" "$health" exit 1 fi destination="$apps/Lumio.app" staged="$apps/.lumio-new-$$.app" backup="$apps/.lumio-previous-$$.app" moved=0 installed=0 success=0 stopped=0 cleanup() { if [ "$success" -eq 0 ]; then if [ "$installed" -eq 1 ]; then pkill -x Lumio 2>/dev/null || true for attempt in 1 2 3 4 5; do pgrep -x Lumio >/dev/null || break; sleep 0.1; done rm -rf "$destination" fi if [ "$moved" -eq 1 ] && [ ! -e "$destination" ]; then mv "$backup" "$destination"; fi if [ "$stopped" -eq 1 ] && [ -e "$destination" ]; then open -g "$destination" 2>/dev/null || true; fi fi rm -rf "$tmp" "$staged" "$health" } trap cleanup EXIT trap 'exit 1' HUP INT TERM echo "Downloading Lumio…" curl --proto '=https' --tlsv1.2 -fsSL --max-filesize 65536 https://lumiomac.com/latest.json -o "$tmp/latest.json" version=$(plutil -extract version raw -o - "$tmp/latest.json") build=$(plutil -extract build raw -o - "$tmp/latest.json") bytes=$(plutil -extract bytes raw -o - "$tmp/latest.json") checksum=$(plutil -extract sha256 raw -o - "$tmp/latest.json") case "$version" in ''|*[!0-9.]*|.*|*..*|*.) echo "Invalid release version" >&2; exit 1;; esac case "$build:$bytes" in *[!0-9:]*) echo "Invalid release size or build" >&2; exit 1;; esac [ "$build" -gt 0 ] && [ "$bytes" -gt 0 ] && [ "$bytes" -le 67108864 ] [ "${#checksum}" -eq 64 ] case "$checksum" in *[!0-9a-f]*) echo "Invalid release checksum" >&2; exit 1;; esac curl --proto '=https' --tlsv1.2 -fsSL --max-filesize "$bytes" https://lumiomac.com/Lumio.zip -o "$tmp/Lumio.zip" [ "$(stat -f %z "$tmp/Lumio.zip")" -eq "$bytes" ] [ "$(shasum -a 256 "$tmp/Lumio.zip" | awk '{print $1}')" = "$checksum" ] # Даже до распаковки исключаем пути вне приложения и внешние символические ссылки. zipinfo -1 "$tmp/Lumio.zip" > "$tmp/paths" awk 'BEGIN {bad=0} /^\// || /\\/ || /(^|\/)\.\.(\/|$)/ {bad=1} !/^Lumio\.app\// && !/^__MACOSX\// {bad=1} END {exit bad || NR == 0 || NR > 20000}' "$tmp/paths" zipinfo -l "$tmp/Lumio.zip" > "$tmp/entries" awk '/^[-dl]/ {total += $4} END {exit total > 268435456}' "$tmp/entries" sed -n 's/^l[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *[^ ]* *//p' "$tmp/entries" > "$tmp/links" while IFS= read -r path; do link=$(unzip -p "$tmp/Lumio.zip" "$path") case "$link" in ''|/*|*\\*) echo "Invalid archive link" >&2; exit 1;; esac printf '%s\n' "$link" | awk '/(^|\/)\.\.(\/|$)/ {exit 1}' done < "$tmp/links" ditto -x -k "$tmp/Lumio.zip" "$tmp" app="$tmp/Lumio.app" info="$app/Contents/Info.plist" [ "$(plutil -extract CFBundleIdentifier raw -o - "$info")" = com.lumiomac.lumio ] [ "$(plutil -extract CFBundleShortVersionString raw -o - "$info")" = "$version" ] [ "$(plutil -extract CFBundleVersion raw -o - "$info")" = "$build" ] codesign --verify --deep --strict "$app" # Не lipo: без инструментов разработчика (обычный Mac) он не работает. file -b "$app/Contents/MacOS/Lumio" | grep -q "$(uname -m)" if [ -e "$destination" ]; then [ ! -L "$destination" ] [ "$(plutil -extract CFBundleIdentifier raw -o - "$destination/Contents/Info.plist")" = com.lumiomac.lumio ] for personal_key in LumioPhoneServer LumioSunLatitude LumioSunLongitude; do personal_current=$(plutil -extract "$personal_key" raw -o - "$destination/Contents/Info.plist" 2>/dev/null) || personal_current= if [ -n "$personal_current" ]; then personal_candidate=$(plutil -extract "$personal_key" raw -o - "$info" 2>/dev/null) || personal_candidate= if [ "$personal_current" != "$personal_candidate" ]; then echo "Personal build detected. Update it from your project to keep your phone office connected." >&2 exit 1 fi fi done fi # Сначала готовим новую копию рядом со старой: неудачная запись не ломает установленное приложение. ditto "$app" "$staged" codesign --verify --deep --strict "$staged" pkill -x Lumio 2>/dev/null || true stopped=1 for attempt in 1 2 3 4 5; do pgrep -x Lumio >/dev/null || break; sleep 1; done if pgrep -x Lumio >/dev/null; then echo "Quit Lumio, then try again." >&2; exit 1; fi if [ -e "$destination" ]; then mv "$destination" "$backup"; moved=1; fi mv "$staged" "$destination" installed=1 xattr -dr com.apple.quarantine "$destination" 2>/dev/null || true open -g "$destination" --args --lumio-update-health "$health/ready" ready=0 for attempt in $(seq 1 30); do if [ -f "$health/ready" ] && [ "$(plutil -extract version raw -o - "$health/ready" 2>/dev/null)" = "$version" ] && [ "$(plutil -extract build raw -o - "$health/ready" 2>/dev/null)" = "$build" ]; then ready=1; break; fi sleep 1 done [ "$ready" -eq 1 ] || { echo "Lumio did not start; restoring the previous version." >&2; exit 1; } success=1 if [ "$moved" -eq 1 ]; then rm -rf "$backup"; fi echo "Lumio is installed in $apps and running."