Last active
February 4, 2021 21:13
-
-
Save goffinet/90573cf762ed3830af50159d5a92a2dc to your computer and use it in GitHub Desktop.
Install useful Linux tools for labs libvirt/kvm terraform packer docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install useful Linux tools for labs | |
# libvirt/kvm terraform packer docker | |
# Todo | |
#- Fix tools list: `$apt`,`$yum` vars | |
#- use `$OPTARG` var for custom packages | |
tf_version="0.14.5" | |
tools_installation () { | |
echo "Begin installation: Tools installation" | |
packages="git make gcc wget unzip screen curl tcpdump" | |
apt="" | |
yum="" | |
custom=${OPTARG} | |
if [[ -f /etc/debian_version ]] ; then | |
apt-get update && apt-get -y upgrade | |
apt-get -y install ${packages} ${apt} ${custom} | |
elif [[ -f /etc/redhat-release ]] ; then | |
yum -y install epel-release | |
yum -y install ${packages} ${yum} ${custom} | |
fi | |
} | |
virtualization_installation () { | |
echo "Begin installation: Libvirt/KVM installation" | |
if [[ -f /etc/debian_version ]] ; then | |
apt-get update && apt-get -y upgrade | |
apt-get -y install wget unzip | |
if [[ -f /etc/ubuntu-advantage ]] ; then | |
apt -y install apparmor-profiles | |
fi | |
apt-get -y install qemu-kvm libvirt-dev virtinst virt-viewer libguestfs-tools virt-manager uuid-runtime curl linux-source libosinfo-bin | |
source /etc/os-release | |
if [[ $ID == "ubuntu" ]] && [[ $VERSION_ID == "20.04" ]] ; then | |
apt-get -y install libvirt-daemon-system dnsmasq | |
fi | |
virsh net-start default | |
virsh net-autostart default | |
elif [[ -f /etc/redhat-release ]]; then | |
yum -y install wget unzip | |
yum -y install epel-release | |
yum -y upgrade | |
yum -y group install "Virtualization Host" | |
yum -y install virt-manager libvirt virt-install qemu-kvm xauth dejavu-lgc-sans-fonts virt-top libguestfs-tools virt-viewer virt-manager curl | |
fi | |
} | |
terraform_provider_libvirt_installation () { | |
echo "Begin installation: Terraform and Libvirt provider installation" | |
echo "security_driver = \"none\"" >> /etc/libvirt/qemu.conf | |
systemctl restart libvirtd | |
currentd=$PWD | |
cd /tmp | |
wget https://releases.hashicorp.com/terraform/${tf_version}/terraform_${tf_version}_linux_amd64.zip | |
unzip terraform_${tf_version}_linux_amd64.zip | |
chmod +x terraform | |
mv terraform /usr/local/bin/ | |
source /etc/os-release | |
if [[ $ID == "ubuntu" ]] && [[ $VERSION_ID == "20.04" ]] ; then | |
echo 'deb http://download.opensuse.org/repositories/systemsmanagement:/terraform/Ubuntu_20.04/ /' | tee /etc/apt/sources.list.d/systemsmanagement:terraform.list | |
curl -fsSL https://download.opensuse.org/repositories/systemsmanagement:terraform/Ubuntu_20.04/Release.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/systemsmanagement_terraform.gpg > /dev/null | |
apt update | |
apt install terraform-provider-libvirt | |
fi | |
if [[ $ID == "ubuntu" ]] && [[ $VERSION_ID == "18.04" ]] ; then | |
wget https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.2/terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz | |
tar xvf terraform-provider-libvirt-0.6.2+git.1585292411.8cbe9ad0.Ubuntu_18.04.amd64.tar.gz | |
mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64 | |
cp -r terraform-provider-libvirt ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.2/linux_amd64/ | |
fi | |
cd $currentd | |
} | |
docker_installation () { | |
echo "Begin installation: Docker installation" | |
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh | |
rm -rf ./get-docker.sh | |
if [[ -f /etc/debian_version ]]; then | |
apt-get update && apt-get -y install python3-pip | |
elif [[ -f /etc/redhat-release ]]; then | |
yum -y install python3-pip | |
fi | |
pip3 install docker-compose | |
} | |
packer_installation () { | |
echo "Begin installation: Packer installation" | |
currentd=$PWD | |
cd /tmp | |
latest=$(curl -L -s https://releases.hashicorp.com/packer | grep 'packer_' | sed 's/^.*<.*\">packer_\(.*\)<\/a>/\1/' | head -1) | |
wget https://releases.hashicorp.com/packer/${latest}/packer_${latest}_linux_amd64.zip | |
unzip packer*.zip | |
chmod +x packer | |
mv packer /usr/local/bin/ | |
cd $currentd | |
} | |
all_tools_installation () { | |
virtualization_installation | |
terraform_provider_libvirt_installation | |
docker_installation | |
packer_installation | |
tools_installation | |
} | |
help () { | |
echo "Description: Install usefull Linux tools for labs" | |
echo "Usage: ./`basename $0` options (-vtdao)" | |
echo "Options:" | |
echo " -v: Libvirt/KVM installation" | |
echo " -t: Terraform and Libvirt provider installation" | |
echo " -d: Docker installation" | |
echo " -p: Packer installation" | |
echo " -o: Tools installation" | |
echo " -a: Install all" | |
echo "Examples:" | |
echo " ./`basename $0` -vtp" | |
echo " ./`basename $0` -v -t -p" | |
echo " ./`basename $0` -a" | |
exit 1 | |
} | |
if [[ "$EUID" -ne 0 ]] ; then | |
echo "Please run as root" | |
exit | |
fi | |
NO_ARGS=0 | |
if [[ $# -eq "$NO_ARGS" ]] ; then | |
help | |
fi | |
while getopts ":vtdpoa" option ; do | |
case ${option} in | |
v ) virtualization_installation ;; | |
t ) terraform_provider_libvirt_installation ;; | |
d ) docker_installation ;; | |
p ) packer_installation ;; | |
o ) tools_installation ;; | |
a ) all_tools_installation ;; | |
* ) help ;; | |
esac | |
done | |
shift $((OPTIND-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment