Advertisement
ph4ntom74

Test v02 - Pnetlab & ishare2 Installation Script OpenSuse

Dec 11th, 2023 (edited)
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.72 KB | Software | 0 0
  1. #!/bin/bash
  2. # Version 002 - Altered by ph4ntom74 - 11th December 2023.
  3. # Still needs to add "alien" to convert .deb to .rpm packages.
  4. # The idea is t,o have a script to install pnetlab on an Tumbleweed
  5. # desktop without the need of VMware Workstation. Maybe its a stupid
  6. # idea but hey, I'm not a coder.
  7.  
  8. # Open debugging output
  9. exec > >(tee -i /tmp/pnet_install.log) 2>&1
  10. set -x
  11.  
  12. clear
  13. export LC_ALL=C
  14.  
  15. # upgrade dependencies in PNETLab OpenSUSE Tumbleweed
  16. # Requirement: You need to have OpenSUSE Tumbleweed
  17.  
  18. # CONSTANTS
  19. GREEN='\033[32m'
  20. RED='\033[31m'
  21. NO_COLOR='\033[0m'
  22.  
  23. KERNEL=pnetlab_kernel.zip
  24.  
  25. zypper --non-interactive refresh
  26.  
  27. # Download the selected packages & unpack them in /tmp/
  28. # Fetch & unzip pnetlab_kernel
  29. KERNEL_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/L/linux-5.17.15-pnetlab-uksm/pnetlab_kernel.zip"
  30. curl -L -o /tmp/pnetlab_kernel.zip "$KERNEL_URL"
  31. unzip /tmp/pnetlab_kernel.zip -d /tmp/
  32. # Fetch & unzip pre-docker
  33. PRE_DOCKER_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/D/pre-docker.zip"
  34. curl -L -o /tmp/pre-docker.zip "$PRE_DOCKER_URL"
  35. unzip /tmp/pre-docker.zip -d /tmp/
  36. # Fetch & unzip pnet_guacamole
  37. 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"
  38. curl -L -o /tmp/pnetlab-guacamole_6.0.0-7_amd64.deb "$PNET_GUACAMOLE"
  39. unzip /tmp/pnetlab-guacamole_6.0.0-7_amd64.deb -d /tmp/
  40. # Fetch & unzip pnet_dynamips
  41. 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"
  42. curl -L -o /tmp/pnetlab-dynamips_6.0.0-30_amd64.deb "$PNET_DYNAMIPS_URL"
  43. unzip /tmp/pnetlab-dynamips_6.0.0-30_amd64.deb -d /tmp/
  44. # Fetch & unzip pnet_schema
  45. 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"
  46. curl -L -o /tmp/pnetlab-schema_6.0.0-30_amd64.deb "$PNET_SCHEMA_URL"
  47. unzip /tmp/pnetlab-schema_6.0.0-30_amd64.deb -d /tmp/
  48. # Fetch & unzip pnet_vpc
  49. 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"
  50. curl -L -o /tmp/pnetlab-vpcs_6.0.0-30_amd64.deb "$PNET_VPC_URL"
  51. unzip /tmp/pnetlab-vpcs_6.0.0-30_amd64.deb -d /tmp/
  52. # Fetch & unzip pnet_qemu
  53. 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"
  54. curl -L -o /tmp/pnetlab-qemu_6.0.0-30_amd64.deb "$PNET_QEMU_URL"
  55. unzip /tmp/pnetlab-qemu_6.0.0-30_amd64.deb -d /tmp/
  56. # Fetch & unzip pnet_docker
  57. 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"
  58. curl -L -o /tmp/pnetlab-docker_6.0.0-30_amd64.deb "$PNET_DOCKER_URL"
  59. unzip /tmp/pnetlab-docker_6.0.0-30_amd64.deb -d /tmp/
  60. # Fetch & unzip pnet_lab
  61. 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"
  62. curl -L -o /tmp/pnetlab_6.0.0-100_amd64.deb "$PNET_PNETLAB_URL"
  63. unzip /tmp/pnetlab_6.0.0-100_amd64.deb -d /tmp/
  64. # Fetch & unzip pnet_wireshark
  65. 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"
  66. curl -L -o /tmp/pnetlab-wireshark_6.0.0-30_amd64.deb "$PNET_WIRESHARK_URL"
  67. unzip /tmp/pnetlab-wireshark_6.0.0-30_amd64.deb -d /tmp/
  68. # Fetch & unzip pnet_tpm
  69. PNET_TPM_URL="https://labhub.eu.org/api/raw/?path=/UNETLAB%20I/upgrades_pnetlab/Focal/T/swtpm-focal.zip"
  70. curl -L -o /tmp/swtpm-focal.zip "$PNET_TPM_URL"
  71. unzip /tmp/swtpm-focal.zip -d /tmp/
  72.  
  73. grep -q "Tumbleweed" /etc/os-release
  74. if [ $? -ne 0 ]; then
  75.     echo -e "${RED}Upgrade has been rejected. You need to have OpenSUSE Tumbleweed to use this script${NO_COLOR}"
  76.     exit 0
  77. fi
  78.  
  79. # Azure disk tuning function
  80. azure_disk_tune() {
  81.     ls -l /dev/disk/by-id/ | grep -q sdc && (
  82.         echo o                   # Create a new empty DOS partition table
  83.         echo n                   # Add a new partition
  84.         echo p                   # Primary partition
  85.         echo 1                   # Partition number
  86.         echo                     # First sector (Accept default: 1)
  87.         echo                     # Last sector (Accept default: varies)
  88.         echo w                   # Write changes
  89.     ) | sudo fdisk /dev/sdc && (
  90.         mke2fs -F /dev/sdc1
  91.         echo "/dev/sdc1    /opt    ext4    defaults,discard    0 0 " >> /etc/fstab
  92.         mount /opt
  93.     )
  94. }
  95.  
  96. # Check if on Azure and apply disk tuning
  97. uname -r | grep -q "azure"
  98. if [ $? -eq 0 ]; then
  99.     azure_disk_tune
  100. fi
  101.  
  102. zypper update -y
  103. # Permit root access from SSH
  104. sed -i -e "s/.*PermitRootLogin .*/PermitRootLogin yes/" /etc/ssh/sshd_config
  105.  
  106. # Install required packages
  107. 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
  108. zypper remove -y docker containerd runc php8*
  109.  
  110. echo -e "${GREEN}Downloading PNETLAB PACKAGES...${NO_COLOR}"
  111. rm -rf /tmp/*
  112. cd /tmp
  113.  
  114. echo -e "${GREEN}Download Packages${NO_COLOR}"
  115.  
  116. # Download and install the kernel if not already installed
  117. rpm -q kernel-default-5.17.15-pnetlab-uksm
  118. if [ $? -ne 0 ]; then
  119.     wget --quiet --show-progress $URL_KERNEL
  120.     unzip /tmp/$KERNEL
  121.     rpm -Uvh /tmp/pnetlab_kernel/*.rpm
  122. fi
  123.  
  124. # Download and install pre-docker
  125. rpm -q pnetlab-pre-docker
  126. if [ $? -ne 0 ]; then
  127.     wget --quiet --show-progress $URL_PRE_DOCKER
  128.     unzip /tmp/pre-docker.zip
  129.     rpm -Uvh /tmp/pre-docker/*.rpm
  130. fi
  131.  
  132. # Download and install swtpm
  133. rpm -q swtpm-focal
  134. if [ $? -ne 0 ]; then
  135.     wget --quiet --show-progress $URL_PNET_TPM
  136.     unzip /tmp/swtpm-focal.zip
  137.     rpm -Uvh /tmp/swtpm-focal/*.rpm
  138. fi
  139.  
  140. # Download and install pnetlab-docker
  141. rpm -q pnetlab-docker
  142. if [ $? -ne 0 ]; then
  143.     wget --quiet --show-progress $URL_PNET_DOCKER
  144.     rpm -Uvh /tmp/pnetlab-docker_*.rpm
  145. fi
  146.  
  147. # Download and install pnetlab-schema
  148. rpm -q pnetlab-schema
  149. if [ $? -ne 0 ]; then
  150.     wget --quiet --show-progress $URL_PNET_SCHEMA
  151.     rpm -Uvh /tmp/pnetlab-schema_*.rpm
  152. fi
  153.  
  154. # Download and install pnetlab-guacamole
  155. rpm -q pnetlab-guacamole
  156. if [ $? -ne 0 ]; then
  157.     wget --quiet --show-progress $URL_PNET_GUACAMOLE
  158.     rpm -Uvh /tmp/pnetlab-guacamole_*.rpm
  159. fi
  160.  
  161. # Download and install pnetlab-vpcs
  162. rpm -q pnetlab-vpcs
  163. if [ $? -ne 0 ]; then
  164.     wget --quiet --show-progress $URL_PNET_VPC
  165.     rpm -Uvh /tmp/pnetlab-vpcs_*.rpm
  166. fi
  167.  
  168. # Download and install pnetlab-dynamips
  169. rpm -q pnetlab-dynamips
  170. if [ $? -ne 0 ]; then
  171.     wget --quiet --show-progress $URL_PNET_DYNAMIPS
  172.     rpm -Uvh /tmp/pnetlab-dynamips_*.rpm
  173. fi
  174.  
  175. # Download and install pnetlab-wireshark
  176. rpm -q pnetlab-wireshark
  177. if [ $? -ne 0 ]; then
  178.     wget --quiet --show-progress $URL_PNET_WIRESHARK
  179.     rpm -Uvh pnetlab-wireshark_6.0.0-30_amd64.rpm
  180. fi
  181.  
  182. # Download and install pnetlab-qemu
  183. rpm -q pnetlab-qemu
  184. if [ $? -ne 0 ]; then
  185.     wget --quiet --show-progress $URL_PNET_QEMU
  186.     rpm -Uvh /tmp/pnetlab-qemu_*.rpm
  187. fi
  188.  
  189. # Ensure the hosts file contains the necessary entry
  190. grep -q "127.0.1.1 pnetlab.example.com pnetlab" /etc/hosts || echo "127.0.2.1 pnetlab.example.com pnetlab" >> /etc/hosts
  191.  
  192. echo "pnetlab" > /etc/hostname
  193.  
  194. echo -e "${GREEN}Installing PNETLab...${NO_COLOR}"
  195. wget --quiet --show-progress $URL_PNET_PNETLAB
  196. rpm -Uvh /tmp/pnetlab_6*.rpm
  197.  
  198. # Detect cloud
  199. gcp_tune() {
  200.     cd /sys/class/net/
  201.     for i in ens*; do
  202.         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
  203.     done
  204.     sed -i -e 's/NAME="ens.*/NAME="eth0"/' /etc/udev/rules.d/70-persistent-net.rules
  205.     sed -i -e 's/ens4/eth0/' /etc/netplan/50-cloud-init.yaml
  206.     sed -i -e 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
  207.     apt-mark hold linux-image-gcp
  208.     mv /boot/vmlinuz-*gcp /root
  209.     update-grub2
  210. }
  211.  
  212. azure_kernel_tune() {
  213.     zypper install -y mkinitrd
  214.     zypper install -y cloud-regionsrv
  215.     zypper install -y cloud-netconfig
  216.     zypper install -y cloud-init
  217.     zypper install -y cloud-init-config
  218.     echo "options kvm_intel nested=1 vmentry_l1d_flush=never" > /etc/modprobe.d/qemu-system-x86.conf
  219.     sed -i -e 's/PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
  220.     systemctl restart ssh
  221. }
  222.  
  223. # Tune for GCP
  224. grep -q "Google" /sys/class/dmi/id/bios_vendor
  225. if [ $? -eq 0 ]; then
  226.     gcp_tune
  227. fi
  228.  
  229. # Tune for Azure
  230. uname -r | grep -q "azure"
  231. if [ $? -eq 0 ]; then
  232.     azure_kernel_tune
  233. fi
  234.  
  235. zypper remove -y docker containerd runc php8*
  236. zypper clean -a
  237.  
  238. echo -e "${GREEN}Upgrade has been done successfully ${NO_COLOR}"
  239. 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