added new flag

This commit is contained in:
crt 2024-06-29 11:11:54 +02:00
parent bdc051c53f
commit 838c13545f
4 changed files with 22 additions and 30 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Default parameter file
DEFAULT_PARAM_FILE="settings.conf"
DEFAULT_PARAM_FILE="params.conf"
# Function to load parameters from a file
load_params() {
@ -42,12 +42,12 @@ while [[ "$#" -gt 0 ]]; do
--storage) STORAGE="$2"; shift ;;
--disk-size) DISK_SIZE="$2"; shift ;;
--mount-point) MOUNT_POINT="$2"; shift ;;
--privileged) PRIVILEGED="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# Load parameters from the parameter file if specified, otherwise use default
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
load_params "$PARAM_FILE"
@ -68,11 +68,9 @@ SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
MIN_ID=${MIN_ID:-200}
STORAGE=${STORAGE:-local-btrfs}
DISK_SIZE=${DISK_SIZE:-8}
ROOTFS="${STORAGE}:${DISK_SIZE}"
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
MOUNT_POINT=${MOUNT_POINT:-}
PRIVILEGED=${PRIVILEGED:-0}
ROOTFS="${STORAGE}:${DISK_SIZE}"
# Check if the script file exists
if [ ! -f "$SCRIPT" ]; then
@ -87,20 +85,19 @@ if pct status $CTID &>/dev/null; then
fi
# Create the container with the correct storage format
if ! pct create $CTID $TEMPLATE --rootfs $ROOTFS --cores $CORES --memory $RAM --swap $SWAP --net0 name=eth0,bridge=$BRIDGE,ip=$IP --hostname $HOSTNAME; then
if ! pct create $CTID $TEMPLATE --rootfs $ROOTFS --cores $CORES --memory $RAM --swap $SWAP --net0 name=eth0,bridge=$BRIDGE,ip=$IP --hostname $HOSTNAME --unprivileged $PRIVILEGED; then
echo "Failed to create the container."
exit 1
fi
# Set the mount point if specified
if [ -n "$MOUNT_POINT" ]; then
if ! pct set $CTID -mp0 $MOUNT_POINT; then
if ! pct set $CTID -mp0 $MOUNT_POINT,backup=1; then
echo "Failed to set the mount point."
exit 1
fi
fi
# Start the container
if ! pct start $CTID; then
echo "Failed to start the container."
@ -128,4 +125,3 @@ if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
fi
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"

View File

@ -1,4 +1,3 @@
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
# Set your Baseimage here
@ -29,7 +28,7 @@ EXPORT_NAME=mycontainer_backup
EXPORT_PATH=
# Leave this empty to use the current directory
SCRIPT=
SCRIPT=install_nginx.sh
# Leave this empty to use script.sh in the current directory
MIN_ID=200
@ -41,6 +40,8 @@ STORAGE=local-btrfs
DISK_SIZE=8
# Set the default disk size for the container
SCRIPT=
# Specify your script file here or leave empty to use script.sh in the current directory
MOUNT_POINT=local-lvm:8,mp=/data,size=8G
# Specify your mount point here
PRIVILEGED=0
# Set to 1 for privileged container, 0 for unprivileged

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Default parameter file
DEFAULT_PARAM_FILE="settings.conf"
DEFAULT_PARAM_FILE="params.conf"
# Function to load parameters from a file
load_params() {
@ -42,12 +42,12 @@ while [[ "$#" -gt 0 ]]; do
--storage) STORAGE="$2"; shift ;;
--disk-size) DISK_SIZE="$2"; shift ;;
--mount-point) MOUNT_POINT="$2"; shift ;;
--privileged) PRIVILEGED="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# Load parameters from the parameter file if specified, otherwise use default
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
load_params "$PARAM_FILE"
@ -68,11 +68,9 @@ SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
MIN_ID=${MIN_ID:-200}
STORAGE=${STORAGE:-local-btrfs}
DISK_SIZE=${DISK_SIZE:-8}
ROOTFS="${STORAGE}:${DISK_SIZE}"
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
MOUNT_POINT=${MOUNT_POINT:-}
PRIVILEGED=${PRIVILEGED:-0}
ROOTFS="${STORAGE}:${DISK_SIZE}"
# Check if the script file exists
if [ ! -f "$SCRIPT" ]; then
@ -87,20 +85,19 @@ if pct status $CTID &>/dev/null; then
fi
# Create the container with the correct storage format
if ! pct create $CTID $TEMPLATE --rootfs $ROOTFS --cores $CORES --memory $RAM --swap $SWAP --net0 name=eth0,bridge=$BRIDGE,ip=$IP --hostname $HOSTNAME; then
if ! pct create $CTID $TEMPLATE --rootfs $ROOTFS --cores $CORES --memory $RAM --swap $SWAP --net0 name=eth0,bridge=$BRIDGE,ip=$IP --hostname $HOSTNAME --unprivileged $PRIVILEGED; then
echo "Failed to create the container."
exit 1
fi
# Set the mount point if specified
if [ -n "$MOUNT_POINT" ]; then
if ! pct set $CTID -mp0 $MOUNT_POINT; then
if ! pct set $CTID -mp0 $MOUNT_POINT,backup=1; then
echo "Failed to set the mount point."
exit 1
fi
fi
# Start the container
if ! pct start $CTID; then
echo "Failed to start the container."
@ -128,4 +125,3 @@ if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
fi
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"

View File

@ -1,4 +1,3 @@
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
# Set your Baseimage here
@ -29,7 +28,7 @@ EXPORT_NAME=mycontainer_backup
EXPORT_PATH=
# Leave this empty to use the current directory
SCRIPT=
SCRIPT=install_nginx.sh
# Leave this empty to use script.sh in the current directory
MIN_ID=200
@ -41,8 +40,8 @@ STORAGE=local-btrfs
DISK_SIZE=8
# Set the default disk size for the container
SCRIPT=
# Specify your script file here or leave empty to use script.sh in the current directory
MOUNT_POINT=
MOUNT_POINT=local-lvm:8,mp=/data,size=8G
# Specify your mount point here
PRIVILEGED=0
# Set to 1 for privileged container, 0 for unprivileged