346 lines
15 KiB
Bash
Executable File
346 lines
15 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function usage() {
|
|
if [ -n "$1" ];then
|
|
echo -e "\nError: $1"
|
|
fi
|
|
|
|
cat<<EOF
|
|
|
|
Usage: `basename $0` -h <remote host> -u <remote user> <network-name>
|
|
|
|
Example: `basename $0` -h wf.oopen.de -u chris WF
|
|
|
|
network-name possible values are:
|
|
|
|
NONE-WF
|
|
NONE-CKUBU
|
|
|
|
AKB
|
|
ANW-URB
|
|
ANW-KM
|
|
B3-Bornim
|
|
CKUBU
|
|
FLR-BRB
|
|
GA-AL
|
|
GA-Ersatz
|
|
GA-NH
|
|
GA-Schloss
|
|
JONAS
|
|
Kanzlei-Kiel
|
|
MBR
|
|
OOLM
|
|
OPP
|
|
ReachOut
|
|
SPR-BE
|
|
WF
|
|
|
|
EOF
|
|
exit
|
|
|
|
}
|
|
|
|
while getopts h:u: opt ; do
|
|
case $opt in
|
|
h) remote_host="$OPTARG"
|
|
;;
|
|
u) remote_user="$OPTARG"
|
|
;;
|
|
*) usage
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$remote_host" ]; then
|
|
usage "Remote host not given"
|
|
fi
|
|
if [ -z "$remote_user" ]; then
|
|
usage "Remote host not given"
|
|
fi
|
|
|
|
shift `expr $OPTIND - 1`
|
|
|
|
[ $# -ne "1" ] && usage "wrong number of arguments"
|
|
|
|
_network=$1
|
|
|
|
office_base_dir=$HOME/Office_Networks
|
|
office_dir=${office_base_dir}/${_network}
|
|
|
|
mkdir -p $office_dir
|
|
cd $office_dir
|
|
|
|
|
|
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/bind_${_network}.tar.gz .
|
|
gunzip < bind_${_network}.tar.gz | tar -xpf -
|
|
rm -f bind_${_network}.tar.gz
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/openvpn_${_network}.tar.gz" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/openvpn_${_network}.tar.gz .
|
|
gunzip < openvpn_${_network}.tar.gz | tar -xpf -
|
|
rm -f openvpn_${_network}.tar.gz
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/root-dot-opennvpndir_${_network}.tar.gz" ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/root-dot-opennvpndir_${_network}.tar.gz .
|
|
gunzip < root-dot-opennvpndir_${_network}.tar.gz | tar -xpf -
|
|
rm -f root-dot-opennvpndir_${_network}.tar.gz
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/ddclient.conf.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ddclient.conf.${_network} .
|
|
fi
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/dhcpd.conf.${_network} .
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/dhcpd6.conf.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/dhcpd6.conf.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/isc-dhcp6-server.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/isc-dhcp6-server.${_network} .
|
|
fi
|
|
|
|
# - DSL PPP
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/dsl-provider.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/dsl-provider.${_network} .
|
|
fi
|
|
_network_name=`echo $_network | tr '[:upper:]' '[:lower:]'`
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/dsl-${_network_name}.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/dsl-${_network_name}.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/pap-secrets.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/pap-secrets.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/chap-secrets.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/chap-secrets.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/email_notice.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/email_notice.${_network} .
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/generic.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/generic.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/generic.db.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/sasl_passwd.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/sasl_passwd.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/sasl_passwd.db.${_network} .
|
|
fi
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/mailname.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/main.cf.${_network} .
|
|
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/hostname.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/hosts.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/interfaces.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/rc.local.${_network} .
|
|
|
|
# - Firewall
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ipt-firewall.service.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ipt-firewall.service.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ipt-firewall-gateway.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ipt-firewall-gateway.conf.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ip6t-firewall.service.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ip6t-firewall.service.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ip6t-firewall-gateway.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ip6t-firewall-gateway.conf.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ipt-firewall.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ipt-firewall.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/ip6t-firewall.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/ip6t-firewall.${_network} .
|
|
fi
|
|
|
|
# - Check Script Onlinestatus
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/check_net.service.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/check_net.service.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/check_net.sh.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/netconfig.sh.${_network} .
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/check_net.conf.${_network} .
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/check_net-logrotate.${_network}" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/check_net-logrotate.${_network} .
|
|
fi
|
|
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/resolv.conf.${_network} .
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/cron_root.${_network} ];then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/cron_root.${_network} .
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/igmpproxy.conf.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/igmpproxy.conf.${_network} .
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/aiccu.conf.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/aiccu.conf.${_network} .
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/aiccu.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/aiccu.${_network} .
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/radvd.conf.${_network} ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/radvd.conf.${_network} .
|
|
fi
|
|
|
|
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/bind_${_network}.tar.gz"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/openvpn_${_network}.tar.gz"
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/root-dot-opennvpndir_${_network}.tar.gz ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/root-dot-opennvpndir_${_network}.tar.gz"
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/ddclient.conf.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ddclient.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/dhcpd.conf.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/dhcpd.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/dhcpd6.conf.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/dhcpd6.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/isc-dhcp6-server.${_network}" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/isc-dhcp6-server.${_network}"
|
|
fi
|
|
|
|
# - DSL PPP
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/dsl-provider.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/dsl-provider.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/dsl-${_network_name}.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/dsl-${_network_name}.${_network}"
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/pap-secrets.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/pap-secrets.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/chap-secrets.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/chap-secrets.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/email_notice.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/email_notice.${_network}"
|
|
fi
|
|
|
|
# - Postfix
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/generic.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/generic.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/generic.db.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/sasl_passwd.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/sasl_passwd.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/sasl_passwd.db.${_network}"
|
|
fi
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/mailname.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/main.cf.${_network}"
|
|
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/hostname.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/hosts.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/interfaces.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/rc.local.${_network}"
|
|
|
|
# - Firewall
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ipt-firewall.service.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ipt-firewall.service.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ipt-firewall-gateway.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ipt-firewall-gateway.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ip6t-firewall.service.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ip6t-firewall.service.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ip6t-firewall-gateway.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ip6t-firewall-gateway.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ipt-firewall.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ipt-firewall.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/ip6t-firewall.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ip6t-firewall.${_network}"
|
|
fi
|
|
|
|
# - Check Script Onlinestatus
|
|
# -
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/check_net.service.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/check_net.service.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/check_net.sh.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/netconfig.sh.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/check_net.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/check_net-logrotate.${_network}" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/check_net-logrotate.${_network}"
|
|
fi
|
|
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/resolv.conf.${_network}"
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/cron_root.${_network} ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/cron_root.${_network}"
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/igmpproxy.conf.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/igmpproxy.conf.${_network}"
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/aiccu.conf.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/aiccu.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/aiccu.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/aiccu.${_network}"
|
|
fi
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/radvd.conf.${_network} ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/radvd.conf.${_network}"
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF > $office_dir/README.txt
|
|
|
|
Notice:
|
|
You have to change some configuration files becaus the because
|
|
the configuration of network interfaces must not be equal.
|
|
|
|
For the backup gateway host:
|
|
eth1 --> LAN
|
|
eth2 --> WAN or ppp0 (DSL device)
|
|
|
|
eth0 --> WLAN or second LAN or what ever
|
|
or
|
|
br0 --> WLAN or second LAN or what ever
|
|
|
|
|
|
So you have to change the following files
|
|
dsl-provider.${_network}: ppp0 comes over eth2
|
|
interfaces.${_network}: see above
|
|
ipt-firewall.${_network}: LAN device (mostly $local_if_1) = eth1
|
|
second LAN WLAN or what ever (if present) = eth0
|
|
|
|
EOF
|
|
|
|
cat $office_dir/README.txt
|
|
|
|
#rm /tmp/README$$
|
|
|
|
exit 0
|
|
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/"
|
|
fi
|