#!/bin/bash

cd "${0%/*}"

echo
echo "Copyright Pointsharp AB"
echo

echo "Install begin"
USER_NAME=${HOME##*/}
if [ -f "/Applications/Net iD Access.app/Contents/MacOS/Net iD" ]; then
    echo "  Delete existing Net iD Access 6.X application"
    rm -rf "/Applications/Net iD Access.app"
fi
if [ -f "/Applications/Net iD Access.app/Contents/MacOS/WebApp" ]; then
    echo "  Delete existing Net iD Access 7.X application"
    rm -rf "/Applications/Net iD Access.app"
fi
if [ -f "Net iD Access.app.zip" ]; then
    echo "  Extract Net iD Access application"
    unzip "Net iD Access.app.zip"
    rm -f "Net iD Access.app.zip"
fi
echo "  Copy Net iD Access application"
cp -rf "Net iD Access.app" /Applications
rm -rf "Net iD Access.app"
echo "  Update execute mode"
chmod 755 "/Applications/Net iD Access.app/Contents/MacOS/WebApp"
chmod 755 "/Applications/Net iD Access.app/Contents/Resources/sdk/netid"
chmod 755 "/Applications/Net iD Access.app/Contents/Resources/setup/uninstall"
echo -n "OK" > /tmp/netid_setup_result.txt
chown $USER_NAME /tmp/netid_setup_result.txt
echo "Install end"
