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 89 lines (75 sloc) 1.65 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
mv /etc/systemd/network/oob.network /etc/systemd/network/oob.network.REPLICA
cat >/etc/systemd/network/oob.network <<EOF
[Match]
Name=oob0
[Network]
Address=$address/16
Gateway=172.20.0.1
DNS=141.14.16.1
NTP=141.14.16.215
EOF
mv /etc/systemd/network/swbridge.network /etc/systemd/network/swbridge.network.REPLICA
cat >/etc/systemd/network/swbridge.network <<EOF
[Match]
Name=swbridge
EOF
mv /etc/systemd/network/swbridge.netdev /etc/systemd/network/swbridge.netdev.REPLICA
cat >/etc/systemd/network/swbridge.netdev <<EOF
[NetDev]
Name=swbridge
Kind=bridge
[Bridge]
STP=true
VLANFiltering=true
EOF
echo '$credentials' | chpasswd -e
mkdir /var/molgen
cat > /var/molgen/setup.sh <<'EOF'
#! /bin/bash
test -e /var/molgen/vlan.sh && /var/molgen/vlan.sh || true
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__