#!/usr/bin/env bash

SCRIPT_DIR=$(dirname $(realpath "$0"))

# docker update
echo "使新的docker compose生效"
cd /apps/services && docker compose up -d --remove-orphans
echo

# prepare permissions
chown snap:snap -R /apps/.data/files

# report version
echo '报告当前版本'
cd $SCRIPT_DIR
source ./lib.sh
source ./version.sh

deviceNo=$(getDeviceNo)

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "deviceNo": "'"$deviceNo"'",
    "currentVersion": {
      "flutter": "'"$flutterVersion"'",
      "algorithm": "'"$algorithmVersion"'",
      "print": "'"$printVersion"'"
    }
  }' \
  --max-time 5 \
  --retry 10 \
  --retry-delay 10 \
  --retry-all-errors \
  -w "\n[URL]: %{url_effective}\n[HTTP_CODE]: %{http_code}\n" \
  'https://api.magicsnap.cn/appVersion/report'