mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-08-29 04:07:02 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51d6f3aeca | ||
|
|
4544620d48 | ||
|
|
de8468161f | ||
|
|
18d6be8210 | ||
|
|
e5b8cf3bf8 | ||
|
|
ec12039f43 | ||
|
|
3c7c3ca1b1 | ||
|
|
2b27f32cd4 | ||
|
|
55d1d50284 | ||
|
|
784b73b5b5 | ||
|
|
85f00bb9cc | ||
|
|
efe8732e47 | ||
|
|
f6871dd61b | ||
|
|
a713b728ff | ||
|
|
0d74c6ac80 | ||
|
|
63e4529eff | ||
|
|
afd848cebb | ||
|
|
695b075130 | ||
|
|
7eff53e722 | ||
|
|
bcaf0e5980 | ||
|
|
faa820c2cc | ||
|
|
81e477fcc4 | ||
|
|
abd3a1c3df | ||
|
|
3b59bcd284 | ||
|
|
f1b56f394a | ||
|
|
1a983ebcd1 | ||
|
|
41c76198fa | ||
|
|
222b5649b0 | ||
|
|
e14fd4b711 | ||
|
|
6fe19a8af4 | ||
|
|
072b5c3070 | ||
|
|
89dbaeb2a4 | ||
|
|
02f76b44cd | ||
|
|
99d6b8f830 | ||
|
|
e6b68b2f08 | ||
|
|
7a8f0041e7 | ||
|
|
64809bb4d4 | ||
|
|
f08b2cbd99 | ||
|
|
18d9ecd434 | ||
|
|
6944293a32 | ||
|
|
d807a365ff | ||
|
|
066af83d07 | ||
|
|
81536818df | ||
|
|
949c288565 | ||
|
|
5d5bbbcf4d | ||
|
|
82a62c0240 | ||
|
|
5399e1d463 | ||
|
|
c7e7b60f01 | ||
|
|
f1defa6890 | ||
|
|
a7fb161974 | ||
|
|
dcdf5e5293 | ||
|
|
1eb0db66ba | ||
|
|
3eec8e03ed | ||
|
|
5483981ed4 | ||
|
|
62330a5bf4 | ||
|
|
2b0b59dfba | ||
|
|
b680ff9dd8 | ||
|
|
5c889b272d | ||
|
|
585ebb3f53 | ||
|
|
401307b981 | ||
|
|
46820fe6eb | ||
|
|
9452d48694 | ||
|
|
5c3fed1387 | ||
|
|
797411ae7f | ||
|
|
e81c509208 | ||
|
|
ace8614a50 | ||
|
|
8263b3a737 | ||
|
|
61c6142988 | ||
|
|
5d26338bb3 | ||
|
|
084d475cde | ||
|
|
c36b0dcb00 | ||
|
|
6e9993742b | ||
|
|
6946af0212 | ||
|
|
0a9361d62f | ||
|
|
7cbfcd44a6 |
@@ -1,10 +1,21 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
- package-ecosystem: docker
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
cooldown:
|
||||
default-days: 7
|
||||
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
cooldown:
|
||||
default-days: 7
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types:
|
||||
- version-update:semver-minor
|
||||
- version-update:semver-patch
|
||||
|
||||
+27
-20
@@ -1,5 +1,7 @@
|
||||
on: [workflow_call]
|
||||
|
||||
name: "Check"
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
@@ -7,24 +9,29 @@ jobs:
|
||||
name: shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
- parallel:
|
||||
-
|
||||
name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
env:
|
||||
SHELLCHECK_OPTS: -x --source-path=src -e SC2001 -e SC2034 -e SC2064 -e SC2317 -e SC2153 -e SC2028
|
||||
-
|
||||
name: Lint Dockerfile
|
||||
uses: hadolint/hadolint-action@v3.3.0
|
||||
with:
|
||||
dockerfile: Dockerfile
|
||||
ignore: DL3008,DL3003,DL3006,DL3013
|
||||
failure-threshold: warning
|
||||
-
|
||||
name: Validate JSON and YML files
|
||||
uses: GrantBirki/json-yaml-validate@v5.0.0
|
||||
with:
|
||||
yaml_exclude_regex: ".*\\kubernetes\\.yml$"
|
||||
name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
- parallel:
|
||||
-
|
||||
name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
env:
|
||||
SHELLCHECK_OPTS: >-
|
||||
-x
|
||||
--source-path=src
|
||||
-e SC1091
|
||||
-e SC2001
|
||||
-e SC2034
|
||||
-e SC2317
|
||||
-e SC2153
|
||||
-
|
||||
name: Lint Dockerfile
|
||||
uses: hadolint/hadolint-action@v3.4.0
|
||||
with:
|
||||
dockerfile: Dockerfile
|
||||
ignore: DL3008
|
||||
failure-threshold: warning
|
||||
-
|
||||
name: Validate JSON and YML files
|
||||
uses: GrantBirki/json-yaml-validate@v5
|
||||
|
||||
@@ -11,61 +11,4 @@ permissions:
|
||||
jobs:
|
||||
review:
|
||||
name: review
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
- parallel:
|
||||
-
|
||||
name: Spelling
|
||||
uses: reviewdog/action-misspell@v1
|
||||
with:
|
||||
locale: "US"
|
||||
level: warning
|
||||
pattern: |
|
||||
*.md
|
||||
*.sh
|
||||
reporter: github-pr-review
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: Hadolint
|
||||
uses: reviewdog/action-hadolint@v1
|
||||
with:
|
||||
level: warning
|
||||
fail_level: error
|
||||
reporter: github-pr-review
|
||||
hadolint_ignore: DL3008 DL3003 DL3006 DL3013
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: YamlLint
|
||||
uses: reviewdog/action-yamllint@v1
|
||||
with:
|
||||
level: warning
|
||||
reporter: github-pr-review
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: ActionLint
|
||||
uses: reviewdog/action-actionlint@v1
|
||||
with:
|
||||
level: warning
|
||||
reporter: github-pr-review
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: Shellformat
|
||||
uses: reviewdog/action-shfmt@v1
|
||||
if: false
|
||||
with:
|
||||
level: warning
|
||||
fail_on_error: "true"
|
||||
shfmt_flags: "-i 2 -ci -bn"
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: Shellcheck
|
||||
uses: reviewdog/action-shellcheck@v1
|
||||
with:
|
||||
level: warning
|
||||
fail_level: error
|
||||
reporter: github-pr-review
|
||||
shellcheck_flags: -x -e SC1091 -e SC2001 -e SC2034 -e SC2064 -e SC2317 -e SC2153 -e SC2028
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
uses: action-pack/.github/.github/workflows/review.yml@master
|
||||
|
||||
+268
-1
@@ -1 +1,268 @@
|
||||
build.sh
|
||||
##############################
|
||||
# Operating System Files
|
||||
##############################
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
Icon?
|
||||
$RECYCLE.BIN/
|
||||
.Spotlight-V100/
|
||||
.Trashes/
|
||||
.fseventsd
|
||||
|
||||
##############################
|
||||
# IDEs
|
||||
##############################
|
||||
|
||||
.vscode/
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
##############################
|
||||
# VS Code
|
||||
##############################
|
||||
|
||||
.history/
|
||||
*.code-workspace
|
||||
|
||||
##############################
|
||||
# Vim
|
||||
##############################
|
||||
|
||||
*.swp
|
||||
*.swo
|
||||
Session.vim
|
||||
|
||||
##############################
|
||||
# Sublime
|
||||
##############################
|
||||
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
|
||||
##############################
|
||||
# Temporary Files
|
||||
##############################
|
||||
|
||||
*.tmp
|
||||
*.temp
|
||||
*.bak
|
||||
*.old
|
||||
*.orig
|
||||
*.rej
|
||||
*.save
|
||||
|
||||
##############################
|
||||
# Logs
|
||||
##############################
|
||||
|
||||
*.log
|
||||
logs/
|
||||
log/
|
||||
*.out
|
||||
*.err
|
||||
*.trace
|
||||
|
||||
##############################
|
||||
# Runtime
|
||||
##############################
|
||||
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
##############################
|
||||
# Secrets
|
||||
##############################
|
||||
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
*.pem
|
||||
*.key
|
||||
*.crt
|
||||
*.cer
|
||||
*.p12
|
||||
*.pfx
|
||||
*.kdbx
|
||||
*.secret
|
||||
*.token
|
||||
|
||||
##############################
|
||||
# SSH
|
||||
##############################
|
||||
|
||||
.ssh/
|
||||
|
||||
##############################
|
||||
# Docker
|
||||
##############################
|
||||
|
||||
docker-compose.override.yml
|
||||
docker-compose.local.yml
|
||||
|
||||
##############################
|
||||
# VM Storage
|
||||
##############################
|
||||
|
||||
storage/
|
||||
windows/
|
||||
downloads/
|
||||
|
||||
##############################
|
||||
# Disk Images
|
||||
##############################
|
||||
|
||||
*.qcow2
|
||||
*.qcow
|
||||
*.vhd
|
||||
*.vhdx
|
||||
*.vdi
|
||||
*.raw
|
||||
*.img
|
||||
*.iso
|
||||
*.bin
|
||||
|
||||
##############################
|
||||
# QEMU
|
||||
##############################
|
||||
|
||||
*.nvram
|
||||
*.fd
|
||||
*.efi
|
||||
*.sock
|
||||
*.monitor
|
||||
*.serial
|
||||
|
||||
##############################
|
||||
# Samba
|
||||
##############################
|
||||
|
||||
shared/
|
||||
share/
|
||||
|
||||
##############################
|
||||
# Backups
|
||||
##############################
|
||||
|
||||
backup/
|
||||
backups/
|
||||
*.backup
|
||||
|
||||
##############################
|
||||
# Cache
|
||||
##############################
|
||||
|
||||
.cache/
|
||||
.cache-loader/
|
||||
.tmp/
|
||||
temp/
|
||||
tmp/
|
||||
|
||||
##############################
|
||||
# Python
|
||||
##############################
|
||||
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
.pytest_cache/
|
||||
.mypy_cache/
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
##############################
|
||||
# Node
|
||||
##############################
|
||||
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
##############################
|
||||
# Build
|
||||
##############################
|
||||
|
||||
dist/
|
||||
build/
|
||||
out/
|
||||
release/
|
||||
|
||||
##############################
|
||||
# Coverage
|
||||
##############################
|
||||
|
||||
coverage/
|
||||
.coverage
|
||||
coverage.xml
|
||||
|
||||
##############################
|
||||
# Archives
|
||||
##############################
|
||||
|
||||
*.zip
|
||||
*.tar
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
*.7z
|
||||
*.rar
|
||||
|
||||
##############################
|
||||
# Generated Config
|
||||
##############################
|
||||
|
||||
config.local.*
|
||||
settings.local.*
|
||||
local.env
|
||||
|
||||
##############################
|
||||
# Test Files
|
||||
##############################
|
||||
|
||||
test-output/
|
||||
playwright-report/
|
||||
|
||||
##############################
|
||||
# macOS
|
||||
##############################
|
||||
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
|
||||
##############################
|
||||
# Linux
|
||||
##############################
|
||||
|
||||
*~
|
||||
.nfs*
|
||||
|
||||
##############################
|
||||
# Windows
|
||||
##############################
|
||||
|
||||
*.stackdump
|
||||
|
||||
##############################
|
||||
# Misc
|
||||
##############################
|
||||
|
||||
*.cache
|
||||
*.lock
|
||||
*.lock.json
|
||||
*.bak.*
|
||||
|
||||
##############################
|
||||
# Keep Examples
|
||||
##############################
|
||||
|
||||
!.gitkeep
|
||||
!.env.example
|
||||
|
||||
+6
-3
@@ -1,12 +1,14 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM qemux/qemu-host:2.05 AS builder
|
||||
FROM qemux/qemu-host:2.06 AS builder
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
ARG VERSION_ARG="0.0"
|
||||
ARG VERSION_PASST="2026_06_11"
|
||||
ARG VERSION_CSTRUCT="4.7"
|
||||
ARG VERSION_PASST="2026_07_28"
|
||||
|
||||
ARG DEBCONF_NOWARNINGS="yes"
|
||||
ARG DEBIAN_FRONTEND="noninteractive"
|
||||
@@ -39,6 +41,7 @@ RUN <<EOF
|
||||
apt-utils \
|
||||
net-tools \
|
||||
e2fsprogs \
|
||||
diffutils \
|
||||
qemu-utils \
|
||||
websocketd \
|
||||
iputils-ping \
|
||||
@@ -54,7 +57,7 @@ RUN <<EOF
|
||||
apt-get clean
|
||||
|
||||
# Install Python dependencies
|
||||
pip3 install --no-cache-dir --break-system-packages --root-user-action=ignore dissect.cstruct
|
||||
pip3 install --no-cache-dir --break-system-packages --root-user-action=ignore "dissect.cstruct==$VERSION_CSTRUCT"
|
||||
|
||||
# Configure QEMU
|
||||
mkdir -p /etc/qemu
|
||||
|
||||
+15
-8
@@ -8,7 +8,8 @@ An empty default means the variable is unset and its value is determined automat
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `URL` | | URL or local path to the DSM `.pat` installation file. Downloads the default Virtual DSM image automatically when unset. |
|
||||
| `URL` | | URL or local path to a custom `.pat` installation file. |
|
||||
| `COUNTRY` | | Country code used to select the Synology download mirror. |
|
||||
| `HOST_MAC` | | MAC address reported to DSM. |
|
||||
| `HOST_MODEL` | | Synology host model reported to DSM. |
|
||||
| `HOST_SERIAL` | | Synology host serial number reported to DSM. |
|
||||
@@ -38,6 +39,7 @@ An empty default means the variable is unset and its value is determined automat
|
||||
| `DISK_DISCARD` | `unmap` | Discard/TRIM mode for the primary disk. |
|
||||
| `DISK_ROTATION` | `1` | Rotation rate reported to the guest. Use `1` to identify the disk as an SSD. |
|
||||
| `DISK_FLAGS` | | Additional options used when creating `qcow2` disks. |
|
||||
| `DISK_OPTIONS` | | Additional options appended to QEMU disk devices. |
|
||||
| `ALLOCATE` | `N` | Preallocates space for the data disks. |
|
||||
| `STORAGE` | `/storage` | Storage directory used for disks, settings, and downloads. |
|
||||
|
||||
@@ -45,15 +47,15 @@ An empty default means the variable is unset and its value is determined automat
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `NETWORK` | | Network mode, such as `nat`, `passt`, `slirp`, or `N` to disable networking. |
|
||||
| `DHCP` | `N` | Enables macvtap networking so DSM receives an address from the external LAN through DHCP. |
|
||||
| `HOST` | `VirtualDSM` | Hostname assigned to DSM. |
|
||||
| `NETWORK` | | Network mode, such as `nat`, `user`, or `N` to disable networking. |
|
||||
| `DHCP` | `N` | Enables macvtap networking so DSM receives a DHCP address. |
|
||||
| `HOST` | | Hostname assigned to the machine on the network. |
|
||||
| `IP` | | Overrides the automatically selected guest IPv4 address. |
|
||||
| `MAC` | | Guest network adapter MAC address. |
|
||||
| `ADAPTER` | `virtio-net-pci` | QEMU network adapter model. |
|
||||
| `DEV` | `eth0` | Container network interface used as the uplink. |
|
||||
| `MTU` | | MTU assigned to the guest network interface. |
|
||||
| `MASK` | `255.255.255.0` | IPv4 netmask. |
|
||||
| `MASK` | `255.255.255.0` | IPv4 netmask for guest network. |
|
||||
| `TAP` | `dsm` | TAP or macvtap interface name. |
|
||||
| `BRIDGE` | `docker` | Bridge name used for NAT networking. |
|
||||
| `HOST_PORTS` | | Ports excluded from guest forwarding. |
|
||||
@@ -69,10 +71,18 @@ An empty default means the variable is unset and its value is determined automat
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `DISPLAY` | `none` | Display backend, such as `vnc`, `disabled`, or `none`. |
|
||||
| `LOSSY` | `N` | Enables lossy VNC compression to reduce bandwidth usage. |
|
||||
| `VGA` | `none` | QEMU video adapter model. |
|
||||
| `GPU` | `N` | Enables Intel iGPU acceleration. |
|
||||
| `RENDERNODE` | `/dev/dri/renderD128` | Render node used for GPU acceleration. |
|
||||
|
||||
## ⚙️ System
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `MACHINE` | `q35` | QEMU machine type. |
|
||||
| `ARGUMENTS` | | Additional raw arguments appended to the QEMU command line. |
|
||||
|
||||
## 🔌 Shutdown
|
||||
|
||||
| Variable | Default | Description |
|
||||
@@ -87,7 +97,4 @@ An empty default means the variable is unset and its value is determined automat
|
||||
|---|---|---|
|
||||
| `DEBUG` | `N` | Enables verbose debug output. |
|
||||
| `TRACE` | `N` | Enables shell command tracing. |
|
||||
| `COM_PORT` | `2210` | Internal communication port used by the DSM host helper. |
|
||||
| `CHR_PORT` | `12345` | Internal character device port used by the DSM host helper. |
|
||||
| `HOST_DEBUG` | `N` | Enables debug output for the DSM host helper. |
|
||||
| `ARGUMENTS` | | Additional raw arguments appended to the QEMU command line. |
|
||||
|
||||
@@ -18,6 +18,8 @@ metadata:
|
||||
name: dsm
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: dsm
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ file="/run/shm/dsm.url"
|
||||
address="/run/shm/qemu.ip"
|
||||
gateway="/run/shm/qemu.gw"
|
||||
|
||||
[ ! -s "$file" ] && echo "DSM has not enabled networking yet..." && exit 1
|
||||
[ ! -s "$file" ] && echo "DSM has not enabled networking yet..." && exit 0
|
||||
|
||||
location=$(<"$file")
|
||||
|
||||
|
||||
+56
-9
@@ -2,15 +2,62 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
DEF_OPTS="-nodefaults -boot strict=on"
|
||||
RAM_OPTS=$(echo "-m ${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
MON_OPTS="-name $PROCESS,process=$PROCESS,debug-threads=on -pidfile $QEMU_PID"
|
||||
CPU_OPTS="-cpu $CPU_FLAGS -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1"
|
||||
MAC_OPTS="-machine type=q35,smm=off,usb=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
|
||||
DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
|
||||
DEV_OPTS+=" -object rng-random,id=objrng0,filename=/dev/urandom"
|
||||
DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
|
||||
DEV_OPTS=""
|
||||
|
||||
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS"
|
||||
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
||||
configureProcessor() {
|
||||
|
||||
CPU_OPTS="-cpu $CPU_FLAGS"
|
||||
CPU_OPTS+=" -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMemory() {
|
||||
|
||||
RAM_OPTS=$(echo "-m ${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMonitor() {
|
||||
|
||||
MON_OPTS="-name $PROCESS,process=$PROCESS,debug-threads=on"
|
||||
MON_OPTS+=" -pidfile $QEMU_PID"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMachine() {
|
||||
|
||||
MAC_OPTS="-machine type=$MACHINE,smm=off,usb=off"
|
||||
MAC_OPTS+=",vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureVirtioDevices() {
|
||||
|
||||
DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
|
||||
DEV_OPTS+=" -object rng-random,id=objrng0,filename=/dev/urandom"
|
||||
DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
buildArguments() {
|
||||
|
||||
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS"
|
||||
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMemory
|
||||
configureMonitor
|
||||
configureMachine
|
||||
configureProcessor
|
||||
configureVirtioDevices
|
||||
|
||||
buildArguments
|
||||
|
||||
return 0
|
||||
|
||||
+349
-302
File diff suppressed because it is too large
Load Diff
+14
-3
@@ -6,19 +6,26 @@ set -Eeuo pipefail
|
||||
: "${GPU:="N"}" # GPU passthrough
|
||||
: "${VGA:="virtio"}" # VGA adaptor
|
||||
: "${DISPLAY:="none"}" # Display type
|
||||
: "${LOSSY:="N"}" # Lossy VNC compression
|
||||
: "${RENDERNODE:="/dev/dri/renderD128"}" # Render node
|
||||
|
||||
# Sanitize variables
|
||||
VGA=$(strip "$VGA")
|
||||
LOSSY=$(strip "$LOSSY")
|
||||
DISPLAY=$(strip "$DISPLAY")
|
||||
RENDERNODE=$(strip "$RENDERNODE")
|
||||
|
||||
CPU_VENDOR=$(lscpu | awk '/Vendor ID/{print $3}')
|
||||
|
||||
if ! enabled "$GPU" || [[ "$CPU_VENDOR" != "GenuineIntel" || "$ARCH" != "amd64" ]]; then
|
||||
if ! enabled "$GPU" || isAmdCpu || [[ "$ARCH" != "amd64" ]]; then
|
||||
|
||||
[[ "${DISPLAY,,}" == "none" ]] && VGA="none"
|
||||
DISPLAY_OPTS="-display $DISPLAY -vga $VGA"
|
||||
|
||||
if enabled "$LOSSY" && [[ "${DISPLAY,,}" == vnc=* ]]; then
|
||||
DISPLAY+=",lossy=on"
|
||||
fi
|
||||
|
||||
DISPLAY_OPTS="-display ${DISPLAY} -vga ${VGA}"
|
||||
return 0
|
||||
|
||||
fi
|
||||
@@ -27,7 +34,7 @@ msg="Configuring display drivers..."
|
||||
html "$msg"
|
||||
enabled "$DEBUG" && echo "$msg"
|
||||
|
||||
DISPLAY_OPTS="-display egl-headless,rendernode=$RENDERNODE"
|
||||
DISPLAY_OPTS="-display egl-headless,rendernode=${RENDERNODE}"
|
||||
DISPLAY_OPTS+=" -vga $VGA"
|
||||
|
||||
[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri
|
||||
@@ -48,6 +55,10 @@ if [ ! -c "$RENDERNODE" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -c "$RENDERNODE" ] || [ ! -r "$RENDERNODE" ] || [ ! -w "$RENDERNODE" ]; then
|
||||
warn "render device '${RENDERNODE}' is unavailable or inaccessible."
|
||||
fi
|
||||
|
||||
addPackage "xserver-xorg-video-intel" "Intel GPU drivers"
|
||||
addPackage "qemu-system-modules-opengl" "OpenGL module"
|
||||
|
||||
|
||||
+6
-3
@@ -32,14 +32,17 @@ if ! enabled "$SHUTDOWN"; then
|
||||
exec "${cmd[@]}" ${ARGS:+ $ARGS}
|
||||
fi
|
||||
|
||||
if [ ! -t 1 ] || [ ! -c /dev/tty ]; then
|
||||
if ! interactive; then
|
||||
"${cmd[@]}" ${ARGS:+ $ARGS} &
|
||||
else
|
||||
"${cmd[@]}" ${ARGS:+ $ARGS} </dev/tty >/dev/tty &
|
||||
startConsole
|
||||
startQemu "${cmd[@]}" ${ARGS:+ $ARGS}
|
||||
fi
|
||||
|
||||
pid=$!
|
||||
rc=0
|
||||
wait $! || rc=$?
|
||||
|
||||
wait "$pid" || rc=$?
|
||||
[ -f "$QEMU_END" ] && exit "$rc"
|
||||
|
||||
sleep 1 & wait $!
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
if enabled "$DEBUG"; then
|
||||
printf "QEMU arguments:\n\n%s\n\n" "${ARGS// -/$'\n-'}"
|
||||
printf "QEMU arguments:\n\n %s\n\n" "${ARGS// -/$'\n -'}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
||||
+15
-13
@@ -126,13 +126,6 @@ SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||
SPACE_GB=$(formatBytes "$SPACE")
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in $STORAGE, have $SPACE_GB available but need at least 14 GB." && exit 94
|
||||
|
||||
# Check if output is to interactive TTY
|
||||
if [ -t 1 ]; then
|
||||
PROGRESS="--progress=bar:noscroll"
|
||||
else
|
||||
PROGRESS="--progress=dot:giga"
|
||||
fi
|
||||
|
||||
if [[ "$URL" == "file://"* ]]; then
|
||||
MSG="Copying DSM"
|
||||
ERR="Failed to copy ${URL:7}"
|
||||
@@ -160,17 +153,26 @@ else
|
||||
|
||||
SIZE=0
|
||||
REASON=""
|
||||
PROGRESS=()
|
||||
OUTPUT=""
|
||||
LOG=$(mktemp)
|
||||
|
||||
[[ "${URL,,}" == *"_72806.pat" ]] && SIZE=361010261
|
||||
[[ "${URL,,}" == *"_69057.pat" ]] && SIZE=363837333
|
||||
[[ "${URL,,}" == *"_42218.pat" ]] && SIZE=379637760
|
||||
|
||||
/run/progress.sh "$PAT" "$SIZE" "$MSG ([P])..." &
|
||||
# Use Wget's progress bar in a terminal and progress.sh in container logs.
|
||||
if [ -t 1 ]; then
|
||||
PROGRESS=( --show-progress --progress=bar:noscroll )
|
||||
else
|
||||
OUTPUT="log"
|
||||
fi
|
||||
|
||||
/run/progress.sh "$PAT" "$SIZE" "$MSG ([P])..." "$OUTPUT" 52428800 &
|
||||
|
||||
{
|
||||
LC_ALL=C wget "$URL" -O "$PAT" --no-verbose --no-check-certificate \
|
||||
--timeout=30 --no-http-keep-alive --show-progress "$PROGRESS" \
|
||||
--timeout=30 --no-http-keep-alive "${PROGRESS[@]}" \
|
||||
--output-file="$LOG"
|
||||
rc=$?
|
||||
} || :
|
||||
@@ -252,7 +254,7 @@ if ! touch "$SYSTEM"; then
|
||||
error "Could not create file $SYSTEM for the system disk." && exit 98
|
||||
fi
|
||||
|
||||
! setOwner "$SYSTEM" && warn "failed to set the owner for \"$SYSTEM\" !"
|
||||
setOwner "$SYSTEM" || warn "failed to set the owner for \"$SYSTEM\" !"
|
||||
|
||||
if [[ "${FS,,}" == "btrfs" ]]; then
|
||||
{ chattr +C "$SYSTEM"; } || :
|
||||
@@ -327,7 +329,7 @@ fakeroot -- bash -c "set -Eeu;\
|
||||
|
||||
rm -rf "$MOUNT"
|
||||
echo "$BASE" > "$STORAGE/dsm.ver"
|
||||
! setOwner "$STORAGE/dsm.ver" && warn "failed to set the owner for \"$STORAGE/dsm.ver\" !"
|
||||
setOwner "$STORAGE/dsm.ver" || warn "failed to set the owner for \"$STORAGE/dsm.ver\" !"
|
||||
|
||||
if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then
|
||||
rm -f "$PAT"
|
||||
@@ -336,11 +338,11 @@ else
|
||||
fi
|
||||
|
||||
if [ -f "$STORAGE/$BASE.pat" ]; then
|
||||
! setOwner "$STORAGE/$BASE.pat" && warn "failed to set the owner for \"$STORAGE/$BASE.pat\" !"
|
||||
setOwner "$STORAGE/$BASE.pat" || warn "failed to set the owner for \"$STORAGE/$BASE.pat\" !"
|
||||
fi
|
||||
|
||||
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
||||
! setOwner "$STORAGE/$BASE.boot.img" && warn "failed to set the owner for \"$STORAGE/$BASE.boot.img\" !"
|
||||
setOwner "$STORAGE/$BASE.boot.img" || warn "failed to set the owner for \"$STORAGE/$BASE.boot.img\" !"
|
||||
|
||||
rm -rf "$TMP"
|
||||
|
||||
|
||||
+4
-4
@@ -10,16 +10,17 @@ app() {
|
||||
}
|
||||
|
||||
checkConfiguredMemory() {
|
||||
local wanted msg
|
||||
|
||||
if disabled "$RAM_CHECK" || [[ "${RAM_SIZE,,}" == "max" || "${RAM_SIZE,,}" == "half" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local wanted msg avail_mem
|
||||
wanted=$(numfmt --from=iec "$RAM_SIZE")
|
||||
avail_mem=$(formatBytes "$RAM_AVAIL")
|
||||
|
||||
if (( (wanted + RAM_SPARE) > RAM_AVAIL )); then
|
||||
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of free memory available,"
|
||||
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $avail_mem of free memory available,"
|
||||
if [[ "${FS,,}" == "zfs" ]]; then
|
||||
info "$msg but since ZFS is active this will be ignored."
|
||||
else
|
||||
@@ -28,7 +29,7 @@ checkConfiguredMemory() {
|
||||
fi
|
||||
else
|
||||
if (( (wanted + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
||||
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $AVAIL_MEM of free memory available,"
|
||||
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $avail_mem of free memory available,"
|
||||
if [[ "${FS,,}" == "zfs" ]]; then
|
||||
info "$msg but since ZFS is active this will be ignored."
|
||||
else
|
||||
@@ -102,7 +103,6 @@ checkMinimumMemory() {
|
||||
}
|
||||
|
||||
getMemoryInfo
|
||||
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
||||
|
||||
checkConfiguredMemory
|
||||
configureHalfMemory
|
||||
|
||||
+882
-358
File diff suppressed because it is too large
Load Diff
+166
-39
@@ -2,25 +2,31 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
: "${SHUTDOWN:="Y"}" # Graceful ACPI shutdown
|
||||
: "${TIMEOUT:="115"}" # QEMU termination timeout
|
||||
: "${TIMEOUT:="105"}" # QEMU termination timeout
|
||||
: "${API_TIMEOUT:="90"}" # External API call timeout
|
||||
|
||||
# Configure QEMU for graceful shutdown
|
||||
|
||||
API_CMD=6
|
||||
API_HOST="127.0.0.1:$COM_PORT"
|
||||
|
||||
# Configure QEMU for graceful shutdown
|
||||
SHUTDOWN_SKIP=0
|
||||
SHUTDOWN_SIGNAL=0
|
||||
|
||||
QEMU_END="$QEMU_DIR/qemu.end"
|
||||
CONSOLE_PID="$QEMU_DIR/console.pid"
|
||||
CONSOLE_SOCKET="$QEMU_DIR/console.sock"
|
||||
QEMU_START_PID="$QEMU_DIR/qemu.start.pid"
|
||||
|
||||
_trap() {
|
||||
|
||||
local func="$1"; shift
|
||||
local sig
|
||||
|
||||
TRAP_PID=$BASHPID
|
||||
|
||||
for sig; do
|
||||
# Capture the local callback and signal while registering the trap.
|
||||
# shellcheck disable=SC2064
|
||||
trap "$func $sig" "$sig"
|
||||
done
|
||||
|
||||
@@ -61,11 +67,38 @@ displayReason() {
|
||||
|
||||
readQemuPid() {
|
||||
|
||||
local -n _pid="$1"
|
||||
readPidFile "$1" "$QEMU_START_PID" && return 0
|
||||
readPidFile "$1" "$QEMU_PID"
|
||||
}
|
||||
|
||||
if [ ! -s "$QEMU_PID" ] || ! read -r _pid <"$QEMU_PID"; then
|
||||
return 1
|
||||
fi
|
||||
qemuPidFile() {
|
||||
|
||||
local -n _file="$1"
|
||||
|
||||
_file="$QEMU_PID"
|
||||
[ -s "$QEMU_START_PID" ] && _file="$QEMU_START_PID"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
waitQemuExit() {
|
||||
|
||||
local timeout="${1:-10}"
|
||||
local file
|
||||
|
||||
qemuPidFile file
|
||||
waitPidFile "$file" "$timeout"
|
||||
}
|
||||
|
||||
waitQemuPid() {
|
||||
|
||||
local cnt=0
|
||||
|
||||
while ! readQemuPid "$1"; do
|
||||
sleep 0.02
|
||||
cnt=$((cnt + 1))
|
||||
(( cnt >= 50 )) && return 1
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -73,11 +106,10 @@ readQemuPid() {
|
||||
forceKillQemu() {
|
||||
|
||||
local reason="$1"
|
||||
local pid=""
|
||||
local display
|
||||
local pid display
|
||||
|
||||
! readQemuPid pid && return 0
|
||||
! isAlive "$pid" && return 0
|
||||
readQemuPid pid || return 0
|
||||
isAlive "$pid" || return 0
|
||||
|
||||
display=$(displayReason "$reason")
|
||||
error "Forcefully terminating $(app), reason: $display..."
|
||||
@@ -88,29 +120,115 @@ forceKillQemu() {
|
||||
|
||||
cleanupHelpers() {
|
||||
|
||||
local pids=( "${HOST_PID:-}" "${WSD_PID:-}" \
|
||||
local pids=( "${HOST_PID:-}" "${WSD_PID:-}" "${CONSOLE_PID:-}" \
|
||||
"${WEB_PID:-}" "${PASST_PID:-}" "${DNSMASQ_PID:-}" )
|
||||
|
||||
mKill "${pids[@]}"
|
||||
fKill "print.sh"
|
||||
|
||||
rm -f -- "$HOST_API_SOCKET" "$HOST_AGENT_SOCKET"
|
||||
|
||||
closeNetwork
|
||||
return 0
|
||||
}
|
||||
|
||||
startConsole() {
|
||||
|
||||
local output="${1:-/dev/tty}"
|
||||
local cnt=0
|
||||
|
||||
rm -f -- "$CONSOLE_SOCKET" "$CONSOLE_PID"
|
||||
|
||||
if ! stty -icanon -echo isig -ixon min 1 time 0 </dev/tty; then
|
||||
error "Failed to configure serial console terminal!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
(
|
||||
trap '' INT QUIT
|
||||
exec nc -lU "$CONSOLE_SOCKET" </dev/tty >"$output"
|
||||
) &
|
||||
|
||||
local pid="$!"
|
||||
echo "$pid" > "$CONSOLE_PID"
|
||||
|
||||
while [ ! -S "$CONSOLE_SOCKET" ]; do
|
||||
|
||||
if ! isAlive "$pid"; then
|
||||
rm -f -- "$CONSOLE_PID"
|
||||
error "Serial console relay exited unexpectedly!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
sleep 0.02
|
||||
cnt=$((cnt + 1))
|
||||
|
||||
if (( cnt > 100 )); then
|
||||
error "Failed to start serial console relay!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
stopConsole() {
|
||||
|
||||
mKill "$CONSOLE_PID"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
startQemu() {
|
||||
|
||||
rm -f -- "$QEMU_START_PID"
|
||||
|
||||
(
|
||||
trap '' INT QUIT
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
exec setsid -f -w sh -c '
|
||||
file=$1
|
||||
shift
|
||||
|
||||
"$@" &
|
||||
pid=$!
|
||||
printf "%s\n" "$pid" > "$file" || exit 1
|
||||
|
||||
rc=0
|
||||
wait "$pid" 2>/dev/null || rc=$?
|
||||
exit "$rc"
|
||||
' sh "$QEMU_START_PID" "$@"
|
||||
) </dev/null &
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
finish() {
|
||||
|
||||
local reason=$1
|
||||
local reason=$1 failed=0
|
||||
|
||||
if [ ! -f "$QEMU_END" ] && (( reason != 0 )); then
|
||||
failed=1
|
||||
fi
|
||||
|
||||
touch "$QEMU_END"
|
||||
|
||||
forceKillQemu "$reason"
|
||||
cleanupHelpers
|
||||
|
||||
if ! waitPidFile "$QEMU_PID" 10; then
|
||||
if ! waitQemuExit 10; then
|
||||
warn "Timed out while waiting for $(app) to exit!"
|
||||
fi
|
||||
|
||||
(( reason != 1 )) && echo && echo "❯ Shutdown completed!"
|
||||
echo
|
||||
|
||||
if (( failed == 0 )); then
|
||||
echo "❯ Shutdown completed!"
|
||||
else
|
||||
error "QEMU exited unexpectedly!"
|
||||
fi
|
||||
|
||||
exit "$reason"
|
||||
}
|
||||
@@ -119,15 +237,14 @@ sendGuestShutdown() {
|
||||
|
||||
local pid="$1"
|
||||
local response
|
||||
local url
|
||||
|
||||
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
||||
# nc -q 1 -w 1 -U "$QEMU_DIR/monitor.sock" &> /dev/null <<<'system_powerdown' || :
|
||||
|
||||
# Send shutdown command to guest agent via serial port
|
||||
API_TIMEOUT=$(strip "$API_TIMEOUT")
|
||||
url="http://$API_HOST/read?command=$API_CMD&timeout=$API_TIMEOUT"
|
||||
response=$(curl -sk -m "$(( API_TIMEOUT+2 ))" -S "$url" 2>&1)
|
||||
local url="http://localhost/read?command=$API_CMD&timeout=$API_TIMEOUT"
|
||||
response=$(curl --unix-socket "$HOST_API_SOCKET" -sk -m "$(( API_TIMEOUT+2 ))" -S "$url" 2>&1)
|
||||
|
||||
if [[ "$response" =~ "\"success\"" ]]; then
|
||||
|
||||
@@ -150,13 +267,10 @@ normalizeTimeout() {
|
||||
|
||||
local term_grace=3 # seconds before loop ends to send SIGTERM
|
||||
local cleanup_grace=3 # seconds reserved after the loop for cleanup
|
||||
local elapsed
|
||||
local timeout_left
|
||||
local min
|
||||
|
||||
TIMEOUT=$(strip "$TIMEOUT")
|
||||
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]]; then
|
||||
TIMEOUT=115
|
||||
TIMEOUT=105
|
||||
fi
|
||||
|
||||
if (( TIMEOUT >= 30 )); then
|
||||
@@ -167,10 +281,10 @@ normalizeTimeout() {
|
||||
cleanup_grace=4
|
||||
fi
|
||||
|
||||
elapsed=$((SECONDS - start))
|
||||
timeout_left=$((TIMEOUT - elapsed))
|
||||
local elapsed=$((SECONDS - start))
|
||||
local timeout_left=$((TIMEOUT - elapsed))
|
||||
|
||||
min=$((term_grace + cleanup_grace + 1))
|
||||
local min=$((term_grace + cleanup_grace + 1))
|
||||
(( timeout_left < min )) && timeout_left=$min
|
||||
|
||||
wait_until=$((timeout_left - cleanup_grace))
|
||||
@@ -184,18 +298,17 @@ waitForShutdown() {
|
||||
local cnt=0
|
||||
local pid="$1"
|
||||
local name="$APP"
|
||||
local slp
|
||||
|
||||
while (( cnt <= wait_until )); do
|
||||
while (( cnt <= wait_until && SHUTDOWN_SKIP == 0 )); do
|
||||
|
||||
sleep 1 &
|
||||
slp=$!
|
||||
local slp=$!
|
||||
|
||||
# Stop waiting if the process has exited
|
||||
! isAlive "$pid" && break
|
||||
isAlive "$pid" || break
|
||||
|
||||
# Workaround for stale/zombie QEMU pid file
|
||||
[ ! -s "$QEMU_PID" ] && break
|
||||
[ ! -s "$QEMU_START_PID" ] && [ ! -s "$QEMU_PID" ] && break
|
||||
|
||||
if (( cnt == sigterm_at )); then
|
||||
info "${name^} is still running, sending SIGTERM... ($cnt/$wait_until)"
|
||||
@@ -204,7 +317,7 @@ waitForShutdown() {
|
||||
info "Waiting for $name to shut down... ($cnt/$wait_until)"
|
||||
fi
|
||||
|
||||
wait "$slp"
|
||||
wait "$slp" || :
|
||||
(( cnt++ ))
|
||||
|
||||
done
|
||||
@@ -215,29 +328,39 @@ waitForShutdown() {
|
||||
graceful_shutdown() {
|
||||
|
||||
local sig="$1"
|
||||
local pid=""
|
||||
local code=0
|
||||
local pid code
|
||||
|
||||
[[ $BASHPID != "$TRAP_PID" ]] && return
|
||||
|
||||
code=$(signalCode "$sig")
|
||||
|
||||
if [ -f "$QEMU_END" ]; then
|
||||
echo && info "Received $1 signal while already shutting down..."
|
||||
|
||||
if (( code == 130 && SHUTDOWN_SIGNAL == code )); then
|
||||
SHUTDOWN_SKIP=1
|
||||
echo && info "Received SIGINT again, forcing shutdown..."
|
||||
return
|
||||
fi
|
||||
|
||||
echo && info "Received $sig signal while already shutting down..."
|
||||
return
|
||||
fi
|
||||
|
||||
set +e
|
||||
start=$SECONDS
|
||||
SHUTDOWN_SIGNAL=$code
|
||||
|
||||
touch "$QEMU_END"
|
||||
echo && info "Received $1 signal, sending shutdown command..."
|
||||
echo && info "Received $sig signal, sending shutdown command..."
|
||||
|
||||
if ! readQemuPid pid; then
|
||||
warn "QEMU PID file ($QEMU_PID) does not exist?"
|
||||
finish "$code"
|
||||
if ! interactive || ! waitQemuPid pid; then
|
||||
warn "QEMU PID file does not exist?"
|
||||
finish "$code"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! isAlive "$pid"; then
|
||||
if [ -z "$pid" ] || ! isAlive "$pid"; then
|
||||
warn "QEMU process with PID $pid does not exist?"
|
||||
finish "$code"
|
||||
fi
|
||||
@@ -249,9 +372,13 @@ graceful_shutdown() {
|
||||
finish "$code"
|
||||
}
|
||||
|
||||
! enabled "$SHUTDOWN" && return 0
|
||||
enabled "$SHUTDOWN" || return 0
|
||||
[ -n "${QEMU_TIMEOUT:-}" ] && TIMEOUT="$QEMU_TIMEOUT"
|
||||
|
||||
if interactive; then
|
||||
_trap graceful_shutdown SIGINT
|
||||
fi
|
||||
|
||||
_trap graceful_shutdown SIGTERM SIGHUP SIGABRT SIGQUIT
|
||||
|
||||
return 0
|
||||
|
||||
+29
-14
@@ -9,6 +9,7 @@ cd /run
|
||||
. utils.sh # Load functions
|
||||
|
||||
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; }
|
||||
warn () { printf "%b%s%b" "\E[1;33m❯ " "WARNING: $1" "\E[0m\n" >&2; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||
|
||||
disabled "$NETWORK" && exit 0
|
||||
@@ -19,8 +20,9 @@ driver="/run/shm/qemu.nic"
|
||||
page="/run/shm/index.html"
|
||||
address="/run/shm/qemu.ip"
|
||||
shutdown="/run/shm/qemu.end"
|
||||
socket="/run/shm/qemu-host-api.sock"
|
||||
template="/var/www/index.html"
|
||||
url="http://127.0.0.1:2210/read?command=10"
|
||||
url="http://localhost/read?command=10"
|
||||
|
||||
resp_err="Guest returned an invalid response:"
|
||||
curl_err="Failed to connect to guest: curl error"
|
||||
@@ -35,9 +37,7 @@ exitIfShuttingDown() {
|
||||
|
||||
queryGuest() {
|
||||
|
||||
local rc
|
||||
|
||||
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
|
||||
{ json=$(curl --unix-socket "$socket" -m 20 -sk "$url"); local rc=$?; } || :
|
||||
|
||||
exitIfShuttingDown
|
||||
|
||||
@@ -53,9 +53,8 @@ readJsonField() {
|
||||
|
||||
local query="$1"
|
||||
local result
|
||||
local rc
|
||||
|
||||
{ result=$(jq -r "$query" <<< "$json"); rc=$?; } || :
|
||||
{ result=$(jq -r "$query" <<< "$json"); local rc=$?; } || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
error "$jq_err $rc ( $json )"
|
||||
@@ -73,12 +72,12 @@ readJsonField() {
|
||||
|
||||
readGuestStatus() {
|
||||
|
||||
local result msg rc
|
||||
local result msg
|
||||
|
||||
result=$(readJsonField '.status') || return 1
|
||||
|
||||
if [[ "$result" != "success" ]]; then
|
||||
{ msg=$(jq -r '.message // empty' <<< "$json"); rc=$?; } || :
|
||||
{ msg=$(jq -r '.message // empty' <<< "$json"); local rc=$?; } || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
error "$jq_err $rc ( $json )"
|
||||
@@ -139,14 +138,29 @@ pollGuestLocation() {
|
||||
return 0
|
||||
}
|
||||
|
||||
checkAddressConflict() {
|
||||
|
||||
local guest_ip="${location%:*}"
|
||||
local container_ip=""
|
||||
|
||||
[ -s "$address" ] && container_ip=$(<"$address")
|
||||
[ -z "$container_ip" ] && return 0
|
||||
[[ "$guest_ip" != "$container_ip" ]] && return 0
|
||||
|
||||
warn "DSM is using the same IP as the container, this will cause connectivity issues."
|
||||
warn "change the container's macvlan IP or assign DSM a different address in your router."
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
writeDhcpPage() {
|
||||
|
||||
local title body script html
|
||||
local html
|
||||
|
||||
msg="http://$location"
|
||||
title="<title>Virtual DSM</title>"
|
||||
body="The location of DSM is <a href='http://$location'>http://$location</a>"
|
||||
script="<script>setTimeout(function(){ window.location.assign('http://$location'); }, 3000);</script>"
|
||||
local title="<title>Virtual DSM</title>"
|
||||
local body="The location of DSM is <a href='http://$location'>http://$location</a>"
|
||||
local script="<script>setTimeout(function(){ window.location.assign('http://$location'); }, 3000);</script>"
|
||||
|
||||
html=$(<"$template")
|
||||
html="${html/\[1\]/$title}"
|
||||
@@ -163,11 +177,11 @@ writeDhcpPage() {
|
||||
|
||||
buildStaticMessage() {
|
||||
|
||||
local nic ip port
|
||||
local nic ip
|
||||
|
||||
nic=$(<"$driver")
|
||||
ip=$(<"$address")
|
||||
port="${location##*:}"
|
||||
local port="${location##*:}"
|
||||
|
||||
if [[ "${nic,,}" != "macvlan" ]]; then
|
||||
msg="port $port"
|
||||
@@ -195,6 +209,7 @@ exitIfShuttingDown
|
||||
location=$(<"$file")
|
||||
|
||||
if enabled "$DHCP"; then
|
||||
checkAddressConflict
|
||||
writeDhcpPage
|
||||
else
|
||||
buildStaticMessage
|
||||
|
||||
+4
-6
@@ -45,9 +45,9 @@ checkClocksource() {
|
||||
|
||||
checkSse42() {
|
||||
|
||||
if ! grep -qw "sse4_2" <<< "$flags"; then
|
||||
if ! hasFlag "sse4_2"; then
|
||||
error "Your CPU does not have the SSE4 instruction set that Virtual DSM requires!"
|
||||
! enabled "$DEBUG" && exit 88
|
||||
enabled "$DEBUG" || exit 88
|
||||
fi
|
||||
|
||||
return 0
|
||||
@@ -94,10 +94,10 @@ configureKvmCpuModel() {
|
||||
|
||||
appendKvmInvtscFeature() {
|
||||
|
||||
if grep -qw "svm" <<< "$flags"; then
|
||||
if hasFlag "svm"; then
|
||||
|
||||
# AMD processor
|
||||
if grep -qw "tsc_scale" <<< "$flags"; then
|
||||
if hasFlag "tsc_scale"; then
|
||||
CPU_FEATURES+=",+invtsc"
|
||||
fi
|
||||
|
||||
@@ -186,8 +186,6 @@ configureHostCpuName() {
|
||||
selectClocksource
|
||||
checkClocksource
|
||||
|
||||
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
|
||||
|
||||
if ! disabled "$KVM"; then
|
||||
configureKvm
|
||||
else
|
||||
|
||||
+280
-23
@@ -2,44 +2,301 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
info="/run/shm/msg.html"
|
||||
info_tmp="${info}.${BASHPID}.tmp"
|
||||
|
||||
escape () {
|
||||
local s
|
||||
s=${1//&/\&}
|
||||
s=${s//</\<}
|
||||
s=${s//>/\>}
|
||||
s=${s//'"'/\"}
|
||||
printf -- %s "$s"
|
||||
escape() {
|
||||
|
||||
local s
|
||||
|
||||
s=${1//&/\&}
|
||||
s=${s//</\<}
|
||||
s=${s//>/\>}
|
||||
s=${s//'"'/\"}
|
||||
s=${s//"'"/\'}
|
||||
|
||||
printf '%s' "$s"
|
||||
return 0
|
||||
}
|
||||
|
||||
writeInfo() {
|
||||
|
||||
local content="$1"
|
||||
|
||||
if ! printf '%s\n' "$content" > "$info_tmp"; then
|
||||
rm -f -- "$info_tmp"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! mv -f -- "$info_tmp" "$info"; then
|
||||
rm -f -- "$info_tmp"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
getBytes() {
|
||||
|
||||
local path="$1"
|
||||
local mode="$2"
|
||||
local bytes="0"
|
||||
|
||||
if [[ "$mode" == "counter" ]]; then
|
||||
if [ -r "$path" ]; then
|
||||
read -r bytes < "$path" || bytes="0"
|
||||
fi
|
||||
|
||||
[[ "$bytes" =~ ^[0-9]+$ ]] || bytes="0"
|
||||
printf '%s\n' "$bytes"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -s "$path" ] && [ ! -d "$path" ]; then
|
||||
printf '0\n'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$mode" == "allocated" ]]; then
|
||||
bytes=$(du -sB1 -- "$path" 2>/dev/null | cut -f1) || bytes="0"
|
||||
else
|
||||
bytes=$(du -sb -- "$path" 2>/dev/null | cut -f1) || bytes="0"
|
||||
fi
|
||||
|
||||
printf '%s\n' "$bytes"
|
||||
return 0
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
|
||||
local file="$1"
|
||||
local bytes total extra=""
|
||||
|
||||
[ -r "$file" ] || return 1
|
||||
read -r bytes total extra < "$file" || return 1
|
||||
|
||||
if [[ ! "$bytes" =~ ^[0-9]+$ ||
|
||||
! "$total" =~ ^[0-9]+$ ||
|
||||
-n "$extra" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf '%s %s\n' "$bytes" "$total"
|
||||
return 0
|
||||
}
|
||||
|
||||
formatSize() {
|
||||
|
||||
local bytes="$1"
|
||||
local size
|
||||
|
||||
size=$(numfmt --to=iec --suffix=B "$bytes" |
|
||||
sed -r 's/([A-Z])/ \1/') ||
|
||||
size="${bytes} bytes"
|
||||
|
||||
printf '%s' "$size"
|
||||
return 0
|
||||
}
|
||||
|
||||
printPercentProgress() {
|
||||
|
||||
local percent="$1"
|
||||
|
||||
while (( next_percent <= percent && next_percent <= 100 )); do
|
||||
if [[ "$printed" == "Y" ]]; then
|
||||
printf ' → %s%%' "$next_percent"
|
||||
else
|
||||
printf '%s%%' "$next_percent"
|
||||
fi
|
||||
|
||||
printed="Y"
|
||||
next_percent=$((next_percent + 10))
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
printCurrentSize() {
|
||||
|
||||
local bytes="$1"
|
||||
local size
|
||||
|
||||
size=$(formatSize "$bytes")
|
||||
|
||||
if [[ "$printed" == "Y" ]]; then
|
||||
printf ' → %s' "$size"
|
||||
else
|
||||
printf '%s' "$size"
|
||||
fi
|
||||
|
||||
printed="Y"
|
||||
return 0
|
||||
}
|
||||
|
||||
printSizeProgress() {
|
||||
|
||||
local bytes="$1"
|
||||
local size
|
||||
|
||||
while (( bytes >= next_bytes )); do
|
||||
size=$(formatSize "$next_bytes")
|
||||
|
||||
if [[ "$printed" == "Y" ]]; then
|
||||
printf ' → %s' "$size"
|
||||
else
|
||||
printf '%s' "$size"
|
||||
fi
|
||||
|
||||
printed="Y"
|
||||
next_bytes=$((next_bytes + step_bytes))
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
stopProgress() {
|
||||
|
||||
if [ -z "$status_file" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
stopping="Y"
|
||||
return 0
|
||||
}
|
||||
|
||||
finishProgress() {
|
||||
|
||||
rm -f -- "$info_tmp"
|
||||
|
||||
if [[ "$output" == "log" && "$printed" == "Y" ]]; then
|
||||
printf '\n'
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
path="$1"
|
||||
total="$2"
|
||||
body=$(escape "$3")
|
||||
output="${4:-}"
|
||||
step_bytes="${5:-536870912}"
|
||||
mode="${6:-apparent}"
|
||||
status_file="${7:-}"
|
||||
|
||||
if [[ -n "$total" && ! "$total" =~ ^(0|[1-9][0-9]*)$ ]]; then
|
||||
printf 'Invalid total size: %s\n' "$total" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ ! "$step_bytes" =~ ^[1-9][0-9]*$ ]]; then
|
||||
printf 'Invalid progress interval: %s\n' "$step_bytes" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
case "$mode" in
|
||||
apparent | allocated | counter ) ;;
|
||||
* )
|
||||
printf 'Invalid progress mode: %s\n' "$mode" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$output" in
|
||||
"" | log ) ;;
|
||||
* )
|
||||
printf 'Invalid progress output: %s\n' "$output" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
printed="N"
|
||||
next_percent=10
|
||||
next_bytes="$step_bytes"
|
||||
log_mode="percent"
|
||||
stopping="N"
|
||||
|
||||
if [ -z "$total" ] || [[ "$total" == "0" ]]; then
|
||||
log_mode="size"
|
||||
fi
|
||||
|
||||
trap finishProgress EXIT
|
||||
trap 'exit 0' HUP INT QUIT
|
||||
trap stopProgress TERM
|
||||
|
||||
if [[ "$body" == *"..." ]]; then
|
||||
body="<p class=\"loading\">${body::-3}</p>"
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
while true; do
|
||||
|
||||
if [ ! -s "$path" ] && [ ! -d "$path" ]; then
|
||||
bytes="0"
|
||||
else
|
||||
bytes=$(du -sb "$path" 2>/dev/null | cut -f1) || bytes="0"
|
||||
fi
|
||||
|
||||
if (( bytes > 4096 )); then
|
||||
if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then
|
||||
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/') || size="${bytes} bytes"
|
||||
else
|
||||
size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')"
|
||||
size="$size%"
|
||||
final_pass="${stopping:-}"
|
||||
bytes=$(getBytes "$path" "$mode")
|
||||
effective_total="$total"
|
||||
|
||||
if [ -n "$status_file" ] && status=$(getStatus "$status_file"); then
|
||||
read -r status_bytes status_total <<< "$status"
|
||||
bytes="$status_bytes"
|
||||
|
||||
if (( status_total > 0 )); then
|
||||
effective_total="$status_total"
|
||||
fi
|
||||
[[ "$size" != "0.0%" ]] && echo "${body//(\[P\])/($size)}"> "$info"
|
||||
fi
|
||||
|
||||
sleep 1 & wait $!
|
||||
# A real total may become available shortly after aria2 starts.
|
||||
if [[ "$log_mode" == "size" &&
|
||||
"$printed" == "N" &&
|
||||
-n "$effective_total" &&
|
||||
"$effective_total" != "0" ]]; then
|
||||
log_mode="percent"
|
||||
fi
|
||||
|
||||
if (( bytes > 4096 )); then
|
||||
|
||||
write_html="Y"
|
||||
|
||||
if [ -z "$effective_total" ] ||
|
||||
[[ "$effective_total" == "0" ]] ||
|
||||
(( bytes > effective_total )); then
|
||||
size=$(formatSize "$bytes")
|
||||
|
||||
if [[ "$output" == "log" ]]; then
|
||||
if [[ "$log_mode" == "percent" ]]; then
|
||||
printCurrentSize "$bytes"
|
||||
next_bytes=$(((bytes / step_bytes + 1) * step_bytes))
|
||||
log_mode="size"
|
||||
else
|
||||
printSizeProgress "$bytes"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Truncate to one decimal so progress is never reported early.
|
||||
progress=$((bytes * 1000 / effective_total))
|
||||
(( progress > 1000 )) && progress=1000
|
||||
|
||||
percent=$((progress / 10))
|
||||
|
||||
printf -v size '%d.%d%%' \
|
||||
"$((progress / 10))" \
|
||||
"$((progress % 10))"
|
||||
|
||||
if [[ "$output" == "log" ]]; then
|
||||
if [[ "$log_mode" == "size" ]]; then
|
||||
printSizeProgress "$bytes"
|
||||
else
|
||||
printPercentProgress "$percent"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Do not update the web viewer until at least 0.1% is reached.
|
||||
(( progress == 0 )) && write_html="N"
|
||||
fi
|
||||
|
||||
if [[ "$write_html" == "Y" ]]; then
|
||||
writeInfo "${body//(\[P\])/($size)}"
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ "$final_pass" == "Y" ]] && break
|
||||
|
||||
sleep 1 &
|
||||
wait $! || :
|
||||
done
|
||||
|
||||
+14
-21
@@ -13,6 +13,7 @@ enabled "${TRACE:-}" && set -o functrace && trap 'echo "# $BASH_COMMAND" >&2' DE
|
||||
: "${KVM:="Y"}" # KVM acceleration
|
||||
: "${DEBUG:="N"}" # Disable debugging mode
|
||||
: "${COUNTRY:=""}" # Country code for mirror
|
||||
: "${MACHINE:="q35"}" # Machine type selection
|
||||
: "${ALLOCATE:=""}" # Preallocate diskspace
|
||||
: "${ARGUMENTS:=""}" # Extra QEMU parameters
|
||||
: "${CPU_CORES:="2"}" # Amount of CPU cores
|
||||
@@ -40,7 +41,7 @@ detectEngine() {
|
||||
|
||||
detectRootless() {
|
||||
|
||||
local uid_map=""
|
||||
local uid_map
|
||||
|
||||
uid_map=$(awk '{$1=$1; print}' /proc/self/uid_map 2>/dev/null || true)
|
||||
|
||||
@@ -57,8 +58,6 @@ checkPrivileged() {
|
||||
|
||||
local cap_bnd
|
||||
local last_cap
|
||||
local max_cap
|
||||
|
||||
# Get the capability bounding set
|
||||
cap_bnd=$(grep '^CapBnd:' /proc/$$/status | awk '{print $2}')
|
||||
cap_bnd=$(printf "%d" "0x${cap_bnd}")
|
||||
@@ -67,7 +66,7 @@ checkPrivileged() {
|
||||
last_cap=$(cat /proc/sys/kernel/cap_last_cap)
|
||||
|
||||
# Calculate the maximum capability value
|
||||
max_cap=$(((1 << (last_cap + 1)) - 1))
|
||||
local max_cap=$(((1 << (last_cap + 1)) - 1))
|
||||
|
||||
if [ "$cap_bnd" -eq "$max_cap" ]; then
|
||||
PRIVILEGED="Y"
|
||||
@@ -143,9 +142,7 @@ finiteMemoryLimit() {
|
||||
|
||||
local limit="$1"
|
||||
local sentinel="4611686018427387904"
|
||||
local i=0
|
||||
local left=""
|
||||
local right=""
|
||||
local i
|
||||
|
||||
[[ "$limit" =~ ^[0-9]+$ ]] || return 1
|
||||
|
||||
@@ -153,8 +150,8 @@ finiteMemoryLimit() {
|
||||
(( ${#limit} > ${#sentinel} )) && return 1
|
||||
|
||||
for (( i=0; i<${#sentinel}; i++ )); do
|
||||
left="${limit:i:1}"
|
||||
right="${sentinel:i:1}"
|
||||
local left="${limit:i:1}"
|
||||
local right="${sentinel:i:1}"
|
||||
|
||||
(( left < right )) && return 0
|
||||
(( left > right )) && return 1
|
||||
@@ -165,11 +162,8 @@ finiteMemoryLimit() {
|
||||
|
||||
getMemoryInfo() {
|
||||
|
||||
local host_total=""
|
||||
local host_avail=""
|
||||
local limit=""
|
||||
local current=""
|
||||
local available=""
|
||||
local limit="" current=""
|
||||
local host_total host_avail
|
||||
|
||||
host_total=$(free -b | awk '/^Mem:/ {print $2; exit}')
|
||||
host_avail=$(free -b | awk '/^Mem:/ {print $7; exit}')
|
||||
@@ -188,7 +182,7 @@ getMemoryInfo() {
|
||||
if finiteMemoryLimit "$limit" && [[ "$current" =~ ^[0-9]+$ ]]; then
|
||||
(( limit < RAM_TOTAL )) && RAM_TOTAL="$limit"
|
||||
|
||||
available=$(( limit - current ))
|
||||
local available=$(( limit - current ))
|
||||
(( available < 0 )) && available=0
|
||||
(( available < RAM_AVAIL )) && RAM_AVAIL="$available"
|
||||
fi
|
||||
@@ -215,7 +209,7 @@ normalizeRamSize() {
|
||||
fi
|
||||
|
||||
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
! numfmt --from=iec "$RAM_SIZE" &>/dev/null && error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16
|
||||
numfmt --from=iec "$RAM_SIZE" &>/dev/null || { error "Invalid RAM_SIZE: $RAM_SIZE" && exit 16; }
|
||||
wanted=$(numfmt --from=iec "$RAM_SIZE")
|
||||
[ "$wanted" -lt "$RAM_MINIMUM" ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
||||
|
||||
@@ -260,7 +254,7 @@ checkKvm() {
|
||||
fi
|
||||
if ! grep -qw "sse4_2" <<< "$flags"; then
|
||||
error "Your CPU does not have the SSE4 instruction set that Virtual DSM requires!"
|
||||
! enabled "$DEBUG" && exit 88
|
||||
enabled "$DEBUG" || exit 88
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -281,7 +275,7 @@ checkKvm() {
|
||||
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
|
||||
! enabled "$DEBUG" && exit 88
|
||||
enabled "$DEBUG" || exit 88
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -320,9 +314,8 @@ FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
||||
SOCKETS=1
|
||||
CPU=$(cpu)
|
||||
SYS=$(uname -r)
|
||||
KERNEL=$(echo "$SYS" | cut -b 1)
|
||||
MINOR=$(echo "$SYS" | cut -d '.' -f2)
|
||||
ARCH=$(dpkg --print-architecture)
|
||||
IFS=. read -r KERNEL MINOR _ <<< "$SYS"
|
||||
CORES=$(grep -c '^processor' /proc/cpuinfo)
|
||||
|
||||
if grep -qi "socket(s)" <<< "$(lscpu)"; then
|
||||
@@ -353,7 +346,7 @@ checkKvm
|
||||
|
||||
# Cleanup files
|
||||
rm -f "$QEMU_DIR"/dsm.url
|
||||
rm -f "$QEMU_DIR"/qemu.* "$QEMU_DIR"/*.pid "$QEMU_DIR"/*.sock
|
||||
rm -f "$QEMU_DIR"/{qemu.*,*.{pid,sock,pipe}}
|
||||
|
||||
# Cleanup dirs
|
||||
rm -rf /tmp/dsm
|
||||
|
||||
+50
-17
@@ -15,6 +15,10 @@ HOST_MODEL=$(strip "$HOST_MODEL")
|
||||
HOST_SERIAL=$(strip "$HOST_SERIAL")
|
||||
GUEST_SERIAL=$(strip "$GUEST_SERIAL")
|
||||
|
||||
HOST_PID="$QEMU_DIR/host.pid"
|
||||
HOST_API_SOCKET="$QEMU_DIR/qemu-host-api.sock"
|
||||
HOST_AGENT_SOCKET="$QEMU_DIR/qemu-host-agent.sock"
|
||||
|
||||
validateHostMac() {
|
||||
local m
|
||||
|
||||
@@ -41,6 +45,8 @@ buildHostArguments() {
|
||||
HOST_ARGS=()
|
||||
HOST_ARGS+=("-cpu=$CPU_CORES")
|
||||
HOST_ARGS+=("-cpu_arch=$HOST_CPU")
|
||||
HOST_ARGS+=("-api=$HOST_API_SOCKET")
|
||||
HOST_ARGS+=("-addr=$HOST_AGENT_SOCKET")
|
||||
|
||||
[ -n "$HOST_MAC" ] && HOST_ARGS+=("-mac=$HOST_MAC")
|
||||
[ -n "$HOST_MODEL" ] && HOST_ARGS+=("-model=$HOST_MODEL")
|
||||
@@ -52,30 +58,46 @@ buildHostArguments() {
|
||||
|
||||
startHostBinary() {
|
||||
|
||||
local pid
|
||||
|
||||
rm -f -- "$HOST_PID" "$HOST_API_SOCKET" "$HOST_AGENT_SOCKET" || return 1
|
||||
|
||||
if enabled "$HOST_DEBUG"; then
|
||||
set -x
|
||||
./host.bin "${HOST_ARGS[@]}" &
|
||||
{ set +x; } 2>/dev/null
|
||||
echo "$!" > "$HOST_PID"
|
||||
pid=$!
|
||||
echo
|
||||
else
|
||||
./host.bin "${HOST_ARGS[@]}" >/dev/null &
|
||||
echo "$!" > "$HOST_PID"
|
||||
pid=$!
|
||||
fi
|
||||
|
||||
printf '%s\n' "$pid" > "$HOST_PID"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
waitForPort() {
|
||||
waitForSocket() {
|
||||
|
||||
local port="$1"
|
||||
local socket="$1"
|
||||
local exit_code="$2"
|
||||
local cnt=0
|
||||
local timeout=5 pid
|
||||
local deadline=$((SECONDS + timeout))
|
||||
|
||||
while [ ! -S "$socket" ]; do
|
||||
|
||||
if ! readPidFile pid "$HOST_PID" || ! isAlive "$pid"; then
|
||||
error "qemu-host exited unexpectedly!"
|
||||
exit "$exit_code"
|
||||
fi
|
||||
|
||||
if (( SECONDS >= deadline )); then
|
||||
error "Failed to create qemu-host socket: $socket"
|
||||
exit "$exit_code"
|
||||
fi
|
||||
|
||||
while ! nc -z -w2 127.0.0.1 "$port" > /dev/null 2>&1; do
|
||||
sleep 0.1
|
||||
cnt=$((cnt + 1))
|
||||
(( cnt > 50 )) && error "Failed to connect to qemu-host.." && exit "$exit_code"
|
||||
done
|
||||
|
||||
return 0
|
||||
@@ -83,10 +105,25 @@ waitForPort() {
|
||||
|
||||
configureSerialPorts() {
|
||||
|
||||
# Configure serial ports
|
||||
SERIAL_OPTS="-serial mon:stdio \
|
||||
if enabled "${SHUTDOWN:-Y}" && interactive; then
|
||||
|
||||
CONSOLE_SOCKET="$QEMU_DIR/console.sock"
|
||||
MONITOR_SOCKET="$QEMU_DIR/monitor.sock"
|
||||
|
||||
SERIAL_OPTS="-chardev socket,id=console0,path=$CONSOLE_SOCKET,reconnect-ms=1000 \
|
||||
-serial chardev:console0 \
|
||||
-chardev socket,id=monitor0,path=$MONITOR_SOCKET,server=on,wait=off \
|
||||
-mon chardev=monitor0,mode=readline"
|
||||
|
||||
else
|
||||
|
||||
SERIAL_OPTS="-serial mon:stdio"
|
||||
|
||||
fi
|
||||
|
||||
SERIAL_OPTS+=" \
|
||||
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
|
||||
-chardev socket,id=charchannel0,host=127.0.0.1,port=$CHR_PORT,reconnect=10 \
|
||||
-chardev socket,id=charchannel0,path=$HOST_AGENT_SOCKET,reconnect-ms=1000 \
|
||||
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"
|
||||
|
||||
return 0
|
||||
@@ -94,15 +131,11 @@ configureSerialPorts() {
|
||||
|
||||
validateHostMac
|
||||
|
||||
HOST_PID="$QEMU_DIR/host.pid"
|
||||
|
||||
buildHostArguments
|
||||
startHostBinary
|
||||
|
||||
sleep 0.2
|
||||
|
||||
waitForPort "$COM_PORT" 58
|
||||
waitForPort "$CHR_PORT" 59
|
||||
waitForSocket "$HOST_API_SOCKET" 58
|
||||
waitForSocket "$HOST_AGENT_SOCKET" 59
|
||||
|
||||
configureSerialPorts
|
||||
|
||||
|
||||
+77
-25
@@ -1,41 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
: "${COM_PORT:="2210"}" # Comm port
|
||||
: "${WEB_PORT:="5000"}" # Webserver port
|
||||
: "${CHR_PORT:="12345"}" # Character port
|
||||
: "${WSD_PORT:="8004"}" # Websockets port
|
||||
|
||||
# Sanitize port variables
|
||||
COM_PORT=$(strip "$COM_PORT")
|
||||
WEB_PORT=$(strip "$WEB_PORT")
|
||||
CHR_PORT=$(strip "$CHR_PORT")
|
||||
WSD_PORT=$(strip "$WSD_PORT")
|
||||
|
||||
WEB_PID="/run/nginx.pid"
|
||||
WSD_LOG="/var/log/websocketd.log"
|
||||
WSD_PID="$QEMU_DIR/websocketd.pid"
|
||||
|
||||
prepareWebFiles() {
|
||||
|
||||
cp -r /var/www/* "$QEMU_DIR" || return 1
|
||||
rm -f "$WSD_PID" "$WEB_PID" || return 1
|
||||
rm -f -- "$WSD_PID" "$WEB_PID" "$WSD_LOG" || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureWebPorts() {
|
||||
|
||||
sed -i "s/listen 5000 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
|
||||
sed -i "s/proxy_pass http:\/\/127.0.0.1:8004\/;/proxy_pass http:\/\/127.0.0.1:$WSD_PORT\/;/g" /etc/nginx/sites-enabled/web.conf
|
||||
if ! sed -i \
|
||||
-e "s|listen 5000 default_server;|listen $WEB_PORT default_server;|g" \
|
||||
-e "s|proxy_pass http://127.0.0.1:8004/;|proxy_pass http://127.0.0.1:$WSD_PORT/;|g" \
|
||||
/etc/nginx/sites-enabled/web.conf; then
|
||||
error "Failed to configure webserver ports!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureIpv6Listen() {
|
||||
|
||||
# shellcheck disable=SC2143
|
||||
if [ -f /proc/net/if_inet6 ] && [[ "$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6 2>/dev/null)" != "1" ]]; then
|
||||
sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
|
||||
|
||||
if ! sed -i \
|
||||
"s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" \
|
||||
/etc/nginx/sites-enabled/web.conf; then
|
||||
error "Failed to configure IPv6 webserver listener!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
return 0
|
||||
@@ -52,6 +60,22 @@ configureWebServer() {
|
||||
return 0
|
||||
}
|
||||
|
||||
stopWebServer() {
|
||||
|
||||
local pid
|
||||
|
||||
if readPidFile pid "$WEB_PID"; then
|
||||
pKill "$pid" 2
|
||||
|
||||
if isAlive "$pid"; then
|
||||
kill -9 -- "$pid" 2>/dev/null || :
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f -- "$WEB_PID"
|
||||
return 0
|
||||
}
|
||||
|
||||
startWebServer() {
|
||||
|
||||
# Start webserver
|
||||
@@ -60,41 +84,69 @@ startWebServer() {
|
||||
return 0
|
||||
}
|
||||
|
||||
stopWebsocketServer() {
|
||||
|
||||
local pid
|
||||
|
||||
if readPidFile pid "$WSD_PID"; then
|
||||
pKill "$pid" 2
|
||||
|
||||
if isAlive "$pid"; then
|
||||
kill -9 -- "$pid" 2>/dev/null || :
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f -- "$WSD_PID"
|
||||
return 0
|
||||
}
|
||||
|
||||
startWebsocketServer() {
|
||||
|
||||
local log="/var/log/websocketd.log"
|
||||
rm -f "$log"
|
||||
|
||||
# Start websocket server
|
||||
websocketd --address 127.0.0.1 --port="$WSD_PORT" /run/socket.sh > "$log" 2>&1 &
|
||||
websocketd \
|
||||
--address 127.0.0.1 \
|
||||
--port="$WSD_PORT" \
|
||||
/run/socket.sh \
|
||||
>"$WSD_LOG" 2>&1 &
|
||||
|
||||
local pid=$!
|
||||
|
||||
if ! echo "$pid" > "$WSD_PID"; then
|
||||
kill "$pid" 2>/dev/null || :
|
||||
rm -f -- "$WSD_PID"
|
||||
return 1
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
local i
|
||||
for (( i = 1; i <= 5; i++ )); do
|
||||
|
||||
if ! isAlive "$pid"; then
|
||||
rm -f "$WSD_PID"
|
||||
[ -s "$log" ] && cat "$log" >&2
|
||||
error "Failed to start websocket server!"
|
||||
return 1
|
||||
fi
|
||||
if ! isAlive "$pid"; then
|
||||
rm -f -- "$WSD_PID"
|
||||
[ -s "$WSD_LOG" ] && cat "$WSD_LOG" >&2
|
||||
error "Failed to start websocket server!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
prepareWebFiles || return 1
|
||||
prepareWebFiles
|
||||
|
||||
html "Starting $APP for $ENGINE..."
|
||||
|
||||
disabled "${WEB:-}" && return 0
|
||||
|
||||
configureWebServer || return 1
|
||||
configureWebServer
|
||||
|
||||
startWebServer || return 1
|
||||
startWebsocketServer || return 1
|
||||
if startWebServer && startWebsocketServer; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 0
|
||||
stopWebsocketServer || :
|
||||
stopWebServer || :
|
||||
|
||||
return 1
|
||||
|
||||
+18
-5
@@ -3,6 +3,8 @@ set -Eeuo pipefail
|
||||
|
||||
lastmsg=""
|
||||
path="/run/shm/msg.html"
|
||||
dir=$(dirname -- "$path")
|
||||
name=$(basename -- "$path")
|
||||
|
||||
refresh() {
|
||||
|
||||
@@ -17,15 +19,26 @@ refresh() {
|
||||
|
||||
lastmsg="$msg"
|
||||
echo "s: $msg"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
refresh
|
||||
|
||||
inotifywait -m "$path" |
|
||||
while read -r fp event fn; do
|
||||
inotifywait \
|
||||
-m -q \
|
||||
-e close_write,moved_to,delete \
|
||||
--format '%e %f' \
|
||||
"$dir" |
|
||||
while read -r event file; do
|
||||
|
||||
[[ "$file" == "$name" ]] || continue
|
||||
|
||||
case "${event,,}" in
|
||||
"modify"* ) refresh ;;
|
||||
"delete_self" ) echo "c: vnc" ;;
|
||||
esac
|
||||
"delete"* )
|
||||
echo "c: vnc" ;;
|
||||
"close_write"* | "moved_to"* )
|
||||
refresh ;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
+97
-45
@@ -7,6 +7,52 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; }
|
||||
warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; }
|
||||
|
||||
readPidFile() {
|
||||
|
||||
local -n _pid="$1"
|
||||
_pid=""
|
||||
|
||||
if ! _pid=$(cat -- "$2" 2>/dev/null); then
|
||||
_pid=""
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! "$_pid" =~ ^[1-9][0-9]*$ ]]; then
|
||||
_pid=""
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
hasFlag() {
|
||||
|
||||
# Match a whitespace-delimited token in /proc/cpuinfo
|
||||
grep -m1 '^flags[[:space:]]*:' /proc/cpuinfo | grep -Fqw -- "$1"
|
||||
|
||||
}
|
||||
|
||||
hasFeature() {
|
||||
|
||||
# Match a whitespace-delimited token in /proc/cpuinfo
|
||||
grep -m1 '^Features[[:space:]]*:' /proc/cpuinfo | grep -Fqw -- "$1"
|
||||
|
||||
}
|
||||
|
||||
isAmdCpu() {
|
||||
|
||||
local vendor
|
||||
vendor=$(awk -F ': *' '/^vendor_id/{print $2; exit}' /proc/cpuinfo)
|
||||
|
||||
[[ "$vendor" == "AuthenticAMD" ]]
|
||||
}
|
||||
|
||||
interactive() {
|
||||
|
||||
[ -t 0 ] && : 2>/dev/null </dev/tty >/dev/tty
|
||||
|
||||
}
|
||||
|
||||
strip() {
|
||||
|
||||
local value="${1:-}"
|
||||
@@ -90,14 +136,13 @@ isAlive() {
|
||||
|
||||
waitPid() {
|
||||
|
||||
local i=0
|
||||
local pid="$1"
|
||||
local timeout="${2:-10}"
|
||||
local deadline=$((SECONDS + timeout))
|
||||
|
||||
while [ -n "$pid" ] && isAlive "$pid"; do
|
||||
(( SECONDS >= deadline )) && return 1
|
||||
sleep 0.2
|
||||
i=$((i + 1))
|
||||
(( i >= timeout * 5 )) && return 1
|
||||
done
|
||||
|
||||
return 0
|
||||
@@ -105,19 +150,16 @@ waitPid() {
|
||||
|
||||
waitPidFile() {
|
||||
|
||||
local i=0
|
||||
local pid=""
|
||||
local pid
|
||||
local file="$1"
|
||||
local timeout="${2:-10}"
|
||||
local deadline=$((SECONDS + timeout))
|
||||
|
||||
[ ! -s "$file" ] && return 0
|
||||
! read -r pid <"$file" && return 0
|
||||
[ -z "$pid" ] && return 0
|
||||
readPidFile pid "$file" || return 0
|
||||
|
||||
while [ -s "$file" ] && isAlive "$pid"; do
|
||||
(( SECONDS >= deadline )) && return 1
|
||||
sleep 0.2
|
||||
i=$((i + 1))
|
||||
(( i >= timeout * 5 )) && return 1
|
||||
done
|
||||
|
||||
rm -f -- "$file"
|
||||
@@ -140,19 +182,19 @@ pKill() {
|
||||
|
||||
fWait() {
|
||||
|
||||
local i=0
|
||||
local name="$1"
|
||||
local timeout="${2:-10}"
|
||||
local deadline=$((SECONDS + timeout))
|
||||
|
||||
[ -z "$name" ] && return 0
|
||||
|
||||
while pgrep -f -l "$name" >/dev/null; do
|
||||
sleep 0.2
|
||||
i=$((i + 1))
|
||||
if (( i >= timeout * 5 )); then
|
||||
if (( SECONDS >= deadline )); then
|
||||
warn "Timed out while waiting for process: $name"
|
||||
break
|
||||
fi
|
||||
|
||||
sleep 0.2
|
||||
done
|
||||
|
||||
return 0
|
||||
@@ -173,12 +215,10 @@ fKill() {
|
||||
|
||||
sKill() {
|
||||
|
||||
local pid=""
|
||||
local pid
|
||||
local file="$1"
|
||||
|
||||
[ ! -s "$file" ] && return 0
|
||||
! read -r pid <"$file" && return 0
|
||||
[ -z "$pid" ] && return 0
|
||||
readPidFile pid "$file" || return 0
|
||||
|
||||
if isAlive "$pid"; then
|
||||
{ kill -15 -- "$pid" || :; } 2>/dev/null
|
||||
@@ -216,7 +256,7 @@ setOwner() {
|
||||
uid=$(stat -c '%u' "$dir") || return 1
|
||||
gid=$(stat -c '%g' "$dir") || return 1
|
||||
|
||||
! chown "$uid:$gid" "$file" && return 1
|
||||
chown "$uid:$gid" "$file" || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -227,7 +267,7 @@ makeDir() {
|
||||
local dir uid gid
|
||||
|
||||
[ -d "$path" ] && return 0
|
||||
! mkdir -p "$path" && return 1
|
||||
mkdir -p "$path" || return 1
|
||||
|
||||
dir=$(dirname -- "$path")
|
||||
|
||||
@@ -272,6 +312,25 @@ writeFile() {
|
||||
return 0
|
||||
}
|
||||
|
||||
writeAtomic() {
|
||||
|
||||
local path="$1"
|
||||
local content="$2"
|
||||
local tmp="${path}.${BASHPID}.tmp"
|
||||
|
||||
if ! printf '%s\n' "$content" > "$tmp"; then
|
||||
rm -f -- "$tmp"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! mv -f -- "$tmp" "$path"; then
|
||||
rm -f -- "$tmp"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
readFile() {
|
||||
|
||||
local path="$1"
|
||||
@@ -334,8 +393,7 @@ restoreState() {
|
||||
|
||||
escape () {
|
||||
|
||||
local s
|
||||
s=${1//&/\&}
|
||||
local s=${1//&/\&}
|
||||
s=${s//</\<}
|
||||
s=${s//>/\>}
|
||||
s=${s//'"'/\"}
|
||||
@@ -345,11 +403,23 @@ escape () {
|
||||
return 0
|
||||
}
|
||||
|
||||
escapeXML() {
|
||||
|
||||
printf '%s' "$1" | sed \
|
||||
-e 's/&/\&/g' \
|
||||
-e 's/</\</g' \
|
||||
-e 's/>/\>/g' \
|
||||
-e 's/"/\"/g' \
|
||||
-e "s/'/\'/g"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
html() {
|
||||
|
||||
local title
|
||||
local body
|
||||
local script
|
||||
local script="${2:-}"
|
||||
local footer
|
||||
|
||||
title=$(escape "$APP")
|
||||
@@ -361,8 +431,6 @@ html() {
|
||||
body="<p class=\"loading\">${body/.../}</p>"
|
||||
fi
|
||||
|
||||
[ -n "${2:-}" ] && script="$2" || script=""
|
||||
|
||||
local HTML
|
||||
HTML=$(<"$TEMPLATE")
|
||||
HTML="${HTML/\[1\]/$title}"
|
||||
@@ -371,8 +439,8 @@ html() {
|
||||
HTML="${HTML/\[4\]/$footer}"
|
||||
HTML="${HTML/\[5\]/$FOOTER2}"
|
||||
|
||||
echo "$HTML" > "$PAGE" || return 1
|
||||
echo "$body" > "$INFO" || return 1
|
||||
writeAtomic "$PAGE" "$HTML" || return 1
|
||||
writeAtomic "$INFO" "$body" || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -415,29 +483,13 @@ cpu() {
|
||||
return 0
|
||||
}
|
||||
|
||||
hasDisk() {
|
||||
|
||||
enabled "${DISK_DISABLE:-}" && return 1
|
||||
|
||||
[ -b "/disk" ] && return 0
|
||||
[ -b "/disk1" ] && return 0
|
||||
[ -b "/dev/disk1" ] && return 0
|
||||
[ -b "${DEVICE:-}" ] && return 0
|
||||
|
||||
[ -z "${DISK_NAME:-}" ] && DISK_NAME="data"
|
||||
[ -s "$STORAGE/$DISK_NAME.img" ] && return 0
|
||||
[ -s "$STORAGE/$DISK_NAME.qcow2" ] && return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
getCountry() {
|
||||
|
||||
local url=$1
|
||||
local query=$2
|
||||
local rc json result
|
||||
local json result
|
||||
|
||||
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
|
||||
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); local rc=$?; } || :
|
||||
(( rc != 0 )) && return 0
|
||||
|
||||
{ result=$(echo "$json" | jq -r "$query" 2> /dev/null); rc=$?; } || :
|
||||
|
||||
+48
-8
@@ -1,15 +1,27 @@
|
||||
var timer;
|
||||
var request;
|
||||
var booting = false;
|
||||
var interval = 1000;
|
||||
|
||||
function abortRequest() {
|
||||
|
||||
if (!request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
request.onreadystatechange = null;
|
||||
request.abort();
|
||||
request = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getInfo() {
|
||||
|
||||
var url = "msg.html";
|
||||
|
||||
try {
|
||||
if (request) {
|
||||
request.abort();
|
||||
}
|
||||
abortRequest();
|
||||
|
||||
if (window.XMLHttpRequest) {
|
||||
request = new XMLHttpRequest();
|
||||
@@ -56,7 +68,17 @@ function processInfo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
var msg = request.responseText;
|
||||
var response = request;
|
||||
request = null;
|
||||
|
||||
var status = response.status;
|
||||
|
||||
if (status == 502 || status == 503 || status == 504) {
|
||||
schedule();
|
||||
return true;
|
||||
}
|
||||
|
||||
var msg = response.responseText;
|
||||
if (msg == null || msg.length == 0) {
|
||||
|
||||
if (booting) {
|
||||
@@ -68,9 +90,9 @@ function processInfo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
var notFound = (request.status == 404);
|
||||
var notFound = (status == 404);
|
||||
|
||||
if (request.status == 200) {
|
||||
if (status == 200) {
|
||||
if (msg.toLowerCase().indexOf("<html>") !== -1) {
|
||||
notFound = true;
|
||||
} else {
|
||||
@@ -88,7 +110,7 @@ function processInfo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
setError("Error: Received statuscode " + request.status);
|
||||
setError("Error: Received statuscode " + status);
|
||||
return false;
|
||||
|
||||
} catch (e) {
|
||||
@@ -157,7 +179,9 @@ function setError(text) {
|
||||
}
|
||||
|
||||
function schedule() {
|
||||
setTimeout(getInfo, interval);
|
||||
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(getInfo, interval);
|
||||
}
|
||||
|
||||
function reload() {
|
||||
@@ -179,11 +203,27 @@ function connect() {
|
||||
|
||||
switch (cmd) {
|
||||
case "s":
|
||||
|
||||
var aborted = abortRequest();
|
||||
|
||||
processMsg(msg);
|
||||
|
||||
if (aborted &&
|
||||
msg.toLowerCase().indexOf("href=") == -1) {
|
||||
schedule();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "e":
|
||||
|
||||
if (abortRequest()) {
|
||||
schedule();
|
||||
}
|
||||
|
||||
setError(msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn("Unknown event: " + cmd);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user