#!/bin/bash
# Some colored makepkg-like functions
# tputcolors
post_install() {
	post_upgrade
}

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

post_upgrade() {

    if [[ -n ${desktop} ]]; then

        kdialog --warningyesno "KCP has migrated from Github to Codeberg.<br>
        This is the last version to use the Github Organiztion.<br>
        Next major will move to Codeberg.<br>
        To prepare the migration, contributors are invited to already <br> create an account on Codeberg.<br><br>
        <b>See the forum at:</b><br>
        https://forum.kaosx.us/d/3265-kcp-130-released for further instructions.<br><br>
        Do you want to save this output?"

        save=${?}

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

                kdialog --msgbox "Output not saved"

            else

                echo "KCP has migrated from Github to Codeberg.<br>
                This is the last version to use the Github Organiztion.<br>
                Next major will move to Codeberg.<br>
                To prepare the migration, contributors are invited to already <br> create an account on Codeberg.<br><br>
                <b>See the forum at:</b><br>
                https://forum.kaosx.us/d/3265-kcp-130-released for further instructions." > /var/log/kcp_install${timestamp}.txt

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

            fi

    else
        echo -e '\e[1;31m Common instructions for kcp'
        echo -e '\e[1;34m ==> To search use: kcp -s partial_package_name'
        echo -e '\e[1;34m ==> To update the cache, run once a week: kcp -u'
        echo -e '\e[1;34m ==> To install use: kcp -i package_name' 
        echo -e '\e[1;34m ==> To install a package needed by another KCP package so pacman -Rns will remove it too: kcp -i package --asdeps'
        echo -e '\e[1;34m ==> To download the files only: kcp -g package_name'
        echo -e '\e[1;34m ==> To list packages by amount of stars: kcp -l --sort'
        echo -e '\e[1;34m ==> To show packages with newer version available: kcp -l --only-outdated'
        echo -e '\e[1;34m ==> To view all the options: kcp -h \e[0m' 
        echo -e '\e[1;31m Instructions for pckcp'
        echo -e '\e[1;34m ==> Check and create corrected PKGBUILD.new, cd to dir and run: pckcp -e \e[0m'
        echo -e '\e[1;36m kcp 1.0.0 uses a database incompatible with previous versions'
        echo -e '\e[1;36m remove ~/.kcp.json and regenerate with: kcp -u'
        echo -e '\e[1;36m now located in ~/.config/kcp/kcp.json \e[0m'
        echo -e '\e[1;31m KCP has started the move to Codeberg'
        echo -e '\e[1;31m This is the last release that still can be used on Github'
        echo -e '\e[1;31m Follow the KaOS Forum and News for further instructions'
    fi
}

