ilius / starcal

StarCalendar: Full-featured International Calendar for Linux Desktop
https://ilius.github.io/starcal/
GNU Affero General Public License v3.0
153 stars 22 forks source link

improvements for Debian package installation #65

Closed eXtrem0us closed 2 years ago

ilius commented 2 years ago
eXtrem0us commented 2 years ago

The command readlink -f returns the absolute path of the file (In this case the .deb package). Any deb packages can be installed using apt or apt-get, but we need to provide the exact path of the .deb package to use this method. I suggest this method, because:

BTW, please note that you have already used apt-get -f install, with the assumption of existence of apt/apt-get.

ilius commented 2 years ago

I have updated the code to this:

function installPackage(){
    # must run `set +e` before running this function
    pkgPath="$1"
    if apt-get install $(realpath "$pkgPath") ; then
        return 0
    fi
    if [ -f /usr/bin/apt ] ; then
        /usr/bin/apt reinstall "$pkgPath" 2>/tmp/starcal-apt-error
        aptExitCode="$?"
        if [[ $aptExitCode == "0" ]] ; then
            return 0
        fi
        cat /tmp/starcal-apt-error
        rm /tmp/starcal-apt-error
        if [[ $aptExitCode == "1" ]] ; then
            # user answered No, abort installation
            return $aptExitCode
        fi
    fi
    dpkg -i "$pkgPath" || apt-get -f install
}
eXtrem0us commented 2 years ago

OK, now consider the scenario in which the user is asked about the extra package installation (apt-get -f install). If the user stops the installation process (when APT asks the user [Y/N]? and user answers N), he/she would end up with an inconsistent "APT Tree". This is why I insisted on the atomic aspect of installation with apt-get. In the scenario of mine, the user is also asked about installation, without side effects. However, if you wanna persist on your own structure, I suggest you that at least use apt-get -fy install, which bypasses the user's confirmation.