Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 128 additions & 7 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,69 @@ export latest := "43"
export default_image := "kinoite"
export default_target := "bazzite"

kernel_flavor := "bazzite"

alias build-iso := build-iso-release
alias run := run-container

_default:
@just --list

[private]
_container_mgr:
@{{ project_root }}/just_scripts/container_mgr.sh
#!/usr/bin/bash
if [[ -n ${CONTAINER_MGR} ]]; then
echo "${CONTAINER_MGR}"
elif command -v docker &>/dev/null; then
echo docker
elif command -v podman &>/dev/null; then
echo podman
elif command -v podman-remote &>/dev/null; then
echo podman-remote
else
echo "No container manager found" >&2
exit 1
fi

[private]
_tag image:
@echo {{ image }}-build

# Resolve target and image name from shorthand inputs
[private]
_resolve_image target image:
#!/usr/bin/bash
set -euo pipefail
target="{{ target }}"
image="{{ image }}"

[[ -z "$image" ]] && image="{{ default_image }}"
[[ -z "$target" ]] && target="{{ default_target }}"
[[ "$target" == "deck" ]] && target="bazzite-deck"
[[ "$target" == "nvidia" ]] && target="bazzite-nvidia"

image="${image,,}"
target="${target,,}"

desktop=""
if [[ "$image" == "gnome" || "$image" == "silverblue" ]]; then
desktop="-gnome"
fi
resolved="${target}${desktop}"
if [[ "$resolved" =~ nvidia ]]; then
resolved="bazzite${desktop}-nvidia"
fi

if [[ "$image" =~ "gnome" || "$image" =~ "silverblue" ]]; then
base_image="silverblue"
else
base_image="kinoite"
fi

echo "${resolved} ${base_image} ${target}"

# Check Just Syntax
[group('Just')]
just-check:
#!/usr/bin/bash
find "${project_root}" -type f -name "*.just" | while read -r file; do
Expand All @@ -26,6 +76,7 @@ just-check:
just --unstable --fmt --check -f ${project_root}/Justfile

# Fix Just Syntax
[group('Just')]
[private]
just-fix:
#!/usr/bin/bash
Expand All @@ -36,33 +87,103 @@ just-fix:
just --unstable --fmt -f ${project_root}/Justfile

# Build image
[group('Image')]
build target="" image="":
@{{ project_root }}/just_scripts/build-image.sh {{ target }} {{ image }}
#!/usr/bin/bash
set -euo pipefail

resolved=$(just _resolve_image "{{ target }}" "{{ image }}")
image_name=$(echo "$resolved" | cut -d' ' -f1)
base_image=$(echo "$resolved" | cut -d' ' -f2)
container_target=$(echo "$resolved" | cut -d' ' -f3)

container_mgr=$(just _container_mgr)
tag=$(just _tag "${image_name}")

if [[ "$container_target" =~ "nvidia" ]]; then
flavor="nvidia"
else
flavor="main"
fi

# Resolve kernel version dynamically
kernel_version=$(skopeo inspect --retry-times 3 \
"docker://ghcr.io/ublue-os/akmods:{{ kernel_flavor }}-{{ latest }}" \
| jq -r '.Labels["ostree.linux"]')

$container_mgr build -f Containerfile \
--build-arg="BASE_IMAGE_NAME=${base_image}" \
--build-arg="FEDORA_VERSION={{ latest }}" \
--build-arg="KERNEL_FLAVOR={{ kernel_flavor }}" \
--build-arg="KERNEL_VERSION=${kernel_version}" \
--build-arg="IMAGE_NAME=${tag}" \
--build-arg="SOURCE_IMAGE=${base_image}-${flavor}" \
--target="${container_target}" \
--tag "localhost/${tag}:{{ latest }}-{{ git_branch }}" \
"${project_root}"

# Build ISO
[group('ISO')]
build-iso-release target="" image="":
@{{ project_root }}/just_scripts/build-iso.sh {{ target }} {{ image }}
@{{ project_root }}/just_scripts/build-iso.sh {{ target }} {{ image }}

# Build ISO using ISO Builder Git Head
[group('ISO')]
build-iso-git target="" image="":
@{{ project_root }}/just_scripts/build-iso-installer-main.sh {{ target }} {{ image }}

# Run ISO
[group('ISO')]
run-iso target="" image="":
@{{ project_root }}/just_scripts/run-iso.sh {{ target }} {{ image }}

# Run Container
[group('Image')]
run-container target="" image="":
@{{ project_root }}/just_scripts/run-image.sh {{ target }} {{ image }}
#!/usr/bin/bash
set -euo pipefail

resolved=$(just _resolve_image "{{ target }}" "{{ image }}")
image_name=$(echo "$resolved" | cut -d' ' -f1)

container_mgr=$(just _container_mgr)
tag=$(just _tag "${image_name}")

# Build if image doesn't exist
ID=$($container_mgr images --filter "reference=localhost/${tag}:{{ latest }}-{{ git_branch }}" --format "{{{{.ID}}")
if [[ -z "$ID" ]]; then
just build "{{ target }}" "{{ image }}"
fi

$container_mgr run -it --rm "localhost/${tag}:{{ latest }}-{{ git_branch }}" /usr/bin/bash

# List Images
[group('Utility')]
list-images:
@{{ project_root }}/just_scripts/list-images.sh
#!/usr/bin/bash
set -euo pipefail
for mgr in docker podman podman-remote; do
if command -v "$mgr" &>/dev/null; then
echo "Container Manager: ${mgr}"
$mgr images --filter "reference=localhost/bazzite*-build"
fi
done

# Clean Images
[group('Utility')]
clean-images:
@{{ project_root }}/just_scripts/cleanup-images.sh
#!/usr/bin/bash
set -euox pipefail
for mgr in docker podman podman-remote; do
if command -v "$mgr" &>/dev/null; then
echo "Container Manager: ${mgr}"
$mgr images --filter "reference=localhost/bazzite*-build" --format "{{{{.ID}}" | xargs -r $mgr image rm
fi
done

# Clean ISOs
[group('Utility')]
clean-isos:
@{{ project_root }}/just_scripts/cleanup-dir.sh
#!/usr/bin/bash
set -euox pipefail
rm -f "${project_root}"/just_scripts/output/*
43 changes: 0 additions & 43 deletions just_scripts/build-image.sh

This file was deleted.

45 changes: 16 additions & 29 deletions just_scripts/build-iso-installer-main.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/bash
#shellcheck disable=SC2154

set -eo pipefail

if [[ -z ${project_root} ]]; then
project_root=$(git rev-parse --show-toplevel)
fi
if [[ -z ${git_branch} ]]; then
git_branch=$(git branch --show-current)
fi

# shellcheck disable=SC1091
. "${project_root}/just_scripts/sudoif.sh"

# Check if inside rootless container
if [[ -f /run/.containerenv ]]; then
#shellcheck disable=SC1091
Expand All @@ -22,57 +21,45 @@ if [[ -f /run/.containerenv ]]; then
fi
fi
container_mgr=$(just _container_mgr)
# If using rootless container manager, exit. Might not be best check
if "${container_mgr}" info | grep Root | grep -q /home; then
echo "Cannot build ISO with rootless container..."
exit 1
fi

# Get Inputs
# Resolve image
target=$1
image=$2
orig_image=$2

# Set image/target/version based on inputs
# shellcheck disable=SC2154,SC1091
. "${project_root}/just_scripts/get-defaults.sh"
resolved=$(just _resolve_image "$target" "$image")
image_name=$(echo "$resolved" | cut -d' ' -f1)
base_image=$(echo "$resolved" | cut -d' ' -f2)

# Set Container tag name
tag=$(just _tag "${image}")
tag=$(just _tag "${image_name}")

# Remove old ISO if present
sudoif rm -f "${project_root}/just_scripts/output/${tag}-${git_branch}.iso"
sudoif rm -f "${project_root}/just_scripts/output/${tag}-${git_branch}.iso-CHECKSUM"

# Set Base Image
if [[ ${image} =~ "gnome" ]]; then
base_image="silverblue"
else
base_image="kinoite"
fi
sudo rm -f "${project_root}/just_scripts/output/${tag}-${git_branch}.iso"
sudo rm -f "${project_root}/just_scripts/output/${tag}-${git_branch}.iso-CHECKSUM"

# Set variant and flatpak dir
if [[ "${base_image}" =~ "silverblue" ]]; then
if [[ "${base_image}" == "silverblue" ]]; then
flatpak_dir_shortname="installer/gnome_flatpaks"
elif [[ "${base_image}" =~ "kinoite" ]]; then
flatpak_dir_shortname="installer/kde_flatpaks"
else
exit 1
flatpak_dir_shortname="installer/kde_flatpaks"
fi
variant="Kinoite"
if [[ ${target} =~ "deck" ]]; then
extra_boot_params=""
if [[ ${image_name} =~ "deck" ]]; then
extra_boot_params="inst.resolution=1280x800"
fi

# Make sure image actually exists, build if it doesn't
#shellcheck disable=SC2154
ID=$(${container_mgr} images --filter reference=localhost/"${tag}:${latest}-${git_branch}" --format "{{.ID}}")
if [[ -z ${ID} ]]; then
just build "${target}" "${orig_image}"
just build "$target" "$image"
fi

# Make temp space
TEMP_FLATPAK_INSTALL_DIR=$(mktemp -d -p "${project_root}" flatpak.XXX)
# Get list of refs from directory
FLATPAK_REFS_DIR=${project_root}/${flatpak_dir_shortname}
FLATPAK_REFS_DIR_LIST=$(tr '\n' ' ' < "${FLATPAK_REFS_DIR}/flatpaks")

Expand Down Expand Up @@ -103,7 +90,7 @@ if [[ ! -f ${project_root}/${flatpak_dir_shortname}/flatpaks_with_deps ]]; then
-e FLATPAK_TRIGGERSDIR=/flatpak/triggers \
--volume "${FLATPAK_REFS_DIR}":/output \
--volume "${TEMP_FLATPAK_INSTALL_DIR}":/temp_flatpak_install_dir \
"ghcr.io/ublue-os/${base_image}-main:${version}" /temp_flatpak_install_dir/script.sh
"ghcr.io/ublue-os/${base_image}-main:${latest}" /temp_flatpak_install_dir/script.sh
fi

# Remove Temp Directory
Expand Down
Loading