# I Want To Heal 2 Deployment

Do not hard-code Gitea tokens in repo files. Export `GITEA_TOKEN` in your shell.

## One-Time Local Git Setup

```bash
cd /Users/warren/Documents/action-mode

git init
git branch -M main
git remote add origin https://git.whoagland.com/phenom/i-want-to-heal-2.git
```

If the remote already exists:

```bash
cd /Users/warren/Documents/action-mode
git remote set-url origin https://git.whoagland.com/phenom/i-want-to-heal-2.git
```

## Step 1: Build APK For Thor

```bash
set -e

cd /Users/warren/Documents/action-mode

VERSION="1.0.0"
scripts/build-thor-apk.sh "$VERSION"
```

## Step 2: Web/Server Build Check

```bash
set -e

cd /Users/warren/Documents/action-mode

npm run lint
npm run build
```

## Step 3: Commit And Push Code

```bash
set -e

cd /Users/warren/Documents/action-mode

VERSION="1.0.0"

git add .
git commit -m "I Want To Heal 2 build v$VERSION"
git push origin main
```

## Step 4: Create Gitea Release

```bash
set -e

cd /Users/warren/Documents/action-mode

export GITEA_URL="https://git.whoagland.com"
export GITEA_OWNER="phenom"
export GITEA_REPO="i-want-to-heal-2"
# export GITEA_TOKEN="paste-current-token-in-shell-only"

VERSION="1.0.0"
APK="IWantToHeal2-Thor-v$VERSION.apk"

RELEASE_JSON=$(curl -sS -X POST "$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases" \
  -H "Authorization: token $GITEA_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"tag_name\":\"v$VERSION\",\"target_commitish\":\"main\",\"name\":\"v$VERSION\",\"body\":\"I Want To Heal 2 Android and web/server build v$VERSION\",\"draft\":false,\"prerelease\":false}")

RELEASE_ID=$(python3 -c 'import sys,json; data=json.load(sys.stdin); print(data.get("id") or data)' <<< "$RELEASE_JSON")
echo "Release ID: $RELEASE_ID"

curl -sS -X POST "$GITEA_URL/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$RELEASE_ID/assets?name=$APK" \
  -H "Authorization: token $GITEA_TOKEN" \
  -F "attachment=@$APK"
```

## Step 5: First TrueNAS Install

In the TrueNAS shell:

```bash
set -e

mkdir -p /mnt/usbssds/apps/iwanttoheal2
cd /mnt/usbssds/apps/iwanttoheal2

git clone https://git.whoagland.com/phenom/i-want-to-heal-2.git app
mkdir -p data db
```

Create the TrueNAS custom app from `docker-compose.truenas.yml`, or paste that compose file into the custom app UI.

Set these app environment values:

```text
POSTGRES_PASSWORD=<strong unique password>
```

Only set this after the reverse proxy/auth layer strips spoofed inbound auth headers and injects trusted user headers:

```text
TRUST_AUTH_HEADERS=1
```

## Step 6: Update TrueNAS

In the TrueNAS shell:

```bash
set -e

cd /mnt/usbssds/apps/iwanttoheal2/app
git pull origin main
```

Then restart the TrueNAS custom app.

## Admin Changes

Mechanic admin is inside the web app under Action Mode settings. This command serves the same app on port `4174` for local mechanic admin work:

```bash
cd /Users/warren/Documents/action-mode
DATABASE_URL="postgres://iwanttoheal:<password>@127.0.0.1:5432/iwanttoheal" PORT=4174 npm run admin:start
```

Asset admin is a local-only helper for replacing dungeon icons and boss or mob sprites:

```bash
cd /Users/warren/Documents/action-mode
npm run assets:admin
```

Open `http://127.0.0.1:4175`. Uploads write into `public/action-assets`, so the next build includes them automatically.
