Skip to content

Commit

Permalink
setup: added script to auto install mtda aritfacts to system
Browse files Browse the repository at this point in the history
Signed-off-by: Onkar Bokshe <[email protected]>
  • Loading branch information
Onkar Bokshe authored and Onkar Bokshe committed Feb 7, 2022
1 parent d9922f7 commit c5a3a2a
Showing 1 changed file with 156 additions and 0 deletions.
156 changes: 156 additions & 0 deletions scripts/setup-mtda
Original file line number Diff line number Diff line change
@@ -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 -i "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

0 comments on commit c5a3a2a

Please sign in to comment.