From e9e343bd6a67f544e2795dd3846e28c14d57e15a Mon Sep 17 00:00:00 2001 From: fithwum Date: Fri, 4 Jul 2025 06:54:39 -0700 Subject: [PATCH] update and test script --- base-image-script/alpine-image_pt1.sh | 36 +++++++++++++++ base-image-script/alpine-image_pt2.sh | 15 +++++++ base-image-script/alpine-image_pt3.sh | 28 ++++++++++++ base-image-script/debian-bookworm_pt1.sh | 4 +- base-image-script/debian-bullseye_pt1.sh | 4 +- base-image-script/debian-buster_pt1.sh | 4 +- base-image-script/debian-docker-build_pt1.sh | 4 +- base-image-script/debian-test_pt1.sh | 46 ++++++++++++++++++++ base-image-script/debian-test_pt2.sh | 18 ++++++++ base-image-script/debian-test_pt3.sh | 31 +++++++++++++ 10 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 base-image-script/alpine-image_pt1.sh create mode 100644 base-image-script/alpine-image_pt2.sh create mode 100644 base-image-script/alpine-image_pt3.sh create mode 100644 base-image-script/debian-test_pt1.sh create mode 100644 base-image-script/debian-test_pt2.sh create mode 100644 base-image-script/debian-test_pt3.sh diff --git a/base-image-script/alpine-image_pt1.sh b/base-image-script/alpine-image_pt1.sh new file mode 100644 index 0000000..d94f7e5 --- /dev/null +++ b/base-image-script/alpine-image_pt1.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +# Alpine version +ALPINE_VERSION="v3.20" +ROOTFS_DIR="alpine-rootfs" +OUTPUT_TAR="alpine-base.tar.gz" +PACKAGES="bash curl ca-certificates nano" + +echo "[INFO] Downloading alpine-make-rootfs if needed..." +if [ ! -f ./alpine-make-rootfs ]; then + wget https://raw.githubusercontent.com/alpinelinux/alpine-make-rootfs/master/alpine-make-rootfs + chmod +x alpine-make-rootfs +fi + +echo "[INFO] Creating Alpine rootfs with selected packages..." +sudo ./alpine-make-rootfs \ + --branch "$ALPINE_VERSION" \ + --mirror http://dl-cdn.alpinelinux.org/alpine \ + --packages "$PACKAGES" \ + "$ROOTFS_DIR" + +echo "[INFO] Binding system directories for chroot..." +sudo mount --bind /dev "$ROOTFS_DIR/dev" +sudo mount --bind /proc "$ROOTFS_DIR/proc" +sudo mount --bind /sys "$ROOTFS_DIR/sys" + +echo "[INFO] Copying part 2 script into chroot..." +sudo cp alpine-base_pt2.sh "$ROOTFS_DIR/alpine-base_pt2.sh" +sudo chmod +x "$ROOTFS_DIR/alpine-base_pt2.sh" + +echo "[INFO] Entering chroot. Run 'exit' when done." +sudo chroot "$ROOTFS_DIR" /alpine-base_pt2.sh + +echo "[INFO] Continuing with packaging after chroot..." +bash alpine-base_pt3.sh "$ROOTFS_DIR" "$OUTPUT_TAR" diff --git a/base-image-script/alpine-image_pt2.sh b/base-image-script/alpine-image_pt2.sh new file mode 100644 index 0000000..6b41be9 --- /dev/null +++ b/base-image-script/alpine-image_pt2.sh @@ -0,0 +1,15 @@ +#!/bin/sh +echo "[CHROOT] Inside Alpine rootfs" + +echo "[CHROOT] Updating system..." +apk update +apk upgrade + +echo "[CHROOT] Optional cleanup of packages" +# apk del some-unneeded-package + +echo "[CHROOT] Cleaning apk cache..." +rm -rf /var/cache/apk/* + +echo "[CHROOT] Done. Type 'exit' to return to host script." +exit diff --git a/base-image-script/alpine-image_pt3.sh b/base-image-script/alpine-image_pt3.sh new file mode 100644 index 0000000..746c23e --- /dev/null +++ b/base-image-script/alpine-image_pt3.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +ROOTFS_DIR="$1" +OUTPUT_TAR="$2" + +echo "[INFO] Unmounting system dirs..." +sudo umount -lf "$ROOTFS_DIR/dev" +sudo umount -lf "$ROOTFS_DIR/proc" +sudo umount -lf "$ROOTFS_DIR/sys" + +echo "[INFO] Cleaning up chroot script..." +sudo rm -f "$ROOTFS_DIR/alpine-base_pt2.sh" + +echo "[INFO] Creating tarball: $OUTPUT_TAR" +sudo tar -czf "$OUTPUT_TAR" -C "$ROOTFS_DIR" . + +echo "[INFO] Image size:" +du -sh "$OUTPUT_TAR" + +# OPTIONAL FTP upload + echo "[INFO] Uploading via FTP..." + ftp-upload -v -h -u --password -d /path "$OUTPUT_TAR" + +echo "[INFO] Cleaning up rootfs directory..." +sudo rm -rf "$ROOTFS_DIR" + +echo "[INFO] Done." diff --git a/base-image-script/debian-bookworm_pt1.sh b/base-image-script/debian-bookworm_pt1.sh index 92bcd8d..53defb6 100644 --- a/base-image-script/debian-bookworm_pt1.sh +++ b/base-image-script/debian-bookworm_pt1.sh @@ -12,7 +12,7 @@ if [ -e /debian-bookworm_pt2.sh ] else echo " " echo "WARNING ! debian-bookworm_pt2.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-bookworm_pt2.sh -O /debian-bookworm_pt2.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-bookworm_pt2.sh -O /debian-bookworm_pt2.sh chmod +x debian-bookworm_pt2.sh fi if [ -e /debian-bookworm_pt3.sh ] @@ -21,7 +21,7 @@ if [ -e /debian-bookworm_pt3.sh ] else echo " " echo "WARNING ! debian-bookworm_pt3.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-bookworm_pt3.sh -O /debian-bookworm_pt3.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-bookworm_pt3.sh -O /debian-bookworm_pt3.sh chmod +x debian-bookworm_pt3.sh fi sleep 1 diff --git a/base-image-script/debian-bullseye_pt1.sh b/base-image-script/debian-bullseye_pt1.sh index 5d1159b..a2b6d15 100644 --- a/base-image-script/debian-bullseye_pt1.sh +++ b/base-image-script/debian-bullseye_pt1.sh @@ -12,7 +12,7 @@ if [ -e /debian-bullseye_pt2.sh ] else echo " " echo "WARNING ! debian-bullseye_pt2.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-bullseye_pt2.sh -O /debian-bullseye_pt2.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-bullseye_pt2.sh -O /debian-bullseye_pt2.sh chmod +x debian-bullseye_pt2.sh fi if [ -e /debian-bullseye_pt3.sh ] @@ -21,7 +21,7 @@ if [ -e /debian-bullseye_pt3.sh ] else echo " " echo "WARNING ! debian-bullseye_pt3.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-bullseye_pt3.sh -O /debian-bullseye_pt3.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-bullseye_pt3.sh -O /debian-bullseye_pt3.sh chmod +x debian-bullseye_pt3.sh fi sleep 1 diff --git a/base-image-script/debian-buster_pt1.sh b/base-image-script/debian-buster_pt1.sh index 248ae40..8f88614 100644 --- a/base-image-script/debian-buster_pt1.sh +++ b/base-image-script/debian-buster_pt1.sh @@ -12,7 +12,7 @@ if [ -e /debian-buster_pt2.sh ] else echo " " echo "WARNING ! debian-buster_pt2.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-buster_pt2.sh -O /debian-buster_pt2.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-buster_pt2.sh -O /debian-buster_pt2.sh chmod +x debian-buster_pt2.sh fi if [ -e /debian-buster_pt3.sh ] @@ -21,7 +21,7 @@ if [ -e /debian-buster_pt3.sh ] else echo " " echo "WARNING ! debian-buster_pt3.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-buster_pt3.sh -O /debian-buster_pt3.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-buster_pt3.sh -O /debian-buster_pt3.sh chmod +x debian-buster_pt3.sh fi sleep 1 diff --git a/base-image-script/debian-docker-build_pt1.sh b/base-image-script/debian-docker-build_pt1.sh index 964e801..270dd56 100644 --- a/base-image-script/debian-docker-build_pt1.sh +++ b/base-image-script/debian-docker-build_pt1.sh @@ -12,7 +12,7 @@ if [ -e /debian-docker-build_pt2.sh ] else echo " " echo "WARNING ! debian-docker-build_pt2.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-docker-build_pt2.sh -O /debian-docker-build_pt2.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-docker-build_pt2.sh -O /debian-docker-build_pt2.sh chmod +x debian-docker-build_pt2.sh fi if [ -e /debian-docker-build_pt3.sh ] @@ -21,7 +21,7 @@ if [ -e /debian-docker-build_pt3.sh ] else echo " " echo "WARNING ! debian-docker-build_pt3.sh not found ... will download new copy." - wget --no-cache https://raw.githubusercontent.com/fithwum/base-image/refs/heads/main/build-script/debian-docker-build_pt3.sh -O /debian-docker-build_pt3.sh + wget --no-cache https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script/debian-docker-build_pt3.sh -O /debian-docker-build_pt3.sh chmod +x debian-docker-build_pt3.sh fi sleep 1 diff --git a/base-image-script/debian-test_pt1.sh b/base-image-script/debian-test_pt1.sh new file mode 100644 index 0000000..18e080e --- /dev/null +++ b/base-image-script/debian-test_pt1.sh @@ -0,0 +1,46 @@ +#!/bin/bash +set -e +set -o pipefail + +DEBIAN_RELEASE="bookworm" +ROOTFS_DIR="debian-${DEBIAN_RELEASE}" +SCRIPTS_URL="https://raw.githubusercontent.com/fithwum/files-for-dockers/refs/heads/master/base-image-script" +PT2_SCRIPT="debian-base_pt2.sh" +PT3_SCRIPT="debian-base_pt3.sh" + +echo "[INFO] Preparing environment..." +apt-get update -y +apt-get upgrade -y +apt-get install -y debootstrap bash curl wget ftp-upload dirmngr + +echo "[INFO] Downloading extra scripts if missing..." +for SCRIPT in $PT2_SCRIPT $PT3_SCRIPT; do + if [ ! -f "./$SCRIPT" ]; then + echo "[INFO] Downloading $SCRIPT..." + wget --no-cache "$SCRIPTS_URL/$SCRIPT" -O "./$SCRIPT" + chmod +x "./$SCRIPT" + fi +done + +echo "[INFO] Bootstrapping Debian $DEBIAN_RELEASE..." +debootstrap \ + --variant=minbase \ + --components=main,contrib,non-free \ + --include=ca-certificates,software-properties-common,bash,wget,curl,nano \ + --arch=amd64 \ + "$DEBIAN_RELEASE" "$ROOTFS_DIR" http://deb.debian.org/debian/ + +echo "[INFO] Mounting system directories..." +for dir in dev dev/pts proc sys; do + mount --bind /$dir "$ROOTFS_DIR/$dir" +done + +echo "[INFO] Copying pt2 script into chroot..." +cp "./$PT2_SCRIPT" "$ROOTFS_DIR/root/$PT2_SCRIPT" +chmod +x "$ROOTFS_DIR/root/$PT2_SCRIPT" + +echo "[INFO] Entering chroot. Type 'exit' when done." +chroot "$ROOTFS_DIR" /root/$PT2_SCRIPT + +echo "[INFO] Running pt3 for packaging and upload..." +./$PT3_SCRIPT "$ROOTFS_DIR" diff --git a/base-image-script/debian-test_pt2.sh b/base-image-script/debian-test_pt2.sh new file mode 100644 index 0000000..e3ad7b4 --- /dev/null +++ b/base-image-script/debian-test_pt2.sh @@ -0,0 +1,18 @@ +#!/bin/bash +echo "[CHROOT] Configuring Debian system..." + +echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/10-assume_yes + +apt-get update +apt-get upgrade + +echo "[CHROOT] Removing unnecessary packages..." +apt-get remove --purge --allow-remove-essential pinentry-curses whiptail kmod iptables iproute2 dmidecode || true + +echo "[CHROOT] Cleaning up..." +apt-get clean +apt-get install -f +find /var/lib/apt/lists/ -type f -delete + +echo "[CHROOT] Done. Type 'exit' to return." +exit diff --git a/base-image-script/debian-test_pt3.sh b/base-image-script/debian-test_pt3.sh new file mode 100644 index 0000000..6014555 --- /dev/null +++ b/base-image-script/debian-test_pt3.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +ROOTFS_DIR="${1:-debian-bookworm}" +TARBALL="${ROOTFS_DIR}.tar.bz2" + +echo "[INFO] Unmounting system directories..." +for dir in sys proc dev/pts dev; do + umount -lf "$ROOTFS_DIR/$dir" +done + +echo "[INFO] Removing chroot script..." +rm -f "$ROOTFS_DIR/root/debian-base_pt2.sh" + +echo "[INFO] Showing rootfs size..." +du -sh "$ROOTFS_DIR" + +echo "[INFO] Creating compressed base image..." +tar -cjf "$TARBALL" -C "$ROOTFS_DIR" . + +echo "[INFO] Image archive size:" +du -sh "$TARBALL" + +# Optional: Upload via FTP +# ftp-upload -v -h "$HOST" -u "$USER" --password "$PASS" -d /target/dir "$TARBALL" + +echo "[INFO] Cleaning up..." +rm -rf "$ROOTFS_DIR" +rm -f "$TARBALL" + +echo "[INFO] Done."