#!/bin/bash
# zypper wrapper for Tumbleweed updater KDE plasmoid

if [ "$1" == "check" ]
then
	zypper --xmlout dup --force-resolution --auto-agree-with-licenses --dry-run | tee /tmp/twupdater/twupdater-check-xml-out
	exitcode="${PIPESTATUS[0]}"

	# Logging
	if [ "$2" == "logs" ]
	then
		/bin/cp -p /tmp/twupdater/twupdater-check-xml-out /tmp/twupdater/twupdater-check-xml-out_${exitcode}_$(date +%Y-%m-%d.%H%M%S).log
	fi

	echo "<exitcode>${exitcode}</exitcode>" >> /tmp/twupdater/twupdater-check-xml-out
elif [ "$1" == "install" ]
then
	param=""
	if [ "$2" == "autoresolve" ]
	then
		param="$param --force-resolution"
	fi
	if [ "$3" == "autolicense" ]
	then
		param="$param --auto-agree-with-licenses"
	fi
	zypper --xmlout dup${param} | tee /tmp/twupdater/twupdater-xml-out
	exitcode="${PIPESTATUS[0]}"

	# Logging
	if [ "$4" == "logs" ]
	then
		/bin/cp -p /tmp/twupdater/twupdater-xml-out /tmp/twupdater/twupdater-xml-out_${exitcode}_$(date +%Y-%m-%d.%H%M%S).log
	fi

	echo "<exitcode>${exitcode}</exitcode>" >> /tmp/twupdater/twupdater-xml-out
fi
