# ------------------------------------------------------------------------------ # Distribution upgrade module, should be ran prior any other module (also # configure APT) # This file is part of the init.sh project # Copyright (c) 2019-2021 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ # Variable: # * PROXY_APT: Proxy to use with APT (eg. APT Cacher), optionnal # * PROXY_APT_PORT: Working port for APT proxy if one declared # * PROXY_SRV: General purpose proxy if PROXY_APT is undefined # * PROXY_SRV_PORT: Working port for general purpose proxy if one declared # ------------------------------------------------------------------------------ export VER_upgrade_dist="0.2.1" # As aptitude might fail if clock is too far from real time, we need to depend # on ntp export DEP_upgrade_dist="conf_ntp" upgrade_dist() { local proxyfile=/etc/apt/apt.conf.d/00proxy local norecommends=/etc/apt/apt.conf.d/99no-recommends # We backup entire apt dir as future version will normalise source.list files backupdist /etc/apt prnt I "Basic apt configuration..." echo "# Generated automatically on $(stdtime) by $0" > $norecommend echo 'APT::Install-Recommends "false";' >> $norecommends echo 'APT::AutoRemove::RecommendsImportant "false";' >> $norecommends echo 'APT::AutoRemove::SuggestsImportant "false";' >> $norecommends prnt I "Configuring proxy for APT..." if [[ -n $PROXY_APT ]]; then if [[ ! -d $(dirname $proxyfile) ]]; then mkdir -pv $(dirname $proxyfile) || ( prnt E "Impossible to create directory to receive APT configuration." die 60 ) fi echo "# Generated automatically on $(stdtime) by $0" > $proxyfile echo "Acquire::http::Proxy \"http://${PROXY_APT}:${PROXY_APT_PORT}\";" >> $proxyfile elif [[ -n $PROXY_SRV ]]; then echo "# Generated automatically on $(stdtime) by $0" > $proxyfile echo "Acquire::http::Proxy \"http://${PROXY_SRV}:${PROXY_SRV_PORT}\";" >> $proxyfile else prnt I "No proxy configured, nothing to do." fi # Remplace source.list from dist with ours (be smarter) installfile "pkgman/${SYS_DIST}_${SYS_VER}.list" /etc/apt/sources.list prnt I "Updating package list..." pkgupdt prnt I "Applying packages upgrades..." pkgupgd prnt I "Deleting no longer needed packages..." pkgautorm } precheck_upgrade_dist() { prnt I "Checking network connectivity..." if [[ $(noerror wget -q --tries=10 --timeout=20 --spider http://www.cnrs.fr) != 0 ]]; then prnt E "It seems network configuration is not functionnal! Giving up." die 160 fi if [[ -n $PROXY_APT && -z $PROXY_APT_PORT ]]; then prnt E "An APT proxy server have been specified but not its working port." die 160 fi if [[ -n $PROXY_SRV && -z $PROXY_SRV_PORT ]]; then prnt E "A general proxy server have been specified but not its working port." die 160 fi file_exists pkgman/${SYS_DIST}_${SYS_VER}.list } cron_upgrade_dist() { pkgupdt pkgupgd } export -f upgrade_dist export -f precheck_upgrade_dist # EOF