#!/bin/bash
# Install Mili into the logged-in user's ~/Applications (user-owned, no admin).
#
# Deploy via Scalefusion: Application Management > Enterprise Store >
# Upload New App > Upload Shell script. In Configure Script set the user
# context to "Yes: Permissions of the logged-in user will be used" so this
# runs AS the user and CurrentUserHomeDirectory resolves to their home.
set -euo pipefail

PKG_URL="https://assets.getmili.ai/electron/mac/installer/MiliSetup.pkg"

tmp="$(mktemp -d)"
/usr/bin/curl -fsSL "$PKG_URL" -o "$tmp/Mili.pkg"
/usr/sbin/installer -pkg "$tmp/Mili.pkg" -target CurrentUserHomeDirectory
/bin/rm -rf "$tmp"

echo "Installed Mili into ~/Applications for $(id -un)"
