grocery-bot

Log | Files | Refs | README

commit 8b9dacf40bd9c308825c0ded648a3c0dfdd3543e
parent a77bb19d9b7f7eefd295d5f652285abd0843a5d2
Author: Chris Roberts <chris.roberts@learningunix.net>
Date:   Thu,  9 Jul 2026 10:06:00 -0500

added script for building lxc to run in

Diffstat:
Aprovision-lxc.sh | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+), 0 deletions(-)

diff --git a/provision-lxc.sh b/provision-lxc.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Provisions the Debian 12 LXC container Anton will run in. Run as root on +# the Proxmox host itself (not inside any container). This only creates and +# starts the container -- it does NOT install the bot. Once this finishes, +# copy this repo into the container and run install.sh there (see +# anton-bot.service's header comment for the full sequence). +# +# Usage: +# ./provision-lxc.sh +# +# Override defaults via env vars if needed, e.g.: +# ANTON_LXC_STORAGE=local-zfs ANTON_LXC_BRIDGE=vmbr1 ./provision-lxc.sh + +CTID="${ANTON_LXC_CTID:-$(pvesh get /cluster/nextid)}" +HOSTNAME="${ANTON_LXC_HOSTNAME:-anton}" +STORAGE="${ANTON_LXC_STORAGE:-local-lvm}" +TEMPLATE_STORAGE="${ANTON_LXC_TEMPLATE_STORAGE:-local}" +BRIDGE="${ANTON_LXC_BRIDGE:-vmbr0}" +IP_CONFIG="${ANTON_LXC_IP:-dhcp}" +DISK_GB="${ANTON_LXC_DISK_GB:-8}" +MEMORY_MB="${ANTON_LXC_MEMORY_MB:-512}" +CORES="${ANTON_LXC_CORES:-1}" +SSH_PUBKEY_FILE="${ANTON_LXC_SSH_PUBKEY_FILE:-}" + +if [[ $EUID -ne 0 ]]; then + echo "Run this as root on the Proxmox host: sudo $0" >&2 + exit 1 +fi + +if ! command -v pct &>/dev/null; then + echo "pct not found -- this must be run on a Proxmox host, not inside a container." >&2 + exit 1 +fi + +echo "==> Storage pool '${STORAGE}' and bridge '${BRIDGE}' are assumed to exist on this host." +echo " If either is wrong, check 'pvesm status' / the Proxmox network config and re-run" +echo " with ANTON_LXC_STORAGE / ANTON_LXC_BRIDGE overridden." + +echo "==> Finding the current debian-12-standard template" +pveam update >/dev/null +TEMPLATE="$(pveam available --section system | awk '/debian-12-standard/ {print $2}' | sort -V | tail -1)" +if [[ -z "$TEMPLATE" ]]; then + echo "No debian-12-standard template found in the appliance list." >&2 + exit 1 +fi + +if ! pveam list "$TEMPLATE_STORAGE" 2>/dev/null | grep -q "$TEMPLATE"; then + echo "==> Downloading ${TEMPLATE} to storage '${TEMPLATE_STORAGE}'" + pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" +else + echo "==> ${TEMPLATE} already present on '${TEMPLATE_STORAGE}'" +fi + +CREATE_ARGS=( + "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" + --hostname "$HOSTNAME" + --memory "$MEMORY_MB" + --cores "$CORES" + --rootfs "${STORAGE}:${DISK_GB}" + --net0 "name=eth0,bridge=${BRIDGE},ip=${IP_CONFIG}" + --unprivileged 1 + --onboot 1 +) + +if [[ -n "$SSH_PUBKEY_FILE" ]]; then + echo "==> Using SSH key from ${SSH_PUBKEY_FILE} for root login (no password set)" + CREATE_ARGS+=(--ssh-public-keys "$SSH_PUBKEY_FILE") +else + # Generated rather than left interactive so this script stays non-interactive + # end to end. Change it after first login. + ROOT_PASSWORD="$(openssl rand -base64 18)" + CREATE_ARGS+=(--password "$ROOT_PASSWORD") +fi + +echo "==> Creating container ${CTID} (${HOSTNAME})" +pct create "${CREATE_ARGS[@]}" + +echo "==> Starting container ${CTID}" +pct start "$CTID" + +echo "==> Container ${CTID} (${HOSTNAME}) is up." +echo " Enter it with: pct enter ${CTID}" +if [[ -z "$SSH_PUBKEY_FILE" ]]; then + echo " Generated root password: ${ROOT_PASSWORD}" + echo " Change it immediately after first login (passwd)." +fi +echo +echo " Next: copy this repo into the container and run install.sh there" +echo " (see the setup steps at the top of anton-bot.service)."