Skip to content

Commit

Permalink
working docker image for extracting ubuntu iso kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
estenrye committed Sep 20, 2023
1 parent 1270e5a commit a3b7f44
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docker/estenrye/ubuntu-pxe-image-mirror/Dockerfile
@@ -0,0 +1,12 @@
FROM debian:stable-slim
RUN apt update \
&& apt install -y \
p7zip-full \
rsync \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

VOLUME /tftp
COPY scripts /scripts

ENTRYPOINT ["bash", "/scripts/ubuntu.sh"]
@@ -0,0 +1,2 @@
#!/bin/sh
echo "Current date and time is " "$(date +%D-%H:%M)"
30 changes: 30 additions & 0 deletions docker/estenrye/ubuntu-pxe-image-mirror/scripts/extract.ubuntu.sh
@@ -0,0 +1,30 @@
#!/bin/bash

fatal() {
echo "$1"
exit 1
}

warn() {
echo "$1"
}

LIVE_KERNEL_ROOT='/tftp/live/ubuntu/live-server-amd64'
IMAGE_ROOT='/tftp/images/ubuntu'
VERSION_PATTERN='[0-9][0-9]\.[0-9][0-9]$'
ISO_PATTERN='live-server-amd64\.iso$'

for ISOFILE in `ls ${IMAGE_ROOT} | grep ${VERSION_PATTERN} | xargs -I% find ${IMAGE_ROOT}/%/ -print | grep ${ISO_PATTERN}`
do
VERSION=`basename $(dirname $ISOFILE)`

echo "Creating directory ${LIVE_KERNEL_ROOT}/${VERSION}"
mkdir -p "${LIVE_KERNEL_ROOT}/${VERSION}"
rm -f ${LIVE_KERNEL_ROOT}/${VERSION}/ubuntu-live-server-amd64.iso

echo "Linking ${ISOFILE} to ${LIVE_KERNEL_ROOT}/${VERSION}/ubuntu-live-server-amd64.iso"
ln -s ${ISOFILE} ${LIVE_KERNEL_ROOT}/${VERSION}/ubuntu-live-server-amd64.iso

echo "Copying ${ISO_MNT_ROOT}/${VERSION}/casper to directory ${LIVE_KERNEL_ROOT}/${VERSION}"
7z e -tiso -o/${LIVE_KERNEL_ROOT}/${VERSION} -i\!casper/initrd -i\!casper/vmlinuz ${ISOFILE}
done
30 changes: 30 additions & 0 deletions docker/estenrye/ubuntu-pxe-image-mirror/scripts/rsync.ubuntu.sh
@@ -0,0 +1,30 @@
#!/bin/bash

fatal() {
echo "$1"
exit 1
}

warn() {
echo "$1"
}

# Find a source mirror near you which supports rsync on
# https://launchpad.net/ubuntu/+cdmirrors
# rsync://<iso-country-code>.rsync.releases.ubuntu.com/releases should always work
RSYNCSOURCE=rsync://mirror.math.princeton.edu/pub/ubuntu-iso/

# Define where you want the mirror-data to be on your mirror
BASEDIR=/tftp/images/ubuntu/

if [ ! -d ${BASEDIR} ]; then
warn "${BASEDIR} does not exist yet, trying to create it..."
mkdir -p ${BASEDIR} || fatal "Creation of ${BASEDIR} failed."
mkdir -p ${BASEDIR}/.trace || fatal "Creation of ${BASEDIR}/.trace failed."
fi

rsync --verbose --recursive --times --links --safe-links --hard-links \
--stats --delete-after \
${RSYNCSOURCE} ${BASEDIR} || fatal "Failed to rsync from ${RSYNCSOURCE}."

date -u > ${BASEDIR}/.trace/$(hostname -f)
16 changes: 16 additions & 0 deletions docker/estenrye/ubuntu-pxe-image-mirror/scripts/ubuntu.sh
@@ -0,0 +1,16 @@
#!/bin/bash

fatal() {
echo "$1"
exit 1
}

warn() {
echo "$1"
}

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

${SCRIPT_DIR}/date-script.sh || fatal "Failed to run date-script.sh."
${SCRIPT_DIR}/rsync.ubuntu.sh || fatal "Failed to rsync from ${RSYNCSOURCE}."
${SCRIPT_DIR}/extract.ubuntu.sh || fatal "Failed to extract from ${RSYNCSOURCE}."

0 comments on commit a3b7f44

Please sign in to comment.