Skip to content

Commit

Permalink
Some work on going distro-agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
T-vK committed Aug 4, 2021
1 parent 33e7e37 commit 635eaa1
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 99 deletions.
51 changes: 0 additions & 51 deletions requirements.json

This file was deleted.

44 changes: 44 additions & 0 deletions requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#####################################################################################################
# This file is supposed to be `source`d by the `scripts/main/setup.sh` bash script.
# It specifies which executables and files and kernel parameters what part of this project depends on
# WARNING: File dependencies can't contain spaces at the moment
# Usage: `source ./requirements.txt`
#####################################################################################################

KERNEL_PARAMS_GENERAL=("iommu=1" "kvm.ignore_msrs=1" "rd.driver.pre=vfio-pci")
KERNEL_PARAMS_INTEL_CPU=("intel_iommu=on")
KERNEL_PARAMS_AMD_CPU=("amd_iommu=on")
KERNEL_PARAMS_INTEL_GPU=("i915.enable_gvt=1")
#KERNEL_PARAMS_AMD_GPU=()
#KERNEL_PARAMS_NVIDIA_GPU=()
KERNEL_PARAMS_BUMBLEBEE_NVIDIA=("nouveau.modeset=0")
#EXEC_DEPS_GENERAL=("sudo" "bash" "mv" "cp" "sed" "awk" "git" "echo" "ls" "wget" "curl" "printf" "cd" "mkdir" "chmod" "chown" "grep" "cut" "which")
EXEC_DEPS_FAKE_BATTERY=("iasl")
EXEC_DEPS_OVMF_VBIOS_PATCH=("git" "docker")
EXEC_DEPS_GENERATE_CONFIG=("crudini")
EXEC_DEPS_VBIOS_FINDER=("git" "wget" "curl" "unzip" "ruby" "gem" "bundle" "7za" "make" "innoextract" "upx")
FILE_DEPS_VBIOS_FINDER=("/usr/include/{ruby,ruby-2.7}/ruby.h")
EXEC_DEPS_VIRTUALIZATION=("qemu-system-x86_x64" "virsh" "virt-viewer" "spicy")
FILE_DEPS_VIRTUALIZATION=("OVMF/OVMF_CODE.fd" "OVMF/OVMF_VARS.fd" "virtio-win/virtio-win.iso") # TODO: get the iso using wget cuz only rhel distros have a package for that anyways
EXEC_DEPS_RDP=("remmina")
EXEC_DEPS_SAMBA=("samba")
EXEC_DEPS_IGPU_PASSTHROUGH=("uuid" "intel-virtual-output")
EXEC_DEPS_HELPER_ISO=("genisoimage")
EXEC_DEPS_UEFI_CHECK=("systool")
EXEC_DEPS_COMPATIBILITY_CHECK=("systool" "lshw" "lspci" "dmidecode" "lsusb" "lsblk" "lscpu")
EXEC_DEPS_CPU_CHECK=("lscpu")
EXEC_DEPS_GPU_CHECK=("lshw")

#############################################################################################################################

ALL_EXEC_DEPS="" # Will contain all content of all variables starting with EXEC_DEPS
ALL_EXEC_DEPS_VARS="$(set -o posix ; set | grep -P '^EXEC_DEPS' | cut -d'=' -f1 | tr '\n' ' ')"
for deps in $ALL_EXEC_DEPS_VARS; do
ALL_EXEC_DEPS+="$(eval "echo \" \${$deps[*]}\"")"
done

ALL_FILE_DEPS="" # Will contain all content of all variables starting with FILE_DEPS
ALL_FILE_DEPS_VARS="$(set -o posix ; set | grep -P '^FILE_DEPS' | cut -d'=' -f1 | tr '\n' ' ')"
for deps in $ALL_FILE_DEPS_VARS; do
ALL_FILE_DEPS+="$(eval "echo \" \${$deps[*]}\"")"
done
16 changes: 0 additions & 16 deletions scripts/main/remove-vm.sh

This file was deleted.

89 changes: 64 additions & 25 deletions scripts/main/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,76 @@ source "$PROJECT_DIR/scripts/utils/common/libs/helpers"
# TODO: the service creation shouldn'T be part of setup.sh. It should be in the auto section of mbpt.sh.
#####################################################################################################

mkdir -p "${THIRDPARTY_DIR}"
source "${PROJECT_DIR}/requirements.sh"
source "$COMMON_UTILS_LIBS_DIR/cpu-check"
source "$COMMON_UTILS_LIBS_DIR/gpu-check"
source "$DISTRO_UTILS_DIR/kernel-param-utils"

alias getExecPkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --executables"
alias getFilePkg="'${COMMON_UTILS_TOOLS_DIR}/install-packages' --files"

# TODO: parse requirements.json and install dependencies automatically
# TODO: complete this list
if ! "${COMMON_UTILS_TOOLS_DIR}/commands-available" "wget curl vim screen git crudini remmina spicy genisoimage uuid iasl docker dumpet imake g++ virt-install qemu-system-x86_64 systool"; then
sudo "$DISTRO_UTILS_DIR/install-dependencies"
else
echo "[Skipped] Required packages already installed."
fi
mkdir -p "${THIRDPARTY_DIR}"

source "$DISTRO_UTILS_DIR/kernel-param-utils"
getExecPkg "$ALL_EXEC_DEPS" # Find and install packages containing executables that we need
getFilePkg "$ALL_FILE_DEPS" # Find and install packages containing specific files that we need

if runtimeKernelHasParam "iommu=1" && \
runtimeKernelHasParam "amd_iommu=on" && \
runtimeKernelHasParam "intel_iommu=on" && \
runtimeKernelHasParam "i915.enable_gvt=1" && \
runtimeKernelHasParam "kvm.ignore_msrs=1" && \
runtimeKernelHasParam "rd.driver.pre=vfio-pci"; then
REBOOT_REQUIRED=false
echo "[Skipped] Kernel parameters are already set."
else
sudo "$COMMON_UTILS_SETUP_DIR/set-kernel-params"
REBOOT_REQUIRED=false
if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_GENERAL[*]}"]; then
echo "> Adding general kernel params..."
addKernelParams "${KERNEL_PARAMS_GENERAL[*]}"
REBOOT_REQUIRED=true
elif
echo "> [Skipped] General kernel params already set on running kernel..."
REBOOT_REQUIRED=false
fi

#if [ $HAS_INTEL_CPU = true ]; then
if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_CPU[*]}"]; then
echo "> Adding Intel CPU-specific kernel params..."
addKernelParams "${KERNEL_PARAMS_INTEL_CPU[*]}"
REBOOT_REQUIRED=true
elif
echo "> [Skipped] Intel CPU-specific kernel params already set on running kernel..."
fi
#fi

#if [ $HAS_AMD_CPU = true ]; then
if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_AMD_CPU[*]}"]; then
echo "> Adding AMD CPU-specific kernel params..."
addKernelParams "${KERNEL_PARAMS_AMD_CPU[*]}"
REBOOT_REQUIRED=true
elif
echo "> [Skipped] AMD CPU-specific kernel params already set on running kernel..."
fi
#fi

#if [ $HAS_INTEL_GPU = true ]; then
if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_INTEL_GPU[*]}"]; then
echo "> Adding Intel GPU-specific kernel params..."
addKernelParams "${KERNEL_PARAMS_INTEL_GPU[*]}"
REBOOT_REQUIRED=true
elif
echo "> [Skipped] Intel GPU-specific kernel params already set on running kernel..."
fi
#fi

if [ $HAS_NVIDIA_GPU = true ]; then # TODO: Don't force Bumblebee and the proprietary Nvidia driver upon the user
if [ ! runtimeKernelHasParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"]; then
echo "> Adding Nvidia GPU-specific kernel params..."
addKernelParams "${KERNEL_PARAMS_BUMBLEBEE_NVIDIA[*]}"
REBOOT_REQUIRED=true
elif
echo "> [Skipped] Nvidia GPU-specific kernel params already set on running kernel..."
fi
fi

if [[ "$(docker images -q ovmf-vbios-patch 2> /dev/null)" == "" ]]; then
echo "> Image 'ovmf-vbios-patch' has already been built."
sudo "$COMMON_UTILS_SETUP_DIR/ovmf-vbios-patch-setup"
else
echo "[Skipped] Image 'ovmf-vbios-patch' has already been built."
echo "> [Skipped] Image 'ovmf-vbios-patch' has already been built."
fi

source "$COMMON_UTILS_LIBS_DIR/gpu-check"

if [ "$HAS_INTEL_GPU" = true ]; then
sudo "$DISTRO_UTILS_DIR/intel-setup"
fi
Expand All @@ -57,21 +93,24 @@ if [ "$SUPPORTS_OPTIMUS" = true ]; then
fi

if [ ! -f "${ACPI_TABLES_DIR}/fake-battery.aml" ]; then
echo "> Building fake ACPI SSDT battery..."
sudo "$COMMON_UTILS_SETUP_DIR/build-fake-battery-ssdt"
else
echo "[Skipped] Fake ACPI SSDT battery has already been built."
echo "> [Skipped] Fake ACPI SSDT battery has already been built."
fi

if [ ! -f "${THIRDPARTY_DIR}/VBiosFinder/vendor/bundle/ruby/3.0.0/bin/coderay" ]; then
echo "> Installing VBiosFinder..."
sudo "$DISTRO_UTILS_DIR/vbios-finder-installer/vbiosfinder"
else
echo "[Skipped] VBiosFinder is already set up."
echo "> [Skipped] VBiosFinder is already set up."
fi

if [ ! -f "${THIRDPARTY_DIR}/LookingGlass/looking-glass-host.exe" ] || [ ! -f "${THIRDPARTY_DIR}/LookingGlass/client/build/looking-glass-client" ]; then
echo "> Installing Looking Glass..."
sudo "$DISTRO_UTILS_DIR/looking-glass-setup"
else
echo "[Skipped] Looking Glass is already set up."
echo "> [Skipped] Looking Glass is already set up."
fi

echo "> Generating helper-iso for auto Windows Configuration / Driver installation..."
Expand Down
21 changes: 18 additions & 3 deletions scripts/main/vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@ loadConfig
# or start the previously created Windows VM, if called like this: `./vm.sh`
#####################################################################################################

VM_START_MODE="qemu" # qemu or virt-install

if [ "$1" = "install" ]; then
VM_INSTALL=true
else
elif [ "$1" = "start" ]; then
VM_INSTALL=false
elif [ "$1" = "remove" ]; then
if [ $VM_START_MODE = "virt-install" ]; then
sudo virsh destroy --domain "${VM_NAME}"
sudo virsh undefine --domain "${VM_NAME}" --nvram
#elif [ $VM_START_MODE = "qemu" ]; then
#
fi
if [[ ${DRIVE_IMG} == *.img ]]; then
sudo rm -f "${DRIVE_IMG}"
fi
rm -f "${OVMF_VARS_VM}"
else
echo "> Error: No valid vm.sh parameter was found!"
exit 1
fi
VM_START_MODE="qemu" # qemu or virt-install

#source "$COMMON_UTILS_LIBS_DIR/gpu-check"
shopt -s expand_aliases
alias driver="sudo '$COMMON_UTILS_TOOLS_DIR/driver-util'"
alias vgpu="sudo '$COMMON_UTILS_TOOLS_DIR/vgpu-util'"

Expand Down Expand Up @@ -373,6 +387,7 @@ if [ "$PATCH_OVMF_WITH_VROM" = true ]; then
sudo chown "$(whoami):$(id -gn "$(whoami)")" "${PATCHED_OVMF_FILES_DIR}"
echo "> Patching OVMF with your vBIOS ROM. This may take a few minutes!"
sleep 5 # Ensure the user can read this first
sudo service docker start
sudo docker run --rm -ti -v "${PATCHED_OVMF_FILES_DIR}/tmp-build:/build:z" -v "${DGPU_ROM_DIR}:/roms:z" -e "VROM=${DGPU_ROM_NAME}" ovmf-vbios-patch
sudo chown "$(whoami):$(id -gn "$(whoami)")" -R "${PATCHED_OVMF_FILES_DIR}/tmp-build"
sudo mv "${PATCHED_OVMF_FILES_DIR}/tmp-build/OVMF_CODE.fd" "${PATCHED_OVMF_FILES_DIR}/${DGPU_ROM_NAME}_OVMF_CODE.fd"
Expand Down
14 changes: 14 additions & 0 deletions scripts/utils/common/libs/cpu-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#####################################################################################################
# This script is not meant to be executed. It should be `source`d.
# It creates a bunch of variables telling you what kinds of CPUs the system has.
# Use it like this: `source "./cpu-check.sh"`
#####################################################################################################

LSCPU_OUTPUT="$(sudo lscpu)"
if echo -e "$LSCPU_OUTPUT" | grep "Model name: " | grep -qi "intel"; then
export HAS_INTEL_CPU=true
fi

if echo -e "$LSCPU_OUTPUT" | grep "Model name: " | grep -qi "AMD"; then
export HAS_AMD_CPU=true
fi
2 changes: 0 additions & 2 deletions scripts/utils/common/libs/gpu-check
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

#####################################################################################################
# This script is not meant to be executed. It should be `source`d.
# It creates a bunch of variables telling you what kinds of GPUs the system has.
Expand Down
2 changes: 0 additions & 2 deletions scripts/utils/common/libs/helpers
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

#####################################################################################################
# This script has to be sourced and is not meant to be executed directly!
# How to use: Insert the following two lines without the `#` symbols below the shebang of all scripts in this project that need it:
Expand Down
Loading

0 comments on commit 635eaa1

Please sign in to comment.