mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-10-12 21:54:59 +08:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
25227944b5 | ||
|
06650e916a | ||
|
2e34dffed5 | ||
|
3db91f077f | ||
|
fae14f4dd9 | ||
|
d190b3ba87 | ||
|
554f3295cb | ||
|
cdc4689d6a |
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@ -1,11 +1,6 @@
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
|
||||||
- '**/*.sh'
|
|
||||||
- 'Dockerfile'
|
|
||||||
- '.github/workflows/test.yml'
|
|
||||||
- '.github/workflows/check.yml'
|
|
||||||
|
|
||||||
name: "Test"
|
name: "Test"
|
||||||
permissions: {}
|
permissions: {}
|
||||||
|
@ -37,13 +37,15 @@ RUN set -eu && \
|
|||||||
xz-utils \
|
xz-utils \
|
||||||
iptables \
|
iptables \
|
||||||
iproute2 \
|
iproute2 \
|
||||||
apt-utils \
|
|
||||||
dnsmasq \
|
dnsmasq \
|
||||||
fakeroot \
|
fakeroot \
|
||||||
|
apt-utils \
|
||||||
net-tools \
|
net-tools \
|
||||||
e2fsprogs \
|
e2fsprogs \
|
||||||
qemu-utils \
|
qemu-utils \
|
||||||
|
websocketd \
|
||||||
iputils-ping \
|
iputils-ping \
|
||||||
|
inotify-tools \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
netcat-openbsd \
|
netcat-openbsd \
|
||||||
qemu-system-x86 && \
|
qemu-system-x86 && \
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
: "${PLATFORM:="x64"}"
|
||||||
: "${APP:="Virtual DSM"}"
|
: "${APP:="Virtual DSM"}"
|
||||||
: "${SUPPORT:="https://github.com/vdsm/virtual-dsm"}"
|
: "${SUPPORT:="https://github.com/vdsm/virtual-dsm"}"
|
||||||
|
|
||||||
cd /run
|
cd /run
|
||||||
|
|
||||||
. start.sh # Placeholder
|
. start.sh # Startup hook
|
||||||
. utils.sh # Load functions
|
. utils.sh # Load functions
|
||||||
. reset.sh # Initialize system
|
. reset.sh # Initialize system
|
||||||
|
. server.sh # Start webserver
|
||||||
. install.sh # Run installation
|
. install.sh # Run installation
|
||||||
. disk.sh # Initialize disks
|
. disk.sh # Initialize disks
|
||||||
. display.sh # Initialize graphics
|
. display.sh # Initialize graphics
|
||||||
@ -31,7 +33,7 @@ fi
|
|||||||
(( rc != 0 )) && error "$(<"$QEMU_LOG")" && exit 15
|
(( rc != 0 )) && error "$(<"$QEMU_LOG")" && exit 15
|
||||||
|
|
||||||
terminal
|
terminal
|
||||||
tail -fn +0 "$QEMU_LOG" 2>/dev/null &
|
tail -fn +0 "$QEMU_LOG" --pid=$$ 2>/dev/null &
|
||||||
cat "$QEMU_TERM" 2>/dev/null & wait $! || :
|
cat "$QEMU_TERM" 2>/dev/null & wait $! || :
|
||||||
|
|
||||||
sleep 1 & wait $!
|
sleep 1 & wait $!
|
||||||
|
@ -301,7 +301,4 @@ fi
|
|||||||
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
||||||
rm -rf "$TMP"
|
rm -rf "$TMP"
|
||||||
|
|
||||||
html "Booting DSM instance..."
|
|
||||||
sleep 1.2
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
178
src/network.sh
178
src/network.sh
@ -20,6 +20,7 @@ set -Eeuo pipefail
|
|||||||
: "${VM_NET_MASK:="255.255.255.0"}"
|
: "${VM_NET_MASK:="255.255.255.0"}"
|
||||||
|
|
||||||
: "${PASST:="passt"}"
|
: "${PASST:="passt"}"
|
||||||
|
: "${PASST_MTU:=""}"
|
||||||
: "${PASST_OPTS:=""}"
|
: "${PASST_OPTS:=""}"
|
||||||
: "${PASST_DEBUG:=""}"
|
: "${PASST_DEBUG:=""}"
|
||||||
|
|
||||||
@ -176,44 +177,12 @@ configureDNS() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$DNSMASQ_DEBUG" == [Yy1]* ]]; then
|
if [[ "$DNSMASQ_DEBUG" == [Yy1]* ]]; then
|
||||||
tail -fn +0 "$log" &
|
tail -fn +0 "$log" --pid=$$ &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserPorts() {
|
|
||||||
|
|
||||||
local args=""
|
|
||||||
local list=$1
|
|
||||||
local ssh="22"
|
|
||||||
local dsm="5000"
|
|
||||||
|
|
||||||
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
|
||||||
|
|
||||||
list="${list//,/ }"
|
|
||||||
list="${list## }"
|
|
||||||
list="${list%% }"
|
|
||||||
|
|
||||||
for port in $list; do
|
|
||||||
proto="tcp"
|
|
||||||
num="$port"
|
|
||||||
|
|
||||||
if [[ "$port" == */udp ]]; then
|
|
||||||
proto="udp"
|
|
||||||
num="${port%/udp}"
|
|
||||||
elif [[ "$port" == */tcp ]]; then
|
|
||||||
proto="tcp"
|
|
||||||
num="${port%/tcp}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${args%?}"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
getHostPorts() {
|
getHostPorts() {
|
||||||
|
|
||||||
local list="$1"
|
local list="$1"
|
||||||
@ -221,23 +190,55 @@ getHostPorts() {
|
|||||||
|
|
||||||
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
||||||
|
|
||||||
if [[ "${NETWORK,,}" == "passt" ]]; then
|
echo "$list"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
local DNS_PORT="53"
|
getUserPorts() {
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
local args=""
|
||||||
[ -z "$list" ] && list="$DNS_PORT" || list+=",$DNS_PORT"
|
local list=$1
|
||||||
fi
|
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||||
|
|
||||||
[ -z "$list" ] && list="$COM_PORT" || list+=",$COM_PORT"
|
local ssh="22"
|
||||||
[ -z "$list" ] && list="$CHR_PORT" || list+=",$CHR_PORT"
|
local dsm="5000"
|
||||||
|
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$list"
|
echo "$list"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSlirp() {
|
||||||
|
|
||||||
|
local args=""
|
||||||
|
local list=""
|
||||||
|
|
||||||
|
list=$(getUserPorts)
|
||||||
|
list="${list//,/ }"
|
||||||
|
list="${list## }"
|
||||||
|
list="${list%% }"
|
||||||
|
|
||||||
|
for port in $list; do
|
||||||
|
|
||||||
|
proto="tcp"
|
||||||
|
num="${port%/tcp}"
|
||||||
|
|
||||||
|
if [[ "$port" == *"/udp" ]]; then
|
||||||
|
proto="udp"
|
||||||
|
num="${port%/udp}"
|
||||||
|
elif [[ "$port" != *"/tcp" ]]; then
|
||||||
|
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||||
|
proto="udp"
|
||||||
|
num="${port%/udp}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "${args%?}"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
configureSlirp() {
|
configureSlirp() {
|
||||||
|
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
||||||
@ -253,17 +254,18 @@ configureSlirp() {
|
|||||||
|
|
||||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
||||||
|
|
||||||
local forward
|
local forward=""
|
||||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
||||||
|
echo "$gateway" > /run/shm/qemu.gw
|
||||||
|
else
|
||||||
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
||||||
|
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
||||||
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
|
||||||
|
|
||||||
VM_NET_IP="$ip"
|
VM_NET_IP="$ip"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -294,17 +296,19 @@ configurePasst() {
|
|||||||
PASST_OPTS+=" -a $ip"
|
PASST_OPTS+=" -a $ip"
|
||||||
PASST_OPTS+=" -g $gateway"
|
PASST_OPTS+=" -g $gateway"
|
||||||
PASST_OPTS+=" -n $VM_NET_MASK"
|
PASST_OPTS+=" -n $VM_NET_MASK"
|
||||||
|
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
||||||
|
|
||||||
exclude=$(getHostPorts "$HOST_PORTS")
|
local forward=""
|
||||||
|
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||||
|
forward="${forward///tcp}"
|
||||||
|
forward="${forward///udp}"
|
||||||
|
|
||||||
if [ -z "$exclude" ]; then
|
if [ -n "$forward" ]; then
|
||||||
exclude="all"
|
forward="%${VM_NET_DEV}/$forward"
|
||||||
else
|
PASST_OPTS+=" -t $forward"
|
||||||
exclude="~${exclude//,/,~}"
|
PASST_OPTS+=" -u $forward"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PASST_OPTS+=" -t $exclude"
|
|
||||||
PASST_OPTS+=" -u $exclude"
|
|
||||||
PASST_OPTS+=" -H $VM_NET_HOST"
|
PASST_OPTS+=" -H $VM_NET_HOST"
|
||||||
PASST_OPTS+=" -M $GATEWAY_MAC"
|
PASST_OPTS+=" -M $GATEWAY_MAC"
|
||||||
PASST_OPTS+=" -P /var/run/passt.pid"
|
PASST_OPTS+=" -P /var/run/passt.pid"
|
||||||
@ -327,7 +331,7 @@ configurePasst() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
||||||
tail -fn +0 "$log" &
|
tail -fn +0 "$log" --pid=$$ &
|
||||||
else
|
else
|
||||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||||
[ -f "$log" ] && cat "$log" && echo ""
|
[ -f "$log" ] && cat "$log" && echo ""
|
||||||
@ -502,14 +506,24 @@ closeBridge() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeWeb() {
|
||||||
|
|
||||||
|
# Shutdown nginx
|
||||||
|
nginx -s stop 2> /dev/null
|
||||||
|
fWait "nginx"
|
||||||
|
|
||||||
|
# Shutdown websocket
|
||||||
|
local pid="/var/run/websocketd.pid"
|
||||||
|
[ -s "$pid" ] && pKill "$(<"$pid")"
|
||||||
|
rm -f "$pid"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
closeNetwork() {
|
closeNetwork() {
|
||||||
|
|
||||||
if [[ "${WEB:-}" != [Nn]* && "$DHCP" == [Yy1]* ]]; then
|
if [[ "${WEB:-}" != [Nn]* && "$DHCP" == [Yy1]* ]]; then
|
||||||
|
closeWeb
|
||||||
# Shutdown nginx
|
|
||||||
nginx -s stop 2> /dev/null
|
|
||||||
fWait "nginx"
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ "$NETWORK" == [Nn]* ]] && return 0
|
[[ "$NETWORK" == [Nn]* ]] && return 0
|
||||||
@ -552,8 +566,8 @@ checkOS() {
|
|||||||
local if="macvlan"
|
local if="macvlan"
|
||||||
kernel=$(uname -a)
|
kernel=$(uname -a)
|
||||||
|
|
||||||
[[ "${kernel,,}" == *"darwin"* ]] && os="Docker Desktop for macOS"
|
[[ "${kernel,,}" == *"darwin"* ]] && os="$ENGINE Desktop for macOS"
|
||||||
[[ "${kernel,,}" == *"microsoft"* ]] && os="Docker Desktop for Windows"
|
[[ "${kernel,,}" == *"microsoft"* ]] && os="$ENGINE Desktop for Windows"
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
if="macvtap"
|
if="macvtap"
|
||||||
@ -586,12 +600,17 @@ getInfo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
||||||
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1)
|
{ IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1); rc=$?; } 2>/dev/null || :
|
||||||
IP6=""
|
|
||||||
|
|
||||||
|
if (( rc != 0 )); then
|
||||||
|
error "Could not determine container IP address!" && exit 26
|
||||||
|
fi
|
||||||
|
|
||||||
|
IP6=""
|
||||||
# shellcheck disable=SC2143
|
# shellcheck disable=SC2143
|
||||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||||
IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up)
|
{ IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up); rc=$?; } 2>/dev/null || :
|
||||||
|
(( rc != 0 )) && IP6=""
|
||||||
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -638,11 +657,6 @@ getInfo() {
|
|||||||
[ -z "$MTU" ] && MTU="$mtu"
|
[ -z "$MTU" ] && MTU="$mtu"
|
||||||
[ -z "$MTU" ] && MTU="0"
|
[ -z "$MTU" ] && MTU="0"
|
||||||
|
|
||||||
if [ "$MTU" -gt "1500" ]; then
|
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "MTU size is too large: $MTU, ignoring..."
|
|
||||||
MTU="0"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
||||||
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
||||||
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
||||||
@ -718,22 +732,19 @@ if [[ "$IP" == "172.17."* ]]; then
|
|||||||
warn "your container IP starts with 172.17.* which will cause conflicts when you install the Container Manager package inside DSM!"
|
warn "your container IP starts with 172.17.* which will cause conflicts when you install the Container Manager package inside DSM!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
MSG="Booting DSM instance..."
|
||||||
|
html "$MSG"
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
|
|
||||||
# Configure for macvtap interface
|
# Configure for macvtap interface
|
||||||
configureDHCP || exit 20
|
configureDHCP || exit 20
|
||||||
|
|
||||||
MSG="Booting DSM instance..."
|
|
||||||
html "$MSG"
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
if [[ "${WEB:-}" != [Nn]* ]]; then
|
if [[ "${WEB:-}" != [Nn]* ]]; then
|
||||||
|
sleep 1.2
|
||||||
# Shutdown nginx
|
closeWeb
|
||||||
nginx -s stop 2> /dev/null
|
|
||||||
fWait "nginx"
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "${NETWORK,,}" in
|
case "${NETWORK,,}" in
|
||||||
@ -770,16 +781,21 @@ else
|
|||||||
if ! configureSlirp; then
|
if ! configureSlirp; then
|
||||||
error "Failed to configure user-mode networking!"
|
error "Failed to configure user-mode networking!"
|
||||||
exit 24
|
exit 24
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$USER_PORTS" ]; then
|
|
||||||
info "Notice: slirp networking is active, so when you want to expose ports, you will need to map them using this variable: \"USER_PORTS=5000,5001\"."
|
|
||||||
fi ;;
|
fi ;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case "${NETWORK,,}" in
|
||||||
|
"passt" | "slirp" )
|
||||||
|
|
||||||
|
if [ -z "$USER_PORTS" ]; then
|
||||||
|
info "Notice: because user-mode networking is active, if you need to expose ports, add them to the \"USER_PORTS\" variable."
|
||||||
|
fi ;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
||||||
|
48
src/proc.sh
48
src/proc.sh
@ -3,7 +3,6 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
# Docker environment variables
|
# Docker environment variables
|
||||||
|
|
||||||
: "${KVM:="Y"}"
|
|
||||||
: "${HOST_CPU:=""}"
|
: "${HOST_CPU:=""}"
|
||||||
: "${CPU_FLAGS:=""}"
|
: "${CPU_FLAGS:=""}"
|
||||||
: "${CPU_MODEL:=""}"
|
: "${CPU_MODEL:=""}"
|
||||||
@ -26,52 +25,7 @@ else
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$KVM" == [Nn]* ]]; then
|
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
|
||||||
warn "KVM acceleration is disabled, this will cause the machine to run about 10 times slower!"
|
|
||||||
else
|
|
||||||
if [[ "${ARCH,,}" != "amd64" ]]; then
|
|
||||||
KVM="N"
|
|
||||||
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 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
|
|
||||||
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
|
|
||||||
if ! grep -qw "vmx\|svm" <<< "$flags"; then
|
|
||||||
KVM_ERR="(not enabled in BIOS)"
|
|
||||||
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
|
|
||||||
|
|
||||||
if [[ "$KVM" != [Nn]* ]]; then
|
if [[ "$KVM" != [Nn]* ]]; then
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ do
|
|||||||
if [ -s "$file" ]; then
|
if [ -s "$file" ]; then
|
||||||
bytes=$(du -sb "$file" | cut -f1)
|
bytes=$(du -sb "$file" | cut -f1)
|
||||||
if (( bytes > 1000 )); then
|
if (( bytes > 1000 )); then
|
||||||
if [ -z "$total" ] || [[ "$total" == "0" ]]; then
|
if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then
|
||||||
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/')
|
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/')
|
||||||
else
|
else
|
||||||
size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')"
|
size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')"
|
||||||
|
148
src/reset.sh
148
src/reset.sh
@ -9,7 +9,8 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
|||||||
|
|
||||||
# Docker environment variables
|
# Docker environment variables
|
||||||
|
|
||||||
: "${TZ:=""}" # System local timezone
|
: "${TZ:=""}" # System timezone
|
||||||
|
: "${KVM:="Y"}" # KVM acceleration
|
||||||
: "${DEBUG:="N"}" # Disable debugging mode
|
: "${DEBUG:="N"}" # Disable debugging mode
|
||||||
: "${COUNTRY:=""}" # Country code for mirror
|
: "${COUNTRY:=""}" # Country code for mirror
|
||||||
: "${CONSOLE:="N"}" # Disable console mode
|
: "${CONSOLE:="N"}" # Disable console mode
|
||||||
@ -141,6 +142,63 @@ if [[ "$RAM_CHECK" != [Nn]* ]] && (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); th
|
|||||||
info "$msg"
|
info "$msg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 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
|
# Cleanup files
|
||||||
rm -f /run/shm/qemu.*
|
rm -f /run/shm/qemu.*
|
||||||
rm -f /run/shm/dsm.url
|
rm -f /run/shm/dsm.url
|
||||||
@ -149,92 +207,4 @@ rm -f /run/shm/dsm.url
|
|||||||
rm -rf /tmp/dsm
|
rm -rf /tmp/dsm
|
||||||
rm -rf "$STORAGE/tmp"
|
rm -rf "$STORAGE/tmp"
|
||||||
|
|
||||||
getCountry() {
|
|
||||||
local url=$1
|
|
||||||
local query=$2
|
|
||||||
local rc json result
|
|
||||||
|
|
||||||
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
|
|
||||||
(( rc != 0 )) && return 0
|
|
||||||
|
|
||||||
{ result=$(echo "$json" | jq -r "$query" 2> /dev/null); rc=$?; } || :
|
|
||||||
(( rc != 0 )) && return 0
|
|
||||||
|
|
||||||
[[ ${#result} -ne 2 ]] && return 0
|
|
||||||
[[ "${result^^}" == "XX" ]] && return 0
|
|
||||||
|
|
||||||
COUNTRY="${result^^}"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
setCountry() {
|
|
||||||
|
|
||||||
[[ "${TZ,,}" == "asia/harbin" ]] && COUNTRY="CN"
|
|
||||||
[[ "${TZ,,}" == "asia/beijing" ]] && COUNTRY="CN"
|
|
||||||
[[ "${TZ,,}" == "asia/urumqi" ]] && COUNTRY="CN"
|
|
||||||
[[ "${TZ,,}" == "asia/kashgar" ]] && COUNTRY="CN"
|
|
||||||
[[ "${TZ,,}" == "asia/shanghai" ]] && COUNTRY="CN"
|
|
||||||
[[ "${TZ,,}" == "asia/chongqing" ]] && COUNTRY="CN"
|
|
||||||
|
|
||||||
[ -z "$COUNTRY" ] && getCountry "https://api.ipapi.is" ".location.country_code"
|
|
||||||
[ -z "$COUNTRY" ] && getCountry "https://ifconfig.co/json" ".country_iso"
|
|
||||||
[ -z "$COUNTRY" ] && getCountry "https://api.ip2location.io" ".country_code"
|
|
||||||
[ -z "$COUNTRY" ] && getCountry "https://ipinfo.io/json" ".country"
|
|
||||||
[ -z "$COUNTRY" ] && getCountry "https://api.ipquery.io/?format=json" ".location.country_code"
|
|
||||||
[ -z "$COUNTRY" ] && getCountry "https://api.myip.com" ".cc"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
[ -z "$COUNTRY" ] && setCountry
|
|
||||||
|
|
||||||
if [[ "${COUNTRY^^}" == "CN" ]]; then
|
|
||||||
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
|
|
||||||
fi
|
|
||||||
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get -qq update
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
: "${COM_PORT:="2210"}" # Comm port
|
|
||||||
: "${MON_PORT:="7100"}" # Monitor port
|
|
||||||
: "${WEB_PORT:="5000"}" # Webserver port
|
|
||||||
: "${CHR_PORT:="12345"}" # Character port
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
sed -i "s/listen 5000 default_server;/listen $WEB_PORT default_server;/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
|
return 0
|
||||||
|
39
src/server.sh
Normal file
39
src/server.sh
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
: "${COM_PORT:="2210"}" # Comm port
|
||||||
|
: "${MON_PORT:="7100"}" # Monitor port
|
||||||
|
: "${WEB_PORT:="5000"}" # Webserver port
|
||||||
|
: "${CHR_PORT:="12345"}" # Character port
|
||||||
|
: "${WSD_PORT:="8004"}" # Websockets port
|
||||||
|
|
||||||
|
cp -r /var/www/* /run/shm
|
||||||
|
rm -f /var/run/websocketd.pid
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Start websocket server
|
||||||
|
websocketd --address 127.0.0.1 --port="$WSD_PORT" /run/socket.sh >/var/log/websocketd.log &
|
||||||
|
echo "$!" > /var/run/websocketd.pid
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
16
src/socket.sh
Normal file
16
src/socket.sh
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
path="/run/shm/msg.html"
|
||||||
|
|
||||||
|
if [ -f "$path" ] && [ -s "$path" ]; then
|
||||||
|
echo -n "s: " && cat "$path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
inotifywait -m "$path" |
|
||||||
|
while read -r fp event fn; do
|
||||||
|
case "${event,,}" in
|
||||||
|
"modify"* ) echo -n "s: " && cat "$path" ;;
|
||||||
|
"delete_self" ) echo "c: vnc" ;;
|
||||||
|
esac
|
||||||
|
done
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
# Override this placeholder file using a Docker bind to execute a script during startup!
|
# You can override this hook to execute a script before startup!
|
||||||
|
|
||||||
|
return 0
|
||||||
|
61
src/utils.sh
61
src/utils.sh
@ -159,4 +159,65 @@ hasDisk() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCountry() {
|
||||||
|
local url=$1
|
||||||
|
local query=$2
|
||||||
|
local rc json result
|
||||||
|
|
||||||
|
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && return 0
|
||||||
|
|
||||||
|
{ result=$(echo "$json" | jq -r "$query" 2> /dev/null); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && return 0
|
||||||
|
|
||||||
|
[[ ${#result} -ne 2 ]] && return 0
|
||||||
|
[[ "${result^^}" == "XX" ]] && return 0
|
||||||
|
|
||||||
|
COUNTRY="${result^^}"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setCountry() {
|
||||||
|
|
||||||
|
[[ "${TZ,,}" == "asia/harbin" ]] && COUNTRY="CN"
|
||||||
|
[[ "${TZ,,}" == "asia/beijing" ]] && COUNTRY="CN"
|
||||||
|
[[ "${TZ,,}" == "asia/urumqi" ]] && COUNTRY="CN"
|
||||||
|
[[ "${TZ,,}" == "asia/kashgar" ]] && COUNTRY="CN"
|
||||||
|
[[ "${TZ,,}" == "asia/shanghai" ]] && COUNTRY="CN"
|
||||||
|
[[ "${TZ,,}" == "asia/chongqing" ]] && COUNTRY="CN"
|
||||||
|
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://api.ipapi.is" ".location.country_code"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://ifconfig.co/json" ".country_iso"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://api.ip2location.io" ".country_code"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://ipinfo.io/json" ".country"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://api.ipquery.io/?format=json" ".location.country_code"
|
||||||
|
[ -z "$COUNTRY" ] && getCountry "https://api.myip.com" ".cc"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
[ -z "$COUNTRY" ] && setCountry
|
||||||
|
|
||||||
|
if [[ "${COUNTRY^^}" == "CN" ]]; then
|
||||||
|
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get -qq update
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -27,4 +27,18 @@ server {
|
|||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /status {
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
|
||||||
|
proxy_buffering off;
|
||||||
|
proxy_read_timeout 3600s;
|
||||||
|
proxy_send_timeout 3600s;
|
||||||
|
|
||||||
|
proxy_pass http://127.0.0.1:8004/;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
138
web/js/script.js
138
web/js/script.js
@ -1,4 +1,5 @@
|
|||||||
var request;
|
var request;
|
||||||
|
var booting = false;
|
||||||
var interval = 1000;
|
var interval = 1000;
|
||||||
|
|
||||||
function getInfo() {
|
function getInfo() {
|
||||||
@ -6,7 +7,6 @@ function getInfo() {
|
|||||||
var url = "msg.html";
|
var url = "msg.html";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (window.XMLHttpRequest) {
|
if (window.XMLHttpRequest) {
|
||||||
request = new XMLHttpRequest();
|
request = new XMLHttpRequest();
|
||||||
} else {
|
} else {
|
||||||
@ -18,22 +18,49 @@ function getInfo() {
|
|||||||
request.send();
|
request.send();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var err = "Error: " + e.message;
|
setError("Error: " + e.message);
|
||||||
console.log(err);
|
|
||||||
setError(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getURL() {
|
||||||
|
|
||||||
|
var protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||||
|
var path = window.location.pathname.replace(/[^/]*$/, '').replace(/\/$/, '');
|
||||||
|
|
||||||
|
return protocol + "//" + window.location.host + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
function processMsg(msg) {
|
||||||
|
|
||||||
|
if (msg.toLowerCase().indexOf("href=") !== -1) {
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.innerHTML = msg;
|
||||||
|
var url = div.querySelector("a").href;
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.assign(url);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
setInfo(msg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function processInfo() {
|
function processInfo() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (request.readyState != 4) {
|
if (request.readyState != 4) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = request.responseText;
|
var msg = request.responseText;
|
||||||
if (msg == null || msg.length == 0) {
|
if (msg == null || msg.length == 0) {
|
||||||
setInfo("Booting DSM instance", true);
|
|
||||||
schedule();
|
if (booting) {
|
||||||
|
schedule();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.reload();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,20 +70,11 @@ function processInfo() {
|
|||||||
if (msg.toLowerCase().indexOf("<html>") !== -1) {
|
if (msg.toLowerCase().indexOf("<html>") !== -1) {
|
||||||
notFound = true;
|
notFound = true;
|
||||||
} else {
|
} else {
|
||||||
if (msg.toLowerCase().indexOf("href=") !== -1) {
|
processMsg(msg);
|
||||||
var div = document.createElement("div");
|
if (msg.toLowerCase().indexOf("href=") == -1) {
|
||||||
div.innerHTML = msg;
|
|
||||||
var url = div.querySelector("a").href;
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.assign(url);
|
|
||||||
}, 3000);
|
|
||||||
setInfo(msg);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
setInfo(msg);
|
|
||||||
schedule();
|
schedule();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,44 +85,60 @@ function processInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setError("Error: Received statuscode " + request.status);
|
setError("Error: Received statuscode " + request.status);
|
||||||
schedule();
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var err = "Error: " + e.message;
|
setError("Error: " + e.message);
|
||||||
console.log(err);
|
|
||||||
setError(err);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInfo(msg, loading, error) {
|
function extractContent(s) {
|
||||||
|
var span = document.createElement('span');
|
||||||
|
span.innerHTML = s;
|
||||||
|
return span.textContent || span.innerText;
|
||||||
|
};
|
||||||
|
|
||||||
|
function setInfo(msg, loading, error) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (msg == null || msg.length == 0) {
|
if (msg == null || msg.length == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var el = document.getElementById("spinner");
|
if (msg.includes("Booting ")) {
|
||||||
|
booting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var el = document.getElementById("info");
|
||||||
|
|
||||||
|
if (el.innerText == msg || el.innerHTML == msg) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var spin = document.getElementById("spinner");
|
||||||
|
|
||||||
error = !!error;
|
error = !!error;
|
||||||
if (!error) {
|
if (!error) {
|
||||||
el.style.visibility = 'visible';
|
spin.style.visibility = 'visible';
|
||||||
} else {
|
} else {
|
||||||
el.style.visibility = 'hidden';
|
spin.style.visibility = 'hidden';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var p = "<p class=\"loading\">";
|
||||||
loading = !!loading;
|
loading = !!loading;
|
||||||
if (loading) {
|
if (loading) {
|
||||||
msg = "<p class=\"loading\">" + msg + "</p>";
|
msg = p + msg + "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
el = document.getElementById("info");
|
if (msg.includes(p)) {
|
||||||
|
if (el.innerHTML.includes(p)) {
|
||||||
if (el.innerHTML != msg) {
|
el.getElementsByClassName('loading')[0].textContent = extractContent(msg);
|
||||||
el.innerHTML = msg;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
el.innerHTML = msg;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -114,6 +148,7 @@ function setInfo(msg, loading, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setError(text) {
|
function setError(text) {
|
||||||
|
console.warn(text);
|
||||||
return setInfo(text, false, true);
|
return setInfo(text, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,8 +158,47 @@ function schedule() {
|
|||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.location.reload();
|
window.location.reload();
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function connect() {
|
||||||
|
|
||||||
|
var wsUrl = getURL() + "/status";
|
||||||
|
var ws = new WebSocket(wsUrl);
|
||||||
|
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
|
||||||
|
var pos = e.data.indexOf(":");
|
||||||
|
var cmd = e.data.substring(0, pos);
|
||||||
|
var msg = e.data.substring(pos + 2);
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case "s":
|
||||||
|
processMsg(msg);
|
||||||
|
break;
|
||||||
|
case "e":
|
||||||
|
setError(msg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn("Unknown event: " + cmd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = function(e) {
|
||||||
|
setTimeout(function() {
|
||||||
|
connect();
|
||||||
|
}, interval);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = function(e) {
|
||||||
|
ws.close();
|
||||||
|
if (!booting) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
schedule();
|
schedule();
|
||||||
|
connect();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user