Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
becki:sources:sbreconfig [2008-11-18 12:22] becki |
becki:sources:sbreconfig [2011-03-20 14:12] (aktuell) becki |
||
|---|---|---|---|
| Zeile 41: | Zeile 41: | ||
| <code bash> | <code bash> | ||
| - | #!/bin/bash | + | #!/bin/bash |
| - | # /etc/sbreconfig/network | + | # /etc/sbreconfig/network |
| - | # List of allowed configurations. This corresponds to the extensions of the | + | # "public" is meant to access an open public wlan without password |
| - | # config template files | + | # With "public" only dflt shall be used |
| - | conflist='home office' | + | # For access to a new wpa encrypted WLAN, it is only necessary to create a |
| - | + | # wpa_supplicant.conf.<newname> file. Everything else shall be .dflt | |
| - | # List of configuration files to be manipulated | + | |
| - | filelist='/etc/wpa_supplicant.conf /etc/rc.d/rc.inet1.conf /etc/HOSTNAME /etc/hosts /etc/networks /etc/resolv.conf' | + | # List of allowed configurations. This corresponds to the extensions of the |
| - | + | # config template files | |
| - | # optional: What to do before copying the files: | + | conflist='public home.wired home.wlan office' |
| - | dobefore='' | + | |
| - | + | # List of configuration files to be manipulated | |
| - | # optional: What to do after copying the files: | + | filelist='/etc/wpa_supplicant.conf /etc/rc.d/rc.inet1.conf /etc/HOSTNAME /etc/hosts /etc/networks /etc/resolv.conf' |
| + | |||
| + | # optional: What to do before copying the files: | ||
| + | dobefore='' | ||
| + | |||
| + | # optional: What to do after copying the files: | ||
| doafter='/etc/rc.d/rc.inet1 restart' # restart the network to apply the changes | doafter='/etc/rc.d/rc.inet1 restart' # restart the network to apply the changes | ||
| </code> | </code> | ||
| Zeile 67: | Zeile 72: | ||
| ===== Source == | ===== Source == | ||
| - | <code bash> | + | FIXME |
| - | #!/bin/bash | + | |
| - | # A adjustable configuration switcher | + | |
| - | # This script can be used to switch between several different | + | |
| - | # preconfigured settings. | + | |
| - | # Use it for example to quickly adjust the network settings of your notebook | + | |
| - | # for office or home use. | + | |
| - | # More info at http://wiki.think-deep.com/becki:sources:sbreconfig | + | |
| - | function usage() { | ||
| - | if [ "$2" ]; then echo -e "ERROR: $2!"; fi | ||
| - | echo "Usage: $(basename $0) filelistfile configname" | ||
| - | echo "Look at http://wiki.think-deep.com/becki:sources:sbreconfig for more info" | ||
| - | exit $1 | ||
| - | } | ||
| - | |||
| - | instructions=$1 | ||
| - | configuration=$2 | ||
| - | |||
| - | # Check if instructions file is ok: | ||
| - | if [ ! "$instructions" ]; then | ||
| - | usage 1 "No filelist file specified" | ||
| - | fi | ||
| - | instructions="/etc/sbreconfig/$instructions" | ||
| - | if [ ! -r "$instructions" ]; then | ||
| - | usage 2 "Cant read \"$instructions\"" | ||
| - | fi | ||
| - | . $instructions | ||
| - | if [ ! "$filelist" ]; then | ||
| - | usage 3 "Filelist in filelistfile missing" | ||
| - | fi | ||
| - | |||
| - | # Check if configuration identifier is given in the command line: | ||
| - | if [ ! "$configuration" ]; then | ||
| - | #echo "filelist: $filelist" | ||
| - | usage 4 "Configuration name is missing" | ||
| - | fi | ||
| - | |||
| - | # Check if given configuration identifier is allowed: | ||
| - | err=1 | ||
| - | for conf in $conflist; do | ||
| - | if [ "$conf" == "$configuration" ]; then | ||
| - | err=0 | ||
| - | break | ||
| - | fi | ||
| - | done | ||
| - | if (( $err )); then | ||
| - | usage 6 "Configuration \"$configuration\" is not allowed.\nAllowed configurations are: \"$conflist\"" | ||
| - | fi | ||
| - | |||
| - | # Check if all configuration file templates are present: | ||
| - | err=0 | ||
| - | for cfile in $filelist; do | ||
| - | if [ ! -r "$cfile.$configuration" ]; then | ||
| - | if [ -r "$cfile.dflt" ]; then | ||
| - | echo "HINT: $cfile.$configuration not found, using $cfile.dflt" | ||
| - | else | ||
| - | echo "ERROR: Neighter $cfile.$configuration nor $cfile.dflt found!" | ||
| - | err=1 | ||
| - | fi | ||
| - | fi | ||
| - | done | ||
| - | if (( $err )); then usage 5; fi | ||
| - | |||
| - | # Do the work: | ||
| - | eval $dobefore | ||
| - | for cfile in $filelist ; do | ||
| - | if [ -r "$cfile.$configuration" ]; then | ||
| - | cp $cfile.$configuration $cfile | ||
| - | else | ||
| - | cp $cfile.dflt $cfile | ||
| - | fi | ||
| - | done | ||
| - | eval $doafter | ||
| - | </code> | ||