Skip to content

Commit

Permalink
remove build-fix.sh
Browse files Browse the repository at this point in the history
simplify sudoif
  • Loading branch information
m2Giles committed Nov 30, 2024
1 parent 9253c33 commit 38b8d6d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 234 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ jobs:
shell: bash
run: |
set -eoux pipefail
output=$(just merge-changelog)
declare -A output=$(just merge-changelog)
cat changelog.md
jq -r <<< $output
echo "title=$(jq -r '."title"' <<< $output)" >> $GITHUB_OUTPUT
echo "tag=$(jq -r '."tag"' <<< $output)" >> $GITHUB_OUTPUT
for item in ${!output[@]}; do
echo ${output[$item]}
echo "$item=${output[$item])" >> $GITHUB_OUTPUT
done
- name: Upload Changelogs as Artifact
uses: actions/upload-artifact@v4
Expand Down
112 changes: 34 additions & 78 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ images := '(
[ucore-nvidia]="stable-nvidia-zfs"
)'

export SUDOIF := if `id -u` == "0" { "" } else { "sudo" }

[private]
default:
@just --list
Expand Down Expand Up @@ -45,20 +47,9 @@ fix:
clean:
#!/usr/bin/bash
set -euox pipefail
function sudoif(){
if [[ "${UID}" -eq 0 ]]; then
"$@"
elif [[ "$(command -v sudo)" && -n "${SSH_ASKPASS:-}" ]] && [[ -n "${DISPLAY:-}" || -n "${WAYLAND_DISPLAY:-}" ]]; then
/usr/bin/sudo --askpass "$@" || exit 1
elif [[ "$(command -v sudo)" ]]; then
/usr/bin/sudo "$@" || exit 1
else
exit 1
fi
}
touch {{ repo_image_name }}_
sudoif find {{ repo_image_name }}_* -type d -exec chmod 0755 {} \;
sudoif find {{ repo_image_name }}_* -type f -exec chmod 0644 {} \;
${SUDOIF} find {{ repo_image_name }}_* -type d -exec chmod 0755 {} \;
${SUDOIF} find {{ repo_image_name }}_* -type f -exec chmod 0644 {} \;
find {{ repo_image_name }}_* -maxdepth 0 -exec rm -rf {} \;
rm -f output*.env changelog*.md version.txt previous.manifest.json

Expand Down Expand Up @@ -127,45 +118,34 @@ build image="bluefin":
rechunk image="bluefin":
#!/usr/bin/bash
set -eoux pipefail
function sudoif(){
if [[ "${UID}" -eq 0 ]]; then
"$@"
elif [[ "$(command -v sudo)" && -n "${SSH_ASKPASS:-}" ]] && [[ -n "${DISPLAY:-}" || -n "${WAYLAND_DISPLAY:-}" ]]; then
/usr/bin/sudo --askpass "$@" || exit 1
elif [[ "$(command -v sudo)" ]]; then
/usr/bin/sudo "$@" || exit 1
else
exit 1
fi
}
ID=$(podman images --filter reference=localhost/{{ repo_image_name }}:{{ image }} --format "'{{ '{{.ID}}' }}'")

if [[ -z "$ID" ]]; then
just build {{ image }}
fi

if [[ "${UID}" -gt "0" ]]; then
sudoif podman image scp ${UID}@localhost::localhost/{{ repo_image_name }}:{{ image }} root@localhost::localhost/{{ repo_image_name }}:{{ image }}
${SUDOIF} podman image scp ${UID}@localhost::localhost/{{ repo_image_name }}:{{ image }} root@localhost::localhost/{{ repo_image_name }}:{{ image }}
fi

CREF=$(sudoif podman create localhost/{{ repo_image_name }}:{{ image }} bash)
MOUNT=$(sudoif podman mount $CREF)
FEDORA_VERSION="$(sudoif podman inspect $CREF | jq -r '.[]["Config"]["Labels"]["ostree.linux"]' | grep -oP 'fc\K[0-9]+')"
CREF=$(${SUDOIF} podman create localhost/{{ repo_image_name }}:{{ image }} bash)
MOUNT=$(${SUDOIF} podman mount $CREF)
FEDORA_VERSION="$(${SUDOIF} podman inspect $CREF | jq -r '.[]["Config"]["Labels"]["ostree.linux"]' | grep -oP 'fc\K[0-9]+')"
OUT_NAME="{{ repo_image_name }}_{{ image }}"
VERSION="{{ image }}-${FEDORA_VERSION}.$(date +%Y%m%d)"
LABELS="
org.opencontainers.image.title={{ repo_image_name }}:{{ image }}
org.opencontainers.image.revision=$(git rev-parse HEAD)
ostree.linux=$(podman inspect localhost/{{ repo_image_name }}:{{ image }} | jq -r '.[].["Config"]["Labels"]["ostree.linux"]')
org.opencontainers.image.description={{ repo_image_name }} is my OCI image built from ublue projects. It mainly extends them for my uses."
sudoif podman run --rm \
${SUDOIF} podman run --rm \
--security-opt label=disable \
--volume "$MOUNT":/var/tree \
--env TREE=/var/tree \
--user 0:0 \
ghcr.io/hhd-dev/rechunk:latest \
/sources/rechunk/1_prune.sh
sudoif podman run --rm \
${SUDOIF} podman run --rm \
--security-opt label=disable \
--volume "$MOUNT":/var/tree \
--volume "cache_ostree:/var/ostree" \
Expand All @@ -175,13 +155,13 @@ rechunk image="bluefin":
--user 0:0 \
ghcr.io/hhd-dev/rechunk:latest \
/sources/rechunk/2_create.sh
sudoif podman unmount "$CREF"
sudoif podman rm "$CREF"
${SUDOIF} podman unmount "$CREF"
${SUDOIF} podman rm "$CREF"
if [[ "${UID}" -gt "0" ]]; then
sudoif podman rmi localhost/{{ repo_image_name }}:{{ image }}
${SUDOIF} podman rmi localhost/{{ repo_image_name }}:{{ image }}
fi
podman rmi localhost/{{ repo_image_name }}:{{ image }}
sudoif podman run --rm \
${SUDOIF} podman run --rm \
--pull=newer \
--security-opt label=disable \
--volume "$PWD:/workspace" \
Expand All @@ -199,15 +179,15 @@ rechunk image="bluefin":
ghcr.io/hhd-dev/rechunk:latest \
/sources/rechunk/3_chunk.sh

sudoif find {{ repo_image_name }}_{{ image }} -type d -exec chmod 0755 {} \; || true
sudoif find {{ repo_image_name }}_{{ image }}* -type f -exec chmod 0644 {} \; || true
${SUDOIF} find {{ repo_image_name }}_{{ image }} -type d -exec chmod 0755 {} \; || true
${SUDOIF} find {{ repo_image_name }}_{{ image }}* -type f -exec chmod 0644 {} \; || true
if [[ "${UID}" -gt "0" ]]; then
sudoif chown -R ${UID}:${GROUPS} "${PWD}"
${SUDOIF} chown -R ${UID}:${GROUPS} "${PWD}"
elif [[ "${UID}" == "0" && -n "${SUDO_USER:-}" ]]; then
sudoif chown -R ${SUDO_UID}:${SUDO_GID} "${PWD}"
${SUDOIF} chown -R ${SUDO_UID}:${SUDO_GID} "${PWD}"
fi

sudoif podman volume rm cache_ostree
${SUDOIF} podman volume rm cache_ostree

# Load Image into Podman and Tag
[private]
Expand All @@ -233,18 +213,6 @@ get-tags image="bluefin":
build-iso image="bluefin" ghcr="0" clean="0":
#!/usr/bin/bash
set -eou pipefail
function sudoif(){
if [[ "${UID}" -eq 0 ]]; then
"$@"
elif [[ "$(command -v sudo)" && -n "${SSH_ASKPASS:-}" ]] && [[ -n "${DISPLAY:-}" || -n "${WAYLAND_DISPLAY:-}" ]]; then
/usr/bin/sudo --askpass "$@" || exit 1
elif [[ "$(command -v sudo)" ]]; then
/usr/bin/sudo "$@" || exit 1
else
exit 1
fi
}

# Validate
declare -A images={{ images }}
check=${images[{{ image }}]-}
Expand Down Expand Up @@ -288,7 +256,7 @@ build-iso image="bluefin" ghcr="0" clean="0":

# Load image into rootful podman
if [[ "${UID}" -gt "0" ]]; then
sudoif podman image scp "${UID}"@localhost::"${IMAGE_FULL}" root@localhost::"${IMAGE_FULL}"
${SUDOIF} podman image scp "${UID}"@localhost::"${IMAGE_FULL}" root@localhost::"${IMAGE_FULL}"
fi

# Generate Flatpak List
Expand Down Expand Up @@ -360,17 +328,17 @@ build-iso image="bluefin" ghcr="0" clean="0":
ostree refs --repo=\${FLATPAK_SYSTEM_DIR}/repo | grep '^deploy/' | grep -v 'org\.freedesktop\.Platform\.openh264' | sed 's/^deploy\///g' > /output/flatpaks-with-deps
EOF
# Create Flatpak List
sudoif podman run --rm --privileged \
${SUDOIF} podman run --rm --privileged \
--entrypoint /bin/bash \
-e FLATPAK_SYSTEM_DIR=/flatpak/flatpak \
-e FLATPAK_TRIGGERS_DIR=/flatpak/triggers \
-v ${FLATPAK_REFS_DIR_ABS}:/output \
-v ${TEMP_FLATPAK_INSTALL_DIR}:/temp_flatpak_install_dir \
${IMAGE_FULL} /temp_flatpak_install_dir/install-flatpaks.sh

VERSION="$(sudoif podman inspect ${IMAGE_FULL} | jq -r '.[]["Config"]["Labels"]["ostree.linux"]' | grep -oP 'fc\K[0-9]+')"
VERSION="$(${SUDOIF} podman inspect ${IMAGE_FULL} | jq -r '.[]["Config"]["Labels"]["ostree.linux"]' | grep -oP 'fc\K[0-9]+')"
if [[ "{{ ghcr }}" == "1" && "{{ clean }}" == "1" ]]; then
sudoif podman rmi ${IMAGE_FULL}
${SUDOIF} podman rmi ${IMAGE_FULL}
fi
# list Flatpaks
cat ${FLATPAK_REFS_DIR}/flatpaks-with-deps
Expand Down Expand Up @@ -398,12 +366,12 @@ build-iso image="bluefin" ghcr="0" clean="0":
iso_build_args+=(VERSION="$VERSION")
iso_build_args+=(WEB_UI="false")
# Build ISO
sudoif podman run --rm --privileged --pull=newer --security-opt label=disable "${iso_build_args[@]}"
${SUDOIF} podman run --rm --privileged --pull=newer --security-opt label=disable "${iso_build_args[@]}"
if [[ "${UID}" -gt "0" ]]; then
sudoif chown -R ${UID}:${GROUPS} "${PWD}"
sudoif podman rmi "${IMAGE_FULL}"
${SUDOIF} chown -R ${UID}:${GROUPS} "${PWD}"
${SUDOIF} podman rmi "${IMAGE_FULL}"
elif [[ "${UID}" == "0" && -n "${SUDO_USER:-}" ]]; then
sudoif chown -R ${SUDO_UID}:${SUDO_GID} "${PWD}"
${SUDOIF} chown -R ${SUDO_UID}:${SUDO_GID} "${PWD}"
fi

# Run ISO
Expand Down Expand Up @@ -449,23 +417,11 @@ verify-container container="" registry="ghcr.io/ublue-os" key="":
#!/usr/bin/bash
set -eoux pipefail

function sudoif(){
if [[ "${UID}" -eq 0 ]]; then
"$@"
elif [[ "$(command -v sudo)" && -n "${SSH_ASKPASS:-}" ]] && [[ -n "${DISPLAY:-}" || -n "${WAYLAND_DISPLAY:-}" ]]; then
/usr/bin/sudo --askpass "$@" || exit 1
elif [[ "$(command -v sudo)" ]]; then
/usr/bin/sudo "$@" || exit 1
else
exit 1
fi
}

# Get Cosign if Needed
if [[ ! $(command -v cosign) ]]; then
COSIGN_CONTAINER_ID=$(sudoif podman create cgr.dev/chainguard/cosign:latest bash)
sudoif podman cp "${COSIGN_CONTAINER_ID}":/usr/bin/cosign /usr/local/bin/cosign
sudoif podman rm -f "${COSIGN_CONTAINER_ID}"
COSIGN_CONTAINER_ID=$(${SUDOIF} podman create cgr.dev/chainguard/cosign:latest bash)
${SUDOIF} podman cp "${COSIGN_CONTAINER_ID}":/usr/bin/cosign /usr/local/bin/cosign
${SUDOIF} podman rm -f "${COSIGN_CONTAINER_ID}"
fi

# Verify Cosign Image Signatures if needed
Expand Down Expand Up @@ -548,8 +504,8 @@ merge-changelog:
tag="{{ repo_image_name }}-$(date +%Y%m%d).0"
fi
cat << EOF
{
"title": "$tag (#$(git rev-parse --short HEAD))",
"tag": "$tag"
}
(
[title]="$tag (#$(git rev-parse --short HEAD))"
[tag]="$tag"
)
EOF
150 changes: 0 additions & 150 deletions build-fix.sh

This file was deleted.

Loading

0 comments on commit 38b8d6d

Please sign in to comment.