ricketsiallpox

createContainer.sh

Aug 28th, 2025
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.12 KB | None | 0 0
  1. #!/bin/bash -aeux
  2.  
  3. # createContainer.sh - Script to create a proxmox lxc container
  4.  
  5. VMID="${1:-1000}"
  6. CNAME="${2:-testreposerver}"
  7. TMPL="/var/lib/vz/template/cache/oracle_8_x86_64_20250827.tar.xz"
  8. PUBKEY="/root/.ssh/id_rsa.pub"
  9.  
  10. function cleanup {
  11.     echo "Removing $CLIST"
  12.     rm -f "$CLIST"
  13. }
  14.  
  15. trap cleanup EXIT
  16.  
  17. if ! test -f "${TMPL}"; then
  18.     echo "Template ${TMPL} not found"
  19.     exit 1
  20. fi
  21.  
  22. if ! test -f "${PUBKEY}"; then
  23.     echo "Public key ${PUBKEY} not found"
  24.     exit 1
  25. fi
  26.  
  27. CLIST=$(mktemp)
  28. if ! pct list > "$CLIST" 2> /dev/null; then
  29.     echo "Failed to get container list"
  30.     exit 1
  31. fi
  32. if grep -w "${VMID}" "$CLIST" ; then
  33.     echo "VMID ${VMID} already exists"
  34.     exit 1
  35. elif grep -w "${CNAME}" "$CLIST" ; then
  36.     echo "Container already exists with name ${CNAME}"
  37.     exit 1
  38. fi
  39.  
  40. pct create "${VMID}" "${TMPL}" \
  41. --ostype centos \
  42. --hostname "${CNAME}" \
  43. --cores 2 \
  44. --memory 512 \
  45. --swap 512 \
  46. --rootfs local-lvm:8 \
  47. --net0 name=eth0,bridge=vmbr0,ip=dhcp \
  48. --password Debbie_Loves_Ian_1993 \
  49. --unprivileged 0 \
  50. --onboot 1 \
  51. --start 0 \
  52. --features mount=nfs \
  53. --timezone host \
  54. --ssh-public-keys "${PUBKEY}" \
  55.  
Advertisement
Add Comment
Please, Sign In to add comment