Súbor: [Platon] / scripts / shell / switchconfig / switchconfig (stiahnutie)
Revízia 1.1, Thu Mar 10 15:05:06 2005 UTC (19 years, 10 months ago) by rajo
New project switchconfig: change configuration of other services if you
travell between multiple networks. Networks are detected automaticaly,
you can easily configure detection alghoritmus.
|
#!/bin/sh
#
# /etc/init.d/switchconfig
#
# Overwrite configuration files for differend network setups
#
# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2004-2005 Platon SDG, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2004-09-15 - created
#
# $Platon$
SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
CONFDIR="/etc/switchconfig"
CONFFILE="/etc/default/switchconfig"
# required programs {{{
for prog in realpath basename dirname; do
if [ -z "`which $prog`" ]; then
echo "Required utility '$prog' not found, can't continue"
exit 1;
# else
# echo "$prog found, using `which $prog`"
fi
done
# cmd for sed:
TOLOWER="y/.-ABCDEFGHIJKLMNOPQRSTUVWXYZ/__abcdefghijklmnopqrstuvwxyz/"
# }}}
# read config file
if [ -f "$CONFFILE" ]; then
. $CONFFILE;
fi
start()
{ # {{{
echo -en "Autodetecting domain "
found="no"
for domain in $DOMAIN_ORDER; do
x_server=SERVER_`echo "$domain" | sed "$TOLOWER"`
server="${!x_server}"
echo -en "." # progressbar ;-)
[ -z "$server" ] && (echo; echo "Error: server for $domain not specified. Error in config file?"; )
ping -W 1 -c 1 -q $server >& /dev/null
if [ $? = '0' ]; then
found="yes"
echo "$domain ($server)";
break;
fi
done
if [ "$found" = "no" ]; then
echo " assuming default";
domain="_default";
fi
cd "$CONFDIR/$domain" || ( echo "Can't change to directory '$CONFDIR/$domain'"; exit 1; )
for file in `find . -type f -print | sed 's/^\.//g;'`; do
echo " Changing file '$file'"
rm -f "$file"
ln -s "$CONFDIR/$domain$file" "$file"
done
} # }}}
stop()
{ # {{{
echo stop
} # }}}
add_config()
{ # {{{
shift; # remove first param
for f in $*; do
echo "Looking for '$f'";
file=`realpath $f || echo $f`;
if [ ! -f "$file" ]; then
echo "File '$file' not found or is not a regular file."
exit 1;
fi
dirname=`dirname $file`
filename=`basename $file`
cd $CONFDIR;
for domain in *; do
[ ! -d $domain ] && continue # ignore files
echo "Found domain $domain ..."
mkdir -p $domain$dirname
echo " Copying file '$file' --> '$CONFDIR/$domain$dirname/$filename'"
cp $file $domain/$dirname/$filename
done
done
} # }}}
case "${1:-''}" in
'start')
start;
;;
'stop')
stop;
;;
add*)
add_config $*;
;;
'restart')
set +e; $SELF stop; set -e
$SELF start
;;
*)
echo "Usage: $SELF start|stop|restart|add"
exit 1
;;
esac
# vim600: fdm=marker fdl=0 fdc=3
Platon Group <platon@platon.sk> http://platon.sk/
|