#!/usr/bin/env bash set -eu synopsis() { cat << EOF Usage : `basename $0` [-h] EOF } help() { cat << EOF `basename $0` affiche le premier identificateur libre pour un nouveau système. `synopsis` -h : affiche cette aide EOF } usage() { synopsis exit 1 } args() { local opt while getopts "h" opt; do case $opt in h) help; exit 0;; ?) usage;; esac done shift $(($OPTIND - 1)) [ $# -ne 0 ] && usage || : } findIdent() { local i=0 local configs="`find $NETWORK_DIR -follow -type f -name \"*.conf\"`" if [ -n "$configs" ]; then for i in `seq 0 256`; do if ! grep -Eq "^IDENT=$i([[:space:]]|$)" $configs; then break fi done if [ $i = 256 ]; then error "Aucun identificateur disponible" fi fi echo $i } # Programme principal VDN_PATH=$(readlink -f $(dirname $0)/..); . $VDN_PATH/bin/functions.sh args "$@" ident=`findIdent` echo $ident