#!/bin/bash
REPO="noovolari/leapp"
BINARY_NAME="leapp"
TARGET_DIR="$HOME/.local/bin"
BINARY_PATH="$TARGET_DIR/$BINARY_NAME"
DOWNLOAD_URL="https://asset.noovolari.com/latest/Leapp-appImage.zip"

if [ ! -x "$BINARY_PATH" ]; then
	notify-send "📦 Installing $BINARY_NAME" "Downloading from $REPO..."

	mkdir -p "$TARGET_DIR"

	wget -q -O /tmp/leapp.zip "$DOWNLOAD_URL" || {
		notify-send -u critical "Installation Failed" "Failed to download $BINARY_NAME from $REPO"
		exit 1
	}

	unzip -q /tmp/leapp.zip -d /tmp/leapp_extract
	find /tmp/leapp_extract -name "Leapp*" -type f | head -1 | xargs -I {} mv {} "$BINARY_PATH"
	chmod +x "$BINARY_PATH"

	rm -rf /tmp/leapp.zip /tmp/leapp_extract

	notify-send "Installation Complete" "$BINARY_NAME has been installed successfully"
fi

exec "$BINARY_PATH" "$@"
