From efbcb2a1fc5a6b224f6386ed79930cf0709224ed Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:40:57 +0100 Subject: [PATCH] chore: Remove usage of `yq` in favor of `jq` --- modules/akmods/akmods.sh | 2 +- modules/bling/bling.sh | 2 +- modules/brew/brew.sh | 16 +++---- modules/chezmoi/chezmoi.sh | 16 +++---- .../default-flatpaks/v1/default-flatpaks.sh | 42 ++++++++++--------- modules/files/files.sh | 12 +++--- modules/fonts/fonts.sh | 8 +--- modules/gnome-extensions/gnome-extensions.sh | 4 +- .../gschema-overrides/gschema-overrides.sh | 2 +- modules/justfiles/justfiles.sh | 4 +- modules/rpm-ostree/rpm-ostree.sh | 16 +++---- modules/script/script.sh | 4 +- modules/signing/signing.sh | 23 +++++----- modules/systemd/systemd.sh | 16 +++---- modules/yafti/yafti.sh | 8 ++-- 15 files changed, 86 insertions(+), 89 deletions(-) diff --git a/modules/akmods/akmods.sh b/modules/akmods/akmods.sh index 1745daef..694b28eb 100644 --- a/modules/akmods/akmods.sh +++ b/modules/akmods/akmods.sh @@ -22,7 +22,7 @@ if "${previously_not_installed_rpm_fusion}"; then fi } -get_yaml_array INSTALL '.install[]' "$1" +get_json_array INSTALL '.install[]' "$1" if [[ ${#INSTALL[@]} -lt 1 ]]; then echo "ERROR: You didn't specify any akmod for installation!" diff --git a/modules/bling/bling.sh b/modules/bling/bling.sh index 17c438ce..674c3ede 100644 --- a/modules/bling/bling.sh +++ b/modules/bling/bling.sh @@ -3,7 +3,7 @@ # Tell build process to exit if there are any errors. set -euo pipefail -get_yaml_array INSTALL '.install[]' "$1" +get_json_array INSTALL '.install[]' "$1" cd "/tmp/modules/bling/installers" diff --git a/modules/brew/brew.sh b/modules/brew/brew.sh index 4f98a77c..2a82e733 100644 --- a/modules/brew/brew.sh +++ b/modules/brew/brew.sh @@ -39,42 +39,42 @@ fi MODULE_DIRECTORY="${MODULE_DIRECTORY:-/tmp/modules}" # Configuration values -AUTO_UPDATE=$(echo "${1}" | yq -I=0 ".auto-update") +AUTO_UPDATE=$(echo "${1}" | jq -r '.["auto-update"]') if [[ -z "${AUTO_UPDATE}" || "${AUTO_UPDATE}" == "null" ]]; then AUTO_UPDATE=true fi -UPDATE_INTERVAL=$(echo "${1}" | yq -I=0 ".update-interval") +UPDATE_INTERVAL=$(echo "${1}" | jq -r '.["update-interval"]') if [[ -z "${UPDATE_INTERVAL}" || "${UPDATE_INTERVAL}" == "null" ]]; then UPDATE_INTERVAL="6h" fi -UPDATE_WAIT_AFTER_BOOT=$(echo "${1}" | yq -I=0 ".update-wait-after-boot") +UPDATE_WAIT_AFTER_BOOT=$(echo "${1}" | jq -r '.["update-wait-after-boot"]') if [[ -z "${UPDATE_WAIT_AFTER_BOOT}" || "${UPDATE_WAIT_AFTER_BOOT}" == "null" ]]; then UPDATE_WAIT_AFTER_BOOT="10min" fi -AUTO_UPGRADE=$(echo "${1}" | yq -I=0 ".auto-upgrade") +AUTO_UPGRADE=$(echo "${1}" | jq -r '.["auto-upgrade"]') if [[ -z "${AUTO_UPGRADE}" || "${AUTO_UPGRADE}" == "null" ]]; then AUTO_UPGRADE=true fi -UPGRADE_INTERVAL=$(echo "$1" | yq -I=0 ".upgrade-interval") +UPGRADE_INTERVAL=$(echo "$1" | jq -r '.["upgrade-interval"]') if [[ -z "${UPGRADE_INTERVAL}" || "${UPGRADE_INTERVAL}" == "null" ]]; then UPGRADE_INTERVAL="8h" fi -UPGRADE_WAIT_AFTER_BOOT=$(echo "${1}" | yq -I=0 ".upgrade-wait-after-boot") +UPGRADE_WAIT_AFTER_BOOT=$(echo "${1}" | jq -r '.["upgrade-wait-after-boot"]') if [[ -z "${UPGRADE_WAIT_AFTER_BOOT}" || "${UPGRADE_WAIT_AFTER_BOOT}" == "null" ]]; then UPGRADE_WAIT_AFTER_BOOT="30min" fi -NOFILE_LIMITS=$(echo "${1}" | yq -I=0 ".nofile-limits") +NOFILE_LIMITS=$(echo "${1}" | jq -r '.["nofile-limits"]') if [[ -z "${NOFILE_LIMITS}" || "${NOFILE_LIMITS}" == "null" ]]; then NOFILE_LIMITS=false fi -BREW_ANALYTICS=$(echo "${1}" | yq -I=0 ".brew-analytics") +BREW_ANALYTICS=$(echo "${1}" | jq -r '.["brew-analytics"]') if [[ -z "${BREW_ANALYTICS}" || "${BREW_ANALYTICS}" == "null" ]]; then BREW_ANALYTICS=true fi diff --git a/modules/chezmoi/chezmoi.sh b/modules/chezmoi/chezmoi.sh index 98401607..2a1daa95 100644 --- a/modules/chezmoi/chezmoi.sh +++ b/modules/chezmoi/chezmoi.sh @@ -16,9 +16,9 @@ if [[ $DEBUG == true ]]; then fi # The repository with your chezmoi dotfiles. (default: null) -DOTFILE_REPOSITORY=$(echo "$1" | yq -I=0 ".repository") # (string) +DOTFILE_REPOSITORY=$(echo "$1" | jq -r '.["repository"]') # (string) # The chezmoi repository branch to use. -DOTFILE_BRANCH=$(echo "$1" | yq -I=0 ".branch") +DOTFILE_BRANCH=$(echo "$1" | jq -r '.["branch"]') if ! [[ -z "${DOTFILE_BRANCH}" ]] || [[ "${DOTFILE_BRANCH}" == "null" ]]; then INIT_BRANCH_FLAG="--branch ${DOTFILE_BRANCH}" else @@ -36,7 +36,7 @@ fi # # To turn on lingering for a given user, run the following commmand with sudo: # 'sudo loginctl enable-linger ' -ALL_USERS=$(echo "$1" | yq -I=0 ".all-users") # (boolean) +ALL_USERS=$(echo "$1" | jq -r '.["all-users"]') # (boolean) if [[ -z $ALL_USERS || $ALL_USERS == "null" ]]; then ALL_USERS=true fi @@ -45,24 +45,24 @@ fi # This string is passed on directly to systemd's OnUnitInactiveSec. Complete syntax is described here: # https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html# # Examples: '1d' (1 day - default), '6h' (6 hours), '10m' (10 minutes) -RUN_EVERY=$(echo "$1" | yq -I=0 ".run-every") # (string) +RUN_EVERY=$(echo "$1" | jq -r '.["run-every"]') # (string) if [[ -z $RUN_EVERY || $RUN_EVERY == "null" ]]; then RUN_EVERY="1d" fi # chezmoi-update.service will also run this much time after the system has booted. # Same syntax as RUN_EVERY (default: '5m') -WAIT_AFTER_BOOT=$(echo "$1" | yq -I=0 ".wait-after-boot") # (string) +WAIT_AFTER_BOOT=$(echo "$1" | jq -r '.["wait-after-boot"]') # (string) if [[ -z $WAIT_AFTER_BOOT || $WAIT_AFTER_BOOT == "null" ]]; then WAIT_AFTER_BOOT="5m" fi # If true, disables automatic initialization of chezmoi if no dotfile directory is found. (default: false) -DISABLE_INIT=$(echo "$1" | yq -I=0 ".disable-init") # (boolean) +DISABLE_INIT=$(echo "$1" | jq -r '.["disable-init"]') # (boolean) if [[ -z $DISABLE_INIT || $DISABLE_INIT == "null" ]]; then DISABLE_INIT=false fi # If true, disables automatic activation of 'chezmoi-update.timer'. (default: false) -DISABLE_UPDATE=$(echo "$1" | yq -I=0 ".disable-update") # (boolean) +DISABLE_UPDATE=$(echo "$1" | jq -r '.["disable-update"]') # (boolean) if [[ -z $DISABLE_UPDATE || $DISABLE_UPDATE == "null" ]]; then DISABLE_UPDATE=false fi @@ -70,7 +70,7 @@ fi # Determines how chezmoi handles conflicting files. (default: "skip") # "skip" will not replace files that have changed. # "replace" will overwrite all files that have changed. -FILE_CONFLICT_POLICY=$(echo "$1" | yq -I=0 ".file-conflict-policy") # (string) +FILE_CONFLICT_POLICY=$(echo "$1" | jq -r '.["file-conflict-policy"]') # (string) if [[ -z $FILE_CONFLICT_POLICY || $FILE_CONFLICT_POLICY == "null" ]]; then FILE_CONFLICT_POLICY="skip" fi diff --git a/modules/default-flatpaks/v1/default-flatpaks.sh b/modules/default-flatpaks/v1/default-flatpaks.sh index f95741cb..57b4f619 100644 --- a/modules/default-flatpaks/v1/default-flatpaks.sh +++ b/modules/default-flatpaks/v1/default-flatpaks.sh @@ -17,16 +17,16 @@ configure_flatpak_repo () { CONFIG_FILE=$1 INSTALL_LEVEL=$2 REPO_INFO="/usr/share/bluebuild/default-flatpaks/$INSTALL_LEVEL/repo-info.yml" - get_yaml_array INSTALL ".$INSTALL_LEVEL.install[]" "$CONFIG_FILE" + get_json_array INSTALL ".$INSTALL_LEVEL.install[]" "$CONFIG_FILE" # Checks pre-configured repo info, if exists if [[ -f $REPO_INFO ]]; then echo "Existing $INSTALL_LEVEL configuration found:" cat $REPO_INFO - CONFIG_URL=$(yq ".repo-url" "$REPO_INFO") - CONFIG_NAME=$(yq ".repo-name" "$REPO_INFO") - CONFIG_TITLE=$(yq ".repo-title" "$REPO_INFO") + CONFIG_URL=$(jq -r '.["repo-url"]' "$REPO_INFO") + CONFIG_NAME=$(jq -r '.["repo-name"]' "$REPO_INFO") + CONFIG_TITLE=$(jq -r '.["repo-title"]' "$REPO_INFO") else CONFIG_URL="null" CONFIG_NAME="null" @@ -34,9 +34,9 @@ configure_flatpak_repo () { fi echo "Configuring $INSTALL_LEVEL repo in $REPO_INFO" - REPO_URL=$(echo "$CONFIG_FILE" | yq -I=0 ".$INSTALL_LEVEL.repo-url") - REPO_NAME=$(echo "$CONFIG_FILE" | yq -I=0 ".$INSTALL_LEVEL.repo-name") - REPO_TITLE=$(echo "$CONFIG_FILE" | yq -I=0 ".$INSTALL_LEVEL.repo-title") + REPO_URL=$(echo "$CONFIG_FILE" | jq -r '.["$INSTALL_LEVEL.repo-url"]') + REPO_NAME=$(echo "$CONFIG_FILE" | jq -r '.["$INSTALL_LEVEL.repo-name"]') + REPO_TITLE=$(echo "$CONFIG_FILE" | jq -r '.["$INSTALL_LEVEL.repo-title"]') # If repo-name isn't configured, use flathub as fallback # Checked separately from URL to allow custom naming @@ -68,10 +68,12 @@ configure_flatpak_repo () { touch $REPO_INFO # EOF breaks if the contents are indented, # so the below lines are intentionally un-indented - cat > $REPO_INFO < $REPO_INFO < /tmp/tmp-policy.json && mv /tmp/tmp-policy.json "$POLICY_FILE" mv "$MODULE_DIRECTORY/signing/registry-config.yaml" "$CONTAINER_DIR/registries.d/$IMAGE_NAME_FILE.yaml" sed -i "s ghcr.io/IMAGENAME $IMAGE_REGISTRY g" "$CONTAINER_DIR/registries.d/$IMAGE_NAME_FILE.yaml" diff --git a/modules/systemd/systemd.sh b/modules/systemd/systemd.sh index 056054a1..eac53ed6 100644 --- a/modules/systemd/systemd.sh +++ b/modules/systemd/systemd.sh @@ -23,14 +23,14 @@ if [[ -d "$USER_UNIT_INCLUDE" ]]; then fi # Systemd units configuration (enable, disable, unmask & mask) -get_yaml_array ENABLED '.system.enabled[]' "$1" -get_yaml_array DISABLED '.system.disabled[]' "$1" -get_yaml_array UNMASKED '.system.unmasked[]' "$1" -get_yaml_array MASKED '.system.masked[]' "$1" -get_yaml_array USER_ENABLED '.user.enabled[]' "$1" -get_yaml_array USER_DISABLED '.user.disabled[]' "$1" -get_yaml_array USER_UNMASKED '.user.unmasked[]' "$1" -get_yaml_array USER_MASKED '.user.masked[]' "$1" +get_json_array ENABLED '.system.enabled[]' "$1" +get_json_array DISABLED '.system.disabled[]' "$1" +get_json_array UNMASKED '.system.unmasked[]' "$1" +get_json_array MASKED '.system.masked[]' "$1" +get_json_array USER_ENABLED '.user.enabled[]' "$1" +get_json_array USER_DISABLED '.user.disabled[]' "$1" +get_json_array USER_UNMASKED '.user.unmasked[]' "$1" +get_json_array USER_MASKED '.user.masked[]' "$1" if [[ ${#ENABLED[@]} -gt 0 ]]; then for unit in "${ENABLED[@]}"; do diff --git a/modules/yafti/yafti.sh b/modules/yafti/yafti.sh index fb8dcb0b..d21ccb58 100644 --- a/modules/yafti/yafti.sh +++ b/modules/yafti/yafti.sh @@ -52,14 +52,14 @@ fi YAFTI_FILE="${FIRSTBOOT_DATA}/yafti.yml" -get_yaml_array FLATPAKS '.custom-flatpaks[]' "$1" +get_json_array FLATPAKS '.custom-flatpaks[]' "$1" if [[ ${#FLATPAKS[@]} -gt 0 ]]; then echo "Adding Flatpaks to yafti.yml" - yq -i '.screens.applications.values.groups.Custom.description = "Flatpaks suggested by the image maintainer."' "${YAFTI_FILE}" - yq -i '.screens.applications.values.groups.Custom.default = true' "${YAFTI_FILE}" + sed -i '/^ Custom:/,/^ / s/description: .*/description: "Flatpaks suggested by the image maintainer."/' "${YAFTI_FILE}" + sed -i '/^ Custom:/,/^ / s/default: .*/default: true/' "${YAFTI_FILE}" for pkg in "${FLATPAKS[@]}"; do echo "Adding to yafti: ${pkg}" - yq -i ".screens.applications.values.groups.Custom.packages += [$pkg]" "${YAFTI_FILE}" + sed -i "/^ packages:/a\ \ - $pkg" "${YAFTI_FILE}" done fi