build-alpine/archive/build.sh.workskinda

52 lines
1.5 KiB
Bash

#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Define variables
WORK_DIR="/root/build-alpine"
OUTPUT_DIR="$WORK_DIR/output"
SCRIPT_NAME="alpine-make-vm-image"
SCRIPT_URL="https://raw.githubusercontent.com/alpinelinux/alpine-make-vm-image/v0.13.0/$SCRIPT_NAME"
SCRIPT_SHA1="0fe2deca927bc91eb8ab32584574eee72a23d033"
ALPINE_IMAGE_NAME="alpine-custom.qcow2"
SETUP_SCRIPT="vm-setup.sh"
CHROOT_PATH="/mnt" # Path where the root filesystem is mounted in chroot
CHROOT_SCRIPT_PATH="$CHROOT_PATH/$SETUP_SCRIPT"
# Create working and output directories
mkdir -p "$OUTPUT_DIR"
cd "$WORK_DIR"
# Install necessary dependencies
sudo apt-get update
sudo apt-get install -y qemu-utils qemu-system-x86 rsync util-linux e2fsprogs dosfstools
# Download the alpine-make-vm-image script
wget "$SCRIPT_URL" -O "$SCRIPT_NAME"
# Verify the script SHA1 hash
echo "$SCRIPT_SHA1 $SCRIPT_NAME" | sha1sum -c || exit 1
# Make the alpine-make-vm-image script executable
chmod +x "$SCRIPT_NAME"
# Ensure vm-setup.sh is executable
chmod +x "$SETUP_SCRIPT"
# Run the alpine-make-vm-image script to create the VM image
./"$SCRIPT_NAME" \
-f qcow2 \
-s 2G \
-a x86_64 \
-B BIOS \
-b latest-stable \
-p "openssh-server htop curl nano zsh" \
-S "$WORK_DIR" \
--fs-skel-chown root:root \
--script-chroot \
"$OUTPUT_DIR/$ALPINE_IMAGE_NAME" \
"$SETUP_SCRIPT" # Removed chroot path, the script will be copied and executed directly
echo "Alpine Linux VM image created at: $OUTPUT_DIR/$ALPINE_IMAGE_NAME"