#!/bin/sh
set -e

mkdir -p "$SNAP_USER_DATA/logs"
chmod 750 "$SNAP_USER_DATA/logs"

# Migrate config if necessary
if [ ! -d $SNAP_USER_COMMON/ipsw ]; then
    mkdir -p $SNAP_USER_COMMON/ipsw
    cp $SNAP/etc/ipsw/config.yml $SNAP_USER_COMMON/ipsw/config.yml
else
    cp $SNAP/etc/ipsw/config.yml $SNAP_USER_COMMON/ipsw/config.yml.default
fi

exec $SNAP/ipswd start --config $SNAP_USER_COMMON/ipsw/config.yml
