#!/bin/bash

set -e

GTK3='/root/.config/gtk-3.0'
if [ -L "${GTK3}" ]; then
    rm "${GTK3}"
    if [ -e ${GTK3}.bak ]; then
        mv -f "${GTK3}".bak "${GTK3}"
    elif [ -e /etc/skel/.config/gtk-3.0 ]; then
        cp -rf /etc/skel/.config/gtk-3.0 /root/.config/
    fi
fi

FLE=/usr/bin/apt
ISDIVERTED=$(LANG=C dpkg-divert --list $FLE)
# First remove the old style diversion, if it exists...
if [ -f $FLE.divert ] && [ "$ISDIVERTED" ]; then
  # Need to move this out of the way or the dpkg-divert --rename will fail.
  [ -f $FLE ] && mv -f $FLE $FLE.bak
  dpkg-divert --remove --rename $FLE
  # At this point, the previously diverted /usr/bin/apt has been restored.
  # However, since the this package 'owns' a file with the same name, this
  # will disappear when the older package's files are removed. We need to
  # fix this in the postinst, but just this once!
  cp -af $FLE $FLE.restored
  ISDIVERTED=$(LANG=C dpkg-divert --list $FLE)
fi

if [ -f $FLE ] && [ ! "$ISDIVERTED" ]; then
  # This *could* be a first install of this package and this is the preinst,
  # so make sure the target location of the diversion is there...
  mkdir -p /usr/lib/solydxk
  dpkg-divert --add --rename --divert /usr/lib/solydxk/apt $FLE
fi


# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
