From 98b1f563c1e1a7faa28c464e56220e3adbc0c5d5 Mon Sep 17 00:00:00 2001 From: Lightemerald Date: Mon, 19 Jun 2023 13:47:33 +0200 Subject: [PATCH] Support fedora 38, fix for debian and arch, added a script to easily make a lxc on proxmox. --- create-lxc.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup-linux.sh | 16 +++++++++----- 2 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 create-lxc.sh diff --git a/create-lxc.sh b/create-lxc.sh new file mode 100644 index 0000000..0fdf20f --- /dev/null +++ b/create-lxc.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -e + +CTID="" +CONTAINER_NAME="" +DISTRO="" +ROOTPASS="" + +while getopts ":c:n:d:p:" flag; do + case "${flag}" in + c) + CTID="${OPTARG}" + ;; + n) + CONTAINER_NAME="${OPTARG}" + ;; + d) + DISTRO="${OPTARG}" + ;; + p) + ROOTPASS="${OPTARG}" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +if [[ -z $CTID || -z $CONTAINER_NAME || -z $DISTRO || -z $ROOTPASS ]]; then + echo "CTID, CONTAINER_NAME, DISTRO, ROOTPASS arguments are required." + echo "Usage: ./create-lxc.sh -c -n -d -p " + exit 1 +fi + +template=$(pveam available | grep $DISTRO | sort -rV | head -n 1 | awk '{print $2}') + +if [[ -z $template ]]; then + echo "$DISTRO template not found." + exit 1 +fi + +template=$(pveam list local | grep $template | awk '{print $1}') +if [[ -z $template ]]; then + echo "$DISTRO template not found. Downloading..." + pveam download local $template +fi + +pct create $CTID $template --hostname $CONTAINER_NAME --memory 1024 --storage local-lvm --net0 name=eth0,bridge=vmbr0,firewall=1,ip=dhcp --unprivileged --ostype $DISTRO --password="$ROOTPASS" +echo -e "lxc.cgroup.devices.allow: c 10:200 rwm\nlxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file" >> /etc/pve/lxc/$CTID.conf +pct start $CTID +pct status $CTID | grep "status: running" || sleep 10 +echo lxc now running \ No newline at end of file diff --git a/setup-linux.sh b/setup-linux.sh index 040e3dd..5cec1c8 100644 --- a/setup-linux.sh +++ b/setup-linux.sh @@ -3,19 +3,25 @@ set -e update_package_manager() { if command -v apt-get &>/dev/null; then + echo "Detected APT package manager." if command -v sudo &>/dev/null; then echo "sudo is installed." else su -c "apt-get update && apt-get install sudo -y" fi - echo "Detected APT package manager." sudo apt-get update && sudo apt-get upgrade -y elif command -v dnf &>/dev/null; then echo "Detected DNF package manager." sudo dnf update -y elif command -v pacman &>/dev/null; then echo "Detected Pacman package manager." - sudo pacman-key --init && sudo pacman-key --populate && sudo pacman -Syu --noconfirm + if command -v sudo &>/dev/null; then + echo "sudo is installed." + sudo pacman-key --init && sudo pacman-key --populate && sudo pacman -Syu --noconfirm + else + su -c "pacman-key --init && pacman-key --populate && pacman -Syu --noconfirm && pacman -Sy sudo --noconfirm" + fi + else echo "Unable to detect the package manager." exit 1 @@ -24,11 +30,11 @@ update_package_manager() { install_requirements() { if command -v apt-get &>/dev/null; then - sudo apt install chromium chromium-driver network-manager network-manager-openvpn openvpn python3 python3-pip python3-tk xvfb git wget unzip nano -y + sudo apt install chromium chromium-driver network-manager network-manager-openvpn openvpn python3 python3-pip python3-tk xvfb git wget curl unzip nano -y elif command -v dnf &>/dev/null; then - sudo dnf install chromium chromium-driver NetworkManager NetworkManager-openvpn openvpn python python*-pip python*-tkinter xorg-x11-server-Xvfb git wget unzip nano -y + sudo dnf install chromium chrom*driver NetworkManager NetworkManager-openvpn openvpn python python*-pip python*-tkinter xorg-x11-server-Xvfb git wget unzip nano -y elif command -v pacman &>/dev/null; then - sudo pacman -Sy chromium networkmanager networkmanager-openvpn openvpn python python-pip xorg-server-xvfb git wget unzip nano base-devel --noconfirm + sudo pacman -Sy chromium networkmanager networkmanager-openvpn openvpn python python-pip xorg-server-xvfb git curl wget unzip nano base-devel --noconfirm fi }