#!/bin/sh

#######################################################
#                                                     #
# v2.2 dinosaur (13-Sep-2026)                         #
#                                                     #
# To activate this dinosaur repository:               #
# - save this file as: dinosaur-install-script.sh     #
# - run command: chmod +x dinosaur-install-script.sh  #
# - run command: ./dinosaur-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 B9FCE86BE9320EF8 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/dinosaur/dinosaur-pgpkey-B9FCE86BE9320EF8.asc | pacman-key --add -'
  $runasroot pacman-key --finger B9FCE86BE9320EF8
  $runasroot pacman-key --lsign-key B9FCE86BE9320EF8
fi

if ! grep -q '^\[dinosaur\]' /etc/pacman.conf ; then
  printf '\n'
  printf '%s\n' 'Adding the dinosaur repository to file /etc/pacman.conf'
  $runasroot sh -c "printf '\n' >> /etc/pacman.conf"
  $runasroot sh -c "printf '%s\n' '[dinosaur]'  >> /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/dinosaur/1-dinosaur-package-overview.html'

printf '%s\n' 'Attention: in case Arch Linux repositories are present in /etc/pacman.conf move the entry'
printf '%s\n' 'for the dinosaur one to a place above these.'

