Naming conventions

This commit is contained in:
Thomas Dhome-Casanova
2025-02-04 11:43:36 -08:00
parent 31d7b1d096
commit fe84a35292
39 changed files with 35 additions and 33 deletions

View File

@@ -0,0 +1,410 @@
#!/usr/bin/env bash
set -Eeuo pipefail
: "${WIDTH:=""}"
: "${HEIGHT:=""}"
: "${VERIFY:=""}"
: "${REGION:=""}"
: "${MANUAL:=""}"
: "${REMOVE:=""}"
: "${VERSION:=""}"
: "${DETECTED:=""}"
: "${KEYBOARD:=""}"
: "${LANGUAGE:=""}"
: "${USERNAME:=""}"
: "${PASSWORD:=""}"
MIRRORS=4
PLATFORM="x64"
parseVersion() {
if [[ "${VERSION}" == \"*\" || "${VERSION}" == \'*\' ]]; then
VERSION="${VERSION:1:-1}"
fi
[ -z "$VERSION" ] && VERSION="win11"
case "${VERSION,,}" in
"11" | "11p" | "win11" | "pro11" | "win11p" | "windows11" | "windows 11" )
VERSION="win11x64"
;;
"11e" | "win11e" | "windows11e" | "windows 11e" | "win11x64-enterprise-eval" )
VERSION="win11x64-enterprise-eval"
;;
esac
return 0
}
getLanguage() {
local id="$1"
local ret="$2"
local lang=""
local desc=""
local culture=""
case "${id,,}" in
"ar" | "ar-"* )
lang="Arabic"
desc="$lang"
culture="ar-SA" ;;
"bg" | "bg-"* )
lang="Bulgarian"
desc="$lang"
culture="bg-BG" ;;
"cs" | "cs-"* | "cz" | "cz-"* )
lang="Czech"
desc="$lang"
culture="cs-CZ" ;;
"da" | "da-"* | "dk" | "dk-"* )
lang="Danish"
desc="$lang"
culture="da-DK" ;;
"de" | "de-"* )
lang="German"
desc="$lang"
culture="de-DE" ;;
"el" | "el-"* | "gr" | "gr-"* )
lang="Greek"
desc="$lang"
culture="el-GR" ;;
"gb" | "en-gb" )
lang="English International"
desc="English"
culture="en-GB" ;;
"en" | "en-"* )
lang="English"
desc="English"
culture="en-US" ;;
"mx" | "es-mx" )
lang="Spanish (Mexico)"
desc="Spanish"
culture="es-MX" ;;
"es" | "es-"* )
lang="Spanish"
desc="$lang"
culture="es-ES" ;;
"et" | "et-"* )
lang="Estonian"
desc="$lang"
culture="et-EE" ;;
"fi" | "fi-"* )
lang="Finnish"
desc="$lang"
culture="fi-FI" ;;
"ca" | "fr-ca" )
lang="French Canadian"
desc="French"
culture="fr-CA" ;;
"fr" | "fr-"* )
lang="French"
desc="$lang"
culture="fr-FR" ;;
"he" | "he-"* | "il" | "il-"* )
lang="Hebrew"
desc="$lang"
culture="he-IL" ;;
"hr" | "hr-"* | "cr" | "cr-"* )
lang="Croatian"
desc="$lang"
culture="hr-HR" ;;
"hu" | "hu-"* )
lang="Hungarian"
desc="$lang"
culture="hu-HU" ;;
"it" | "it-"* )
lang="Italian"
desc="$lang"
culture="it-IT" ;;
"ja" | "ja-"* | "jp" | "jp-"* )
lang="Japanese"
desc="$lang"
culture="ja-JP" ;;
"ko" | "ko-"* | "kr" | "kr-"* )
lang="Korean"
desc="$lang"
culture="ko-KR" ;;
"lt" | "lt-"* )
lang="Lithuanian"
desc="$lang"
culture="lv-LV" ;;
"lv" | "lv-"* )
lang="Latvian"
desc="$lang"
culture="lt-LT" ;;
"nb" | "nb-"* |"nn" | "nn-"* | "no" | "no-"* )
lang="Norwegian"
desc="$lang"
culture="nb-NO" ;;
"nl" | "nl-"* )
lang="Dutch"
desc="$lang"
culture="nl-NL" ;;
"pl" | "pl-"* )
lang="Polish"
desc="$lang"
culture="pl-PL" ;;
"br" | "pt-br" )
lang="Brazilian Portuguese"
desc="Portuguese"
culture="pt-BR" ;;
"pt" | "pt-"* )
lang="Portuguese"
desc="$lang"
culture="pt-BR" ;;
"ro" | "ro-"* )
lang="Romanian"
desc="$lang"
culture="ro-RO" ;;
"ru" | "ru-"* )
lang="Russian"
desc="$lang"
culture="ru-RU" ;;
"sk" | "sk-"* )
lang="Slovak"
desc="$lang"
culture="sk-SK" ;;
"sl" | "sl-"* | "si" | "si-"* )
lang="Slovenian"
desc="$lang"
culture="sl-SI" ;;
"sr" | "sr-"* )
lang="Serbian Latin"
desc="Serbian"
culture="sr-Latn-RS" ;;
"sv" | "sv-"* | "se" | "se-"* )
lang="Swedish"
desc="$lang"
culture="sv-SE" ;;
"th" | "th-"* )
lang="Thai"
desc="$lang"
culture="th-TH" ;;
"tr" | "tr-"* )
lang="Turkish"
desc="$lang"
culture="tr-TR" ;;
"ua" | "ua-"* | "uk" | "uk-"* )
lang="Ukrainian"
desc="$lang"
culture="uk-UA" ;;
"hk" | "zh-hk" | "cn-hk" )
lang="Chinese (Traditional)"
desc="Chinese HK"
culture="zh-TW" ;;
"tw" | "zh-tw" | "cn-tw" )
lang="Chinese (Traditional)"
desc="Chinese TW"
culture="zh-TW" ;;
"zh" | "zh-"* | "cn" | "cn-"* )
lang="Chinese (Simplified)"
desc="Chinese"
culture="zh-CN" ;;
esac
case "${ret,,}" in
"desc" ) echo "$desc" ;;
"name" ) echo "$lang" ;;
"culture" ) echo "$culture" ;;
*) echo "$desc";;
esac
return 0
}
parseLanguage() {
REGION="${REGION//_/-/}"
KEYBOARD="${KEYBOARD//_/-/}"
LANGUAGE="${LANGUAGE//_/-/}"
[ -z "$LANGUAGE" ] && LANGUAGE="en"
case "${LANGUAGE,,}" in
"arabic" | "arab" ) LANGUAGE="ar" ;;
"bulgarian" | "bu" ) LANGUAGE="bg" ;;
"chinese" | "cn" ) LANGUAGE="zh" ;;
"croatian" | "cr" | "hrvatski" ) LANGUAGE="hr" ;;
"czech" | "cz" | "cesky" ) LANGUAGE="cs" ;;
"danish" | "dk" | "danske" ) LANGUAGE="da" ;;
"dutch" | "nederlands" ) LANGUAGE="nl" ;;
"english" | "gb" | "british" ) LANGUAGE="en" ;;
"estonian" | "eesti" ) LANGUAGE="et" ;;
"finnish" | "suomi" ) LANGUAGE="fi" ;;
"french" | "français" | "francais" ) LANGUAGE="fr" ;;
"german" | "deutsch" ) LANGUAGE="de" ;;
"greek" | "gr" ) LANGUAGE="el" ;;
"hebrew" | "il" ) LANGUAGE="he" ;;
"hungarian" | "magyar" ) LANGUAGE="hu" ;;
"italian" | "italiano" ) LANGUAGE="it" ;;
"japanese" | "jp" ) LANGUAGE="ja" ;;
"korean" | "kr" ) LANGUAGE="ko" ;;
"latvian" | "latvijas" ) LANGUAGE="lv" ;;
"lithuanian" | "lietuvos" ) LANGUAGE="lt" ;;
"norwegian" | "no" | "nb" | "norsk" ) LANGUAGE="nn" ;;
"polish" | "polski" ) LANGUAGE="pl" ;;
"portuguese" | "pt" | "br" ) LANGUAGE="pt-br" ;;
"português" | "portugues" ) LANGUAGE="pt-br" ;;
"romanian" | "română" | "romana" ) LANGUAGE="ro" ;;
"russian" | "ruski" ) LANGUAGE="ru" ;;
"serbian" | "serbian latin" ) LANGUAGE="sr" ;;
"slovak" | "slovenský" | "slovensky" ) LANGUAGE="sk" ;;
"slovenian" | "si" | "slovenski" ) LANGUAGE="sl" ;;
"spanish" | "espanol" | "español" ) LANGUAGE="es" ;;
"swedish" | "se" | "svenska" ) LANGUAGE="sv" ;;
"turkish" | "türk" | "turk" ) LANGUAGE="tr" ;;
"thai" ) LANGUAGE="th" ;;
"ukrainian" | "ua" ) LANGUAGE="uk" ;;
esac
local culture
culture=$(getLanguage "$LANGUAGE" "culture")
[ -n "$culture" ] && return 0
error "Invalid LANGUAGE specified, value \"$LANGUAGE\" is not recognized!"
return 1
}
printVersion() {
local id="$1"
local desc="$2"
case "${id,,}" in
"win11"* ) desc="Windows 11" ;;
esac
if [ -z "$desc" ]; then
desc="Windows"
[[ "${PLATFORM,,}" != "x64" ]] && desc+=" for ${PLATFORM}"
fi
echo "$desc"
return 0
}
printEdition() {
local id="$1"
local desc="$2"
local result=""
local edition=""
result=$(printVersion "$id" "x")
[[ "$result" == "x" ]] && echo "$desc" && return 0
case "${id,,}" in
*"-enterprise" )
edition="Enterprise"
;;
*"-enterprise-eval" )
edition="Enterprise (Evaluation)"
;;
esac
[ -n "$edition" ] && result+=" $edition"
echo "$result"
return 0
}
fromName() {
local id=""
local name="$1"
local arch="$2"
local add=""
[[ "$arch" != "x64" ]] && add="$arch"
case "${name,,}" in
*"windows 11"* ) id="win11${arch}" ;;
esac
echo "$id"
return 0
}
getVersion() {
local id
local name="$1"
local arch="$2"
id=$(fromName "$name" "$arch")
case "${id,,}" in
"win11"* )
case "${name,,}" in
*" enterprise evaluation"* ) id="$id-enterprise-eval" ;;
*" enterprise"* ) id="$id-enterprise" ;;
esac
;;
esac
echo "$id"
return 0
}
addFolder() {
local src="$1"
local folder="/oem"
[ ! -d "$folder" ] && folder="/OEM"
[ ! -d "$folder" ] && folder="$STORAGE/oem"
[ ! -d "$folder" ] && folder="$STORAGE/OEM"
[ ! -d "$folder" ] && return 0
local msg="Adding OEM folder to image..."
info "$msg" && html "$msg"
local dest="$src/\$OEM\$/\$1/OEM"
mkdir -p "$dest" || return 1
cp -Lr "$folder/." "$dest" || return 1
local file
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat | head -n 1)
[ -f "$file" ] && unix2dos -q "$file"
return 0
}
# migrateFiles() {
# local base="$1"
# local version="$2"
# local file=""
# [ -f "$base" ] && return 0
# [[ "${version,,}" == "tiny10" ]] && file="tiny10_x64_23h2.iso"
# [[ "${version,,}" == "tiny11" ]] && file="tiny11_2311_x64.iso"
# [[ "${version,,}" == "core11" ]] && file="tiny11_core_x64_beta_1.iso"
# [[ "${version,,}" == "winxpx86" ]] && file="en_windows_xp_professional_with_service_pack_3_x86_cd_x14-80428.iso"
# [[ "${version,,}" == "winvistax64" ]] && file="en_windows_vista_sp2_x64_dvd_342267.iso"
# [[ "${version,,}" == "win7x64" ]] && file="en_windows_7_enterprise_with_sp1_x64_dvd_u_677651.iso"
# [ ! -f "$STORAGE/$file" ] && return 0
# mv -f "$STORAGE/$file" "$base" || return 1
# return 0
# }
migrateFiles() {
local base="$1"
local version="$2"
local file=""
[ -f "$base" ] && return 0
[ ! -f "$STORAGE/$file" ] && return 0
mv -f "$STORAGE/$file" "$base" || return 1
return 0
}
return 0

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -Eeuo pipefail
: "${BOOT_MODE:="windows"}"
APP="OmniParser Windows"
SUPPORT="https://github.com/microsoft/OmniParser"
cd /run
. reset.sh # Initialize system
. define.sh # Define versions
. install.sh # Run installation
. disk.sh # Initialize disks
. display.sh # Initialize graphics
. network.sh # Initialize network
. samba.sh # Configure samba
. boot.sh # Configure boot
. proc.sh # Initialize processor
. power.sh # Configure shutdown
. config.sh # Configure arguments
trap - ERR
version=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1 | awk '{ print $NF }')
info "Booting ${APP}${BOOT_DESC} using QEMU v$version..."
{ qemu-system-x86_64 ${ARGS:+ $ARGS} >"$QEMU_OUT" 2>"$QEMU_LOG"; rc=$?; } || :
(( rc != 0 )) && error "$(<"$QEMU_LOG")" && exit 15
terminal
( sleep 30; boot ) &
tail -fn +0 "$QEMU_LOG" 2>/dev/null &
cat "$QEMU_TERM" 2> /dev/null | tee "$QEMU_PTY" &
wait $! || :
sleep 1 & wait $!
[ ! -f "$QEMU_END" ] && finish 0

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,223 @@
#!/usr/bin/env bash
set -Eeuo pipefail
# Configure QEMU for graceful shutdown
QEMU_TERM=""
QEMU_PORT=7100
QEMU_TIMEOUT=110
QEMU_DIR="/run/shm"
QEMU_PID="$QEMU_DIR/qemu.pid"
QEMU_PTY="$QEMU_DIR/qemu.pty"
QEMU_LOG="$QEMU_DIR/qemu.log"
QEMU_OUT="$QEMU_DIR/qemu.out"
QEMU_END="$QEMU_DIR/qemu.end"
rm -f "$QEMU_DIR/qemu.*"
touch "$QEMU_LOG"
_trap() {
func="$1" ; shift
for sig ; do
trap "$func $sig" "$sig"
done
}
boot() {
[ -f "$QEMU_END" ] && return 0
if [ -s "$QEMU_PTY" ]; then
if [ "$(stat -c%s "$QEMU_PTY")" -gt 7 ]; then
local fail=""
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
grep -Fq "No bootable device." "$QEMU_PTY" && fail="y"
grep -Fq "BOOTMGR is missing" "$QEMU_PTY" && fail="y"
fi
if [ -z "$fail" ]; then
info "Windows has started successfully. You can directly view the VM at http://localhost:8006/vnc.html?view_only=1&autoconnect=1&resize=scale. Wait until setup is complete before interacting manually."
return 0
fi
fi
fi
error "Timeout while waiting for QEMU to boot the machine!"
local pid
pid=$(<"$QEMU_PID")
{ kill -15 "$pid" || true; } 2>/dev/null
return 0
}
ready() {
[ -f "$STORAGE/windows.boot" ] && return 0
[ ! -s "$QEMU_PTY" ] && return 1
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
local last
local bios="Booting from Hard"
last=$(grep "^Booting.*" "$QEMU_PTY" | tail -1)
[[ "${last,,}" != "${bios,,}"* ]] && return 1
grep -Fq "No bootable device." "$QEMU_PTY" && return 1
grep -Fq "BOOTMGR is missing" "$QEMU_PTY" && return 1
return 0
fi
local line="\"Windows Boot Manager\""
grep -Fq "$line" "$QEMU_PTY" && return 0
return 1
}
finish() {
local pid
local reason=$1
touch "$QEMU_END"
if [ -s "$QEMU_PID" ]; then
pid=$(<"$QEMU_PID")
error "Forcefully terminating Windows, reason: $reason..."
{ kill -15 "$pid" || true; } 2>/dev/null
while isAlive "$pid"; do
sleep 1
# Workaround for zombie pid
[ ! -s "$QEMU_PID" ] && break
done
fi
if [ ! -f "$STORAGE/windows.boot" ] && [ -f "$BOOT" ]; then
# Remove CD-ROM ISO after install
if ready; then
touch "$STORAGE/windows.boot"
if [[ "$REMOVE" != [Nn]* ]]; then
rm -f "$BOOT" 2>/dev/null || true
fi
fi
fi
pid="/var/run/tpm.pid"
[ -s "$pid" ] && pKill "$(<"$pid")"
pid="/var/run/wsdd.pid"
[ -s "$pid" ] && pKill "$(<"$pid")"
fKill "smbd"
closeNetwork
sleep 0.5
echo " Shutdown completed!"
exit "$reason"
}
terminal() {
local dev=""
if [ -s "$QEMU_OUT" ]; then
local msg
msg=$(<"$QEMU_OUT")
if [ -n "$msg" ]; then
if [[ "${msg,,}" != "char"* || "$msg" != *"serial0)" ]]; then
echo "$msg"
fi
dev="${msg#*/dev/p}"
dev="/dev/p${dev%% *}"
fi
fi
if [ ! -c "$dev" ]; then
dev=$(echo 'info chardev' | nc -q 1 -w 1 localhost "$QEMU_PORT" | tr -d '\000')
dev="${dev#*serial0}"
dev="${dev#*pty:}"
dev="${dev%%$'\n'*}"
dev="${dev%%$'\r'*}"
fi
if [ ! -c "$dev" ]; then
error "Device '$dev' not found!"
finish 34 && return 34
fi
QEMU_TERM="$dev"
return 0
}
_graceful_shutdown() {
local code=$?
set +e
if [ -f "$QEMU_END" ]; then
info "Received $1 while already shutting down..."
return
fi
touch "$QEMU_END"
info "Received $1, sending ACPI shutdown signal..."
if [ ! -s "$QEMU_PID" ]; then
error "QEMU PID file does not exist?"
finish "$code" && return "$code"
fi
local pid=""
pid=$(<"$QEMU_PID")
if ! isAlive "$pid"; then
error "QEMU process does not exist?"
finish "$code" && return "$code"
fi
if ! ready; then
info "Cannot send ACPI signal during Windows setup, aborting..."
finish "$code" && return "$code"
fi
# Send ACPI shutdown signal
echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
local cnt=0
while [ "$cnt" -lt "$QEMU_TIMEOUT" ]; do
sleep 1
cnt=$((cnt+1))
! isAlive "$pid" && break
# Workaround for zombie pid
[ ! -s "$QEMU_PID" ] && break
info "Waiting for Windows to shutdown... ($cnt/$QEMU_TIMEOUT)"
# Send ACPI shutdown signal
echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
done
if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then
error "Shutdown timeout reached, aborting..."
fi
finish "$code" && return "$code"
}
SERIAL="pty"
MONITOR="telnet:localhost:$QEMU_PORT,server,nowait,nodelay"
MONITOR+=" -daemonize -D $QEMU_LOG -pidfile $QEMU_PID"
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
return 0

View File

@@ -0,0 +1,109 @@
#!/usr/bin/env bash
set -Eeuo pipefail
: "${SAMBA:="Y"}"
[[ "$SAMBA" == [Nn]* ]] && return 0
[[ "$NETWORK" == [Nn]* ]] && return 0
hostname="host.lan"
interface="dockerbridge"
if [[ "$DHCP" == [Yy1]* ]]; then
hostname="$IP"
interface="$VM_NET_DEV"
fi
addShare() {
local dir="$1"
local name="$2"
local comment="$3"
mkdir -p "$dir" || return 1
if [ -z "$(ls -A "$dir")" ]; then
chmod 777 "$dir"
{ echo "--------------------------------------------------------"
echo " $APP"
echo " For support visit $SUPPORT"
echo "--------------------------------------------------------"
echo ""
echo "Using this folder you can share files with the host machine."
echo ""
echo "To change its location, include the following bind mount in your compose file:"
echo ""
echo " volumes:"
echo " - \"/home/example:/${name,,}\""
echo ""
echo "Or in your run command:"
echo ""
echo " -v \"/home/example:/${name,,}\""
echo ""
echo "Replace the example path /home/example with the desired shared folder."
echo ""
} | unix2dos > "$dir/readme.txt"
fi
{ echo ""
echo "[$name]"
echo " path = $dir"
echo " comment = $comment"
echo " writable = yes"
echo " guest ok = yes"
echo " guest only = yes"
echo " force user = root"
echo " force group = root"
} >> "/etc/samba/smb.conf"
return 0
}
{ echo "[global]"
echo " server string = Dockur"
echo " netbios name = $hostname"
echo " workgroup = WORKGROUP"
echo " interfaces = $interface"
echo " bind interfaces only = yes"
echo " security = user"
echo " guest account = nobody"
echo " map to guest = Bad User"
echo " server min protocol = NT1"
echo ""
echo " # disable printing services"
echo " load printers = no"
echo " printing = bsd"
echo " printcap name = /dev/null"
echo " disable spoolss = yes"
} > "/etc/samba/smb.conf"
share="/data"
[ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data"
[ ! -d "$share" ] && [ -d "/shared" ] && share="/shared"
[ ! -d "$share" ] && [ -d "$STORAGE/shared" ] && share="$STORAGE/shared"
addShare "$share" "Data" "Shared" || error "Failed to create shared folder!"
[ -d "/data2" ] && addShare "/data2" "Data2" "Shared"
[ -d "/data3" ] && addShare "/data3" "Data3" "Shared"
if ! smbd; then
error "Samba daemon failed to start!"
smbd -i --debug-stdout || true
fi
if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
# Enable NetBIOS on Windows 7 and lower
if ! nmbd; then
error "NetBIOS daemon failed to start!"
nmbd -i --debug-stdout || true
fi
else
# Enable Web Service Discovery on Vista and up
wsdd -i "$interface" -p -n "$hostname" &
echo "$!" > /var/run/wsdd.pid
fi
return 0