464 lines
14 KiB
Bash
Executable File
464 lines
14 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
|
|
|
|
123
|
|
AK
|
|
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
|
|
|
|
}
|
|
|
|
manage_files() {
|
|
|
|
for file in $* ; do
|
|
if ssh -l $remote_user ${remote_host} [ -f ${_network}-config/$file ] ; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/$file .
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/$file"
|
|
fi
|
|
done
|
|
|
|
}
|
|
|
|
manage_archives() {
|
|
for archive in $* ; do
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/$archive" ]; then
|
|
scp -o User=$remote_user ${remote_host}:${_network}-config/$archive .
|
|
gunzip < $archive | tar -xpf -
|
|
rm -f $archive
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/$archive"
|
|
fi
|
|
done
|
|
}
|
|
|
|
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
|
|
|
|
# - Nameserver Bind
|
|
# - /etc/bind/*
|
|
# -
|
|
manage_archives bind_${_network}.tar.gz
|
|
|
|
# - OpenVPN:
|
|
# - /etc/openvpn/*
|
|
# -
|
|
# - /root/.openvpn
|
|
# -
|
|
archives="openvpn_${_network}.tar.gz
|
|
root-dot-opennvpndir_${_network}.tar.gz"
|
|
manage_archives $archives
|
|
|
|
# - DynDNS
|
|
# -
|
|
# - /etc/ddclient.conf
|
|
# -
|
|
manage_files ddclient.conf.${_network}
|
|
|
|
# - DHCP Server
|
|
# -
|
|
# - /etc/dhcp/dhcpd.conf - /etc/dhcp3/dhcpd.conf
|
|
# - /etc/dhcp/dhcpd6.conf - /etc/dhcp3/dhcpd6.conf
|
|
# -
|
|
# - hosts.lan.conf # dhcp failover kanzlei kiel
|
|
# - hosts.w-lan.conf # dhcp failover kanzlei kiel
|
|
# -
|
|
# - /etc/init.d/isc-dhcp6-server
|
|
# -
|
|
files="dhcpd.conf.${_network}
|
|
dhcpd6.conf.${_network}
|
|
isc-dhcp6-server.${_network}
|
|
hosts.lan.conf.${_network}
|
|
hosts.w-lan.conf.${_network}
|
|
default_isc-dhcp-server.${_network}"
|
|
manage_files "$files"
|
|
|
|
# - DSL PPP
|
|
# -
|
|
# - /etc/ppp/peers/*
|
|
# -
|
|
# - /etc/ppp/pap-secrets
|
|
# - /etc/ppp/chap-secrets
|
|
# -
|
|
# - /etc/ppp/ip-up.d/email_notice
|
|
# -
|
|
manage_files pap-secrets.${_network} chap-secrets.${_network} email_notice.${_network}
|
|
manage_archives etc_ppp_peers_${_network}.tar.gz
|
|
|
|
# - Postfix SMTP
|
|
# -
|
|
# - /etc/postfix/main.cf
|
|
# - /etc/mailname
|
|
# - /etc/postfix/generic
|
|
# - /etc/postfix/generic.db
|
|
# - /etc/postfix/sasl_passwd
|
|
# - /etc/postfix/sasl_passwd.db
|
|
# -
|
|
files="main.cf.${_network}
|
|
mailname.${_network}
|
|
sasl_passwd.${_network}
|
|
sasl_passwd.db.${_network}
|
|
generic.${_network}
|
|
generic.db.${_network}"
|
|
manage_files $files
|
|
|
|
# - Netzwerk:
|
|
# - /etc/hostname
|
|
# - /etc/hosts
|
|
# - /etc/network/interfaces
|
|
# - /etc/resolv.conf
|
|
files="hostname.${_network}
|
|
hosts.${_network}
|
|
interfaces.${_network}
|
|
resolv.conf.${_network}
|
|
hostapd.conf.${_network}"
|
|
manage_files $files
|
|
|
|
|
|
# - /root/bin directory
|
|
# -
|
|
manage_archives root_bin_${_network}.tar.gz
|
|
|
|
|
|
# - /usr/local/src directory
|
|
# -
|
|
manage_archives usr_local_src_${_network}.tar.gz
|
|
|
|
|
|
# - /usr/local/sbin directory
|
|
# -
|
|
manage_archives usr_local_sbin_${_network}.tar.gz
|
|
|
|
|
|
# - Firewall
|
|
# -
|
|
# - /etc/systemd/system/ipt-firewall.service
|
|
# - /etc/systemd/system/ip6t-firewall.service
|
|
# -
|
|
# - /etc/init.d/ipt-firewall
|
|
# - /etc/init.d/ipt-firewall
|
|
# -
|
|
# - /etc/ipt-firewall/*
|
|
# -
|
|
manage_archives etc_ipt-firewall_${_network}.tar.gz
|
|
files="ipt-firewall.service.${_network}
|
|
ip6t-firewall.service.${_network}
|
|
ipt-firewall.${_network}
|
|
ip6t-firewall.${_network}
|
|
ipt-firewall-gateway.${_network}
|
|
ip6t-firewall-gateway.${_network}"
|
|
manage_files $files
|
|
|
|
|
|
# - Check Script Onlinestatus
|
|
# -
|
|
# - /etc/systemd/system/check_net.service
|
|
# -
|
|
# - /usr/local/sbin/check_net.sh
|
|
# - /usr/local/sbin/netconfig.sh
|
|
# -
|
|
# - /etc/check_net/*
|
|
# -
|
|
# - /etc/logrotate.d/check_net
|
|
# -
|
|
manage_archives etc_check_net_${_network}.tar.gz
|
|
files="check_net.service.${_network}
|
|
check_net-logrotate.${_network}"
|
|
manage_files $files
|
|
|
|
|
|
# - Other
|
|
# -
|
|
# - /etc/rc.local
|
|
# - /var/spool/cron/crontabs/root
|
|
# - /usr/local/igmpproxy/etc/igmpproxy.conf
|
|
# - /etc/aiccu.conf
|
|
# - /etc/default/aiccu
|
|
# - /etc/radvd.conf
|
|
# -
|
|
files="rc.local.${_network}
|
|
cron_root.${_network}
|
|
igmpproxy.conf.${_network}
|
|
aiccu.conf.${_network}
|
|
aiccu.${_network}
|
|
radvd.conf.${_network}"
|
|
manage_files $files
|
|
|
|
|
|
|
|
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.
|
|
|
|
!! Take care, to use the right device names !!
|
|
Maybe they are called i.e. 'enp0sXX', but you can rename it.
|
|
See also : README.rename.netdevices
|
|
|
|
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
|
|
default_isc-dhcp-server.${_network}
|
|
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
|
|
|
|
# ---
|
|
# - Delete remote files
|
|
# ----
|
|
|
|
# - Bind
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/bind_${_network}.tar.gz" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/bind_${_network}.tar.gz"
|
|
fi
|
|
|
|
# - OpenVPN
|
|
# -
|
|
#if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/openvpn_${_network}.tar.gz" ]; then
|
|
# ssh -l $remote_user ${remote_host} "rm ${_network}-config/openvpn_${_network}.tar.gz"
|
|
#fi
|
|
#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
|
|
|
|
# - DynDNS
|
|
# -
|
|
#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
|
|
|
|
# - DHCP Server
|
|
# -
|
|
|
|
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
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/hosts.lan.conf.${_network}" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/hosts.lan.conf.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/hosts.w-lan.conf.${_network}" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/hosts.w-lan.conf.${_network}"
|
|
fi
|
|
|
|
# - DSL PPP
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/etc_ppp_peers_${_network}.tar.gz" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/etc_ppp_peers_${_network}.tar.gz"
|
|
fi
|
|
#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
|
|
# -
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/main.cf.${_network}"
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/mailname.${_network}"
|
|
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
|
|
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
|
|
|
|
# - Netzwerk
|
|
# -
|
|
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/resolv.conf.${_network}"
|
|
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/rc.local.${_network}"
|
|
|
|
# - /root/bin directory
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/root_bin_${_network}.tar.gz" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/root_bin_${_network}.tar.gz"
|
|
fi
|
|
|
|
# - /usr/local/src directory
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/usr_local_src_${_network}.tar.gz" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/usr_local_src_${_network}.tar.gz"
|
|
fi
|
|
|
|
# - /usr/local/sbin directory
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/usr_local_sbin_${_network}.tar.gz" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/usr_local_sbin_${_network}.tar.gz"
|
|
fi
|
|
|
|
# - Firewall
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/etc_ipt-firewall_${_network}.tar.gz" ] ; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/etc_ipt-firewall_${_network}.tar.gz"
|
|
fi
|
|
|
|
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}"
|
|
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}"
|
|
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
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ipt-firewall-gateway.${_network}" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ipt-firewall-gateway.${_network}"
|
|
fi
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/ip6t-firewall-gateway.${_network}" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/ipt-firewall-gateway.${_network}"
|
|
fi
|
|
|
|
# - Check Script Onlinestatus
|
|
# -
|
|
if ssh -l $remote_user ${remote_host} [ -f "${_network}-config/etc_check_net_${_network}.tar.gz" ]; then
|
|
ssh -l $remote_user ${remote_host} "rm ${_network}-config/etc_check_net_${_network}.tar.gz"
|
|
fi
|
|
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}"
|
|
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
|
|
|
|
# - Other
|
|
# -
|
|
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
|
|
|
|
# ----------
|
|
|
|
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
|