#! /bin/bash

echo "-------------------------------------"
echo "Enpass Setup Script"
echo "-------------------------------------"

if [[ -z $MASTERPW ]]; then
    export MASTERPW=$(gum input --header="Enpass Master password" --password)
fi

VAULT_DIR="$HOME/.local/share/Enpass/Enpass/Vaults/primary"

if [ -f "$VAULT_DIR/vault.enpassdb" ]; then
    echo "Vault already exists, skipping Enpass setup."
else
    echo -n "stofflees@gmail.com" | wl-copy

    station-launch-password-manager

    zenity --title="Enpass Setup" \
        --info \
        --text="Email copied.\nPress OK when it asks for webdav URL" \
        || gum confirm "You closed the dialog, do you want to continue?" \
        || exit 1

    echo -n "https://tower.scarif.space" | wl-copy

    zenity --title="Enpass Setup" \
        --info \
        --text="Tower URL copied.\nPress OK when it asks for master password" \
        || gum confirm "You closed the dialog, do you want to continue?" \
        || exit 1

    echo -n "$MASTERPW" | wl-copy

    read -n 1 -r -s -p $'Press enter when you have synced enpass...\n'

    wl-copy --clear

    echo "Enpass setup complete."
fi

