pre_upgrade() {
  echo "pre_upgrade"
  

if pgrep -f '/opt/aimp/AIMP' > /dev/null; then
	echo "Terminating app instance..."
	pkill -f '/opt/aimp/AIMP' || true
	sleep 1
fi


}

pre_install() {
  echo "pre_install"
  

if pgrep -f '/opt/aimp/AIMP' > /dev/null; then
	echo "Terminating app instance..."
	pkill -f '/opt/aimp/AIMP' || true
	sleep 1
fi


}

pre_remove() {
  echo "pre_remove"
  

if pgrep -f '/opt/aimp/AIMP' > /dev/null; then
	echo "Terminating app instance..."
	pkill -f '/opt/aimp/AIMP' || true
	sleep 1
fi


  

if [ -f "/usr/share/applications/aimp.desktop" ]; then
	xdg-desktop-icon uninstall --novendor "/usr/share/applications/aimp.desktop"
fi

if [ -f "/opt/aimp/System/FileFormats.xml" ]; then
	xdg-mime uninstall "/opt/aimp/System/FileFormats.xml"
fi


}

post_upgrade() {
  echo "post_upgrade"
  

config="/opt/aimp/AIMP.ini" 
if [ ! -f "$config" ]; 
then
	echo "[System]" >> $config
	echo "UserMode=1" >> $config
	echo "ID={$(cat /proc/sys/kernel/random/uuid)}" >> $config
fi

xdg-mime install --novendor /opt/aimp/System/FileFormats.xml


}

post_install() {
  echo "post_install"
  

config="/opt/aimp/AIMP.ini" 
if [ ! -f "$config" ]; 
then
	echo "[System]" >> $config
	echo "UserMode=1" >> $config
	echo "ID={$(cat /proc/sys/kernel/random/uuid)}" >> $config
fi

xdg-mime install --novendor /opt/aimp/System/FileFormats.xml


}

post_remove() {
  echo "post_remove"
  

echo "> removing..."
rm -f /usr/bin/aimp
rm -f /usr/lib64/libbass-aimp.so
rm -f /usr/lib64/libav*-aimp.so*
rm -f /usr/lib64/libsw*-aimp.so*
rm -f /usr/lib/x86_64-linux-gnu/libbass-aimp.so
rm -f /usr/lib/x86_64-linux-gnu/libav*-aimp.so*
rm -f /usr/lib/x86_64-linux-gnu/libsw*-aimp.so*
rm -f -d -r /opt/aimp/
}