#!/bin/bash
# By Ratel
#
# This script unlocks the typical Arch Linux environment (pacman/yay).
# Enjoy!

if [ $EUID -eq 0 ]; then
    echo "The script cannot be run as root. Exiting..."
    exit 1
fi

# Disable SteamOS read-only mode (if applicable)
sudo steamos-readonly disable

# Install the Arch Linux keyring package to ensure proper key management
sudo pacman -S archlinux-keyring

# Initialize the pacman keyring
sudo pacman-key --init

# Populate the Arch Linux and holo keyrings with trusted keys
sudo pacman-key --populate archlinux
sudo pacman-key --populate holo

# Install git and base-devel (development tools) if not already installed
sudo pacman -S --needed git base-devel

# Update the pacman database and upgrade the system to the latest packages
sudo pacman -Syu --noconfirm

# Clone the yay AUR helper repository
cd
git clone https://aur.archlinux.org/yay-bin.git

# Navigate to the yay-bin directory
cd yay-bin

# Check out a specific commit for yay-bin
git checkout cb857e898d7081a60cf8742d26247fd6a3c5443c

# Build and install yay from the cloned repository
yes | makepkg -si

# Return to the home directory
cd

# Print a completion message
echo "Environment setup complete."
