#!/bin/env fish
begin
    set -l dir (status dirname)
    source "$dir/../../Scripts/software.fish"

    function installSW -V dir
        set -l repo linux-surface
        set -l file "/etc/pacman.conf"

        curl -s https://raw.githubusercontent.com/linux-surface/linux-surface/master/pkg/keys/surface.asc \
            | sudo pacman-key --add -

        sudo pacman-key --finger 56C464BAAC421453
        sudo pacman-key --lsign-key 56C464BAAC421453

        if ! grep "^\[$repo\]\$" $file
            begin
                printf %s\n \
                    "" \
                    "[$repo]" \
                    "Server = https://pkg.surfacelinux.com/arch/"
            end | sudo tee -a $file >/dev/null

            sudo pacinst

            sudo pacinst \
                intel-ucode \
                linux-surface \
                linux-surface-headers \
                linux-surface-secureboot-mok \
                iptsd \
                linux-firmware-marvell

            yes | runYay libwacom-surface
            yayinst libcamera-git
        end
    end

    function configureSW -V dir
        fish "$dir/../../Software/grub/main.fish" configure
    end

    runInstaller --force $argv
end