-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example script to help build airgapped package repo
- Loading branch information
Showing
1 changed file
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#!/usr/bin/env bash | ||
# SUSE Edge Image Builder RPM Dependency Script | ||
# ONLY FOR TESTING | ||
|
||
# NOTE: Please place any user-provided RPM's into /tmp/eib/rpms/ first | ||
|
||
# Clean up any previous variables | ||
unset PKG_LIST | ||
unset ISO_PATH | ||
unset ADD_REPO | ||
|
||
# Set the location of your SLE Micro SelfInstall ISO on the filesystem | ||
#ISO_PATH=/path/to/SLE-Micro.x86_64-5.5.0-Default-SelfInstall-GM.install.iso | ||
|
||
# Provide a list of packages that you want to install from SUSE repositories | ||
PKG_LIST="nvidia-open-driver-G06-signed-kmp-default lshw hwdata" | ||
|
||
# Provide a list of additional repos to add to the dependency solver | ||
ADD_REPO="" | ||
|
||
# Specify your SUSE registration code for pulling SUSE packages | ||
REG_CODE="XXXX-XXXX-XXXX" | ||
|
||
# Make sure that the existing repo is clean | ||
rm -rf /tmp/eib/repo/ | ||
|
||
# Make temporary eib work-dir and separate for user-provided rpms | ||
mkdir -p /tmp/eib | ||
mkdir -p /tmp/eib/rpms | ||
mkdir -p /tmp/eib/root | ||
mkdir -p /tmp/eib/repo | ||
|
||
# Copy the path to the original ISO to /tmp | ||
cp $ISO_PATH /tmp/eib/SLE-Micro-original.iso | ||
|
||
# Extract the contents of the ISO and extract the raw squashfs | ||
xorriso -osirrox on -indev /tmp/eib/SLE-Micro-original.iso extract / /tmp/eib/iso-root/ | ||
cd /tmp/eib/iso-root/ | ||
unsquashfs /tmp/eib/iso-root/SLE-Micro.raw.squashfs | ||
|
||
# Find the image offset of the rootfs on the raw image | ||
cd squashfs-root | ||
sector=$(/usr/sbin/fdisk -l SLE-Micro.raw | awk '/raw3/ {print $2};') | ||
offset=$(($sector * 512)) | ||
|
||
# Mount the raw disk image locally to use as a baseline for rpm database | ||
sudo mount -o loop,offset=$offset SLE-Micro.raw /tmp/eib/root | ||
|
||
# Mount the /var btrfs subvolume into the rootfs | ||
loopdev=$(lsblk | awk '/eib/ {print $1};') | ||
sudo mount /dev/$loopdev -o subvol=@/var /tmp/eib/root/var | ||
|
||
# Make the btrfs filesystem read-write on the raw disk image | ||
cd /tmp/eib/root | ||
sudo systemd-nspawn btrfs property set / ro false | ||
|
||
# Copy the rpms directory locally in the image and make directory for extract | ||
sudo mkdir -p /tmp/eib/root/eib-rpms | ||
sudo mkdir -p /tmp/eib/root/eib-repo | ||
sudo cp /tmp/eib/rpms/* /tmp/eib/root/eib-rpms/ | ||
|
||
# Append local RPM's to package list and modify directory location | ||
PKG_LIST="$PKG_LIST $(find /tmp/eib/rpms -type f)" | ||
PKG_LIST=$(sed 's|/tmp/eib/rpms/|/eib-rpms/|g' <<< "$PKG_LIST") | ||
|
||
# Make sure that the package list is not empty before proceeding | ||
if [ ${#PKG_LIST} == 1 ]; | ||
then | ||
echo "[ERROR] Package list is empty, and didn't discover any user RPM's" | ||
exit 22 | ||
fi | ||
|
||
# Get SLE15 Service Pack number so we enable PackageHub properly | ||
SLE_SP=$(cat /tmp/eib/root/etc/rpm/macros.sle | awk '/sle/ {print $2};' | cut -c4) | ||
|
||
# Download required packages into the /mnt/eib-repo directory via systemd-nspawn | ||
sudo systemd-nspawn --pipe << EOF | ||
suseconnect -r $REG_CODE | ||
suseconnect -p PackageHub/15.$SLE_SP/x86_64 | ||
zypper ref | ||
counter=1 | ||
for i in $ADD_REPO; | ||
do | ||
# Add the additional repositories specified by the user | ||
zypper ar -f \$i addrepo\$counter | ||
counter=\$((counter+1)) | ||
done | ||
zypper --pkg-cache-dir /eib-repo/ --no-gpg-checks install -y \ | ||
--download-only --force-resolution --auto-agree-with-licenses \ | ||
--allow-vendor-change -n $PKG_LIST | ||
# Check if the zypper command executed successfully | ||
if [ "\$?" == 0 ]; | ||
then | ||
# This enables already installed packages to force | ||
# repo generation later, or if there are no additional | ||
# dependencies required for user-specified rpms | ||
touch /eib-repo/zypper-success | ||
fi | ||
suseconnect -d | ||
EOF | ||
|
||
# Copy the RPM's out from the repo created in the container | ||
cp -rf /tmp/eib/root/eib-repo/* /tmp/eib/repo | ||
|
||
# Clean up the resources created during the dependency process | ||
cd /tmp | ||
sudo umount /tmp/eib/root/var | ||
sudo umount /tmp/eib/root | ||
sudo rm -rf /tmp/eib/iso-root /tmp/eib/root /tmp/eib/SLE-Micro-original.iso | ||
|
||
# Check if there has been a failure in the dependency retrieval | ||
if [ ! -z "$PKG_LIST" ] && [ -z "$(ls -A /tmp/eib/repo)" ]; | ||
then | ||
# PKG_LIST is not empty and the repo directory is empty | ||
echo "[ERROR] Dependency retrieval unsuccessful, exiting..." | ||
exit 126 | ||
else | ||
# PKG_LIST is not empty and we have packages in the repo | ||
echo "[INFO] Dependency retrieval successful." | ||
|
||
# Copy in the locally specified RPM's | ||
mkdir -p /tmp/eib/repo/local | ||
cp /tmp/eib/rpms/* /tmp/eib/repo/local/. | ||
|
||
# Run createrepo so we can add this to the Combustion phase | ||
/usr/bin/createrepo /tmp/eib/repo | ||
echo "[SUCCESS] Repository successfully created at /tmp/eib/repo." | ||
|
||
# Strip the path and extension from the list of rpms | ||
PKG_LIST=$(sed 's|/eib-rpms/||g' <<< "$PKG_LIST") | ||
PKG_LIST=$(sed 's|.rpm||g' <<< "$PKG_LIST") | ||
echo $PKG_LIST > /tmp/eib/repo/package-list.txt | ||
exit 0 | ||
fi |