Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 76 lines (67 sloc) 1.5 KB
#! /bin/bash
die() {
echo "$*" >&2
exit 1
}
if (($# != 1)); then
echo "usage: $0 switchname" >&2
exit 1
fi
name="$1"
r="$(getent hosts "$name")" || die "$name: no ip address"
address=$(echo "$r"|awk '{print $1}')
fullname=$(echo "$r"|awk '{print $2}')
shortname=${fullname%.molgen.mpg.de}
now=$(date -u +%m%d%H%M%Y )
credentials="$(cat .credentials)" || exit 1
case "$name" in
delta-tn48m-poe-*)
ports=52
;;
ec-as5114-48x-*)
ports=48
;;
*)
die "$name: unknown switch type"
;;
esac
cat <<__EOF__
date -u $now
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
echo "$fullname" > /etc/hostname
cat >> /etc/network/interfaces<<EOF
auto ma1
iface ma1 inet static
address $address
netmask 255.255.0.0
gateway 172.20.0.1
dns-nameservers 141.14.16.1
EOF
ifup ma1
echo '$credentials' | chpasswd -e
echo "server time.molgen.mpg.de" >> /etc/ntp.conf
sed -i 's/^pool/#pool/' /etc/ntp.conf
update-rc.d -n ntp defaults
mkdir /var/molgen
cat > /var/molgen/setup.sh <<'EOF'
#! /bin/bash
ip link add br0 type bridge vlan_filtering 1
for i in \$(seq 1 $ports); do ip link set swp\$i master br0 up;done
brctl stp br0 on
test -e /var/molge/vlan.sh && /var/molge/vlan.sh
ip link set dev br0 up
EOF
chmod +x /var/molgen/setup.sh
cat > /etc/systemd/system/molgen.service <<'EOF'
[Unit]
After=network.target
[Service]
Type=oneshot
ExecStart=/var/molgen/setup.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
systemctl enable molgen
reboot
__EOF__