#!/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 : "${TZ:=""}" # System timezone : "${KVM:="Y"}" # KVM acceleration : "${DEBUG:="N"}" # Disable debugging mode : "${COUNTRY:=""}" # Country code for mirror : "${CONSOLE:="N"}" # Disable console mode : "${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:="16G"}" # Initial data disk size : "${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 fi # Print system info SYS="${SYS/-generic/}" 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 KVM support if [[ "${PLATFORM,,}" == "x64" ]]; then TARGET="amd64" else TARGET="arm64" fi if [[ "$KVM" == [Nn]* ]]; then warn "KVM acceleration is disabled, this will cause the machine to run about 10 times slower!" else if [[ "${ARCH,,}" != "$TARGET" ]]; then KVM="N" warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for ${PLATFORM^^} instructions, so the machine will run about 10 times slower." fi fi if [[ "$KVM" != [Nn]* ]]; then KVM_ERR="" if [ ! -e /dev/kvm ]; then KVM_ERR="(/dev/kvm is missing)" else if ! sh -c 'echo -n > /dev/kvm' &> /dev/null; then KVM_ERR="(/dev/kvm is unwriteable)" else if [[ "${PLATFORM,,}" == "x64" ]]; then flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo) if ! grep -qw "vmx\|svm" <<< "$flags"; then KVM_ERR="(not enabled in BIOS)" fi fi fi fi if [ -n "$KVM_ERR" ]; then KVM="N" if [[ "$OSTYPE" =~ ^darwin ]]; then warn "you are using macOS which has no KVM support, so the machine will run about 10 times slower." else kernel=$(uname -a) case "${kernel,,}" in *"microsoft"* ) error "Please bind '/dev/kvm' as a volume in the optional container settings when using Docker Desktop." ;; *"synology"* ) error "Please make sure that Synology VMM (Virtual Machine Manager) is installed and that '/dev/kvm' is binded to this container." ;; *) error "KVM acceleration is not available $KVM_ERR, this will cause the machine to run about 10 times slower." error "See the FAQ for possible causes, or disable acceleration by adding the \"KVM=N\" variable (not recommended)." ;; esac [[ "$DEBUG" != [Yy1]* ]] && exit 88 fi fi fi # Cleanup files rm -f /run/shm/qemu.* rm -f /run/shm/dsm.url # Cleanup dirs rm -rf /tmp/dsm rm -rf "$STORAGE/tmp" return 0