Skip to content

Commit

Permalink
Merge pull request #28 from cloudymax/extra-files-fix
Browse files Browse the repository at this point in the history
Extra files fix
  • Loading branch information
cloudymax authored Feb 27, 2023
2 parents e573d15 + d052e90 commit c7518f7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
24 changes: 17 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
FROM ubuntu:latest

RUN apt-get -y update && \
apt-get -y install xorriso sed curl gpg wget fdisk isolinux && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys && \
apt-get -y autoremove && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/* && \
mkdir /root/.gnupg && \
chmod 600 /root/.gnupg
apt-get -y install squashfuse \
squashfs-tools \
xorriso \
fakeroot \
sed \
curl \
gpg \
wget \
fdisk \
sudo \
isolinux && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys && \
apt-get -y autoremove && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/* && \
mkdir /root/.gnupg && \
chmod 600 /root/.gnupg

COPY image-create.sh /app/

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The resulting product is a fully-automated Ubuntu installer. This serves as an e
| -e | --use-hwe-kernel| Force the generated ISO to boot using the hardware enablement (HWE) kernel. Not supported by early Ubuntu 20.04 release ISOs. |
| -u | --user-data| Path to user-data file. Required if using -a|
| -m | --meta-data| Path to meta-data file. Will be an empty file if not specified and using the `-a` flag. You may read more about providing a `meta-data` file [HERE](https://cloudinit.readthedocs.io/en/latest/topics/instancedata.html)|
| -x | --extra-files| Specifies an folder with files and folders, which will be copied into the root of the iso image. If not set, nothing is copied. Requires use of `--privileged` flag when running in docker|
| -x | --extra-files| Specifies a folder with files and folders, which will be copied into the root of the iso image. If not set, nothing is copied. Requires use of `--privileged` flag when running in docker|
| -k | --no-verify| Disable GPG verification of the source ISO file. By default SHA256SUMS-<current date> and SHA256SUMS-<current date>.gpg files in the script directory will be used to verify the authenticity and integrity of the source ISO file. If they are not present the latest daily SHA256SUMS will be downloaded and saved in the script directory. The Ubuntu signing key will be downloaded and saved in a new keyring in the script directory.|
| -r | --use-release-iso| Use the current release ISO instead of the daily ISO. The file will be used if it already exists.|
| -s | --source| Source ISO file. By default the latest daily ISO for Ubuntu 20.04 will be downloaded and saved as `script directory/ubuntu-original-current date.iso` That file will be used by default if it already exists.|
Expand Down
44 changes: 39 additions & 5 deletions image-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Available options:
-m, --meta-data Path to meta-data file. Will be an empty file if not specified and using -a
-x, --extra-files Specifies an folder with files and folders, which will be copied into the root of the iso image.
-x, --extra-files Specifies a folder whos contents will be copied into the /media directroy of the squashfs.
If not set, nothing is copied
-k, --no-verify Disable GPG verification of the source ISO file. By default SHA256SUMS-<current date> and
Expand Down Expand Up @@ -352,9 +352,41 @@ set_kernel_autoinstall(){

# Add extra files from a folder into the build dir
insert_extra_files(){
log "➕ Adding additional files to the iso image..."
cp -R "${EXTRA_FILES_FOLDER}/." "${BUILD_DIR}/"
log "👍 Added additional files"

SQUASH_DIR=$(mktemp -d)

if [ ${LEGACY_IMAGE} -eq 1 ]; then
SQUASH_FS="filesystem.squashfs"
else
SQUASH_FS="ubuntu-server-minimal.squashfs"
fi

rm -rf "${SQUASH_FS}"

log "Adding additional files to the iso image..."

log " - Step 1. Copy squashfs to safe location..."
cp "${BUILD_DIR}/casper/${SQUASH_FS}" "${SQUASH_DIR}"

cd "${SQUASH_DIR}"

log " - Step 2. Expand filesystem..."
sudo nsquashfs "${SQUASH_FS}"

log " - Step 3. Copy extra files to /media..."
sudo cp -R "${EXTRA_FILES_FOLDER}/." "squashfs-root/media/"

log " - Step 4. Rebuilding squashfs.."
sudo mksquashfs squashfs-root/ "${SQUASH_FS}" -comp xz -b 1M -noappend

log " - Step 5. Copy squashfs copied back to {BUILD_DIR}/casper/${SQUASH_FS}"
cp "${SQUASH_FS}" "${BUILD_DIR}/casper/${SQUASH_FS}"

log " - Step 6. Cleaning up directories..."
rm -rf "${SQUASH_FS}"
rm -rf squashfs-root

cd /data
}

# re-create the MD5 checksum data
Expand All @@ -366,6 +398,8 @@ md5_checksums(){
md5=$(md5sum "${BUILD_DIR}/boot/grub/loopback.cfg" | cut -f1 -d ' ')
sed -i -e 's,^.*[[:space:]] ./boot/grub/loopback.cfg,'"$md5"' ./boot/grub/loopback.cfg,' "${BUILD_DIR}/md5sum.txt"
log "👍 Updated hashes."
md5=$(md5sum "${BUILD_DIR}/.disk/info" | cut -f1 -d ' ')
sed -i -e 's,^.*[[:space:]] .disk/info,'"$md5"' .disk/info,' "${BUILD_DIR}/md5sum.txt"
else
log "🗑️ Clearing MD5 hashes..."
echo > "${BUILD_DIR}/md5sum.txt"
Expand Down Expand Up @@ -452,7 +486,7 @@ main(){
parse_params "$@"

if [ ! -f "$SOURCE_ISO" ]; then

if [ "${USE_RELEASE_ISO}" -eq 1 ]; then
latest_release
else
Expand Down

0 comments on commit c7518f7

Please sign in to comment.