nutools/update-nutools

117 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
SCRIPTNAME=update-nutools
TMPSCRIPT="/tmp/$SCRIPTNAME"
PRIV_REPO=http://vs-git.univ.run/modules/nutools
PUB_REPO=https://git.univ-reunion.fr/modules/nutools
REPO_SUFFIX=modules/nutools
NAME=nutools
################################################################################
eval "set -- $(getopt -n update-nutools -o dpx -l develop,public,use-proxy,do-update -- "$@" || echo exit 1)"
develop=
public=
use_proxy=
do_update=
while [ "$1" != -- ]; do
case "$1" in
--help)
echo "update-nutools: mettre à jour nutools
USAGE:
update-nutools [--develop]
OPTIONS
-d, --develop
Mettre à jour avec la branche develop pour avoir les dernières fonctions
qui ne sont pas encore stabilisées. Par défaut, la mise à jour est faite
avec la branche master.
-p, --public
Forcer l'utilisation de l'url publique"
exit 0
;;
-d|--develop)
develop=develop
;;
-p|--public)
public=1
NUTOOLS_REPO="$PUB_REPO"
;;
-x|--use-proxy)
use_proxy=1
;;
--do-update)
do_update=1
;;
esac
shift
done
[ -n "$use_proxy" ] || export http_proxy=
if [ -z "$do_update" ]; then
scriptdir="$(dirname -- "$0")"
cp "$0" "$TMPSCRIPT"
chmod 755 "$TMPSCRIPT"
exec bash "$TMPSCRIPT" ${develop:+--develop} ${public:+--public} --do-update "$scriptdir"
fi
CURL="$(which curl 2>/dev/null)"
WGET="$(which wget 2>/dev/null)"
if [ -n "$NUTOOLS_REPO" ]; then
REPO="$NUTOOLS_REPO"
elif [ -n "$CURL" ]; then
if curl -fs -m 3 "${PUB_REPO%$REPO_SUFFIX}" >&/dev/null; then
REPO="$PUB_REPO"
else
REPO="$PRIV_REPO"
fi
elif [ -n "$WGET" ]; then
if wget -q --timeout=3 -O - "${PUB_REPO%$REPO_SUFFIX}" >&/dev/null; then
REPO="$PUB_REPO"
else
REPO="$PRIV_REPO"
fi
else
REPO="$PUB_REPO"
echo "\
WARN: impossible de déterminer la source pour la mise à jour.
sélection de l'adresse publique $PUB_REPO"
echo "\
NOTE: si une erreur se produit, utiliser l'adresse privée, e.g.
NUTOOLS_REPO=$PRIV_REPO $0"
fi
scriptdir="$1"
tmpclone=
if [ -z "$NUTOOLS_REPO" -a -f "$scriptdir/.nutools-devel" -a -d "$scriptdir/.git" ]; then
echo "NOTE: tentative de mise à jour du dépôt local"
cd "$scriptdir"
git pull || tmpclone=1
else
tmpclone=1
fi
if [ -n "$tmpclone" ]; then
echo "NOTE: clonage du dépôt distant $REPO"
cd /tmp
rm -rf "$NAME"
git clone --depth 1 ${develop:+--branch "$develop"} "$REPO" || exit 1
cd "$NAME"
fi
if ! diff -q "$SCRIPTNAME" "$0"; then
echo "NOTE: Le script $SCRIPTNAME a été mis à jour. Il va être relancé."
exec bash "./$SCRIPTNAME" ${develop:+--develop} ${public:+--public}
fi
bash ./uinst -y || exit 1
if [ -n "$tmpclone" ]; then
cd ..
rm -rf "$NAME"
fi
# IMPORTANT: la ligne suivante ne doit pas se terminer par un retour à la ligne:
rm "$0"; exit 0