Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Version 002 - Altered by ph4ntom74 - 11th December 2023.
- # Still needs to add "alien" to convert .deb to .rpm packages.
- # The idea is t,o have a script to install pnetlab on an Tumbleweed
- # desktop without the need of VMware Workstation. Maybe its a stupid
- # idea but hey, I'm not a coder.
- # Open debugging output
- exec > >(tee -i /tmp/pnet_install.log) 2>&1
- set -x
- clear
- export LC_ALL=C
- # upgrade dependencies in PNETLab OpenSUSE Tumbleweed
- # Requirement: You need to have OpenSUSE Tumbleweed
- # CONSTANTS
- GREEN='\033[32m'
- RED='\033[31m'
- NO_COLOR='\033[0m'
- KERNEL=pnetlab_kernel.zip
- zypper --non-interactive refresh
- # Download the selected packages & unpack them in /tmp/
- # Fetch & unzip pnetlab_kernel
- KERNEL_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/L/linux-5.17.15-pnetlab-uksm/pnetlab_kernel.zip"
- curl -L -o /tmp/pnetlab_kernel.zip "$KERNEL_URL"
- unzip /tmp/pnetlab_kernel.zip -d /tmp/
- # Fetch & unzip pre-docker
- PRE_DOCKER_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/D/pre-docker.zip"
- curl -L -o /tmp/pre-docker.zip "$PRE_DOCKER_URL"
- unzip /tmp/pre-docker.zip -d /tmp/
- # Fetch & unzip pnet_guacamole
- PNET_GUACAMOLE_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_GUACAMOLE/pnetlab-guacamole_6.0.0-7_amd64.deb"
- curl -L -o /tmp/pnetlab-guacamole_6.0.0-7_amd64.deb "$PNET_GUACAMOLE"
- unzip /tmp/pnetlab-guacamole_6.0.0-7_amd64.deb -d /tmp/
- # Fetch & unzip pnet_dynamips
- PNET_DYNAMIPS_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_DYNAMIPS/pnetlab-dynamips_6.0.0-30_amd64.deb"
- curl -L -o /tmp/pnetlab-dynamips_6.0.0-30_amd64.deb "$PNET_DYNAMIPS_URL"
- unzip /tmp/pnetlab-dynamips_6.0.0-30_amd64.deb -d /tmp/
- # Fetch & unzip pnet_schema
- PNET_SCHEMA_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_SCHEMA/pnetlab-schema_6.0.0-30_amd64.deb"
- curl -L -o /tmp/pnetlab-schema_6.0.0-30_amd64.deb "$PNET_SCHEMA_URL"
- unzip /tmp/pnetlab-schema_6.0.0-30_amd64.deb -d /tmp/
- # Fetch & unzip pnet_vpc
- PNET_VPC_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_VPC/pnetlab-vpcs_6.0.0-30_amd64.deb"
- curl -L -o /tmp/pnetlab-vpcs_6.0.0-30_amd64.deb "$PNET_VPC_URL"
- unzip /tmp/pnetlab-vpcs_6.0.0-30_amd64.deb -d /tmp/
- # Fetch & unzip pnet_qemu
- PNET_QEMU_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_QEMU/pnetlab-qemu_6.0.0-30_amd64.deb"
- curl -L -o /tmp/pnetlab-qemu_6.0.0-30_amd64.deb "$PNET_QEMU_URL"
- unzip /tmp/pnetlab-qemu_6.0.0-30_amd64.deb -d /tmp/
- # Fetch & unzip pnet_docker
- PNET_DOCKER_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_DOCKER/pnetlab-docker_6.0.0-30_amd64.deb"
- curl -L -o /tmp/pnetlab-docker_6.0.0-30_amd64.deb "$PNET_DOCKER_URL"
- unzip /tmp/pnetlab-docker_6.0.0-30_amd64.deb -d /tmp/
- # Fetch & unzip pnet_lab
- PNET_PNETLAB_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_PNETLAB/pnetlab_6.0.0-100_amd64.deb"
- curl -L -o /tmp/pnetlab_6.0.0-100_amd64.deb "$PNET_PNETLAB_URL"
- unzip /tmp/pnetlab_6.0.0-100_amd64.deb -d /tmp/
- # Fetch & unzip pnet_wireshark
- PNET_WIRESHARK_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/P/PNET_WIRESHARK/pnetlab-wireshark_6.0.0-30_amd64.deb"
- curl -L -o /tmp/pnetlab-wireshark_6.0.0-30_amd64.deb "$PNET_WIRESHARK_URL"
- unzip /tmp/pnetlab-wireshark_6.0.0-30_amd64.deb -d /tmp/
- # Fetch & unzip pnet_tpm
- PNET_TPM_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/T/swtpm-focal.zip"
- curl -L -o /tmp/swtpm-focal.zip "$PNET_TPM_URL"
- unzip /tmp/swtpm-focal.zip -d /tmp/
- grep -q "Tumbleweed" /etc/os-release
- if [ $? -ne 0 ]; then
- echo -e "${RED}Upgrade has been rejected. You need to have OpenSUSE Tumbleweed to use this script${NO_COLOR}"
- exit 0
- fi
- # Azure disk tuning function
- azure_disk_tune() {
- ls -l /dev/disk/by-id/ | grep -q sdc && (
- echo o # Create a new empty DOS partition table
- echo n # Add a new partition
- echo p # Primary partition
- echo 1 # Partition number
- echo # First sector (Accept default: 1)
- echo # Last sector (Accept default: varies)
- echo w # Write changes
- ) | sudo fdisk /dev/sdc && (
- mke2fs -F /dev/sdc1
- echo "/dev/sdc1 /opt ext4 defaults,discard 0 0 " >> /etc/fstab
- mount /opt
- )
- }
- # Check if on Azure and apply disk tuning
- uname -r | grep -q "azure"
- if [ $? -eq 0 ]; then
- azure_disk_tune
- fi
- zypper update -y
- # Permit root access from SSH
- sed -i -e "s/.*PermitRootLogin .*/PermitRootLogin yes/" /etc/ssh/sshd_config
- # Install required packages
- zypper install -y resolvconf libnet-pcap-perl duc libspice-client-glib-2.0-8 libtinfo5 libncurses5 libncursesw5 php7-pear php7-devel ntpdate vim dos2unix apache2 bridge-utils patterns-devel-C-C++-devel_C_C++ build-essential cpulimit debconf-utils dialog dmidecode genisoimage iptables lib32gcc1 lib32z1 pastebinit php7-gd php7-mysql php7-xml libc6 libc6-i386 libelf1 libpcap0_1 libsdl1_2debian libstdc++6 logrotate lsb-release lvm2 ntp php7-ctype php7-dom php7-json php7-mbstring php7-pdo php7-posix php7-tokenizer php7-zip php7-xmlwriter php7-xmlreader python3-pexpect sqlite3 tcpdump telnet uml-utilities zip libguestfs-tools cgroup-tools libyaml-0-2 php7-curl php7-mbstring net-tools php7-zip python2 libapache2-mod_php7 mysql-server libavcodec58 libavformat58 libavutil56 libswscale5 libfreerdp-client2-2 libfreerdp-server2-2 libfreerdp-shadow-subsystem2-2 libfreerdp-shadow2-2 libfreerdp2-2 winpr-utils gir1_2-pango-1_0 libpango-1_0-0 libpangocairo-1_0-0 libpangoft2-1_0-0 libpangoxft-1_0-0 pango1_0-tools pkg-config libssh2-1 libtelnet2 libvncclient1 libvncserver1 libwebsockets15 libpulse0 libpulse-mainloop-glib0 libssl1_1 libvorbis0a libvorbisenc2 libvorbisfile3 libwebp6 libwebpmux3 libwebpdemux2 libcairo2 libcairo-gobject2 libcairo-script-interpreter2 libjpeg62 libpng16-16 libtool libuuid1 libossp-uuid16 default-jdk default-jdk-headless lsb-release rsync sshpass autossh php7-cli php7-imagick php7-mysql php7-sqlite3 plymouth-label python3-pexpect sqlite3 tcpdump telnet tomcat tomcat-admin-webapps tomcat-webapps libaio1 libasound2 libbrlapi0_7 libc6 libcacard0 libepoxy0 libfdt1 libgbm1 libgcc_s1 libglib2_0-0 libgnutls30 libibverbs1 libjpeg8 libncursesw6 libnettle7 libnuma1 libpixman-1-0 libpmem1 libpng16-16 librdmacm1 libsasl2-2 libseccomp2 libslirp0 libspice-server1 libtinfo6 libusb-1_0-0 libusbredirparser1 libvirglrenderer1 zlib1g qemu-system-common libseccomp2 qemu-system-data ipxe-qemu-256k-compat-efi-roms seabios ipxe-qemu udhcpd busybox libsdl2-2_0-0 libxenmisc4_11 libcapstone3 libvdeplug2 libnfs13 ovmf
- zypper remove -y docker containerd runc php8*
- echo -e "${GREEN}Downloading PNETLAB PACKAGES...${NO_COLOR}"
- rm -rf /tmp/*
- cd /tmp
- echo -e "${GREEN}Download Packages${NO_COLOR}"
- # Download and install the kernel if not already installed
- rpm -q kernel-default-5.17.15-pnetlab-uksm
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_KERNEL
- unzip /tmp/$KERNEL
- rpm -Uvh /tmp/pnetlab_kernel/*.rpm
- fi
- # Download and install pre-docker
- rpm -q pnetlab-pre-docker
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PRE_DOCKER
- unzip /tmp/pre-docker.zip
- rpm -Uvh /tmp/pre-docker/*.rpm
- fi
- # Download and install swtpm
- rpm -q swtpm-focal
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_TPM
- unzip /tmp/swtpm-focal.zip
- rpm -Uvh /tmp/swtpm-focal/*.rpm
- fi
- # Download and install pnetlab-docker
- rpm -q pnetlab-docker
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_DOCKER
- rpm -Uvh /tmp/pnetlab-docker_*.rpm
- fi
- # Download and install pnetlab-schema
- rpm -q pnetlab-schema
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_SCHEMA
- rpm -Uvh /tmp/pnetlab-schema_*.rpm
- fi
- # Download and install pnetlab-guacamole
- rpm -q pnetlab-guacamole
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_GUACAMOLE
- rpm -Uvh /tmp/pnetlab-guacamole_*.rpm
- fi
- # Download and install pnetlab-vpcs
- rpm -q pnetlab-vpcs
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_VPC
- rpm -Uvh /tmp/pnetlab-vpcs_*.rpm
- fi
- # Download and install pnetlab-dynamips
- rpm -q pnetlab-dynamips
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_DYNAMIPS
- rpm -Uvh /tmp/pnetlab-dynamips_*.rpm
- fi
- # Download and install pnetlab-wireshark
- rpm -q pnetlab-wireshark
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_WIRESHARK
- rpm -Uvh pnetlab-wireshark_6.0.0-30_amd64.rpm
- fi
- # Download and install pnetlab-qemu
- rpm -q pnetlab-qemu
- if [ $? -ne 0 ]; then
- wget --quiet --show-progress $URL_PNET_QEMU
- rpm -Uvh /tmp/pnetlab-qemu_*.rpm
- fi
- # Ensure the hosts file contains the necessary entry
- grep -q "127.0.1.1 pnetlab.example.com pnetlab" /etc/hosts || echo "127.0.2.1 pnetlab.example.com pnetlab" >> /etc/hosts
- echo "pnetlab" > /etc/hostname
- echo -e "${GREEN}Installing PNETLab...${NO_COLOR}"
- wget --quiet --show-progress $URL_PNET_PNETLAB
- rpm -Uvh /tmp/pnetlab_6*.rpm
- # Detect cloud
- gcp_tune() {
- cd /sys/class/net/
- for i in ens*; do
- echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$(cat $i/address)'", ATTR{type}=="1", KERNEL=="ens*", NAME="'$i'"' > /etc/udev/rules.d/70-persistent-net.rules
- done
- sed -i -e 's/NAME="ens.*/NAME="eth0"/' /etc/udev/rules.d/70-persistent-net.rules
- sed -i -e 's/ens4/eth0/' /etc/netplan/50-cloud-init.yaml
- sed -i -e 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
- apt-mark hold linux-image-gcp
- mv /boot/vmlinuz-*gcp /root
- update-grub2
- }
- azure_kernel_tune() {
- zypper install -y mkinitrd
- zypper install -y cloud-regionsrv
- zypper install -y cloud-netconfig
- zypper install -y cloud-init
- zypper install -y cloud-init-config
- echo "options kvm_intel nested=1 vmentry_l1d_flush=never" > /etc/modprobe.d/qemu-system-x86.conf
- sed -i -e 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
- systemctl restart ssh
- }
- # Tune for GCP
- grep -q "Google" /sys/class/dmi/id/bios_vendor
- if [ $? -eq 0 ]; then
- gcp_tune
- fi
- # Tune for Azure
- uname -r | grep -q "azure"
- if [ $? -eq 0 ]; then
- azure_kernel_tune
- fi
- zypper remove -y docker containerd runc php8*
- zypper clean -a
- echo -e "${GREEN}Upgrade has been done successfully ${NO_COLOR}"
- echo -e "${GREEN}Default credentials: username=root password=pnet Make sure to reboot if you install PNETLab for the first time ${NO_COLOR}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement