Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 3111 → Rev 3112

/alcasar.sh
233,13 → 233,24
{
# Detect external/internal interfaces
if [ -z "$EXTIF" ]; then
EXTIF=$(/usr/sbin/ip route list | awk '/ via / {print $5}' | uniq)
if [ -z "$EXTIF" ]; then
GwListSorted=$(/usr/sbin/ip r list | grep default | cut -d" " -f5 | uniq )
nb_gw=$(echo $GwListSorted | wc -w)
if [ $nb_gw -eq 0 ]; then
if [ "$Lang" == 'fr' ]
then echo "Aucune passerelle par défaut configurée"
else echo "No default gateway configured"
fi
exit 1
elif [ $nb_gw -eq 1 ]; then
EXTIF="$GwListSorted"
else
if [ "$Lang" == 'fr' ]
then echo -n "Erreur : Plusieurs interfaces ont une passerelle par défaut ( "
else echo -n "Error : Several interfaces have a default gateway ( "
fi
echo "$GwListSorted" | tr "\n" " "
echo ")"
exit 1
fi
fi
if [ "$Lang" == 'fr' ]
248,36 → 259,34
fi
 
if [ -z "$INTIF" ]; then
interfacesList=$(/usr/sbin/ip -br link show | cut -d' ' -f1 | grep -v "^\(lo\|tun0\|$EXTIF\)\$")
interfacesCount=$(echo "$interfacesList" | wc -w)
if [ $interfacesCount -eq 0 ]; then
IntifListSorted=$(/usr/sbin/ip -br link show | cut -d' ' -f1 | grep -v "^\(lo\|tun0\|$EXTIF\)\$" | uniq | sort)
IntifCount=$(echo "$IntifListSorted" | wc -w)
if [ $IntifCount -eq 0 ]; then
if [ "$Lang" == 'fr' ]
then echo "Aucune interface de disponible pour le réseau interne"
else echo "No interface available for the internal network"
fi
exit 1
elif [ $interfacesCount -eq 1 ]; then
INTIF="$interfacesList"
elif [ $IntifCount -eq 1 ]; then
INTIF="$IntifListSorted"
else
interfacesSorted=$(/usr/sbin/ip -br addr | grep -v "^\(lo\|tun0\|$EXTIF\) " | sort -b -k3n -k2r -k1)
interfacePreferred=$(echo "$interfacesSorted" | head -1 | cut -d' ' -f1)
IntifPreferred=$(echo "$IntifListSorted" | head -1 | cut -d' ' -f1)
if [ "$Lang" == 'fr' ]
then echo 'Liste des interfaces disponible :'
else echo 'List of available interfaces:'
then echo 'Liste des interfaces disponibles pour le réseau interne :'
else echo 'List of available interfaces for internal network:'
fi
echo "$interfacesSorted"
echo "$IntifListSorted"
response=''
while true; do
if [ "$Lang" == 'fr' ]
then echo -n "Choix de l'interface interne ? [$interfacePreferred] "
else echo -n "Choice of internal interface ? [$interfacePreferred] "
then echo -n "Choix de l'interface interne ? [$IntifPreferred] "
else echo -n "Choice of internal interface ? [$IntifPreferred] "
fi
read response
[ -z "$response" ] && response="$IntifPreferred"
 
[ -z "$response" ] && response="$interfacePreferred"
 
# Check if interface exist
if [ "$(echo "$interfacesList" | grep -c "^$response\$")" -eq 1 ]; then
if [ "$(echo "$IntifListSorted" | grep -c "^$response\$")" -eq 1 ]; then
INTIF="$response"
break
else