You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
1.9 KiB

#!/usr/bin/env bash
#set -x
EDIT=0
synopsis() {
cat << EOF
Usage : `basename $0` [-h] [-e] [networkDir...]
EOF
}
help() {
cat << EOF
`basename $0` construit le réseau.
`synopsis`
-h : affiche cette aide.
-e : propose l'édition du script avant la reconstruction
(la reconstruction n'est faite que si modifications il y a)
Cette commande, après avoir fixé quelques variables, appelle
le script build du réseau.
Si networkDir n'est pas précisé, le réseau défini par la
variable NETWORK_DIR est (re)créé.
EOF
}
usage() {
synopsis
exit 1
}
args() {
local opt
while getopts "he" opt; do
case $opt in
h) help; exit 0;;
e) EDIT=1;;
?) usage;;
esac
done
shift $(($OPTIND - 1))
NETS=$@
}
# main
VDN_PATH=$(readlink -f $(dirname $0)/..); . $VDN_PATH/bin/functions.sh
args "$@"
if [ -z "$NETS" ]; then
NETS=$NETWORK_DIR
fi
if [ -z "$NETS" ]; then
error "NETWORK_DIR not set !"
fi
for i in $NETS; do
if [ -d $i ]; then
NETWORK_DIR=$i
elif [ -d $VDN_NETWORKS_BASE_DIR/$i ]; then
NETWORK_DIR=$VDN_NETWORKS_BASE_DIR/$i
else
error "Network : $i not found !"
fi
echo
echo "Build : $NETWORK_DIR"
[ ! -r $NETWORK_DIR/build ] && error "$NETWORK_DIR/build script not found !"
if [ $EDIT = 1 ]; then
if [ -w $NETWORK_DIR/build ]; then
cp $NETWORK_DIR/build $NETWORK_DIR/.build.save
$EDITOR $NETWORK_DIR/build
if diff -q $NETWORK_DIR/build $NETWORK_DIR/.build.save > /dev/null; then
rm $NETWORK_DIR/.build.save
echo "No modification !"
exit
fi
rm $NETWORK_DIR/.build.save
else
echo "En lecture seule !"
sleep 2
$EDITOR $NETWORK_DIR/build
exit
fi
rm $NETWORK_DIR/.build.save
fi
if [ -w $NETWORK_DIR ]; then
(
cd $NETWORK_DIR
rm -f *.conf
. build
echo "Create \"$(basename $NETWORK_DIR)\" config files..."
echo
build && echo && vdn-graph
touch $(readlink -f $NETWORK_DIR)/network.vdn
)
else
echo "$NETWORK_DIR not writable !" >&2
fi
done