Skip to content

Commit

Permalink
Rework build_iso.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles committed May 7, 2023
1 parent 1df53c1 commit f699066
Showing 1 changed file with 75 additions and 22 deletions.
97 changes: 75 additions & 22 deletions build_iso.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/bin/bash

packages_file="/tmp/archlive/packages.x86_64"
set -eu

# Packages to add to the archiso profile packages
readonly base_profile="/usr/share/archiso/configs/releng/"
readonly custom_profile="/tmp/archlive"
readonly packages_file="$custom_profile/packages.x86_64"
readonly airootfs="$custom_profile/airootfs"
readonly archinstall_dir="/root/archinstall"
readonly build_script="/root/build-archinstall.sh"
readonly build_service="/etc/systemd/system/build-archinstall.service"

# Packages to add to the archiso custom profile
packages=(
git
python
Expand All @@ -13,34 +21,79 @@ packages=(
python-pyparted
)

mkdir -p /tmp/archlive/airootfs/root/archinstall-git
cp -r . /tmp/archlive/airootfs/root/archinstall-git

cat <<- _EOF_ | tee /tmp/archlive/airootfs/root/.zprofile
cd archinstall-git
rm -rf dist
python -m build --wheel --no-isolation
pip install dist/archinstall*.whl
echo "This is an unofficial ISO for development and testing of archinstall. No support will be provided."
echo "This ISO was built from Git SHA $GITHUB_SHA"
echo "Type archinstall to launch the installer."
_EOF_

pacman -Sy
pacman --noconfirm -S git archiso

cp -r /usr/share/archiso/configs/releng/* /tmp/archlive
# Copy an archiso base profile to create a custom profile from
cp -r $base_profile $custom_profile

# Copy the archinstall directory to the archiso custom profile
cp -r "$(dirname "$0")" ${airootfs}${archinstall_dir}

# Remove the archinstall package from the archiso custom profile
sed -i /archinstall/d $packages_file

# Add packages to the archiso profile packages
# Add packages to the archiso custom profile
for package in "${packages[@]}"; do
echo "$package" >> $packages_file
done

find /tmp/archlive
cd /tmp/archlive
# Use the `GITHUB_SHA` environment variable for the commit hash if it exists
if [[ -v GITHUB_SHA ]]; then
commit_hash="$GITHUB_SHA"
# Use git for the commit hash if the `GITHUB_SHA` environment varible is not set
else
commit_hash="$(git rev-parse HEAD)"
fi

# Append an archinstall developement message to motd
cat <<- _EOF_ >> $airootfs/etc/motd
archinstall development ISO
Git commit hash: $commit_hash
This is an unofficial ISO for development and testing of archinstall. No support will be provided.
_EOF_

# A script to build archinstall in the live environment
cat <<- _EOF_ > ${airootfs}${build_script}
cd $archinstall_dir
rm -rf dist
python -m build --wheel --no-isolation
pip install dist/*.whl
_EOF_

# A service to run the archinstall build script in the live environment
cat <<- _EOF_ > ${airootfs}${build_service}
[Unit]
Description=Build archinstall
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/sh $build_script
[Install]
WantedBy=multi-user.target
_EOF_

# Enable the service that runs the archinstall build script
ln -sf $build_service $airootfs/etc/systemd/system/multi-user.target.wants/

# A startup file to wait for the completion of the service that runs the archinstall build script
cat <<- _EOF_ > $airootfs/root/.zprofile
if [ "\$(systemctl show -p SubState --value ${build_service##*/})" != "dead" ]; then
printf "Building archinstall (${build_service##*/})..."
while [ "\$(systemctl show -p SubState --value ${build_service##*/})" != "dead" ]; do
sleep 1
done
echo " done"
echo "Type archinstall to launch the installer."
fi
cd $archinstall_dir
_EOF_

cd $custom_profile

mkarchiso -v -w work/ -o out/ ./
mkarchiso -v $custom_profile

0 comments on commit f699066

Please sign in to comment.