Add Podman container and virsh VM options to wrapper scripts
Some checks failed
Build ostree Backports / Build ostree Backport for noble (push) Waiting to run
Build libostree Backport / Build libostree Backport (push) Has been cancelled

- Add --podman option for isolated container testing (recommended)
- Add --vm option for full VM isolation with virsh
- Add --help option with comprehensive usage information
- Add colored output and safety warnings
- Add interactive prompts for direct host execution
- Update usage-guide.sh with new safety features
- Add proper error handling and command validation

Features:
- Podman containers with Ubuntu 24.04 and Debian 12 images
- virsh VMs with proper networking and storage
- Automatic repository cloning and script setup
- Volume mounting for workspace sharing
- Safety-first approach with clear warnings
This commit is contained in:
robojerk 2025-08-05 10:22:50 -07:00
parent 38e017cef3
commit 1b307bcd17
3 changed files with 362 additions and 18 deletions

View file

@ -2,11 +2,179 @@
# Wrapper script for Ubuntu Noble ostree backport
# This script calls the main backport script with noble as the target
# Options: --podman, --vm, --help
echo "=== Ubuntu Noble (24.04 LTS) ostree Backport ==="
echo "Source: Ubuntu Questing"
echo "Target: Ubuntu Noble"
echo ""
set -e
# Call the main backport script with noble as the target
./ostree-backport.sh noble
# Default values
USE_PODMAN=false
USE_VM=false
VM_NAME="ostree-noble-test"
CONTAINER_NAME="ostree-noble-backport"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to show usage
show_usage() {
echo -e "${BLUE}=== Ubuntu Noble (24.04 LTS) ostree Backport ===${NC}"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --podman Run in Podman container (recommended for testing)"
echo " --vm Run in virsh VM (requires KVM/libvirt)"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run directly on host (not recommended)"
echo " $0 --podman # Run in isolated Podman container"
echo " $0 --vm # Run in isolated VM"
echo ""
echo "Safety:"
echo " - Podman containers are isolated and safe"
echo " - VMs provide full isolation but require more resources"
echo " - Direct host execution may affect your system"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to create and run Podman container
run_in_podman() {
echo -e "${BLUE}=== Setting up Podman container for Ubuntu Noble backport ===${NC}"
if ! command_exists podman; then
echo -e "${RED}Error: Podman is not installed. Please install podman first.${NC}"
exit 1
fi
echo "Creating Ubuntu Noble container..."
# Create container with necessary privileges
podman run --rm -it \
--name "$CONTAINER_NAME" \
--privileged \
--security-opt label=disable \
-v /opt:/opt:shared \
-v "$(pwd):/workspace:Z" \
-w /workspace \
ubuntu:24.04 \
bash -c "
echo '=== Setting up container environment ==='
apt update -y
apt install -y git curl wget
git clone https://git.raines.xyz/robojerk/libostree-dev.git /tmp/libostree-dev
cp -r /tmp/libostree-dev/* /workspace/
cp -r /tmp/libostree-dev/.* /workspace/ 2>/dev/null || true
chmod +x /workspace/*.sh
echo '=== Container ready, running backport ==='
cd /workspace
./ostree-backport.sh noble
"
}
# Function to create and run VM
run_in_vm() {
echo -e "${BLUE}=== Setting up VM for Ubuntu Noble backport ===${NC}"
if ! command_exists virsh; then
echo -e "${RED}Error: virsh is not installed. Please install libvirt-clients first.${NC}"
exit 1
fi
if ! command_exists virt-install; then
echo -e "${RED}Error: virt-install is not installed. Please install virt-install first.${NC}"
exit 1
fi
echo "Creating Ubuntu Noble VM..."
# Check if VM already exists
if virsh list --all --name | grep -q "$VM_NAME"; then
echo -e "${YELLOW}VM $VM_NAME already exists. Starting it...${NC}"
virsh start "$VM_NAME"
virsh console "$VM_NAME"
else
echo "Creating new VM: $VM_NAME"
# Create VM with Ubuntu Noble
virt-install \
--name "$VM_NAME" \
--memory 4096 \
--vcpus 2 \
--disk size=20 \
--network default \
--os-variant ubuntu24.04 \
--location http://archive.ubuntu.com/ubuntu/dists/noble/main/installer-amd64/ \
--extra-args "console=ttyS0,115200n8 serial" \
--graphics none \
--noautoconsole
echo -e "${GREEN}VM created successfully. You can connect to it with:${NC}"
echo "virsh console $VM_NAME"
echo ""
echo "Once connected, run:"
echo "git clone https://git.raines.xyz/robojerk/libostree-dev.git"
echo "cd libostree-dev"
echo "./backport-noble.sh"
fi
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--podman)
USE_PODMAN=true
shift
;;
--vm)
USE_VM=true
shift
;;
--help|-h)
show_usage
exit 0
;;
*)
echo -e "${RED}Error: Unknown option $1${NC}"
show_usage
exit 1
;;
esac
done
# Check for conflicting options
if [ "$USE_PODMAN" = true ] && [ "$USE_VM" = true ]; then
echo -e "${RED}Error: Cannot use both --podman and --vm options${NC}"
exit 1
fi
# Main execution logic
if [ "$USE_PODMAN" = true ]; then
run_in_podman
elif [ "$USE_VM" = true ]; then
run_in_vm
else
echo -e "${YELLOW}=== Ubuntu Noble (24.04 LTS) ostree Backport ===${NC}"
echo "Source: Ubuntu Questing"
echo "Target: Ubuntu Noble"
echo ""
echo -e "${YELLOW}Warning: Running directly on host. Consider using --podman or --vm for safety.${NC}"
echo ""
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted. Use --podman or --vm for safe testing."
exit 0
fi
# Call the main backport script with noble as the target
./ostree-backport.sh noble
fi

View file

@ -2,11 +2,179 @@
# Wrapper script for Debian Trixie ostree backport
# This script calls the main backport script with trixie as the target
# Options: --podman, --vm, --help
echo "=== Debian Trixie (12) ostree Backport ==="
echo "Source: Debian sid"
echo "Target: Debian Trixie"
echo ""
set -e
# Call the main backport script with trixie as the target
./ostree-backport.sh trixie
# Default values
USE_PODMAN=false
USE_VM=false
VM_NAME="ostree-trixie-test"
CONTAINER_NAME="ostree-trixie-backport"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to show usage
show_usage() {
echo -e "${BLUE}=== Debian Trixie (12) ostree Backport ===${NC}"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --podman Run in Podman container (recommended for testing)"
echo " --vm Run in virsh VM (requires KVM/libvirt)"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run directly on host (not recommended)"
echo " $0 --podman # Run in isolated Podman container"
echo " $0 --vm # Run in isolated VM"
echo ""
echo "Safety:"
echo " - Podman containers are isolated and safe"
echo " - VMs provide full isolation but require more resources"
echo " - Direct host execution may affect your system"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to create and run Podman container
run_in_podman() {
echo -e "${BLUE}=== Setting up Podman container for Debian Trixie backport ===${NC}"
if ! command_exists podman; then
echo -e "${RED}Error: Podman is not installed. Please install podman first.${NC}"
exit 1
fi
echo "Creating Debian Trixie container..."
# Create container with necessary privileges
podman run --rm -it \
--name "$CONTAINER_NAME" \
--privileged \
--security-opt label=disable \
-v /opt:/opt:shared \
-v "$(pwd):/workspace:Z" \
-w /workspace \
debian:12 \
bash -c "
echo '=== Setting up container environment ==='
apt update -y
apt install -y git curl wget
git clone https://git.raines.xyz/robojerk/libostree-dev.git /tmp/libostree-dev
cp -r /tmp/libostree-dev/* /workspace/
cp -r /tmp/libostree-dev/.* /workspace/ 2>/dev/null || true
chmod +x /workspace/*.sh
echo '=== Container ready, running backport ==='
cd /workspace
./ostree-backport.sh trixie
"
}
# Function to create and run VM
run_in_vm() {
echo -e "${BLUE}=== Setting up VM for Debian Trixie backport ===${NC}"
if ! command_exists virsh; then
echo -e "${RED}Error: virsh is not installed. Please install libvirt-clients first.${NC}"
exit 1
fi
if ! command_exists virt-install; then
echo -e "${RED}Error: virt-install is not installed. Please install virt-install first.${NC}"
exit 1
fi
echo "Creating Debian Trixie VM..."
# Check if VM already exists
if virsh list --all --name | grep -q "$VM_NAME"; then
echo -e "${YELLOW}VM $VM_NAME already exists. Starting it...${NC}"
virsh start "$VM_NAME"
virsh console "$VM_NAME"
else
echo "Creating new VM: $VM_NAME"
# Create VM with Debian Trixie
virt-install \
--name "$VM_NAME" \
--memory 4096 \
--vcpus 2 \
--disk size=20 \
--network default \
--os-variant debian12 \
--location http://deb.debian.org/debian/dists/bookworm/main/installer-amd64/ \
--extra-args "console=ttyS0,115200n8 serial" \
--graphics none \
--noautoconsole
echo -e "${GREEN}VM created successfully. You can connect to it with:${NC}"
echo "virsh console $VM_NAME"
echo ""
echo "Once connected, run:"
echo "git clone https://git.raines.xyz/robojerk/libostree-dev.git"
echo "cd libostree-dev"
echo "./backport-trixie.sh"
fi
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--podman)
USE_PODMAN=true
shift
;;
--vm)
USE_VM=true
shift
;;
--help|-h)
show_usage
exit 0
;;
*)
echo -e "${RED}Error: Unknown option $1${NC}"
show_usage
exit 1
;;
esac
done
# Check for conflicting options
if [ "$USE_PODMAN" = true ] && [ "$USE_VM" = true ]; then
echo -e "${RED}Error: Cannot use both --podman and --vm options${NC}"
exit 1
fi
# Main execution logic
if [ "$USE_PODMAN" = true ]; then
run_in_podman
elif [ "$USE_VM" = true ]; then
run_in_vm
else
echo -e "${YELLOW}=== Debian Trixie (12) ostree Backport ===${NC}"
echo "Source: Debian sid"
echo "Target: Debian Trixie"
echo ""
echo -e "${YELLOW}Warning: Running directly on host. Consider using --podman or --vm for safety.${NC}"
echo ""
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted. Use --podman or --vm for safe testing."
exit 0
fi
# Call the main backport script with trixie as the target
./ostree-backport.sh trixie
fi

View file

@ -20,14 +20,16 @@ echo ""
echo "🚀 Quick Start Examples:"
echo ""
echo "For Ubuntu Noble:"
echo " ./backport-noble.sh"
echo " # or"
echo " ./ostree-backport.sh noble"
echo " ./backport-noble.sh --podman # Safe: Run in Podman container"
echo " ./backport-noble.sh --vm # Safe: Run in VM"
echo " ./backport-noble.sh # Direct: Run on host (not recommended)"
echo " ./ostree-backport.sh noble # Direct: Main script"
echo ""
echo "For Debian Trixie:"
echo " ./backport-trixie.sh"
echo " # or"
echo " ./ostree-backport.sh trixie"
echo " ./backport-trixie.sh --podman # Safe: Run in Podman container"
echo " ./backport-trixie.sh --vm # Safe: Run in VM"
echo " ./backport-trixie.sh # Direct: Run on host (not recommended)"
echo " ./ostree-backport.sh trixie # Direct: Main script"
echo ""
echo "🔧 What Each Script Does:"
@ -37,6 +39,12 @@ echo " 3. Installs build dependencies"
echo " 4. Builds all ostree packages"
echo " 5. Installs the backported packages"
echo ""
echo "🛡️ Safety Features:"
echo " • --podman: Run in isolated Podman container (recommended)"
echo " • --vm: Run in isolated VM with virsh (full isolation)"
echo " • --help: Show usage information and safety warnings"
echo " • Interactive prompts for direct host execution"
echo ""
echo "⚠️ Safety Notes:"
echo " • Test in a VM first"