Closed eXtrem0us closed 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.
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
}
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.
The first commit is not needed anymore, I fixed it in https://github.com/ilius/starcal/commit/1b8269e1b5ae9d7daa041f8a9c3c38201cd7cada
The second commit https://github.com/eXtrem0us/starcal/commit/5b256520bdbae70a940727317473538102156007 does not seem rational.
/usr/bin/apt
does not exist, how canapt-get
exist?readlink
really needed here? The package is created in our script and it's not a link.