Skip to content

Instantly share code, notes, and snippets.

@abhishek9686
Last active October 14, 2022 16:31
Show Gist options
  • Save abhishek9686/191eaf31c634b00bcc0e9da5dc8e8c5e to your computer and use it in GitHub Desktop.
Save abhishek9686/191eaf31c634b00bcc0e9da5dc8e8c5e to your computer and use it in GitHub Desktop.
Netmake v0.16.1 Upgrade Script
#!/bin/bash
# set -x
****** YOU CAN PASS YOUR OWN BASE DOMAIN AS ARGUMENT TO SCRIPT [ example: ./upgrade.sh nm.167-99-151-159.nip.io ] *******
docker-compose down
# get required files
wget https://github.com/mikefarah/yq/releases/download/v4.28.1/yq_linux_amd64 -O /usr/local/bin/yq && chmod +x /usr/local/bin/yq
wget -O /root/mosquitto.conf https://raw.githubusercontent.com/gravitl/netmaker/release_v0.16.1/docker/mosquitto.conf
wget -O /root/wait.sh https://raw.githubusercontent.com/gravitl/netmaker/release_v0.16.1/docker/wait.sh
chmod +x /root/wait.sh
NETMAKER_BASE_DOMAIN=${1}
if [[ -z ${NETMAKER_BASE_DOMAIN} ]]; then
NETMAKER_BASE_DOMAIN=nm.$(curl -s ifconfig.me | tr . -).nip.io
fi
# Update docker-compose.yml
## Netmaker service updates
yq -i '.services.netmaker.image = "gravitl/netmaker:v0.16.1"' /root/docker-compose.yml
MQ_ADMIN_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 64 ; echo '') yq -i '.services.netmaker.environment.MQ_ADMIN_PASSWORD = strenv(MQ_ADMIN_PASSWORD)' /root/docker-compose.yml
if yq -e '(.services.netmaker.volumes.[] | select(. == "shared_certs:/etc/netmaker"))' /root/docker-compose.yml; then
yq -i '(.services.netmaker.volumes.[] | select(. == "shared_certs:/etc/netmaker")) |= "mosquitto_data:/etc/netmaker"' /root/docker-compose.yml
else
yq -i '.services.netmaker.volumes += "mosquitto_data:/etc/netmaker"' /root/docker-compose.yml
fi
## MQ service updates
yq -i '.services.mq.command = ["/mosquitto/config/wait.sh"]' /root/docker-compose.yml
yq -i '.services.mq.environment.NETMAKER_SERVER_HOST = "https://api.NETMAKER_BASE_DOMAIN"' /root/docker-compose.yml
yq -i '.services.mq.volumes += "/root/wait.sh:/mosquitto/config/wait.sh"' /root/docker-compose.yml
yq -i 'del( .services.mq.volumes.[] | select(. == "shared_certs:/mosquitto/certs") )' /root/docker-compose.yml
yq -i '.services.mq.labels = ["traefik.enable=true","traefik.tcp.routers.mqtt.rule=HostSNI(`broker.NETMAKER_BASE_DOMAIN`)","traefik.tcp.routers.mqtt.tls.certresolver=http","traefik.tcp.services.mqtt.loadbalancer.server.port=8883","traefik.tcp.routers.mqtt.entrypoints=websecure"]' /root/docker-compose.yml
yq -i 'del( .volumes.shared_certs )' /root/docker-compose.yml
sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/docker-compose.yml
## Netmaker-Ui service updates
yq -i '.services.netmaker-ui.image = "gravitl/netmaker-ui:v0.16.1"' /root/docker-compose.yml
docker-compose up -d
@fersingb
Copy link

wget https://github.com/mikefarah/yq/releases/download/v4.28.1/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq

This should be changed for wget https://github.com/mikefarah/yq/releases/download/v4.28.1/yq_linux_amd64 -O /usr/local/bin/yq && chmod +x /usr/local/bin/yq, the current script would overwrite an existing yq binary managed by the package manager if already installed

Also the script should probably let the user specify the NETMAKER_BASE_DOMAIN value and not assume it's based on nip.io

@abhishek9686
Copy link
Author

wget https://github.com/mikefarah/yq/releases/download/v4.28.1/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq

This should be changed for wget https://github.com/mikefarah/yq/releases/download/v4.28.1/yq_linux_amd64 -O /usr/local/bin/yq && chmod +x /usr/local/bin/yq, the current script would overwrite an existing yq binary managed by the package manager if already installed

Also the script should probably let the user specify the NETMAKER_BASE_DOMAIN value and not assume it's based on nip.io

thanks for the feedback updated the script accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment