#!/bin/bash
clear
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive

# Script designed to upgrade dependencies in PNETLab UBUNTU 18.04
# Requirement: You need to have UBUNTU 18.04
# CONSTANTS
GREEN='\033[32m'
RED='\033[31m'
NO_COLOR='\033[0m'
rm 5.3.*
URL_PNET_PNETLAB=https://drive.labhub.eu.org/0:/upgrades_pnetlab/bionic/stable/5.3.13.zip

lsb_release -r -s | grep -q 18.04
if [ $? -ne 0 ]; then
    echo -e "${RED}Upgrade has been rejected. You need to have UBUNTU 18.04 to use this script${NO_COLOR}"
    exit 0
fi
echo -e "${GREEN}backup labs from  /opt/unetlab/labs/ ${NO_COLOR}"
tar -czvf /root/labs-$(date +%Y%m%d%H%M).tgz /opt/unetlab/labs/
wget --content-disposition -q --show-progress $URL_PNET_PNETLAB
unzip 5.3.13.zip -d ./upgrade >/dev/null 2>&1
chmod 755 -R upgrade
find upgrade -type f -print0 | xargs -0 dos2unix 2>&1 >/dev/null 2>&1
./upgrade/upgrade
apt autoremove -y -q
apt autoclean -y -q
