#!/bin/sh

# Experimental DUD funtionality for Agama
#
# Usage: inst.dud=URI [inst.dud=URI]
#
# This is a very simple version of the DUD functionality
# - There can be multiple inst.dud=URI entries, but...
# - All of them are considered to be RPMs
# - The script does not check if downloading succeeded
# - Or for any deps of the package
# - Of whether installation/upgrade succeeded
# - Does not restart itself if the script is updated

# check if there is any DUD
if ! grep -q "\b\(inst\|agama\)\.dud=.\+\b" /run/agama/cmdline.d/agama.conf; then
  echo "No DUD present"
  exit 0
fi

for URI in `sed -n 's/\(.*[[:space:]]\|^\)\(inst\|agama\)\.dud=\([^[:space:]]\+\).*/\3/p' /run/agama/cmdline.d/agama.conf`; do
  echo "Downloading DUD from" $URI
  TMPDUD=`mktemp /tmp/agama-XXXXXXXXXX.rpm`
  agama download $URI $TMPDUD;
  rpm --upgrade --force --verbose --hash --noverify --nodeps --excludedocs $TMPDUD
  rm $TMPDUD
done
