#!/bin/sh

#########################################################
#                                                       #
# v2.3 Dinosaur (16-Sep-2026)                           #
#                                                       #
# To activate this enhancedX11 repository:              #
# - save this file as: enhancedX11-install-script.sh    #
# - run command: chmod +x enhancedX11-install-script.sh #
# - run command: ./enhancedX11-install-script.sh        #
#                                                       #
# Note: this script requires root permissions to        #
# perform the installation;                             #
# if not root, it requires 'sudo' or 'doas' installed   #
#                                                       #
#########################################################

if [ $EUID -ne 0 ]; then
  if command -v doas 1>/dev/null; then
    runasroot=doas
  elif command -v sudo 1>/dev/null; then
    runasroot=sudo
  else
    printf '\n'
    printf '%s\n' 'ERROR: No root permissions, sudo or doas are not installed, exiting'
    exit 1
  fi
else
  runasroot=""
fi

if ! pacman-key -f 2FC84CE10A0C6483 1> /dev/null 2>&1 ; then
  printf '\n'
  printf '%s\n' 'Obtaning, importing and adding pacman key'
  $runasroot sh -c 'curl -sS https://dinosaur.homelinuxserver.org/enhancedX11/Dinosaur-pgpkey-2FC84CE10A0C6483.asc | pacman-key --add -'
  $runasroot pacman-key --finger 2FC84CE10A0C6483
  $runasroot pacman-key --lsign-key 2FC84CE10A0C6483
fi

if ! grep -q '^\[enhancedX11\]' /etc/pacman.conf ; then
  printf '\n'
  printf '%s\n' 'Adding the enhancedX11 repository to file /etc/pacman.conf'
  $runasroot sh -c "printf '\n' >> /etc/pacman.conf"
  $runasroot sh -c "printf '%s\n' '[enhancedX11]'  >> /etc/pacman.conf"
  $runasroot sh -c "printf '%s\n' ''' Server = https://dinosaur.homelinuxserver.org/\$repo/os/\$arch/''' >> /etc/pacman.conf"
fi 

printf '\n'
printf '%s\n' 'Refreshing pacman database caches'
$runasroot pacman -Syy

printf '\n'
printf '%s\n' 'All done.'

printf '\n'
printf '%s\n' 'Check this URL for available packages:'
printf '%s\n' ' https://dinosaur.homelinuxserver.org/enhancedX11/1-enhancedX11-package-overview.html'

