84 lines
2.7 KiB
Bash
84 lines
2.7 KiB
Bash
# ------------------------------------------------------------------------------
|
|
# 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 <fatalerrors@geoffray-levasseur.org>
|
|
# ------------------------------------------------------------------------------
|
|
# 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:
|
|
# * PROXYAPT: Proxy to use with APT (eg. APT Cacher)
|
|
# * PROXYAPTPORT: Working port for APT proxy
|
|
# ------------------------------------------------------------------------------
|
|
|
|
export VER_upgrade_dist="0.2.0"
|
|
|
|
# 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
|
|
|
|
# We backup entire apt dir as future version will normalise source.list files
|
|
backupdist /etc/apt
|
|
|
|
prnt I "Configuration du proxy pour APT..."
|
|
if [[ -n $PROXYAPT ]]; then
|
|
if [[ ! -d $(dirname $proxyfile) ]]; then
|
|
mkdir -pv $(dirname $proxyfile) || (
|
|
prnt E "Impossiblle de créer le répertoire d'accueil pour la configuration d'APT."
|
|
die 60
|
|
)
|
|
fi
|
|
echo "# Generated automatically on $(stdtime) by $0" > $proxyfile
|
|
echo "Acquire::http::Proxy \"http://${PROXYAPT}:${PROXYAPTPORT}\";" >> $proxyfile
|
|
elif [[ -n $http_proxy ]]; then
|
|
echo "# Generated automatically on $(stdtime) by $0" > $proxyfile
|
|
echo "Acquire::http::Proxy \"http://${http_proxy}\";" >> $proxyfile
|
|
else
|
|
prnt I "Pas de proxy configuré, ne fait rien."
|
|
fi
|
|
|
|
# Remplace source.list from dist with ours (be smarter)
|
|
installfile "${SYS_DIST}_${SYS_VER}.list" /etc/apt/sources.list
|
|
|
|
prnt I "Mise à jour de la liste des paquets..."
|
|
pkgupdt
|
|
|
|
prnt I "Application des mises à jour de paquets..."
|
|
pkgupgd
|
|
|
|
prnt I "Suppression des paquets résiduels..."
|
|
pkgautorm
|
|
}
|
|
|
|
precheck_upgrade_dist()
|
|
{
|
|
prnt I "Vérification du réseau..."
|
|
|
|
if [[ $(noerror wget -q --tries=10 --timeout=20 --spider http://www.cnrs.fr) != 0 ]]; then
|
|
prnt E "Réseau non fonctionnel ! Abandon."
|
|
die 160
|
|
fi
|
|
if [[ -n $PROXYAPT && -z $PROXYAPTPORT ]]; then
|
|
prnt E "Un serveur proxy a été spécifié mais pas son port d'usage."
|
|
die 160
|
|
fi
|
|
}
|
|
|
|
cron_upgrade_dist()
|
|
{
|
|
pkgupdt
|
|
pkgupgd
|
|
}
|
|
|
|
|
|
export -f upgrade_dist
|
|
export -f precheck_upgrade_dist
|
|
|
|
# EOF
|