From 7e4fdf350c2ec5a84cdd6ab36290165af990c041 Mon Sep 17 00:00:00 2001 From: Onkar Bokshe Date: Mon, 7 Feb 2022 11:36:38 -0500 Subject: [PATCH] setup: added script to auto install mtda aritfacts to system Signed-off-by: Onkar Bokshe --- scripts/setup-mtda | 156 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100755 scripts/setup-mtda diff --git a/scripts/setup-mtda b/scripts/setup-mtda new file mode 100755 index 00000000..26e29cb1 --- /dev/null +++ b/scripts/setup-mtda @@ -0,0 +1,156 @@ +#!/bin/bash +# --------------------------------------------------------------------------------------------------------------------- +# Setup Multi-Tenant Device Access on system +# Copyright (c) 2021-2022, Mentor Graphics, a Siemens business +# --------------------------------------------------------------------------------------------------------------------- + +# --------------------------------------------------------------------------------------------------------------------- +# Check distro of running system +# --------------------------------------------------------------------------------------------------------------------- + +dist_name() { + if [ -f /etc/os-release ]; then + # shellcheck disable=SC1091 + dist=$(cat /etc/os-release | grep -w "ID" | cut -d"=" -f2) + elif [ -x /usr/bin/lsb_release ]; then + dist="$(lsb_release -si)" + elif [ -f /etc/lsb-release ]; then + # shellcheck disable=SC1091 + dist=$(cat /etc/lsb-release | grep -w "DISTRIB_ID" | cut -d"=" -f2) + elif [ -f /etc/debian_version ]; then + dist="debian" + elif [ -f /etc/fedora-release ]; then + dist="fedora" + echo "W:Unsupported distro: mtda installation is not yet tested on this system" + exit 1 + elif [ -f /etc/centos-release ]; then + dist="centos" + echo "W:Unsupported distro: mtda installation is not yet tested on this system" + exit 1 + else + dist="unknown" + echo "W:Unsupported distro: cannot determine distribution name" + fi + + # convert dist to lower case + dist=$(echo ${dist} | tr '[:upper:]' '[:lower:]') + case "${dist}" in + rpb*) dist="oe-rpb" ;; + esac +} + +# --------------------------------------------------------------------------------------------------------------------- +# This script shall be run with admin privileges +# --------------------------------------------------------------------------------------------------------------------- + +uid=$(id -u) +if [ ${uid} -ne 0 -o -z "${SUDO_USER}" ] +then + echo "error: please run this script as root using sudo!" >&2 + exit 1 +fi + +# --------------------------------------------------------------------------------------------------------------------- +# Add apt mirror for MTDA +# --------------------------------------------------------------------------------------------------------------------- + +add_apt_mirror() { + dist_name + case "${dist}" in + debian) + echo 'deb [trusted=yes] https://apt.fury.io/mtda/ /' | \ + tee /etc/apt/sources.list.d/mtda.list + ;; + ubuntu) + add-apt-repository ppa:chombourger/mtda-focal + ;; + esac +} + +# --------------------------------------------------------------------------------------------------------------------- +# MTDA and mtda-pytest installation +# --------------------------------------------------------------------------------------------------------------------- + +mtda_install() { + apt-get update -y + apt-get -y install mtda mtda-pytest +} + +# --------------------------------------------------------------------------------------------------------------------- +# docker installation +# --------------------------------------------------------------------------------------------------------------------- + +docker_install() { + apt-get -y remove docker docker-engine docker.io containerd runc + apt-get update -y + apt-get -y install \ + ca-certificates \ + curl \ + gnupg \ + lsb-release + curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update -y + apt-get -y install docker-ce docker-ce-cli containerd.io + /sbin/adduser $USER docker + systemctl enable docker + systemctl start docker +} + +# --------------------------------------------------------------------------------------------------------------------- +# mtda-kvm installation +# --------------------------------------------------------------------------------------------------------------------- + +mtda_kvm_install() { + apt-get -y install mtda-kvm +} + +# --------------------------------------------------------------------------------------------------------------------- +# mtda-kvm installation +# --------------------------------------------------------------------------------------------------------------------- + +mtda_docker_install() { + docker_install + apt-get -y install mtda-docker +} + +# --------------------------------------------------------------------------------------------------------------------- +# Selection of installtion from list +# --------------------------------------------------------------------------------------------------------------------- + +options=("mtda" "mtda-kvm" "mtda-docker" "Select all" "Quit") +select opt in "${options[@]}" +do + case $opt in + "mtda") + echo "you choose mtda and mtda-pytest for installation" + add_apt_mirror + mtda_install + ;; + "mtda-kvm") + echo "you choose mtda-kvm for installation" + add_apt_mirror + mtda_install + mtda_kvm_install + ;; + "mtda-docker") + echo "you choose mtda-kvm for installation" + add_apt_mirror + mtda_install + mtda_docker_install + ;; + "Select all") + echo "you choose all for installation" + add_apt_mirror + mtda_install + mtda_kvm_install + mtda_docker_install + ;; + "Quit") + break + ;; + *) echo "invalid option $REPLY";; + esac +done