[docs]defdist_upgrade(c,frontend='noninteractive'):""" Run a full dist-upgrade for APT. Essentially this runs: .. code-block:: sh apt update apt dist-upgrade """update(c)upgrade(c,dist_upgrade=True,frontend=frontend)
[docs]definstall(c,*packages,**kwargs):""" Install some package(s) via APT. Essentially this runs: .. code-block:: sh apt install PKG [PKG ...] """frontend=kwargs.pop('frontend','noninteractive')packages=' '.join(packages)returnc.run(f'DEBIAN_FRONTEND={frontend} apt-get --assume-yes install {packages}')
[docs]defis_installed(c,package):""" Check if the given APT package is installed. :param c: Fabric connection. :param package: Name of package to be checked. :returns: ``True`` if package is installed, else ``False``. """returnc.run(f'dpkg-query -s {package}',warn=True).ok
[docs]defupdate(c):""" Update the APT package lists. Essentially this runs: .. code-block:: sh apt update """c.run('apt-get update')
[docs]defupgrade(c,dist_upgrade=False,frontend='noninteractive'):""" Upgrade packages via APT. Essentially this runs: .. code-block:: sh apt upgrade # ..or.. apt dist-upgrade """options=''iffrontend=='noninteractive':options='--option Dpkg::Options::="--force-confdef" --option Dpkg::Options::="--force-confold"'upgrade='dist-upgrade'ifdist_upgradeelse'upgrade'c.run(f'DEBIAN_FRONTEND={frontend} apt-get --assume-yes {options}{upgrade}')