#!/bin/bash

desktop=$(ps -e | grep kwin)
timestamp=$( date +%F-%T )

post_upgrade() {
  (( $(vercmp $2 '2.4') > 0 )) && return
  
    # 2.4 warning
    if [[ -n ${desktop} ]]; then

        kdialog --yesno "The upgrade from openvpn $2 to openvpn $1 made changes that requires manual intervention:<br>
        Configuration has moved to directories.<br>
        Move your files from /etc/openvpn/ to /etc/openvpn/server/ or /etc/openvpn/client/.<br><br>
        The systemd unit openvpn@.service was replaced with openvpn-client@.service and openvpn-server@.service.<br>
        Restart and reenable accordingly. <br><br>
        Do you want to save this output?"

        save=${?}

            if [[ ${save} == 1 ]]; then

                kdialog --msgbox "Output not saved"

            else

                echo "The upgrade from openvpn $2 to openvpn $1 made changes that requires manual intervention:<br>
                Configuration has moved to directories.<br>
                Move your files from /etc/openvpn/ to /etc/openvpn/server/ or /etc/openvpn/client/.<br><br>
                The systemd unit openvpn@.service was replaced with openvpn-client@.service and openvpn-server@.service.<br>
                Restart and reenable accordingly." > /var/log/update${timestamp}.txt

                kdialog --msgbox "Output is saved in /var/log/update${timestamp}.txt"
                
            fi   

    else

        echo -e "The upgrade from openvpn $2 to openvpn $1 made changes that requires"
        echo -e "manual intervention:"
        echo -e " * Configuration has moved to directories. Move your files"
        echo -e "   from /etc/openvpn/ to /etc/openvpn/server/ or /etc/openvpn/client/."
        echo -e " * The systemd unit openvpn@.service was replaced with openvpn-client@.service"
        echo -e "   and openvpn-server@.service. Restart and reenable accordingly. \e[0m"

    fi
}


