#!/bin/bash # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 source "$(dirname "$0")/../load.sh" || exit 1 projdir= args=( "Mettre à jour le script rundk" "[path/to/rundk]" -d:,--projdir:PROJDIR . "Copier les fichiers pour un projet de l'université de la Réunion" ) parse_args "$@"; set -- "${args[@]}" if [ -n "$projdir" ]; then setx projdir=abspath "$projdir" set -- "$projdir/sbin/rundk" fi rundk="${1:-.}" [ -d "$rundk" ] && rundk="$rundk/rundk" setx rundir=dirname -- "$rundk" [ -d "$rundir" ] || mkdir -p "$rundir" if [ -f "$rundk" ]; then ac_set_tmpfile userconf <"$rundk" awk ' # extraire la configuration depuis le fichier BEGIN { p = 0 } /SOF:rundk.userconf:/ { p = 1; next } /EOF:rundk.userconf:/ { p = 0; next } p == 1 { print } ' | awk ' # mettre en forme le fichier: pas de lignes vides avant et après BEGIN { p = 0; have_pending = 0; pending = "" } $0 != "" { p = 1 } p == 1 { if ($0 != "") { if (have_pending) print pending print have_pending = 0 pending = "" } else { if (!have_pending) have_pending = 1 else pending = pending "\n" } } ' >"$userconf" initial_config= elif [ -n "$projdir" ]; then # forcer BUILDENV0=..env.dist et BUILDENV=.env pour les projets de # l'université de la Réunion initial_config=1 ac_set_tmpfile userconf sed <"$MYDIR/rundk.userconf" >"$userconf" ' /^BUILDENV0=/s/=.*/=..env.dist/ /^BUILDENV=/s/=.*/=.env/ ' else initial_config=1 userconf="$MYDIR/rundk.userconf" fi ( cat "$MYDIR/rundk.1preamble" echo cat "$userconf" echo cat "$MYDIR/rundk.2postamble" ) >"$rundk" [ -x "$rundk" ] || chmod +x "$rundk" rsync -lpt "$MYDIR/Dockerfile.rundk" "$rundir/" if [ -n "$projdir" ]; then if should_update "$rundir/build" "$MYDIR/build"; then cp "$MYDIR/build" "$rundir/build" chmod +x "$rundir/build" fi if [ ! -f "$projdir/..env.dist" ]; then sed <"$MYDIR/dot-build.env.dist" >"$projdir/..env.dist" ' /^IMAGENAME=/s/=.*\//='"$(basename -- "$projdir")"'\// ' initial_config=1 fi fi [ -n "$initial_config" ]