Permalink
Cannot retrieve contributors at this time
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?
switchdev/create-setup.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
80 lines (70 sloc)
1.68 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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-* | ec-as4224-52p-* ) | |
ports=52 | |
;; | |
delta-tn4810m-* | 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 lo | |
iface lo inet loopback | |
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 | |
mkdir .ssh | |
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICt7f+MZnko5X/g8kWskjcRBDxv1wSElcJYJ59TPV/o4 switchdev@wtf.molgen.mpg.de" > .ssh/authorized_keys | |
sed -i 's/^pool/#pool/' /etc/ntp.conf | |
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/molgen/vlan.sh && /var/molgen/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__ |