#!/bin/bash
echo -e "\n\e[1;31mWARNING - READ CAREFULLY THE CODE BEFORE USING THIS SCRIPT\e[0m\n"
# Never run any code that you don’t trust.
# And the only way to truly trust code is to understand what it does.
# Read carefully the following documents before you run this script:
# https://svensemmler.org/notes/deb-min-templates
# https://www.qubes-os.org/doc/templates/minimal
echo -e "\n\e[1;34m[1/4] SCRIPT DEFINITION AND REMARKS...\e[0m"
SOURCE_TEMPLATE=deb-11-m
NAME=unknown
echo -e "This script will add \e[1;32mPROGRAM_A\e[0m and \e[1;32mPROGRAM_B\e[0m ...
Furhermore, it will set \e[1;32mSOMETHING_X\e[0m and \e[1;32mSOMETHING_Y\e[0m ...
source: https://...
source: https://..."
echo -e "\n\e[1;34m[2/4] PREPARATION AND SETTINGS...\e[0m"
TPL_NAME=$SOURCE_TEMPLATE-$NAME
TPL_PROMPT=$TPL_NAME
APPVM_NAME=$NAME-m
APPVM_LABEL=blue
#APPVM_MEMORY=400
#APPVM_VCPUS=2
echo "Enter customized template name OR press ENTER for default"
read -r -p "($TPL_NAME): " TPL_PROMPT
if [ ${#TPL_PROMPT} != 0 ]; then TPL_NAME=$TPL_PROMPT ; fi
echo "Mimimal template name ($TPL_NAME) is set."
read -p "Do you want to create an AppVM afterwards? (y/n): " APPVM_Y_N
if [ $APPVM_Y_N = y ]; then
echo "Enter customized AppVM name OR press ENTER for default"
read -r -p "($APPVM_NAME): " APPVM_PROMPT
if [ ${#APPVM_PROMPT} != 0 ]; then APPVM_NAME=$APPVM_PROMPT ; fi
else
if [ $APPVM_Y_N = y ]; then echo "Kept default AppVM naming ($APPVM_NAME)."; fi
fi
echo ""
echo "Type (i) to make individual settings OR press ENTER for default"
read -r -p "(i/press ENTER): " SET_PROMPT
if [ ${#SET_PROMPT} = 0 ]; then
TPL_STD=YES
elif [ $SET_PROMPT = i ]; then
TPL_STD=NO
fi
if [ $TPL_STD = NO ]; then
read -p "Do you want to use PROGRAM_A? (y/n): " PROGRAM_A
read -p "Do you want to set PROGRAM_B? (y/n): " PROGRAM_B
fi
echo "qvm-clone $SOURCE_TEMPLATE $TPL_NAME"
echo -e "\n\e[1;34m[3/4] INSTALLATION OF ALL BUT ONLY NECESSARY PACKAGES...\e[0m"
echo "qvm-run --pass-io -u root $TPL_NAME "apt install PACKAGE -y""
if [ $TPL_STD = YES ] || [ $PROGRAM_A = y ]; then
echo "qvm-run --pass-io -u root $TPL_NAME "apt install PACKAGE -y""
fi
if [ $TPL_STD = YES ] || [ $PROGRAM_A = y ]; then
echo "qvm-run --pass-io -u root $TPL_NAME "apt install PACKAGE -y""
fi
echo "qvm-shutdown --wait $TPL_NAME"
echo -e "\n\e[1;34m[4/4] POST-INSTALLATION ROUTINE...\e[0m"
if [ $APPVM_Y_N = y ]; then
echo "qvm-create $APPVM_NAME -t $TPL_NAME --label $APPVM_LABEL"
echo "INFO: The AppVM ($APPVM_NAME) has been created."
fi