mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-09 03:23:40 +08:00
Compare commits
13 Commits
v7.30
...
1e83757494
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e83757494 | ||
|
|
fad463a439 | ||
|
|
608563d029 | ||
|
|
5fcd22b09f | ||
|
|
65548da2ef | ||
|
|
111e513dac | ||
|
|
7fce3a98fe | ||
|
|
4018eeadb4 | ||
|
|
a8e4647fa6 | ||
|
|
36d3fca4fc | ||
|
|
89b28f36d3 | ||
|
|
b4f7d70a7a | ||
|
|
902bafbd0c |
6
.devcontainer.json
Normal file
6
.devcontainer.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "dsm",
|
||||||
|
"service": "dsm",
|
||||||
|
"forwardPorts": [5000],
|
||||||
|
"dockerComposeFile": "compose.yml"
|
||||||
|
}
|
||||||
34
readme.md
34
readme.md
@@ -22,7 +22,7 @@ Virtual DSM in a Docker container.
|
|||||||
|
|
||||||
## Usage 🐳
|
## Usage 🐳
|
||||||
|
|
||||||
Via Docker Compose:
|
##### Via Docker Compose:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
@@ -44,27 +44,32 @@ services:
|
|||||||
stop_grace_period: 2m
|
stop_grace_period: 2m
|
||||||
```
|
```
|
||||||
|
|
||||||
Via Docker CLI:
|
##### Via Docker CLI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -it --rm --name dsm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v ${PWD:-.}/dsm:/storage --stop-timeout 120 vdsm/virtual-dsm
|
docker run -it --rm --name dsm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v ${PWD:-.}/dsm:/storage --stop-timeout 120 vdsm/virtual-dsm
|
||||||
```
|
```
|
||||||
|
|
||||||
Via Kubernetes:
|
##### Via Kubernetes:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/master/kubernetes.yml
|
kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/master/kubernetes.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Via Github Codespaces:
|
||||||
|
|
||||||
|
[`Click here to launch this container in the cloud!`](https://github.com/codespaces/new?skip_quickstart=true&machine=basicLinux32gb&repo=619260050&ref=master&devcontainer_path=.devcontainer.json)
|
||||||
|
|
||||||
## Compatibility ⚙️
|
## Compatibility ⚙️
|
||||||
|
|
||||||
| **Product** | **Platform** | |
|
| **Product** | **Platform** | |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Docker Engine | Linux| ✅ |
|
| Docker Engine | Linux | ✅ |
|
||||||
| Docker Desktop | Linux | ❌ |
|
| Docker Desktop | Linux | ❌ |
|
||||||
| Docker Desktop | macOS | ❌ |
|
| Docker Desktop | macOS | ❌ |
|
||||||
| Docker Desktop | Windows 11 | ✅ |
|
| Docker Desktop | Windows 11 | ✅ |
|
||||||
| Docker Desktop | Windows 10 | ❌ |
|
| Docker Desktop | Windows 10 | ❌ |
|
||||||
|
| Github Codespaces | Cloud | ✅ |
|
||||||
|
|
||||||
## FAQ 💬
|
## FAQ 💬
|
||||||
|
|
||||||
@@ -72,9 +77,11 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
Very simple! These are the steps:
|
Very simple! These are the steps:
|
||||||
|
|
||||||
- Start the container and connect to [port 5000](http://localhost:5000) using your web browser.
|
- Start the container and connect to [port 5000](http://127.0.0.1:5000/) using your web browser.
|
||||||
|
|
||||||
- Wait until DSM is ready, choose an username and password, and you will be taken to the desktop.
|
- Wait until DSM finishes its installation
|
||||||
|
|
||||||
|
- Choose an username and password, and you will be taken to the desktop.
|
||||||
|
|
||||||
Enjoy your brand new NAS, and don't forget to star this repo!
|
Enjoy your brand new NAS, and don't forget to star this repo!
|
||||||
|
|
||||||
@@ -103,7 +110,7 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
### How do I create a growable disk?
|
### How do I create a growable disk?
|
||||||
|
|
||||||
By default, the entire capacity of the disk is reserved in advance.
|
By default, the entire capacity of the disk will be reserved in advance.
|
||||||
|
|
||||||
To create a growable disk that only allocates space that is actually used, add the following environment variable:
|
To create a growable disk that only allocates space that is actually used, add the following environment variable:
|
||||||
|
|
||||||
@@ -127,20 +134,21 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
### How do I pass-through a disk?
|
### How do I pass-through a disk?
|
||||||
|
|
||||||
It is possible to pass-through a disk device directly, by adding it to your compose file in this way:
|
It is possible to pass-through a disk device directly, which can be useful when your host is a virtual machine, as it removes an extra layer and allows for easier management. For use with physical disks this method provides little advantage and is not recommended.
|
||||||
|
|
||||||
|
You can add the virtual device to your compose file like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
devices:
|
devices:
|
||||||
- /dev/disk/by-uuid/12345-12345-12345-12345-12345:/disk2
|
- /dev/disk/by-uuid/12345-12345-12345-12345-12345:/disk2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The device needs to be totally empty (without any partition table) otherwise DSM does not always format it into a volume.
|
||||||
|
|
||||||
Make sure to bind the disk via its UUID (obtainable via `lsblk -o name,uuid`) instead of its name (`/dev/sdc`), to prevent ever binding the wrong disk when the drive letters happen to change.
|
Make sure to bind the disk via its UUID (obtainable via `lsblk -o name,uuid`) instead of its name (`/dev/sdc`), to prevent ever binding the wrong disk when the drive letters happen to change.
|
||||||
|
|
||||||
> [!IMPORTANT]
|
|
||||||
> The device needs to be totally empty (without any partition table) otherwise DSM does not always format it into a volume.
|
|
||||||
|
|
||||||
> [!CAUTION]
|
> [!CAUTION]
|
||||||
> Do NOT use this feature with the goal of sharing files from the host, they will all be lost without warning when DSM creates the volume.
|
> Do NOT use this feature with the goal of sharing files from the host, they might all get lost without warning when DSM creates the volume.
|
||||||
|
|
||||||
### How do I change the amount of CPU or RAM?
|
### How do I change the amount of CPU or RAM?
|
||||||
|
|
||||||
@@ -256,7 +264,7 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
With this method, it is even possible to switch back and forth between versions while keeping your file data intact.
|
With this method, it is even possible to switch back and forth between versions while keeping your file data intact.
|
||||||
|
|
||||||
If you don't have internet access, it's also possible to skip the download by setting URL to:
|
If you don't have internet access, it's also possible to skip the download by setting `URL` to:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
12
src/disk.sh
12
src/disk.sh
@@ -141,12 +141,14 @@ createDisk() {
|
|||||||
else
|
else
|
||||||
|
|
||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! fallocate -l "$DATA_SIZE" "$DISK_FILE"; then
|
if ! fallocate -l "$DATA_SIZE" "$DISK_FILE" &>/dev/null; then
|
||||||
|
if ! fallocate -l -x "$DATA_SIZE" "$DISK_FILE"; then
|
||||||
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
|
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 77
|
error "$FAIL" && exit 77
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -219,11 +221,13 @@ resizeDisk() {
|
|||||||
else
|
else
|
||||||
|
|
||||||
# Resize file by allocating more space
|
# Resize file by allocating more space
|
||||||
if ! fallocate -l "$DATA_SIZE" "$DISK_FILE"; then
|
if ! fallocate -l "$DATA_SIZE" "$DISK_FILE" &>/dev/null; then
|
||||||
|
if ! fallocate -l -x "$DATA_SIZE" "$DISK_FILE"; then
|
||||||
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
|
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
|
||||||
error "$FAIL" && exit 75
|
error "$FAIL" && exit 75
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -296,11 +300,13 @@ convertDisk() {
|
|||||||
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
||||||
# Work around qemu-img bug
|
# Work around qemu-img bug
|
||||||
CUR_SIZE=$(stat -c%s "$TMP_FILE")
|
CUR_SIZE=$(stat -c%s "$TMP_FILE")
|
||||||
if ! fallocate -l "$CUR_SIZE" "$TMP_FILE"; then
|
if ! fallocate -l "$CUR_SIZE" "$TMP_FILE" &>/dev/null; then
|
||||||
|
if ! fallocate -l -x "$CUR_SIZE" "$TMP_FILE"; then
|
||||||
error "Failed to allocate $CUR_SIZE bytes for $DISK_DESC image $TMP_FILE"
|
error "Failed to allocate $CUR_SIZE bytes for $DISK_DESC image $TMP_FILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
rm -f "$SOURCE_FILE"
|
rm -f "$SOURCE_FILE"
|
||||||
mv "$TMP_FILE" "$DST_FILE"
|
mv "$TMP_FILE" "$DST_FILE"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
cd /run
|
cd /run
|
||||||
|
|
||||||
|
. utils.sh # Load functions
|
||||||
. reset.sh # Initialize system
|
. reset.sh # Initialize system
|
||||||
. install.sh # Run installation
|
. install.sh # Run installation
|
||||||
. disk.sh # Initialize disks
|
. disk.sh # Initialize disks
|
||||||
|
|||||||
@@ -328,11 +328,13 @@ if [[ "${FS,,}" == "btrfs" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! fallocate -l "$SYSTEM_SIZE" "$SYSTEM"; then
|
if ! fallocate -l "$SYSTEM_SIZE" "$SYSTEM" &>/dev/null; then
|
||||||
|
if ! fallocate -l -x "$SYSTEM_SIZE" "$SYSTEM"; then
|
||||||
if ! truncate -s "$SYSTEM_SIZE" "$SYSTEM"; then
|
if ! truncate -s "$SYSTEM_SIZE" "$SYSTEM"; then
|
||||||
rm -f "$SYSTEM"
|
rm -f "$SYSTEM"
|
||||||
error "Could not allocate file $SYSTEM for the system disk." && exit 98
|
error "Could not allocate file $SYSTEM for the system disk." && exit 98
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PART="$TMP/partition.fdisk"
|
PART="$TMP/partition.fdisk"
|
||||||
|
|||||||
@@ -119,6 +119,12 @@ configureDNS() {
|
|||||||
|
|
||||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||||
|
|
||||||
|
if [[ "${DEBUG_DNS:-}" == [Yy1]* ]]; then
|
||||||
|
DNSMASQ_OPTS+=" -d"
|
||||||
|
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} &
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
if ! $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}; then
|
if ! $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}; then
|
||||||
error "Failed to start dnsmasq, reason: $?" && return 1
|
error "Failed to start dnsmasq, reason: $?" && return 1
|
||||||
fi
|
fi
|
||||||
@@ -206,7 +212,7 @@ configureNAT() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! ip address add "${VM_NET_IP%.*}.1/24" broadcast "${VM_NET_IP%.*}.255" dev dockerbridge; then
|
if ! ip address add "${VM_NET_IP%.*}.1/24" broadcast "${VM_NET_IP%.*}.255" dev dockerbridge; then
|
||||||
error "Failed to add IP address!" && return 1
|
error "Failed to add IP address pool!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while ! ip link set dockerbridge up; do
|
while ! ip link set dockerbridge up; do
|
||||||
@@ -359,7 +365,13 @@ getInfo() {
|
|||||||
|
|
||||||
if [ ! -d "/sys/class/net/$VM_NET_DEV" ]; then
|
if [ ! -d "/sys/class/net/$VM_NET_DEV" ]; then
|
||||||
error "Network interface '$VM_NET_DEV' does not exist inside the container!"
|
error "Network interface '$VM_NET_DEV' does not exist inside the container!"
|
||||||
error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 27
|
error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 26
|
||||||
|
fi
|
||||||
|
|
||||||
|
BASE_IP="${VM_NET_IP%.*}."
|
||||||
|
|
||||||
|
if [ "${VM_NET_IP/$BASE_IP/}" -lt "3" ]; then
|
||||||
|
error "Invalid VM_NET_IP, must end in a higher number than .3" && exit 27
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$MTU" ]; then
|
if [ -z "$MTU" ]; then
|
||||||
@@ -398,8 +410,16 @@ getInfo() {
|
|||||||
error "Invalid MAC address: '$VM_NET_MAC', should be 12 or 17 digits long!" && exit 28
|
error "Invalid MAC address: '$VM_NET_MAC', should be 12 or 17 digits long!" && exit 28
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}')
|
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/)
|
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1)
|
||||||
|
|
||||||
|
IP6=""
|
||||||
|
# shellcheck disable=SC2143
|
||||||
|
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||||
|
IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up)
|
||||||
|
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$IP" > /run/shm/qemu.ip
|
echo "$IP" > /run/shm/qemu.ip
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -422,7 +442,10 @@ if [[ "$DEBUG" == [Yy1]* ]]; then
|
|||||||
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
|
||||||
[[ "$MTU" != "0" ]] && [[ "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
[[ "$MTU" != "0" ]] && [[ "$MTU" != "$mtu" ]] && line+=" ($MTU)"
|
||||||
info "$line"
|
info "$line"
|
||||||
[ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf
|
if [ -f /etc/resolv.conf ]; then
|
||||||
|
nameservers=$(grep '^nameserver*' /etc/resolv.conf | head -c -1 | sed 's/nameserver //g;' | sed -z 's/\n/, /g')
|
||||||
|
[ -n "$nameservers" ] && info "Nameservers: $nameservers"
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -466,7 +489,7 @@ else
|
|||||||
|
|
||||||
closeBridge
|
closeBridge
|
||||||
NETWORK="user"
|
NETWORK="user"
|
||||||
warn "falling back to usermode networking! Performance will be bad and port mapping will not work."
|
warn "falling back to user-mode networking! Performance will be bad and port mapping will not work."
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -474,7 +497,7 @@ else
|
|||||||
|
|
||||||
if [[ "${NETWORK,,}" == "user"* ]]; then
|
if [[ "${NETWORK,,}" == "user"* ]]; then
|
||||||
|
|
||||||
# Configure for usermode networking (slirp)
|
# Configure for user-mode networking (slirp)
|
||||||
configureUser || exit 24
|
configureUser || exit 24
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
152
src/reset.sh
152
src/reset.sh
@@ -1,10 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
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; }
|
|
||||||
|
|
||||||
trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
|
||||||
|
|
||||||
[ ! -f "/run/entry.sh" ] && error "Script must run inside Docker container!" && exit 11
|
[ ! -f "/run/entry.sh" ] && error "Script must run inside Docker container!" && exit 11
|
||||||
@@ -38,7 +34,7 @@ TEMPLATE="/var/www/index.html"
|
|||||||
FOOTER1="$APP for Docker v$(</run/version)"
|
FOOTER1="$APP for Docker v$(</run/version)"
|
||||||
FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
FOOTER2="<a href='$SUPPORT'>$SUPPORT</a>"
|
||||||
|
|
||||||
CPI=$(lscpu)
|
CPU=$(cpu)
|
||||||
SYS=$(uname -r)
|
SYS=$(uname -r)
|
||||||
HOST=$(hostname -s)
|
HOST=$(hostname -s)
|
||||||
KERNEL=$(echo "$SYS" | cut -b 1)
|
KERNEL=$(echo "$SYS" | cut -b 1)
|
||||||
@@ -46,34 +42,12 @@ MINOR=$(echo "$SYS" | cut -d '.' -f2)
|
|||||||
ARCH=$(dpkg --print-architecture)
|
ARCH=$(dpkg --print-architecture)
|
||||||
CORES=$(grep -c '^processor' /proc/cpuinfo)
|
CORES=$(grep -c '^processor' /proc/cpuinfo)
|
||||||
|
|
||||||
if ! grep -qi "socket(s)" <<< "$CPI"; then
|
if ! grep -qi "socket(s)" <<< "$(lscpu)"; then
|
||||||
SOCKETS=1
|
SOCKETS=1
|
||||||
else
|
else
|
||||||
SOCKETS=$(echo "$CPI" | grep -m 1 -i 'socket(s)' | awk '{print $(2)}')
|
SOCKETS=$(lscpu | grep -m 1 -i 'socket(s)' | awk '{print $(2)}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! grep -qi "model name" <<< "$CPI"; then
|
|
||||||
CPU=""
|
|
||||||
else
|
|
||||||
CPU=$(echo "$CPI" | grep -m 1 -i 'model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${CPU// /}" ] && grep -qi "model:" <<< "$CPI"; then
|
|
||||||
CPU=$(echo "$CPI" | grep -m 1 -i 'model:' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
|
|
||||||
fi
|
|
||||||
|
|
||||||
CPU="${CPU// CPU/}"
|
|
||||||
CPU="${CPU// 8 Core/}"
|
|
||||||
CPU="${CPU// 16 Core/}"
|
|
||||||
CPU="${CPU// 32 Core/}"
|
|
||||||
CPU="${CPU// 64 Core/}"
|
|
||||||
CPU="${CPU// Processor/}"
|
|
||||||
CPU="${CPU// Quad core/}"
|
|
||||||
CPU="${CPU// Core TM/ Core}"
|
|
||||||
CPU="${CPU// with Radeon Graphics/}"
|
|
||||||
CPU="${CPU// with Radeon Vega Graphics/}"
|
|
||||||
|
|
||||||
[ -z "${CPU// /}" ] && CPU="Unknown"
|
|
||||||
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
||||||
|
|
||||||
# Check system
|
# Check system
|
||||||
@@ -103,30 +77,6 @@ if [[ "${FS,,}" == "ecryptfs" ]] || [[ "${FS,,}" == "tmpfs" ]]; then
|
|||||||
DISK_CACHE="writeback"
|
DISK_CACHE="writeback"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
formatBytes() {
|
|
||||||
local result
|
|
||||||
result=$(numfmt --to=iec "$1")
|
|
||||||
local unit="${result//[0-9. ]}"
|
|
||||||
if [ -z "$unit" ]; then
|
|
||||||
unit="bytes"
|
|
||||||
else
|
|
||||||
unit=$(echo "${unit^^}" | sed 's/K/KB/g;s/M/MB/g;s/G/GB/g;s/T/TB/g')
|
|
||||||
fi
|
|
||||||
result="${result//[a-zA-Z ]/}"
|
|
||||||
if [[ "${2:-}" == "up" ]]; then
|
|
||||||
if [[ "$result" == *"."* ]]; then
|
|
||||||
result="${result%%.*}"
|
|
||||||
result=$((result+1))
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ "${2:-}" == "down" ]]; then
|
|
||||||
result="${result%%.*}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo "$result $unit"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read memory
|
# Read memory
|
||||||
RAM_SPARE=500000000
|
RAM_SPARE=500000000
|
||||||
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
||||||
@@ -174,91 +124,6 @@ rm -f /run/shm/dsm.url
|
|||||||
rm -rf /tmp/dsm
|
rm -rf /tmp/dsm
|
||||||
rm -rf "$STORAGE/tmp"
|
rm -rf "$STORAGE/tmp"
|
||||||
|
|
||||||
# Helper functions
|
|
||||||
|
|
||||||
isAlive() {
|
|
||||||
local pid="$1"
|
|
||||||
|
|
||||||
if kill -0 "$pid" 2>/dev/null; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
pKill() {
|
|
||||||
local pid="$1"
|
|
||||||
|
|
||||||
{ kill -15 "$pid" || true; } 2>/dev/null
|
|
||||||
|
|
||||||
while isAlive "$pid"; do
|
|
||||||
sleep 0.2
|
|
||||||
done
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fWait() {
|
|
||||||
local name="$1"
|
|
||||||
|
|
||||||
while pgrep -f -l "$name" >/dev/null; do
|
|
||||||
sleep 0.2
|
|
||||||
done
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fKill() {
|
|
||||||
local name="$1"
|
|
||||||
|
|
||||||
{ pkill -f "$name" || true; } 2>/dev/null
|
|
||||||
fWait "$name"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
escape () {
|
|
||||||
local s
|
|
||||||
s=${1//&/\&}
|
|
||||||
s=${s//</\<}
|
|
||||||
s=${s//>/\>}
|
|
||||||
s=${s//'"'/\"}
|
|
||||||
printf -- %s "$s"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
html()
|
|
||||||
{
|
|
||||||
local title
|
|
||||||
local body
|
|
||||||
local script
|
|
||||||
local footer
|
|
||||||
|
|
||||||
title=$(escape "$APP")
|
|
||||||
title="<title>$title</title>"
|
|
||||||
footer=$(escape "$FOOTER1")
|
|
||||||
|
|
||||||
body=$(escape "$1")
|
|
||||||
if [[ "$body" == *"..." ]]; then
|
|
||||||
body="<p class=\"loading\">${body/.../}</p>"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -n "${2:-}" ] && script="$2" || script=""
|
|
||||||
|
|
||||||
local HTML
|
|
||||||
HTML=$(<"$TEMPLATE")
|
|
||||||
HTML="${HTML/\[1\]/$title}"
|
|
||||||
HTML="${HTML/\[2\]/$script}"
|
|
||||||
HTML="${HTML/\[3\]/$body}"
|
|
||||||
HTML="${HTML/\[4\]/$footer}"
|
|
||||||
HTML="${HTML/\[5\]/$FOOTER2}"
|
|
||||||
|
|
||||||
echo "$HTML" > "$PAGE"
|
|
||||||
echo "$body" > "$INFO"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
getCountry() {
|
getCountry() {
|
||||||
local url=$1
|
local url=$1
|
||||||
local query=$2
|
local query=$2
|
||||||
@@ -319,6 +184,17 @@ addPackage() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2143
|
||||||
|
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
||||||
|
|
||||||
|
sed -i "s/listen 5000 default_server;/listen [::]:5000 default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
sed -i "s/listen [::]:5000 default_server ipv6only=off;/listen 5000 default_server;/g" /etc/nginx/sites-enabled/web.conf
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Start webserver
|
# Start webserver
|
||||||
cp -r /var/www/* /run/shm
|
cp -r /var/www/* /run/shm
|
||||||
html "Starting $APP for Docker..."
|
html "Starting $APP for Docker..."
|
||||||
|
|||||||
171
src/utils.sh
Normal file
171
src/utils.sh
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
|
formatBytes() {
|
||||||
|
local result
|
||||||
|
result=$(numfmt --to=iec --suffix=B "$1" | sed -r 's/([A-Z])/ \1/' | sed 's/ B/ bytes/g;')
|
||||||
|
local unit="${result//[0-9. ]}"
|
||||||
|
result="${result//[a-zA-Z ]/}"
|
||||||
|
if [[ "${2:-}" == "up" ]]; then
|
||||||
|
if [[ "$result" == *"."* ]]; then
|
||||||
|
result="${result%%.*}"
|
||||||
|
result=$((result+1))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ "${2:-}" == "down" ]]; then
|
||||||
|
result="${result%%.*}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "$result $unit"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
isAlive() {
|
||||||
|
local pid="$1"
|
||||||
|
|
||||||
|
if kill -0 "$pid" 2>/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
pKill() {
|
||||||
|
local pid="$1"
|
||||||
|
|
||||||
|
{ kill -15 "$pid" || true; } 2>/dev/null
|
||||||
|
|
||||||
|
while isAlive "$pid"; do
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fWait() {
|
||||||
|
local name="$1"
|
||||||
|
|
||||||
|
while pgrep -f -l "$name" >/dev/null; do
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fKill() {
|
||||||
|
local name="$1"
|
||||||
|
|
||||||
|
{ pkill -f "$name" || true; } 2>/dev/null
|
||||||
|
fWait "$name"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
escape () {
|
||||||
|
local s
|
||||||
|
s=${1//&/\&}
|
||||||
|
s=${s//</\<}
|
||||||
|
s=${s//>/\>}
|
||||||
|
s=${s//'"'/\"}
|
||||||
|
printf -- %s "$s"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
html() {
|
||||||
|
local title
|
||||||
|
local body
|
||||||
|
local script
|
||||||
|
local footer
|
||||||
|
|
||||||
|
title=$(escape "$APP")
|
||||||
|
title="<title>$title</title>"
|
||||||
|
footer=$(escape "$FOOTER1")
|
||||||
|
|
||||||
|
body=$(escape "$1")
|
||||||
|
if [[ "$body" == *"..." ]]; then
|
||||||
|
body="<p class=\"loading\">${body/.../}</p>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -n "${2:-}" ] && script="$2" || script=""
|
||||||
|
|
||||||
|
local HTML
|
||||||
|
HTML=$(<"$TEMPLATE")
|
||||||
|
HTML="${HTML/\[1\]/$title}"
|
||||||
|
HTML="${HTML/\[2\]/$script}"
|
||||||
|
HTML="${HTML/\[3\]/$body}"
|
||||||
|
HTML="${HTML/\[4\]/$footer}"
|
||||||
|
HTML="${HTML/\[5\]/$FOOTER2}"
|
||||||
|
|
||||||
|
echo "$HTML" > "$PAGE"
|
||||||
|
echo "$body" > "$INFO"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu() {
|
||||||
|
local ret
|
||||||
|
local cpu=""
|
||||||
|
|
||||||
|
ret=$(lscpu)
|
||||||
|
|
||||||
|
if grep -qi "model name" <<< "$ret"; then
|
||||||
|
cpu=$(echo "$ret" | grep -m 1 -i 'model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${cpu// /}" ] && grep -qi "model:" <<< "$ret"; then
|
||||||
|
cpu=$(echo "$ret" | grep -m 1 -i 'model:' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
|
||||||
|
fi
|
||||||
|
|
||||||
|
cpu="${cpu// CPU/}"
|
||||||
|
cpu="${cpu// 4 Core/}"
|
||||||
|
cpu="${cpu// 6 Core/}"
|
||||||
|
cpu="${cpu// 8 Core/}"
|
||||||
|
cpu="${cpu// 10 Core/}"
|
||||||
|
cpu="${cpu// 12 Core/}"
|
||||||
|
cpu="${cpu// 16 Core/}"
|
||||||
|
cpu="${cpu// 32 Core/}"
|
||||||
|
cpu="${cpu// 64 Core/}"
|
||||||
|
cpu="${cpu//7th Gen /}"
|
||||||
|
cpu="${cpu//8th Gen /}"
|
||||||
|
cpu="${cpu//9th Gen /}"
|
||||||
|
cpu="${cpu//10th Gen /}"
|
||||||
|
cpu="${cpu//11th Gen /}"
|
||||||
|
cpu="${cpu//12th Gen /}"
|
||||||
|
cpu="${cpu//13th Gen /}"
|
||||||
|
cpu="${cpu//14th Gen /}"
|
||||||
|
cpu="${cpu//15th Gen /}"
|
||||||
|
cpu="${cpu// Processor/}"
|
||||||
|
cpu="${cpu// Quad core/}"
|
||||||
|
cpu="${cpu// Dual core/}"
|
||||||
|
cpu="${cpu// Octa core/}"
|
||||||
|
cpu="${cpu// Core TM/ Core}"
|
||||||
|
cpu="${cpu// with Radeon Graphics/}"
|
||||||
|
cpu="${cpu// with Radeon Vega Graphics/}"
|
||||||
|
|
||||||
|
[ -z "${cpu// /}" ] && cpu="Unknown"
|
||||||
|
|
||||||
|
echo "$cpu"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
hasDisk() {
|
||||||
|
|
||||||
|
[ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
|
||||||
listen 5000 default_server;
|
listen 5000 default_server;
|
||||||
|
|
||||||
autoindex on;
|
autoindex on;
|
||||||
|
|||||||
Reference in New Issue
Block a user