# ------------------------------------------------------------------------------ # 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 # TODO: Split apt conf and actuel update to avoid repeating configuration if # for a reason apt fail # TODO: This is Debian only, make this universal (at least yum/dnf compatible) # ------------------------------------------------------------------------------ export VER_upgrade_dist="0.2.5" # 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 backup_dist /etc/apt prnt I "Basic apt configuration..." # TODO: No recommend section should be optionnal tag_file $norecommends { echo 'APT::Install-Recommends "false";' echo 'APT::AutoRemove::RecommendsImportant "false";' 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 ) else # Cleanup if [[ -s $proxyfile ]]; then true > "$proxyfile" fi if grep -q "^Acquire::http::Proxy" /etc/apt/apt.conf; then sed -i -e "/^Acquire::http::Proxy/d" /etc/apt/apt.conf fi fi tag_file $proxyfile echo "Acquire::http::Proxy \"http://${PROXY_APT}:${PROXY_APT_PORT}\";" >> $proxyfile elif [[ -n $PROXY_SRV ]]; then tag_file $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) install_file "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.tetaneutral.net) != 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_must_exists pkgman/${SYS_DIST}_${SYS_VER}.list } cron_upgrade_dist() { pkgupdt pkgupgd } export -f upgrade_dist export -f precheck_upgrade_dist # EOF