mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4018eeadb4 | ||
|
|
a8e4647fa6 | ||
|
|
36d3fca4fc | ||
|
|
89b28f36d3 | ||
|
|
b4f7d70a7a | ||
|
|
902bafbd0c | ||
|
|
7ad5c7fa70 | ||
|
|
4d29f056b7 | ||
|
|
36af9a3483 | ||
|
|
5e6f931433 | ||
|
|
beadfe720c | ||
|
|
92b4bfc383 | ||
|
|
092ed23085 | ||
|
|
c70fa3d00a | ||
|
|
fea0ba09f6 | ||
|
|
7d2af63eac | ||
|
|
2e73bf560e | ||
|
|
bfc8d7a9c6 |
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
dsm:
|
dsm:
|
||||||
container_name: dsm
|
container_name: dsm
|
||||||
image: vdsm/virtual-dsm:latest
|
image: vdsm/virtual-dsm
|
||||||
environment:
|
environment:
|
||||||
DISK_SIZE: "16G"
|
DISK_SIZE: "16G"
|
||||||
devices:
|
devices:
|
||||||
@@ -12,5 +12,6 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 5000:5000
|
- 5000:5000
|
||||||
volumes:
|
volumes:
|
||||||
- /var/dsm:/storage
|
- ./dsm:/storage
|
||||||
|
restart: always
|
||||||
stop_grace_period: 2m
|
stop_grace_period: 2m
|
||||||
|
|||||||
@@ -10,25 +10,32 @@ spec:
|
|||||||
requests:
|
requests:
|
||||||
storage: 16Gi
|
storage: 16Gi
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: apps/v1
|
||||||
kind: Pod
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: dsm
|
name: dsm
|
||||||
labels:
|
labels:
|
||||||
name: dsm
|
name: dsm
|
||||||
spec:
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: dsm
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: dsm
|
||||||
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: dsm
|
- name: dsm
|
||||||
image: vdsm/virtual-dsm
|
image: vdsm/virtual-dsm
|
||||||
env:
|
env:
|
||||||
- name: RAM_SIZE
|
|
||||||
value: "1G"
|
|
||||||
- name: CPU_CORES
|
|
||||||
value: "1"
|
|
||||||
- name: DISK_SIZE
|
- name: DISK_SIZE
|
||||||
value: "16G"
|
value: "16G"
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 5000
|
- containerPort: 5000
|
||||||
|
name: http
|
||||||
|
protocol: TCP
|
||||||
securityContext:
|
securityContext:
|
||||||
capabilities:
|
capabilities:
|
||||||
add:
|
add:
|
||||||
@@ -59,9 +66,12 @@ kind: Service
|
|||||||
metadata:
|
metadata:
|
||||||
name: dsm
|
name: dsm
|
||||||
spec:
|
spec:
|
||||||
|
internalTrafficPolicy: Cluster
|
||||||
ports:
|
ports:
|
||||||
- name: tcp-5000
|
- name: http
|
||||||
port: 5000
|
port: 5000
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 5000
|
||||||
selector:
|
selector:
|
||||||
name: dsm
|
app: dsm
|
||||||
type: NodePort
|
type: ClusterIP
|
||||||
|
|||||||
54
readme.md
54
readme.md
@@ -39,7 +39,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 5000:5000
|
- 5000:5000
|
||||||
volumes:
|
volumes:
|
||||||
- /var/dsm:/storage
|
- ./dsm:/storage
|
||||||
restart: always
|
restart: always
|
||||||
stop_grace_period: 2m
|
stop_grace_period: 2m
|
||||||
```
|
```
|
||||||
@@ -47,7 +47,7 @@ services:
|
|||||||
Via Docker CLI:
|
Via Docker CLI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -it --rm -p 5000:5000 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN --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:
|
||||||
@@ -72,9 +72,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!
|
||||||
|
|
||||||
@@ -84,10 +86,10 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
volumes:
|
volumes:
|
||||||
- /var/dsm:/storage
|
- ./dsm:/storage
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace the example path `/var/dsm` with the desired storage folder.
|
Replace the example path `./dsm` with the desired storage folder or named volume.
|
||||||
|
|
||||||
### How do I change the size of the disk?
|
### How do I change the size of the disk?
|
||||||
|
|
||||||
@@ -103,7 +105,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:
|
||||||
|
|
||||||
@@ -112,9 +114,6 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
DISK_FMT: "qcow2"
|
DISK_FMT: "qcow2"
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
> This may reduce the write performance of the disk.
|
|
||||||
|
|
||||||
### How do I add multiple disks?
|
### How do I add multiple disks?
|
||||||
|
|
||||||
To create additional disks, modify your compose file like this:
|
To create additional disks, modify your compose file like this:
|
||||||
@@ -124,26 +123,27 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
DISK2_SIZE: "32G"
|
DISK2_SIZE: "32G"
|
||||||
DISK3_SIZE: "64G"
|
DISK3_SIZE: "64G"
|
||||||
volumes:
|
volumes:
|
||||||
- /home/example:/storage2
|
- ./example2:/storage2
|
||||||
- /mnt/data/example:/storage3
|
- ./example3:/storage3
|
||||||
```
|
```
|
||||||
|
|
||||||
### 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?
|
||||||
|
|
||||||
@@ -245,33 +245,41 @@ kubectl apply -f https://raw.githubusercontent.com/vdsm/virtual-dsm/refs/heads/m
|
|||||||
- /dev/dri
|
- /dev/dri
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!TIP]
|
> [!NOTE]
|
||||||
> This can be used to enable the facial recognition function in Synology Photos for example.
|
> This can be used to enable the facial recognition function in Synology Photos, but does not provide hardware transcoding for video.
|
||||||
|
|
||||||
### How do I install a specific version of vDSM?
|
### How do I install a specific version of vDSM?
|
||||||
|
|
||||||
By default, version 7.2 will be installed, but if you prefer an older version, you can add its download URL to your compose file as follows:
|
By default, version 7.2 will be installed, but if you prefer an older version, you can add the download URL of the `.pat` file to your compose file as follows:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
URL: "https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
URL: "https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||||
```
|
```
|
||||||
|
|
||||||
With this method, it is even possible to switch between different versions while keeping all 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:
|
||||||
URL: "DSM_VirtualDSM_42218.pat"
|
URL: "DSM_VirtualDSM_42218.pat"
|
||||||
```
|
```
|
||||||
|
|
||||||
after placing a file called `DSM_VirtualDSM_42218.pat` in your `/storage` folder.
|
after placing a copy of [DSM_VirtualDSM_42218.pat](https://global.synologydownload.com/download/DSM/release/7.0.1/42218/DSM_VirtualDSM_42218.pat) in the root of your `/storage` folder.
|
||||||
|
|
||||||
### What are the differences compared to the standard DSM?
|
### What are the differences compared to the standard DSM?
|
||||||
|
|
||||||
There are only two minor differences: the Virtual Machine Manager package is not available, and Surveillance Station will not include any free licenses.
|
There are only two minor differences: the Virtual Machine Manager package is not available, and Surveillance Station will not include any free licenses.
|
||||||
|
|
||||||
|
### How do I run Windows in a container?
|
||||||
|
|
||||||
|
You can use [dockur/windows](https://github.com/dockur/windows) for that. It shares many of the same features, and even has completely automatic installation.
|
||||||
|
|
||||||
|
### How do I run a Linux desktop in a container?
|
||||||
|
|
||||||
|
You can use [qemus/qemu](https://github.com/qemus/qemu) in that case.
|
||||||
|
|
||||||
### Is this project legal?
|
### Is this project legal?
|
||||||
|
|
||||||
Yes, this project contains only open-source code and does not distribute any copyrighted material. Neither does it try to circumvent any copyright protection measures. So under all applicable laws, this project will be considered legal.
|
Yes, this project contains only open-source code and does not distribute any copyrighted material. Neither does it try to circumvent any copyright protection measures. So under all applicable laws, this project will be considered legal.
|
||||||
|
|||||||
@@ -17,15 +17,21 @@ ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
|||||||
if [[ "$RAM_CHECK" != [Nn]* ]]; then
|
if [[ "$RAM_CHECK" != [Nn]* ]]; then
|
||||||
|
|
||||||
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
|
||||||
AVAIL_GB=$(( RAM_AVAIL/1073741824 ))
|
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
||||||
|
|
||||||
if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
||||||
error "Your configured RAM_SIZE of $WANTED_GB GB is too high for the $AVAIL_GB GB of memory available, please set a lower value."
|
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available, please set a lower value."
|
||||||
exit 17
|
[[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17
|
||||||
fi
|
info "$msg"
|
||||||
|
else
|
||||||
if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then
|
||||||
warn "your configured RAM_SIZE of $WANTED_GB GB is very close to the $AVAIL_GB GB of memory available, please consider a lower value."
|
msg="your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is very close to the $AVAIL_MEM of memory available, please consider a lower value."
|
||||||
|
if [[ "${FS,,}" != "zfs" ]]; then
|
||||||
|
warn "$msg"
|
||||||
|
else
|
||||||
|
info "$msg"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
58
src/disk.sh
58
src/disk.sh
@@ -96,7 +96,7 @@ createDisk() {
|
|||||||
local DISK_DESC=$3
|
local DISK_DESC=$3
|
||||||
local DISK_FMT=$4
|
local DISK_FMT=$4
|
||||||
local FS=$5
|
local FS=$5
|
||||||
local DATA_SIZE DIR SPACE FA
|
local DATA_SIZE DIR SPACE GB FA
|
||||||
|
|
||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
|
|
||||||
@@ -109,16 +109,16 @@ createDisk() {
|
|||||||
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||||
|
|
||||||
if (( DATA_SIZE > SPACE )); then
|
if (( DATA_SIZE > SPACE )); then
|
||||||
local SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
GB=$(formatBytes "$SPACE")
|
||||||
error "Not enough free space to create a $DISK_DESC of $DISK_SPACE in $DIR, it has only $SPACE_GB GB available..."
|
error "Not enough free space to create a $DISK_DESC of ${DISK_SPACE/G/ GB} in $DIR, it has only $GB available..."
|
||||||
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting ALLOCATE=N." && exit 76
|
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting ALLOCATE=N." && exit 76
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
html "Creating a $DISK_DESC image..."
|
html "Creating a $DISK_DESC image..."
|
||||||
info "Creating a $DISK_SPACE $DISK_STYLE $DISK_DESC image in $DISK_FMT format..."
|
info "Creating a ${DISK_SPACE/G/ GB} $DISK_STYLE $DISK_DESC image in $DISK_FMT format..."
|
||||||
|
|
||||||
local FAIL="Could not create a $DISK_STYLE $DISK_FMT $DISK_DESC image of $DISK_SPACE ($DISK_FILE)"
|
local FAIL="Could not create a $DISK_STYLE $DISK_FMT $DISK_DESC image of ${DISK_SPACE/G/ GB} ($DISK_FILE)"
|
||||||
|
|
||||||
case "${DISK_FMT,,}" in
|
case "${DISK_FMT,,}" in
|
||||||
raw)
|
raw)
|
||||||
@@ -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
|
||||||
;;
|
;;
|
||||||
@@ -180,7 +182,7 @@ resizeDisk() {
|
|||||||
local DISK_DESC=$3
|
local DISK_DESC=$3
|
||||||
local DISK_FMT=$4
|
local DISK_FMT=$4
|
||||||
local FS=$5
|
local FS=$5
|
||||||
local CUR_SIZE DATA_SIZE DIR SPACE
|
local CUR_SIZE DATA_SIZE DIR SPACE GB
|
||||||
|
|
||||||
CUR_SIZE=$(getSize "$DISK_FILE")
|
CUR_SIZE=$(getSize "$DISK_FILE")
|
||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
@@ -194,17 +196,17 @@ resizeDisk() {
|
|||||||
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||||
|
|
||||||
if (( REQ > SPACE )); then
|
if (( REQ > SPACE )); then
|
||||||
local SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
GB=$(formatBytes "$SPACE")
|
||||||
error "Not enough free space to resize $DISK_DESC to $DISK_SPACE in $DIR, it has only $SPACE_GB GB available.."
|
error "Not enough free space to resize $DISK_DESC to ${DISK_SPACE/G/ GB} in $DIR, it has only $GB available.."
|
||||||
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting ALLOCATE=N." && exit 74
|
error "Please specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation by setting ALLOCATE=N." && exit 74
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local GB=$(( (CUR_SIZE + 1073741823)/1073741824 ))
|
GB=$(formatBytes "$CUR_SIZE")
|
||||||
MSG="Resizing $DISK_DESC from ${GB}G to $DISK_SPACE..."
|
MSG="Resizing $DISK_DESC from $GB to ${DISK_SPACE/G/ GB}..."
|
||||||
info "$MSG" && html "$MSG"
|
info "$MSG" && html "$MSG"
|
||||||
|
|
||||||
local FAIL="Could not resize the $DISK_STYLE $DISK_FMT $DISK_DESC image from ${GB}G to $DISK_SPACE ($DISK_FILE)"
|
local FAIL="Could not resize the $DISK_STYLE $DISK_FMT $DISK_DESC image from ${GB} to ${DISK_SPACE/G/ GB} ($DISK_FILE)"
|
||||||
|
|
||||||
case "${DISK_FMT,,}" in
|
case "${DISK_FMT,,}" in
|
||||||
raw)
|
raw)
|
||||||
@@ -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
|
||||||
;;
|
;;
|
||||||
@@ -257,7 +261,7 @@ convertDisk() {
|
|||||||
|
|
||||||
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
||||||
|
|
||||||
local DIR CUR_SIZE SPACE
|
local DIR CUR_SIZE SPACE GB
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
DIR=$(dirname "$TMP_FILE")
|
DIR=$(dirname "$TMP_FILE")
|
||||||
@@ -265,8 +269,8 @@ convertDisk() {
|
|||||||
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
|
||||||
|
|
||||||
if (( CUR_SIZE > SPACE )); then
|
if (( CUR_SIZE > SPACE )); then
|
||||||
local SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
GB=$(formatBytes "$SPACE")
|
||||||
error "Not enough free space to convert $DISK_DESC to $DST_FMT in $DIR, it has only $SPACE_GB GB available..."
|
error "Not enough free space to convert $DISK_DESC to $DST_FMT in $DIR, it has only $GB available..."
|
||||||
error "Please free up some disk space or disable preallocation by setting ALLOCATE=N." && exit 76
|
error "Please free up some disk space or disable preallocation by setting ALLOCATE=N." && exit 76
|
||||||
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"
|
||||||
@@ -416,7 +422,7 @@ addDisk () {
|
|||||||
local DISK_FMT=$7
|
local DISK_FMT=$7
|
||||||
local DISK_IO=$8
|
local DISK_IO=$8
|
||||||
local DISK_CACHE=$9
|
local DISK_CACHE=$9
|
||||||
local DISK_EXT DIR DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE
|
local DISK_EXT DIR SPACE DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE
|
||||||
|
|
||||||
DISK_EXT=$(fmt2ext "$DISK_FMT")
|
DISK_EXT=$(fmt2ext "$DISK_FMT")
|
||||||
local DISK_FILE="$DISK_BASE.$DISK_EXT"
|
local DISK_FILE="$DISK_BASE.$DISK_EXT"
|
||||||
@@ -424,15 +430,17 @@ addDisk () {
|
|||||||
DIR=$(dirname "$DISK_FILE")
|
DIR=$(dirname "$DISK_FILE")
|
||||||
[ ! -d "$DIR" ] && return 0
|
[ ! -d "$DIR" ] && return 0
|
||||||
|
|
||||||
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
SPACE="${DISK_SPACE// /}"
|
||||||
DISK_SPACE=$(echo "${DISK_SPACE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
[ -z "$SPACE" ] && SPACE="16G"
|
||||||
[[ -z "${DISK_SPACE//[0-9]}" ]] && DISK_SPACE="${DISK_SPACE}G"
|
[ -z "${SPACE//[0-9. ]}" ] && SPACE="${SPACE}G"
|
||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
SPACE=$(echo "${SPACE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||||
|
|
||||||
if (( DATA_SIZE < 1 )); then
|
if ! numfmt --from=iec "$SPACE" &>/dev/null; then
|
||||||
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
|
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
DATA_SIZE=$(numfmt --from=iec "$SPACE")
|
||||||
|
|
||||||
if (( DATA_SIZE < 6442450944 )); then
|
if (( DATA_SIZE < 6442450944 )); then
|
||||||
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
|
error "Please increase ${DISK_DESC^^}_SIZE to at least 6 GB." && exit 73
|
||||||
fi
|
fi
|
||||||
@@ -465,12 +473,12 @@ addDisk () {
|
|||||||
CUR_SIZE=$(getSize "$DISK_FILE")
|
CUR_SIZE=$(getSize "$DISK_FILE")
|
||||||
|
|
||||||
if (( DATA_SIZE > CUR_SIZE )); then
|
if (( DATA_SIZE > CUR_SIZE )); then
|
||||||
resizeDisk "$DISK_FILE" "$DISK_SPACE" "$DISK_DESC" "$DISK_FMT" "$FS" || exit $?
|
resizeDisk "$DISK_FILE" "$SPACE" "$DISK_DESC" "$DISK_FMT" "$FS" || exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
createDisk "$DISK_FILE" "$DISK_SPACE" "$DISK_DESC" "$DISK_FMT" "$FS" || exit $?
|
createDisk "$DISK_FILE" "$SPACE" "$DISK_DESC" "$DISK_FMT" "$FS" || exit $?
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ else
|
|||||||
TMP="/tmp/dsm"
|
TMP="/tmp/dsm"
|
||||||
TMP_SPACE=2147483648
|
TMP_SPACE=2147483648
|
||||||
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
||||||
SPACE_MB=$(( (SPACE + 1048575)/1048576 ))
|
SPACE_MB=$(formatBytes "$SPACE")
|
||||||
if (( TMP_SPACE > SPACE )); then
|
if (( TMP_SPACE > SPACE )); then
|
||||||
error "Not enough free space inside the container, have $SPACE_MB MB available but need at least 2 GB." && exit 93
|
error "Not enough free space inside the container, have $SPACE_MB available but need at least 2 GB." && exit 93
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -96,13 +96,13 @@ rm -rf "$TMP" && mkdir -p "$TMP"
|
|||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
ROOT_SPACE=536870912
|
ROOT_SPACE=536870912
|
||||||
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
||||||
SPACE_MB=$(( (SPACE + 1048575)/1048576 ))
|
SPACE_MB=$(formatBytes "$SPACE" "down")
|
||||||
(( ROOT_SPACE > SPACE )) && error "Not enough free space inside the container, have $SPACE_MB MB available but need at least 500 MB." && exit 96
|
(( ROOT_SPACE > SPACE )) && error "Not enough free space inside the container, have $SPACE_MB available but need at least 500 MB." && exit 96
|
||||||
|
|
||||||
MIN_SPACE=15032385536
|
MIN_SPACE=15032385536
|
||||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
SPACE_GB=$(formatBytes "$SPACE")
|
||||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in $STORAGE, have $SPACE_GB GB available but need at least 14 GB." && exit 94
|
(( 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
|
# Check if output is to interactive TTY
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
@@ -310,10 +310,10 @@ rm -f "$SYSTEM"
|
|||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
SYSTEM_SIZE=10738466816
|
SYSTEM_SIZE=10738466816
|
||||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||||
SPACE_MB=$(( (SPACE + 1048575)/1048576 ))
|
SPACE_MB=$(formatBytes "$SPACE")
|
||||||
|
|
||||||
if (( SYSTEM_SIZE > SPACE )); then
|
if (( SYSTEM_SIZE > SPACE )); then
|
||||||
error "Not enough free space in $STORAGE to create a 10 GB system disk, have only $SPACE_MB MB available." && exit 97
|
error "Not enough free space in $STORAGE to create a 10 GB system disk, have only $SPACE_MB available." && exit 97
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! touch "$SYSTEM"; then
|
if ! touch "$SYSTEM"; then
|
||||||
@@ -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
|
||||||
@@ -199,7 +205,6 @@ configureNAT() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a bridge with a static IP for the VM guest
|
# Create a bridge with a static IP for the VM guest
|
||||||
|
|
||||||
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
@@ -207,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
|
||||||
@@ -279,6 +284,22 @@ configureNAT() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeBridge() {
|
||||||
|
|
||||||
|
local pid="/var/run/dnsmasq.pid"
|
||||||
|
[ -s "$pid" ] && pKill "$(<"$pid")"
|
||||||
|
|
||||||
|
[[ "${NETWORK,,}" == "user"* ]] && return 0
|
||||||
|
|
||||||
|
ip link set "$VM_NET_TAP" down promisc off &> null || true
|
||||||
|
ip link delete "$VM_NET_TAP" &> null || true
|
||||||
|
|
||||||
|
ip link set dockerbridge down &> null || true
|
||||||
|
ip link delete dockerbridge &> null || true
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
closeNetwork() {
|
closeNetwork() {
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
@@ -294,26 +315,16 @@ closeNetwork() {
|
|||||||
exec 30<&- || true
|
exec 30<&- || true
|
||||||
exec 40<&- || true
|
exec 40<&- || true
|
||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" != [Yy1]* ]]; then
|
||||||
|
|
||||||
|
closeBridge
|
||||||
|
return 0
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down || true
|
ip link set "$VM_NET_TAP" down || true
|
||||||
ip link delete "$VM_NET_TAP" || true
|
ip link delete "$VM_NET_TAP" || true
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
local pid="/var/run/dnsmasq.pid"
|
|
||||||
[ -s "$pid" ] && pKill "$(<"$pid")"
|
|
||||||
|
|
||||||
[[ "${NETWORK,,}" == "user"* ]] && return 0
|
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off || true
|
|
||||||
ip link delete "$VM_NET_TAP" || true
|
|
||||||
|
|
||||||
ip link set dockerbridge down || true
|
|
||||||
ip link delete dockerbridge || true
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,8 +404,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
|
||||||
@@ -459,14 +478,9 @@ else
|
|||||||
# Configure for tap interface
|
# Configure for tap interface
|
||||||
if ! configureNAT; then
|
if ! configureNAT; then
|
||||||
|
|
||||||
|
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."
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off &> null || true
|
|
||||||
ip link delete "$VM_NET_TAP" &> null || true
|
|
||||||
|
|
||||||
ip link set dockerbridge down &> null || true
|
|
||||||
ip link delete dockerbridge &> null || true
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -474,7 +488,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
|
||||||
|
|||||||
29
src/proc.sh
29
src/proc.sh
@@ -9,6 +9,23 @@ set -Eeuo pipefail
|
|||||||
: "${CPU_MODEL:=""}"
|
: "${CPU_MODEL:=""}"
|
||||||
: "${DEF_MODEL:="qemu64"}"
|
: "${DEF_MODEL:="qemu64"}"
|
||||||
|
|
||||||
|
CLOCKSOURCE="tsc"
|
||||||
|
[[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter"
|
||||||
|
CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource"
|
||||||
|
|
||||||
|
if [ ! -f "$CLOCK" ]; then
|
||||||
|
warn "file \"$CLOCK\" cannot not found?"
|
||||||
|
else
|
||||||
|
result=$(<"$CLOCK")
|
||||||
|
case "${result,,}" in
|
||||||
|
"${CLOCKSOURCE,,}" ) ;;
|
||||||
|
"kvm-clock" ) info "Nested KVM virtualization detected.." ;;
|
||||||
|
"hyperv_clocksource_tsc_page" ) info "Nested Hyper-V virtualization detected.." ;;
|
||||||
|
"hpet" ) warn "unsupported clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE'" ;;
|
||||||
|
*) warn "unexpected clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE'" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${ARCH,,}" != "amd64" ]]; then
|
if [[ "${ARCH,,}" != "amd64" ]]; then
|
||||||
KVM="N"
|
KVM="N"
|
||||||
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, this will cause a major loss of performance."
|
warn "your CPU architecture is ${ARCH^^} and cannot provide KVM acceleration for x64 instructions, this will cause a major loss of performance."
|
||||||
@@ -47,7 +64,6 @@ fi
|
|||||||
if [[ "$KVM" != [Nn]* ]]; then
|
if [[ "$KVM" != [Nn]* ]]; then
|
||||||
|
|
||||||
CPU_FEATURES="kvm=on,l3-cache=on,+hypervisor"
|
CPU_FEATURES="kvm=on,l3-cache=on,+hypervisor"
|
||||||
CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource"
|
|
||||||
KVM_OPTS=",accel=kvm -enable-kvm -global kvm-pit.lost_tick_policy=discard"
|
KVM_OPTS=",accel=kvm -enable-kvm -global kvm-pit.lost_tick_policy=discard"
|
||||||
|
|
||||||
if ! grep -qw "sse4_2" <<< "$flags"; then
|
if ! grep -qw "sse4_2" <<< "$flags"; then
|
||||||
@@ -61,15 +77,6 @@ if [[ "$KVM" != [Nn]* ]]; then
|
|||||||
CPU_FEATURES+=",migratable=no"
|
CPU_FEATURES+=",migratable=no"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$CLOCK" ]; then
|
|
||||||
CLOCK=$(<"$CLOCK")
|
|
||||||
if [[ "${CLOCK,,}" != "tsc" ]]; then
|
|
||||||
warn "unexpected clocksource: $CLOCK"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "file \"$CLOCK\" cannot not found?"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if grep -qw "svm" <<< "$flags"; then
|
if grep -qw "svm" <<< "$flags"; then
|
||||||
|
|
||||||
# AMD processor
|
# AMD processor
|
||||||
@@ -127,7 +134,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$HOST_CPU" ]; then
|
if [ -z "$HOST_CPU" ]; then
|
||||||
HOST_CPU=$(lscpu | grep -m 1 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g')
|
[[ "${CPU,,}" != "unknown" ]] && HOST_CPU="$CPU"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$HOST_CPU" ]; then
|
if [ -n "$HOST_CPU" ]; then
|
||||||
|
|||||||
91
src/reset.sh
91
src/reset.sh
@@ -17,7 +17,6 @@ echo "❯ For support visit $SUPPORT"
|
|||||||
|
|
||||||
: "${TZ:=""}" # System local timezone
|
: "${TZ:=""}" # System local timezone
|
||||||
: "${DEBUG:="N"}" # Disable debugging mode
|
: "${DEBUG:="N"}" # Disable debugging mode
|
||||||
: "${COMMIT:="N"}" # Commit to local image
|
|
||||||
: "${COUNTRY:=""}" # Country code for mirror
|
: "${COUNTRY:=""}" # Country code for mirror
|
||||||
: "${CONSOLE:="N"}" # Disable console mode
|
: "${CONSOLE:="N"}" # Disable console mode
|
||||||
: "${ALLOCATE:=""}" # Preallocate diskspace
|
: "${ALLOCATE:=""}" # Preallocate diskspace
|
||||||
@@ -64,10 +63,17 @@ if [ -z "${CPU// /}" ] && grep -qi "model:" <<< "$CPI"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
CPU="${CPU// CPU/}"
|
CPU="${CPU// CPU/}"
|
||||||
|
CPU="${CPU// 6 Core/}"
|
||||||
CPU="${CPU// 8 Core/}"
|
CPU="${CPU// 8 Core/}"
|
||||||
CPU="${CPU// 16 Core/}"
|
CPU="${CPU// 16 Core/}"
|
||||||
CPU="${CPU// 32 Core/}"
|
CPU="${CPU// 32 Core/}"
|
||||||
CPU="${CPU// 64 Core/}"
|
CPU="${CPU// 64 Core/}"
|
||||||
|
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// Processor/}"
|
||||||
CPU="${CPU// Quad core/}"
|
CPU="${CPU// Quad core/}"
|
||||||
CPU="${CPU// Core TM/ Core}"
|
CPU="${CPU// Core TM/ Core}"
|
||||||
@@ -75,6 +81,7 @@ CPU="${CPU// with Radeon Graphics/}"
|
|||||||
CPU="${CPU// with Radeon Vega Graphics/}"
|
CPU="${CPU// with Radeon Vega Graphics/}"
|
||||||
|
|
||||||
[ -z "${CPU// /}" ] && CPU="Unknown"
|
[ -z "${CPU// /}" ] && CPU="Unknown"
|
||||||
|
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
||||||
|
|
||||||
# Check system
|
# Check system
|
||||||
|
|
||||||
@@ -86,13 +93,13 @@ fi
|
|||||||
|
|
||||||
# Check folder
|
# Check folder
|
||||||
|
|
||||||
if [[ "$COMMIT" != [Nn]* ]]; then
|
if [[ "${COMMIT:-}" == [Yy1]* ]]; then
|
||||||
STORAGE="/local"
|
STORAGE="/local"
|
||||||
mkdir -p "$STORAGE"
|
mkdir -p "$STORAGE"
|
||||||
else
|
fi
|
||||||
if [ ! -d "$STORAGE" ]; then
|
|
||||||
|
if [ ! -d "$STORAGE" ]; then
|
||||||
error "Storage folder ($STORAGE) not found!" && exit 13
|
error "Storage folder ($STORAGE) not found!" && exit 13
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check filesystem
|
# Check filesystem
|
||||||
@@ -103,15 +110,46 @@ 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}')
|
||||||
RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
|
RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
|
||||||
|
|
||||||
|
RAM_SIZE="${RAM_SIZE// /}"
|
||||||
|
[ -z "$RAM_SIZE" ] && error "RAM_SIZE not specified!" && exit 16
|
||||||
|
|
||||||
|
if [ -z "${RAM_SIZE//[0-9. ]}" ]; then
|
||||||
|
[ "${RAM_SIZE%%.*}" -lt "130" ] && RAM_SIZE="${RAM_SIZE}G" || RAM_SIZE="${RAM_SIZE}M"
|
||||||
|
fi
|
||||||
|
|
||||||
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
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
|
||||||
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
|
||||||
AVAIL_GB=$(( RAM_AVAIL/1073741824 ))
|
[ "$RAM_WANTED" -lt "136314880 " ] && error "RAM_SIZE is too low: $RAM_SIZE" && exit 16
|
||||||
TOTAL_GB=$(( (RAM_TOTAL + 1073741823)/1073741824 ))
|
|
||||||
WANTED_GB=$(( (RAM_WANTED + 1073741823)/1073741824 ))
|
|
||||||
|
|
||||||
# Print system info
|
# Print system info
|
||||||
SYS="${SYS/-generic/}"
|
SYS="${SYS/-generic/}"
|
||||||
@@ -119,18 +157,20 @@ FS="${FS/UNKNOWN //}"
|
|||||||
FS="${FS/ext2\/ext3/ext4}"
|
FS="${FS/ext2\/ext3/ext4}"
|
||||||
FS=$(echo "$FS" | sed 's/[)(]//g')
|
FS=$(echo "$FS" | sed 's/[)(]//g')
|
||||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
SPACE_GB=$(formatBytes "$SPACE" "down")
|
||||||
|
AVAIL_MEM=$(formatBytes "$RAM_AVAIL" "down")
|
||||||
|
TOTAL_MEM=$(formatBytes "$RAM_TOTAL" "up")
|
||||||
|
|
||||||
echo "❯ CPU: ${CPU} | RAM: $AVAIL_GB/$TOTAL_GB GB | DISK: $SPACE_GB GB (${FS}) | KERNEL: ${SYS}..."
|
echo "❯ CPU: ${CPU} | RAM: ${AVAIL_MEM/ GB/}/$TOTAL_MEM | DISK: $SPACE_GB (${FS}) | KERNEL: ${SYS}..."
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Check memory
|
# Check available memory
|
||||||
|
|
||||||
if [[ "$RAM_CHECK" != [Nn]* ]]; then
|
if [[ "$RAM_CHECK" != [Nn]* ]] && (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
||||||
if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then
|
AVAIL_MEM=$(formatBytes "$RAM_AVAIL")
|
||||||
error "Your configured RAM_SIZE of $WANTED_GB GB is too high for the $AVAIL_GB GB of memory available, please set a lower value."
|
msg="Your configured RAM_SIZE of ${RAM_SIZE/G/ GB} is too high for the $AVAIL_MEM of memory available, please set a lower value."
|
||||||
exit 17
|
[[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17
|
||||||
fi
|
info "$msg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup files
|
# Cleanup files
|
||||||
@@ -144,7 +184,7 @@ rm -rf "$STORAGE/tmp"
|
|||||||
# Helper functions
|
# Helper functions
|
||||||
|
|
||||||
isAlive() {
|
isAlive() {
|
||||||
local pid=$1
|
local pid="$1"
|
||||||
|
|
||||||
if kill -0 "$pid" 2>/dev/null; then
|
if kill -0 "$pid" 2>/dev/null; then
|
||||||
return 0
|
return 0
|
||||||
@@ -154,7 +194,7 @@ isAlive() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pKill() {
|
pKill() {
|
||||||
local pid=$1
|
local pid="$1"
|
||||||
|
|
||||||
{ kill -15 "$pid" || true; } 2>/dev/null
|
{ kill -15 "$pid" || true; } 2>/dev/null
|
||||||
|
|
||||||
@@ -166,7 +206,7 @@ pKill() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fWait() {
|
fWait() {
|
||||||
local name=$1
|
local name="$1"
|
||||||
|
|
||||||
while pgrep -f -l "$name" >/dev/null; do
|
while pgrep -f -l "$name" >/dev/null; do
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
@@ -176,7 +216,7 @@ fWait() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fKill() {
|
fKill() {
|
||||||
local name=$1
|
local name="$1"
|
||||||
|
|
||||||
{ pkill -f "$name" || true; } 2>/dev/null
|
{ pkill -f "$name" || true; } 2>/dev/null
|
||||||
fWait "$name"
|
fWait "$name"
|
||||||
@@ -286,6 +326,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..."
|
||||||
|
|||||||
@@ -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