92 lines
1.9 KiB
Bash
Executable File
92 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "$SCRIPT_DIR/libsupabase.sh"
|
|
setup_traps
|
|
|
|
########################################
|
|
# Defaults
|
|
########################################
|
|
|
|
cores=2
|
|
memory=4096
|
|
swap=512
|
|
disk=50
|
|
bridge="vmbr0"
|
|
storage="local-zfs"
|
|
ip="dhcp"
|
|
unpriv=1
|
|
ctid=""
|
|
|
|
########################################
|
|
# Args
|
|
########################################
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--cores) cores="$2"; shift 2 ;;
|
|
--memory) memory="$2"; shift 2 ;;
|
|
--swap) swap="$2"; shift 2 ;;
|
|
--disk) disk="$2"; shift 2 ;;
|
|
--bridge) bridge="$2"; shift 2 ;;
|
|
--storage) storage="$2"; shift 2 ;;
|
|
--ip) ip="$2"; shift 2 ;;
|
|
--ctid) ctid="$2"; shift 2 ;;
|
|
--help)
|
|
echo "Usage: bash install.sh [options]"
|
|
exit 0
|
|
;;
|
|
*)
|
|
die "Unknown argument: $1"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
info "Argument-Parsing OK"
|
|
|
|
########################################
|
|
# Checks
|
|
########################################
|
|
|
|
need_cmd pct pvesm pveam pvesh awk grep sort
|
|
|
|
pve_bridge_exists "$bridge" || die "Bridge $bridge not found"
|
|
pve_storage_exists "$storage" || die "Storage $storage not found"
|
|
|
|
template="$(pve_template_ensure_debian12 "$storage")"
|
|
info "Template OK: $template"
|
|
|
|
if [[ -z "$ctid" ]]; then
|
|
ctid="$(pve_next_free_ctid)"
|
|
fi
|
|
|
|
[[ -n "$ctid" ]] || die "CTID empty"
|
|
|
|
hostname="sb-$(date +%s)"
|
|
|
|
info "Using CTID=$ctid Hostname=$hostname"
|
|
|
|
########################################
|
|
# Create CT
|
|
########################################
|
|
|
|
net0="$(pve_build_net0 "$bridge" "$ip")"
|
|
rootfs="$storage:$disk"
|
|
features="nesting=1,keyctl=1,fuse=1"
|
|
|
|
info "Creating CT $ctid"
|
|
|
|
pct create "$ctid" "$template" \
|
|
--hostname "$hostname" \
|
|
--cores "$cores" \
|
|
--memory "$memory" \
|
|
--swap "$swap" \
|
|
--net0 "$net0" \
|
|
--rootfs "$rootfs" \
|
|
--unprivileged "$unpriv" \
|
|
--features "$features" \
|
|
--start 0
|
|
|
|
info "CT created successfully"
|