added new flag
This commit is contained in:
parent
bdc051c53f
commit
838c13545f
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Default parameter file
|
# Default parameter file
|
||||||
DEFAULT_PARAM_FILE="settings.conf"
|
DEFAULT_PARAM_FILE="params.conf"
|
||||||
|
|
||||||
# Function to load parameters from a file
|
# Function to load parameters from a file
|
||||||
load_params() {
|
load_params() {
|
||||||
|
@ -42,12 +42,12 @@ while [[ "$#" -gt 0 ]]; do
|
||||||
--storage) STORAGE="$2"; shift ;;
|
--storage) STORAGE="$2"; shift ;;
|
||||||
--disk-size) DISK_SIZE="$2"; shift ;;
|
--disk-size) DISK_SIZE="$2"; shift ;;
|
||||||
--mount-point) MOUNT_POINT="$2"; shift ;;
|
--mount-point) MOUNT_POINT="$2"; shift ;;
|
||||||
|
--privileged) PRIVILEGED="$2"; shift ;;
|
||||||
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# Load parameters from the parameter file if specified, otherwise use default
|
# Load parameters from the parameter file if specified, otherwise use default
|
||||||
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
|
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
|
||||||
load_params "$PARAM_FILE"
|
load_params "$PARAM_FILE"
|
||||||
|
@ -68,11 +68,9 @@ SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
||||||
MIN_ID=${MIN_ID:-200}
|
MIN_ID=${MIN_ID:-200}
|
||||||
STORAGE=${STORAGE:-local-btrfs}
|
STORAGE=${STORAGE:-local-btrfs}
|
||||||
DISK_SIZE=${DISK_SIZE:-8}
|
DISK_SIZE=${DISK_SIZE:-8}
|
||||||
ROOTFS="${STORAGE}:${DISK_SIZE}"
|
|
||||||
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
|
||||||
MOUNT_POINT=${MOUNT_POINT:-}
|
MOUNT_POINT=${MOUNT_POINT:-}
|
||||||
|
PRIVILEGED=${PRIVILEGED:-0}
|
||||||
|
ROOTFS="${STORAGE}:${DISK_SIZE}"
|
||||||
|
|
||||||
# Check if the script file exists
|
# Check if the script file exists
|
||||||
if [ ! -f "$SCRIPT" ]; then
|
if [ ! -f "$SCRIPT" ]; then
|
||||||
|
@ -87,20 +85,19 @@ if pct status $CTID &>/dev/null; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the container with the correct storage format
|
# 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."
|
echo "Failed to create the container."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set the mount point if specified
|
# Set the mount point if specified
|
||||||
if [ -n "$MOUNT_POINT" ]; then
|
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."
|
echo "Failed to set the mount point."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Start the container
|
# Start the container
|
||||||
if ! pct start $CTID; then
|
if ! pct start $CTID; then
|
||||||
echo "Failed to start the container."
|
echo "Failed to start the container."
|
||||||
|
@ -128,4 +125,3 @@ if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"
|
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
|
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
|
||||||
# Set your Baseimage here
|
# Set your Baseimage here
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ EXPORT_NAME=mycontainer_backup
|
||||||
EXPORT_PATH=
|
EXPORT_PATH=
|
||||||
# Leave this empty to use the current directory
|
# Leave this empty to use the current directory
|
||||||
|
|
||||||
SCRIPT=
|
SCRIPT=install_nginx.sh
|
||||||
# Leave this empty to use script.sh in the current directory
|
# Leave this empty to use script.sh in the current directory
|
||||||
|
|
||||||
MIN_ID=200
|
MIN_ID=200
|
||||||
|
@ -41,6 +40,8 @@ STORAGE=local-btrfs
|
||||||
DISK_SIZE=8
|
DISK_SIZE=8
|
||||||
# Set the default disk size for the container
|
# Set the default disk size for the container
|
||||||
|
|
||||||
SCRIPT=
|
MOUNT_POINT=local-lvm:8,mp=/data,size=8G
|
||||||
# Specify your script file here or leave empty to use script.sh in the current directory
|
# Specify your mount point here
|
||||||
|
|
||||||
|
PRIVILEGED=0
|
||||||
|
# Set to 1 for privileged container, 0 for unprivileged
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Default parameter file
|
# Default parameter file
|
||||||
DEFAULT_PARAM_FILE="settings.conf"
|
DEFAULT_PARAM_FILE="params.conf"
|
||||||
|
|
||||||
# Function to load parameters from a file
|
# Function to load parameters from a file
|
||||||
load_params() {
|
load_params() {
|
||||||
|
@ -42,12 +42,12 @@ while [[ "$#" -gt 0 ]]; do
|
||||||
--storage) STORAGE="$2"; shift ;;
|
--storage) STORAGE="$2"; shift ;;
|
||||||
--disk-size) DISK_SIZE="$2"; shift ;;
|
--disk-size) DISK_SIZE="$2"; shift ;;
|
||||||
--mount-point) MOUNT_POINT="$2"; shift ;;
|
--mount-point) MOUNT_POINT="$2"; shift ;;
|
||||||
|
--privileged) PRIVILEGED="$2"; shift ;;
|
||||||
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# Load parameters from the parameter file if specified, otherwise use default
|
# Load parameters from the parameter file if specified, otherwise use default
|
||||||
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
|
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
|
||||||
load_params "$PARAM_FILE"
|
load_params "$PARAM_FILE"
|
||||||
|
@ -68,11 +68,9 @@ SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
||||||
MIN_ID=${MIN_ID:-200}
|
MIN_ID=${MIN_ID:-200}
|
||||||
STORAGE=${STORAGE:-local-btrfs}
|
STORAGE=${STORAGE:-local-btrfs}
|
||||||
DISK_SIZE=${DISK_SIZE:-8}
|
DISK_SIZE=${DISK_SIZE:-8}
|
||||||
ROOTFS="${STORAGE}:${DISK_SIZE}"
|
|
||||||
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
|
||||||
MOUNT_POINT=${MOUNT_POINT:-}
|
MOUNT_POINT=${MOUNT_POINT:-}
|
||||||
|
PRIVILEGED=${PRIVILEGED:-0}
|
||||||
|
ROOTFS="${STORAGE}:${DISK_SIZE}"
|
||||||
|
|
||||||
# Check if the script file exists
|
# Check if the script file exists
|
||||||
if [ ! -f "$SCRIPT" ]; then
|
if [ ! -f "$SCRIPT" ]; then
|
||||||
|
@ -87,20 +85,19 @@ if pct status $CTID &>/dev/null; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the container with the correct storage format
|
# 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."
|
echo "Failed to create the container."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set the mount point if specified
|
# Set the mount point if specified
|
||||||
if [ -n "$MOUNT_POINT" ]; then
|
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."
|
echo "Failed to set the mount point."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Start the container
|
# Start the container
|
||||||
if ! pct start $CTID; then
|
if ! pct start $CTID; then
|
||||||
echo "Failed to start the container."
|
echo "Failed to start the container."
|
||||||
|
@ -128,4 +125,3 @@ if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"
|
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
|
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
|
||||||
# Set your Baseimage here
|
# Set your Baseimage here
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ EXPORT_NAME=mycontainer_backup
|
||||||
EXPORT_PATH=
|
EXPORT_PATH=
|
||||||
# Leave this empty to use the current directory
|
# Leave this empty to use the current directory
|
||||||
|
|
||||||
SCRIPT=
|
SCRIPT=install_nginx.sh
|
||||||
# Leave this empty to use script.sh in the current directory
|
# Leave this empty to use script.sh in the current directory
|
||||||
|
|
||||||
MIN_ID=200
|
MIN_ID=200
|
||||||
|
@ -41,8 +40,8 @@ STORAGE=local-btrfs
|
||||||
DISK_SIZE=8
|
DISK_SIZE=8
|
||||||
# Set the default disk size for the container
|
# Set the default disk size for the container
|
||||||
|
|
||||||
SCRIPT=
|
MOUNT_POINT=local-lvm:8,mp=/data,size=8G
|
||||||
# Specify your script file here or leave empty to use script.sh in the current directory
|
|
||||||
|
|
||||||
MOUNT_POINT=
|
|
||||||
# Specify your mount point here
|
# Specify your mount point here
|
||||||
|
|
||||||
|
PRIVILEGED=0
|
||||||
|
# Set to 1 for privileged container, 0 for unprivileged
|
||||||
|
|
Loading…
Reference in New Issue