Created
April 3, 2019 16:29
-
-
Save giovannicandido/b3cc1875205c45a977c20ba062fccd8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
upgrade() { | |
# Initial updates | |
apt update | |
apt upgrade -y | |
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade | |
apt install -y jq | |
apt install -y ipcalc | |
snap install yq | |
} | |
calculate_mask() { | |
MASK=`ipcalc -n 1.1.1.1 $1 | sed -n '/^Netm/{s#.*= #/#;s/ .*//p;q}'` | |
} | |
configure_private_ip() { | |
curl -o /tmp/metadata.json http://169.254.169.254/v1.json | |
PRIVATE_IP=`cat /tmp/metadata.json | jq '.interfaces[1].ipv4.address' -r` | |
NET_MASK=`cat /tmp/metadata.json | jq '.interfaces[1].ipv4.netmask' -r` | |
calculate_mask $NET_MASK | |
jq -n --arg ip_cidr "$PRIVATE_IP$MASK" '{"network": {"version": 2, "renderer": "networkd", "ethernets": {"ens7": {"dhcp4": "no", "mtu": 1450, "addresses": [$ip_cidr]}}}}' > /tmp/01-netcfg.json | |
cat /tmp/01-netcfg.json | yq r - > /etc/netplan/01-netcfg.yaml | |
netplan apply | |
} | |
upgrade | |
configure_private_ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upgrade the system and configures private network with the vultr api. You can see the ip in the settings tab of your server.
It may take a few minutes to finish the upgrade