#!/bin/bash

if [ $(whoami) != 'root' ]; then
    echo "Must be root to run. Try using 'sudo'."
    exit 1;
fi

# Download and install the repository key
curl -O https://app.drivestrike.com/static/drivestrike.pubkey.txt
pacman-key --add drivestrike.pubkey.txt
pacman-key --lsign-key 6B48829B
rm -f drivestrike.pubkey.txt

# Add the DriveStrike repository to /etc/pacman.conf
if [[ $(grep -c drivestrike /etc/pacman.conf 2> /dev/null) == 0 ]]; then
    cat <<EOF >> /etc/pacman.conf

[drivestrike]
SigLevel = Required DatabaseOptional
Server = https://app.drivestrike.com/static/arch
EOF
fi

# Install DriveStrike
pacman --noconfirm -Sy drivestrike

# Register DriveStrike and start the service
if [[ -f /usr/sbin/drivestrikerun.sh ]]; then
    /usr/sbin/drivestrikerun.sh
else
    /usr/bin/drivestrikerun.sh
fi
