[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

interfaces und mapping script



Hallo,

ich habe für die Konfiguration meiner Netzwerkkarte ein
Mapping-Script geschrieben. Allerdings bin ich mit dem Ergebnis
nicht zufrieden. Da man wohl dem Script keine Parameter übergeben
kann, habe ich diese in diese als Kommentar in die darauf
folgende Zeile geschrieben.

--- cut /etc/network/interfaces ---
mapping eth0
    script /usr/local/bin/map-scheme
    # dhcp_normal dhcp_company dmz fixed1 fixed2 home home_wlan
...
--- end of cut ---

Im script wird die letzte Auswahl als "Preselection" übernommen.
Zu jedem der Auswahlpunkte gibt es noch einen kurzen Kommentar.
In ermangelung einer besseren Idee -- ich wollte _nur_ Daten in
die interfaces-Datei schreiben -- steht der Kommentar als
Nachfolger der iface-Zeile. So z.B.
iface dhcp_normal inet dhcp
    # get ip via dhcp


Hier mal das komplette Script
--- cut ---
#!/bin/bash

interfaces=/etc/network/interfaces
dialogfile=/tmp/dialog.$$
last_selection_file=/etc/network/.last-selection
timeout=30
width=70
items=`grep -E "[[:space:]]script[[:space:]]{1,}$0[[:space:]]*$" -m 1 -A 1 $interfaces | tail -n 1 | cut -d "#" -f 2-`
itemcount=`echo "$items" | wc -w`
height=$((itemcount + 6))
[ $height -gt 21 ] && height=21
preselect=`cat $last_selection_file 2> /dev/null`

echo "$items" | grep -q "\b$preselect\b"
if [ $? -eq 0 ]; then
    echo "--timeout $timeout --stdout --no-cancel \
        --radiolist \"Select interface config (timeout = $timeout seconds)\" \
        $height $width $itemcount " > $dialogfile
else
    echo "--stdout --no-cancel \
        --radiolist \"Select interface config\" \
        $height $width $itemcount " > $dialogfile
fi

for c in $items; do
    comment=`grep "^iface $c inet" -m 1 -A 1 $interfaces | tail -n 1 | cut -d "#" -f 2- | sed -e 's/^ *//g'`
    /bin/grep -q "^$c$" $last_selection_file > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo $c \"$comment\" on >> $dialogfile
    else
        echo $c \"$comment\" off >> $dialogfile
    fi
done

result=`/usr/bin/dialog --file $dialogfile 2> /dev/null`

result=`echo $result | sed -e 's/^"//' | sed -e 's/"$//'`
if [ -z $result ]; then result=$preselect; fi
echo $result > $last_selection_file
echo "$result"
rm $dialogfile
--- end ---

Bitte gebt mit Verbesserungsvorschläge.

Jörg

-- 
Jörg Schütter                      http://www.schuetter.org/joerg
joerg@schuetter.org                http://www.lug-untermain.de/



Reply to: