Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung | |||
becki:sources:sbreconfig [2009-12-27 19:16] becki |
becki:sources:sbreconfig [2011-03-20 14:12] (aktuell) becki |
||
---|---|---|---|
Zeile 72: | 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> |