#!/usr/bin/env bash set -Eeuo pipefail trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR [[ "${TRACE:-}" == [Yy1]* ]] && set -o functrace && trap 'echo "# $BASH_COMMAND" >&2' DEBUG [ ! -f "/run/entry.sh" ] && error "Script must be run inside the container!" && exit 11 [ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12 # Docker environment variables : "${BOOT:=""}" # Path of ISO file : "${DEBUG:="N"}" # Disable debugging : "${MACHINE:="q35"}" # Machine selection : "${ALLOCATE:=""}" # Preallocate diskspace : "${ARGUMENTS:=""}" # Extra QEMU parameters : "${CPU_CORES:="2"}" # Amount of CPU cores : "${RAM_SIZE:="2G"}" # Maximum RAM amount : "${RAM_CHECK:="Y"}" # Check available RAM : "${DISK_SIZE:="64G"}" # Initial data disk size : "${BOOT_MODE:=""}" # Boot system with UEFI : "${BOOT_INDEX:="9"}" # Boot index of CD drive : "${STORAGE:="/storage"}" # Storage folder location # Helper variables PODMAN="N" ENGINE="Docker" PROCESS="${APP,,}" PROCESS="${PROCESS// /-}" if [ -f "/run/.containerenv" ]; then PODMAN="Y" ENGINE="Podman" fi echo "❯ Starting $APP for $ENGINE v$(/dev/null && error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16 RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE") [ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16 # Print system info SYS="${SYS/-generic/}" FS=$(stat -f -c %T "$STORAGE") FS="${FS/UNKNOWN //}" FS="${FS/ext2\/ext3/ext4}" FS=$(echo "$FS" | sed 's/[)(]//g') SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1) SPACE_GB=$(formatBytes "$SPACE" "down") AVAIL_MEM=$(formatBytes "$RAM_AVAIL" "down") TOTAL_MEM=$(formatBytes "$RAM_TOTAL" "up") echo "❯ CPU: ${CPU} | RAM: ${AVAIL_MEM/ GB/}/$TOTAL_MEM | DISK: $SPACE_GB (${FS}) | KERNEL: ${SYS}..." echo # Check compatibilty if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then DISK_IO="threads" DISK_CACHE="writeback" fi if [[ "${BOOT_MODE:-}" == "windows"* ]]; then if [[ "${FS,,}" == "btrfs" ]]; then warn "you are using the BTRFS filesystem for /storage, this might introduce issues with Windows Setup!" fi fi # Check available memory if [[ "$RAM_CHECK" != [Nn]* ]] && (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then AVAIL_MEM=$(formatBytes "$RAM_AVAIL") msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available, please set a lower value." [[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17 info "$msg" fi addPackage() { local pkg=$1 local desc=$2 if apt-mark showinstall | grep -qx "$pkg"; then return 0 fi MSG="Installing $desc..." info "$MSG" && html "$MSG" DEBIAN_FRONTEND=noninteractive apt-get -qq update DEBIAN_FRONTEND=noninteractive apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null return 0 } : "${VNC_PORT:="5900"}" # VNC port : "${MON_PORT:="7100"}" # Monitor port : "${WEB_PORT:="8006"}" # Webserver port : "${WSS_PORT:="5700"}" # Websockets port if (( VNC_PORT < 5900 )); then warn "VNC port cannot be set lower than 5900, ignoring value $VNC_PORT." VNC_PORT="5900" fi cp -r /var/www/* /run/shm html "Starting $APP for $ENGINE..." if [[ "${WEB:-}" != [Nn]* ]]; then mkdir -p /etc/nginx/sites-enabled cp /etc/nginx/default.conf /etc/nginx/sites-enabled/web.conf user="admin" [ -n "${USER:-}" ] && user="${USER:-}" if [ -n "${PASS:-}" ]; then # Set password echo "$user:{PLAIN}${PASS:-}" > /etc/nginx/.htpasswd sed -i "s/auth_basic off/auth_basic \"NoVNC\"/g" /etc/nginx/sites-enabled/web.conf fi sed -i "s/listen 8006 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf sed -i "s/proxy_pass http:\/\/127.0.0.1:5700\/;/proxy_pass http:\/\/127.0.0.1:$WSS_PORT\/;/g" /etc/nginx/sites-enabled/web.conf # shellcheck disable=SC2143 if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf fi # Start webserver nginx -e stderr fi return 0