From 41574c143aa713dd3376d5ef8877e9dab8539d9e Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 12 Aug 2025 20:02:42 +0200 Subject: [PATCH] Added install software on VM guest feature --- README.md | 24 ++- env_scripts/common.sh | 2 + env_scripts/functions.sh | 143 +++++++++++++++++- files/software.json | 24 +++ vm_example_scripts/apply_netplan.sh | 2 +- vm_example_scripts/docker_debian.sh | 54 ++++--- vm_example_scripts/docker_fedora.sh | 24 +++ vm_example_scripts/docker_ubuntu.sh | 68 ++++++--- .../{gitlab_ce.sh => gitlab_ce_deb.sh} | 16 +- vm_example_scripts/gitlab_ce_fedora.sh | 20 +++ vm_example_scripts/gitlab_runner.sh | 12 -- vm_example_scripts/gitlab_runner_deb.sh | 16 ++ vm_example_scripts/gitlab_runner_fedora.sh | 8 + vm_example_scripts/gitlab_runner_freebsd.sh | 60 ++++++++ vm_example_scripts/ingress-haproxy.sh | 2 +- vm_example_scripts/init_freebsd.sh | 0 vm_example_scripts/jenkins.sh | 2 +- vm_example_scripts/k8s.sh | 2 +- vm_example_scripts/podman_deb.sh | 7 + vm_example_scripts/podman_fedora.sh | 7 + vm_example_scripts/podman_freebsd.sh | 62 ++++++++ vm_manage.sh | 8 +- 22 files changed, 493 insertions(+), 70 deletions(-) create mode 100644 files/software.json create mode 100755 vm_example_scripts/docker_fedora.sh rename vm_example_scripts/{gitlab_ce.sh => gitlab_ce_deb.sh} (52%) create mode 100755 vm_example_scripts/gitlab_ce_fedora.sh delete mode 100755 vm_example_scripts/gitlab_runner.sh create mode 100755 vm_example_scripts/gitlab_runner_deb.sh create mode 100755 vm_example_scripts/gitlab_runner_fedora.sh create mode 100755 vm_example_scripts/gitlab_runner_freebsd.sh mode change 100644 => 100755 vm_example_scripts/init_freebsd.sh create mode 100755 vm_example_scripts/podman_deb.sh create mode 100755 vm_example_scripts/podman_fedora.sh create mode 100644 vm_example_scripts/podman_freebsd.sh diff --git a/README.md b/README.md index 809dac3..3f54261 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ sudo virsh --connect qemu:///session net-define /dev/stdin << EOF EOF ``` --> -## Examples -### Command usage +## Command Usage +### Command help ```shell NAME ./vm_manage.sh @@ -78,6 +78,7 @@ USAGE ./vm_manage.sh delete NAME ./vm_manage.sh info NAME ./vm_manage.sh connect NAME + ./vm_manage.sh install NAME ./vm_manage.sh list ACTIONS @@ -86,6 +87,7 @@ ACTIONS list List all defined virtual machines info Show information about a virtual machine connect Connect to the console of a virtual machine + install Install specific software into an existing VM OPTIONS -h Show this help message @@ -149,6 +151,24 @@ Domain 'ubuntuTest' has been undefined VM 'ubuntuTest' removed successfully. ``` +## Install software on VM + + +`./vm_manage.sh install VM_NAME` + +Example: + +```shell +./vm_manage.sh install Debian +Select software to install: +-------------- + 1. Docker + 2. Podman + 3. Gitlab CE + 4. Gitlab Runner +Enter your choice [1-4]: +``` + ## TODO - Maybe add more BSD flavours guests support diff --git a/env_scripts/common.sh b/env_scripts/common.sh index 2195e34..28d57b1 100644 --- a/env_scripts/common.sh +++ b/env_scripts/common.sh @@ -3,12 +3,14 @@ DISTRO="" LIBVIRT_NET_MODEL="virtio" LIBVIRT_NET_OPTION="network=$VM_NETWORK,model=$LIBVIRT_NET_MODEL" OS_JSON_FILE="files/os_options.json" +OS_JSON_FILE_INSTALL="files/software.json" #VM_BASE_DIR=${VM_BASE_DIR:-"${HOME}/.local/share/libvirt"} #VM_BASE_DIR=${VM_BASE_DIR:-"${HOME}/var/lib/libvirt"} VM_BASE_DIR="${HOME}/vms" VM_BASE_IMAGES="base" VM_DISK_EXTENSION="img" VM_USERNAME="user" +VM_SOFT=""; VM_IMAGE_PATH="${VM_BASE_DIR}/images/$1.img" CI_IMAGE_PATH="${VM_BASE_DIR}/images/$1-cidata.iso" diff --git a/env_scripts/functions.sh b/env_scripts/functions.sh index 25d583f..236e933 100644 --- a/env_scripts/functions.sh +++ b/env_scripts/functions.sh @@ -175,11 +175,12 @@ show_vm_menu() { compare_checksum() { CHECKSUM_TMP_FOLDER=$(mktemp) - - wget --recursive \ - --user-agent="Mozilla/5.0 (X11; Linux x86_64)" \ - -O "${CHECKSUM_TMP_FOLDER}" \ + curl -L -o "${CHECKSUM_TMP_FOLDER}" \ "${VM_CHECKSUMS_URL}" + # wget --recursive \ + # --user-agent="Mozilla/5.0 (X11; Linux x86_64)" \ + # -O "${CHECKSUM_TMP_FOLDER}" \ + # "${VM_CHECKSUMS_URL}" if [[ "$VM_OS_TYPE" == "BSD" && "${VM_OS_VARIANT}" == *"freebsd"* ]]; then if [[ "${VM_BASE_IMAGE}" == *"zfs"* ]]; then @@ -347,10 +348,14 @@ vm_download_base_image() fi VM_BASE_IMAGE_LOCATION="${VM_BASE_DIR}/${VM_BASE_IMAGES}/${VM_BASE_IMAGE_NAME}.${VM_BASE_IMAGE_EXTENSION}" if ! test -f "${VM_BASE_IMAGE_LOCATION}"; then - wget \ - --user-agent="Mozilla/5.0 (X11; Linux x86_64)" \ - -O "${VM_BASE_IMAGE_LOCATION}" \ - ${VM_BASE_IMAGE_URL} + # wget \ + # --user-agent="Mozilla/5.0 (X11; Linux x86_64)" \ + # -O "${VM_BASE_IMAGE_LOCATION}" \ + # ${VM_BASE_IMAGE_URL} + + curl -L ${VM_BASE_IMAGE_URL} \ + -o ${VM_BASE_IMAGE_LOCATION} \ + fi } @@ -533,3 +538,125 @@ vm_guest_install() echo "user pass is: ${VM_USER_PASS}" echo "virsh console ${VM_HOSTNAME} --safe" } +vm_get_guest_info() +{ + # Obtener el ID del sistema operativo + # Obtener el ID del sistema operativo + OS_ID=$(grep -o 'id="[^"]*"' "$1" | tr -d '"' | awk '{print $1}') + + # Eliminar el protocolo y el dominio del ID + OS_ID=$(echo "$OS_ID" | cut -d '/' -f 2-) + #echo $OS_ID + # Convertir la URL a un nombre de distribución y versión + VM_DISTRO=$(echo "$OS_ID" | awk -F '/' '{print $3}') + VM_VERSION=$(echo "$OS_ID" | awk -F '/' '{print $4}') +} + +show_software_menu() { + # Display dynamic OS selection menu + echo "Select software to install:" + echo "--------------" + + # Array to store valid IDs for validation + VALID_IDS=() + while IFS= read -r entry; do + DECODED=$(echo "$entry" | base64 --decode) + ID=$(echo "$DECODED" | jq -r '.id') + NAME=$(echo "$DECODED" | jq -r '.show_name') + printf "%2s. %s\n" "$ID" "$NAME" + VALID_IDS+=("$ID") + done < <(jq -r '.software[] | @base64' "$OS_JSON_FILE_INSTALL") + + # Calculate max ID for range validation + ID_MAX=$(jq -r '[.software[].id] | max' "$OS_JSON_FILE_INSTALL") + ID_MIN=$(jq -r '[.software[].id] | min' "$OS_JSON_FILE_INSTALL") + + # Read user input + read -r -p "Enter your choice [${ID_MIN}-${ID_MAX}]: " CHOICE + + # Validate input: must be a number and within range + if ! [[ "$CHOICE" =~ ^[0-9]+$ ]]; then + echo "Error: Please enter a valid number." >&2 + exit 1 + fi + + if (( CHOICE < ID_MIN || CHOICE > ID_MAX )); then + echo "Error: Please enter a number between ${ID_MIN} and ${ID_MAX}." >&2 + exit 1 + fi + + # Get selected OS variant + SELECTED=$(jq -r ".software[] | select(.id == ${CHOICE})" "$OS_JSON_FILE_INSTALL") + + if [ -z "$SELECTED" ]; then + echo "Error: Invalid selection." >&2 + exit 1 + fi + + # Export variables in uppercase + VM_SOFT=$(echo "$SELECTED" | jq -r '.name') + +} + +vm_install_utils() +{ + local VM=$1 + local SCRIPT='' + local VM_DISTRO='' + local VM_VERSION='' + local VM_IP=$(vm_net_get_ip "$VM") + vm_get_guest_info ${VM_BASE_DIR}/xml/${VM}.xml + case ${VM_SOFT} in + docker) + if [[ "$VM_DISTRO" == "debian" ]]; then + SCRIPT='vm_example_scripts/docker_debian.sh' + elif [[ "$VM_DISTRO" == "ubuntu" ]]; then + SCRIPT='vm_example_scripts/docker_ubuntu.sh' + elif [[ "$VM_DISTRO" == "fedora" ]]; then + SCRIPT='vm_example_scripts/docker_fedora.sh' + elif [[ "$VM_DISTRO" == "freebsd" ]]; then + echo "Automated installation for Docker on ${VM_DISTRO} is not available." + echo "It's better to use Pidman instead" + exit 1 + fi + ;; + podman) + if [[ "$VM_DISTRO" == "debian" || "$VM_DISTRO" == "ubuntu" ]]; then + SCRIPT='vm_example_scripts/podman_deb.sh' + elif [[ "$VM_DISTRO" == "fedora" ]]; then + SCRIPT='vm_example_scripts/podman_fedora.sh' + elif [[ "$VM_DISTRO" == "freebsd" ]]; then + SCRIPT='vm_example_scripts/podman_freebsd.sh' + fi + ;; + gitlab_ce) + if [[ "$VM_DISTRO" == "debian" || "$VM_DISTRO" == "ubuntu" ]]; then + SCRIPT='vm_example_scripts/gitlab_ce_deb.sh' + elif [[ "$VM_DISTRO" == "fedora" || "$VM_DISTRO" == "freebsd" ]]; then + #SCRIPT='vm_example_scripts/gitlab_ce_fedora.sh' + echo "Automated installation for Gitlab CE on ${VM_DISTRO} is not available by the moment." + exit 1 + fi + ;; + gitlab_runner) + if [[ "$VM_DISTRO" == "debian" || "$VM_DISTRO" == "ubuntu" ]]; then + SCRIPT='vm_example_scripts/gitlab_runner_deb.sh' + elif [[ "$VM_DISTRO" == "fedora" ]]; then + SCRIPT='vm_example_scripts/gitlab_runner_fedora.sh' + elif [[ "$VM_DISTRO" == "freebsd" ]]; then + SCRIPT='vm_example_scripts/gitlab_runner_freebsd.sh' + fi + ;; + *) + echo "Unknown action: ${ACTION}" >&2 + usage + ;; + esac + #Exec script + #bash ${SCRIPT} + if [[ "$VM_DISTRO" == "freebsd" ]]; then + ssh -i ${VM_BASE_DIR}/ssh/${VM} -l${VM_USERNAME} ${VM_IP} "sudo sh -s" - < ${SCRIPT} + else + ssh -i ${VM_BASE_DIR}/ssh/${VM} -l${VM_USERNAME} ${VM_IP} "sudo bash -s" - < ${SCRIPT} + fi +} \ No newline at end of file diff --git a/files/software.json b/files/software.json new file mode 100644 index 0000000..1dacaf0 --- /dev/null +++ b/files/software.json @@ -0,0 +1,24 @@ +{ + "software": [ + { + "id": 1, + "show_name": "Docker", + "name": "docker" + }, + { + "id": 2, + "show_name": "Podman", + "name": "podman" + }, + { + "id": 3, + "show_name": "Gitlab CE", + "name": "gitlab_ce" + }, + { + "id": 4, + "show_name": "Gitlab Runner", + "name": "gitlab_runner" + } + ] +} diff --git a/vm_example_scripts/apply_netplan.sh b/vm_example_scripts/apply_netplan.sh index fa69d47..0e85316 100755 --- a/vm_example_scripts/apply_netplan.sh +++ b/vm_example_scripts/apply_netplan.sh @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash sudo mv /home/user/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml sudo netplan apply \ No newline at end of file diff --git a/vm_example_scripts/docker_debian.sh b/vm_example_scripts/docker_debian.sh index 20495ea..fb061f8 100755 --- a/vm_example_scripts/docker_debian.sh +++ b/vm_example_scripts/docker_debian.sh @@ -1,20 +1,36 @@ -#!/bin/sh -#SOURCE: https://docs.docker.com/engine/install/debian/ -# https://docs.docker.com/engine/install/linux-postinstall/ -export DEBIAN_FRONTEND=noninteractive -for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done -# Add Docker's official GPG key: -sudo apt-get update -sudo apt-get -y install ca-certificates curl gnupg -sudo install -m 0755 -d /etc/apt/keyrings -curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg -sudo chmod a+r /etc/apt/keyrings/docker.gpg -# Add the repository to Apt sources: -echo \ - "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ - "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null -sudo apt-get update -sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -sudo usermod -aG docker $USER +#!/usr/bin/env bash +# SOURCE: https://docs.docker.com/engine/install/debian/ +# https://docs.docker.com/engine/install/linux-postinstall/ + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + +export DEBIAN_FRONTEND=noninteractive + +# Remove old conflicting packages +for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do + apt-get remove -y "$pkg" 2>/dev/null || true +done + +# Add Docker's official GPG key +apt-get update +apt-get -y install ca-certificates curl gnupg +install -m 0755 -d /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +chmod a+r /etc/apt/keyrings/docker.gpg + +# Add the repository to Apt sources +# shellcheck disable=SC2027,SC2046 # We handle word splitting safely here +# shellcheck source=/dev/null +echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Update and install Docker +apt-get update +apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +# Add user to docker group +usermod -aG docker "${USER}" + +# Refresh group membership (optional, user may need to log out) newgrp docker \ No newline at end of file diff --git a/vm_example_scripts/docker_fedora.sh b/vm_example_scripts/docker_fedora.sh new file mode 100755 index 0000000..5170c6d --- /dev/null +++ b/vm_example_scripts/docker_fedora.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +#SOURCE: https://docs.docker.com/engine/install/fedora/ +# https://docs.docker.com/engine/install/linux-postinstall/ + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + +dnf -y remove docker \ + docker-client \ + docker-client-latest \ + docker-common \ + docker-latest \ + docker-latest-logrotate \ + docker-logrotate \ + docker-selinux \ + docker-engine-selinux \ + docker-engine +dnf -y install dnf-plugins-core +dnf-3 config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo +dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin +systemctl enable --now docker +usermod -aG docker "$USER" +echo "To use docker execute :" +echo "newgrp docker" \ No newline at end of file diff --git a/vm_example_scripts/docker_ubuntu.sh b/vm_example_scripts/docker_ubuntu.sh index b701cff..54c3a1a 100755 --- a/vm_example_scripts/docker_ubuntu.sh +++ b/vm_example_scripts/docker_ubuntu.sh @@ -1,18 +1,50 @@ -#!/bin/bash -export DEBIAN_FRONTEND=noninteractive -for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done -# Add Docker's official GPG key: -sudo apt-get update -sudo apt-get install -y ca-certificates curl -sudo install -m 0755 -d /etc/apt/keyrings -sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc -sudo chmod a+r /etc/apt/keyrings/docker.asc -# Add the repository to Apt sources: -echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null -sudo apt-get update -sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -sudo usermod -aG docker $USER -newgrp docker \ No newline at end of file +#!/usr/bin/env bash +# SOURCE: https://docs.docker.com/engine/install/ubuntu/ +# https://docs.docker.com/engine/install/linux-postinstall/ + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + +export DEBIAN_FRONTEND=noninteractive + +# Remove old or conflicting packages +for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do + apt-get remove -y "$pkg" 2>/dev/null || true +done + +# Install prerequisites +apt-get update +apt-get install -y ca-certificates curl gnupg + +# Create keyrings directory and add Docker GPG key +install -m 0755 -d /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ + gpg --dearmor -o /etc/apt/keyrings/docker.gpg +chmod a+r /etc/apt/keyrings/docker.gpg + +# Add Docker repository +# shellcheck source=/dev/null +. /etc/os-release +ARCH=$(dpkg --print-architecture) +CODENAME="$VERSION_CODENAME" + +echo "deb [arch=$ARCH signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $CODENAME stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Update and install Docker +apt-get update +apt-get install -y \ + docker-ce \ + docker-ce-cli \ + containerd.io \ + docker-buildx-plugin \ + docker-compose-plugin + +# Add user to docker group +usermod -aG docker "$USER" + +# Refresh group membership +echo "Docker installation completed." +echo "To use Docker without sudo, run:" +echo " newgrp docker" +echo "Or log out and back" \ No newline at end of file diff --git a/vm_example_scripts/gitlab_ce.sh b/vm_example_scripts/gitlab_ce_deb.sh similarity index 52% rename from vm_example_scripts/gitlab_ce.sh rename to vm_example_scripts/gitlab_ce_deb.sh index 1708298..f3c9519 100755 --- a/vm_example_scripts/gitlab_ce.sh +++ b/vm_example_scripts/gitlab_ce_deb.sh @@ -1,13 +1,17 @@ -#!/bin/sh +#!/usr/bin/env bash #SOURCE: https://about.gitlab.com/install/#debian + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + export DEBIAN_FRONTEND=noninteractive NET_DEVICE='enp1s0' GITLAB_URL=$(ip -o -4 addr list ${NET_DEVICE} | awk '{print $4}' | cut -d/ -f1) #Base dependencies -sudo apt-get update -sudo apt-get install -y curl openssh-server ca-certificates perl +apt-get update +apt-get install -y curl openssh-server ca-certificates perl #OPTIONAL: postfix -#sudo apt-get install -y postfix +#apt-get install -y postfix #Add gitlab repo -curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash -sudo EXTERNAL_URL="${GITLAB_URL}" apt-get install gitlab-ee \ No newline at end of file +curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash +EXTERNAL_URL="${GITLAB_URL}" apt-get install gitlab-ee \ No newline at end of file diff --git a/vm_example_scripts/gitlab_ce_fedora.sh b/vm_example_scripts/gitlab_ce_fedora.sh new file mode 100755 index 0000000..2b4d095 --- /dev/null +++ b/vm_example_scripts/gitlab_ce_fedora.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +#Source: https://docs.gitlab.com/install/package/almalinux/?tab=Community+Edition + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + +NET_DEVICE='enp1s0' +GITLAB_URL=$(ip -o -4 addr list ${NET_DEVICE} | awk '{print $4}' | cut -d/ -f1) + +#Enable sshd. enabled on cloud-image by default +#systemctl enable --now sshd +#Set firewall rules +firewall-cmd --permanent --add-service=http +firewall-cmd --permanent --add-service=https +firewall-cmd --permanent --add-service=ssh +systemctl reload firewalld +#Add repo +curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh" | bash +#Install Gitlab CE +EXTERNAL_URL="${GITLAB_URL}" dnf install gitlab-ce \ No newline at end of file diff --git a/vm_example_scripts/gitlab_runner.sh b/vm_example_scripts/gitlab_runner.sh deleted file mode 100755 index db21246..0000000 --- a/vm_example_scripts/gitlab_runner.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -#SOURCE: https://about.gitlab.com/install/#debian -export DEBIAN_FRONTEND=noninteractive -cat < /usr/local/etc/rc.d/gitlab_runner' << "EOF" +#!/bin/sh +# PROVIDE: gitlab_runner +# REQUIRE: DAEMON NETWORKING +# BEFORE: +# KEYWORD: + +. /etc/rc.subr + +name="gitlab_runner" +rcvar="gitlab_runner_enable" + +user="gitlab-runner" +user_home="/home/gitlab-runner" +command="/usr/local/bin/gitlab-runner" +command_args="run" +pidfile="/var/run/${name}.pid" + +start_cmd="gitlab_runner_start" + +gitlab_runner_start() +{ + export USER=${user} + export HOME=${user_home} + if checkyesno ${rcvar}; then + cd ${user_home} + /usr/sbin/daemon -u ${user} -p ${pidfile} ${command} ${command_args} > /var/log/gitlab_runner.log 2>&1 + fi +} + +load_rc_config $name +run_rc_command $1 +EOF + +sudo chmod +x /usr/local/etc/rc.d/gitlab_runner + +echo "Now register a runner and then:" +echo "sudo sysrc gitlab_runner_enable=YES" +echo "sudo service gitlab_runner start" \ No newline at end of file diff --git a/vm_example_scripts/ingress-haproxy.sh b/vm_example_scripts/ingress-haproxy.sh index 8d8b110..b05c743 100755 --- a/vm_example_scripts/ingress-haproxy.sh +++ b/vm_example_scripts/ingress-haproxy.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash HAPROXY_URL="https://github.com/haproxytech/kubernetes-ingress/releases/download/v1.10.11/haproxy-ingress-controller_1.10.11_Linux_x86_64.tar.gz" # Install HAProxy apt update diff --git a/vm_example_scripts/init_freebsd.sh b/vm_example_scripts/init_freebsd.sh old mode 100644 new mode 100755 diff --git a/vm_example_scripts/jenkins.sh b/vm_example_scripts/jenkins.sh index 356b9ea..e5db47b 100755 --- a/vm_example_scripts/jenkins.sh +++ b/vm_example_scripts/jenkins.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash helm repo add jenkins https://charts.jenkins.io helm repo update kubectl create namespace jenkins diff --git a/vm_example_scripts/k8s.sh b/vm_example_scripts/k8s.sh index c6f54bb..ff4bd11 100755 --- a/vm_example_scripts/k8s.sh +++ b/vm_example_scripts/k8s.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash VM_BASE_DIR=${VM_BASE_DIR:-"${HOME}/vms"} VM_USER="user" VM=$1 diff --git a/vm_example_scripts/podman_deb.sh b/vm_example_scripts/podman_deb.sh new file mode 100755 index 0000000..09ce657 --- /dev/null +++ b/vm_example_scripts/podman_deb.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + +apt-get update +apt-get -y install podman buildah \ No newline at end of file diff --git a/vm_example_scripts/podman_fedora.sh b/vm_example_scripts/podman_fedora.sh new file mode 100755 index 0000000..d0b4ddc --- /dev/null +++ b/vm_example_scripts/podman_fedora.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Exit on error, undefined vars, and pipe failures +set -euo pipefail + +dnf update +dnf -y install podman buildah \ No newline at end of file diff --git a/vm_example_scripts/podman_freebsd.sh b/vm_example_scripts/podman_freebsd.sh new file mode 100644 index 0000000..a975fe4 --- /dev/null +++ b/vm_example_scripts/podman_freebsd.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env sh +# Source: https://podman.io/docs/installation#installing-on-freebsd-140 + +# Variables +LINE='fdesc /dev/fd fdescfs rw 0 0' +FSTAB="/etc/fstab" +FD_MOUNTPOINT="/dev/fd" +FSTYPE="fdescfs" +SERVICE_NAME='linux' + +# Enable Linux compatibility +sysrc linux_enable=YES + +# Start the service if not running +if ! service "${SERVICE_NAME}" status >/dev/null 2>&1; then + if ! service "${SERVICE_NAME}" start; then + echo "Error: Cannot start ${SERVICE_NAME}." >&2 + exit 1 + fi + echo "Service ${SERVICE_NAME} started" +fi + +# Add fdescfs to /etc/fstab if not present +if ! grep -q 'fdesc[[:space:]]\+/dev/fd[[:space:]]\+fdescfs[[:space:]]\+rw[[:space:]]\+0[[:space:]]\+0' "$FSTAB"; then + printf '%s\n' "$LINE" | tee -a "$FSTAB" > /dev/null +fi + +# Install and enable Podman +pkg install -y podman-suite +service podman enable + +# Mount fdescfs if not already mounted +if ! mount | grep -w "${FD_MOUNTPOINT}" | grep -q "$FSTYPE"; then + mount -t fdescfs fdesc /dev/fd +fi + +# Configure pf firewall +cp /usr/local/etc/containers/pf.conf.sample /etc/pf.conf +sed -i '' 's/ix0/vtnet0/g' /etc/pf.conf + +# Enable pf at boot +if ! grep -q 'pf_load="YES"' "/boot/loader.conf"; then + echo 'pf_load="YES"' | tee -a /boot/loader.conf > /dev/null +fi + +# Load pf module and enable local filtering +kldload pf +sysctl net.pf.filter_local=1 + +if ! grep -q 'net.pf.filter_local=1' "/etc/sysctl.conf.local"; then + echo 'net.pf.filter_local=1' | tee -a /etc/sysctl.conf.local > /dev/null +fi + +service pf enable +service pf restart + +# Configure storage backend +if pgrep -x zfskern >/dev/null 2>&1; then + zfs create -o mountpoint=/var/db/containers zroot/containers +else + sed -I .bak -e 's/driver = "zfs"/driver = "vfs"/' /usr/local/etc/containers/storage.conf +fi \ No newline at end of file diff --git a/vm_manage.sh b/vm_manage.sh index 049d8da..9a3bf91 100755 --- a/vm_manage.sh +++ b/vm_manage.sh @@ -18,6 +18,7 @@ USAGE $0 delete NAME $0 info NAME $0 connect NAME + $0 install NAME $0 list ACTIONS @@ -26,6 +27,7 @@ ACTIONS list List all defined virtual machines info Show information about a virtual machine connect Connect to the console of a virtual machine + install Install specific software into an existing VM OPTIONS -h Show this help message @@ -147,7 +149,11 @@ case "${ACTION}" in vm_connect ${VM_HOSTNAME} fi ;; - + install) + VM_HOSTNAME="$1" + show_software_menu + vm_install_utils $VM_HOSTNAME + ;; list) vm_list ;;