Skip to content

Commit

Permalink
chore(default-flatpaks): Replace yq with jq in run-time setup bin…
Browse files Browse the repository at this point in the history
…aries
  • Loading branch information
fiftydinar authored Dec 1, 2024
1 parent 54dd828 commit ebfdd8f
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 45 deletions.
16 changes: 8 additions & 8 deletions modules/brew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,42 @@ fi
MODULE_DIRECTORY="${MODULE_DIRECTORY:-/tmp/modules}"

# Configuration values
AUTO_UPDATE=$(echo "${1}" | jq -r '.["auto-update"]')
AUTO_UPDATE=$(echo "${1}" | jq -r 'try .["auto-update"]')
if [[ -z "${AUTO_UPDATE}" || "${AUTO_UPDATE}" == "null" ]]; then
AUTO_UPDATE=true
fi

UPDATE_INTERVAL=$(echo "${1}" | jq -r '.["update-interval"]')
UPDATE_INTERVAL=$(echo "${1}" | jq -r 'try .["update-interval"]')
if [[ -z "${UPDATE_INTERVAL}" || "${UPDATE_INTERVAL}" == "null" ]]; then
UPDATE_INTERVAL="6h"
fi

UPDATE_WAIT_AFTER_BOOT=$(echo "${1}" | jq -r '.["update-wait-after-boot"]')
UPDATE_WAIT_AFTER_BOOT=$(echo "${1}" | jq -r 'try .["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}" | jq -r '.["auto-upgrade"]')
AUTO_UPGRADE=$(echo "${1}" | jq -r 'try .["auto-upgrade"]')
if [[ -z "${AUTO_UPGRADE}" || "${AUTO_UPGRADE}" == "null" ]]; then
AUTO_UPGRADE=true
fi

UPGRADE_INTERVAL=$(echo "$1" | jq -r '.["upgrade-interval"]')
UPGRADE_INTERVAL=$(echo "$1" | jq -r 'try .["upgrade-interval"]')
if [[ -z "${UPGRADE_INTERVAL}" || "${UPGRADE_INTERVAL}" == "null" ]]; then
UPGRADE_INTERVAL="8h"
fi

UPGRADE_WAIT_AFTER_BOOT=$(echo "${1}" | jq -r '.["upgrade-wait-after-boot"]')
UPGRADE_WAIT_AFTER_BOOT=$(echo "${1}" | jq -r 'try .["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}" | jq -r '.["nofile-limits"]')
NOFILE_LIMITS=$(echo "${1}" | jq -r 'try .["nofile-limits"]')
if [[ -z "${NOFILE_LIMITS}" || "${NOFILE_LIMITS}" == "null" ]]; then
NOFILE_LIMITS=false
fi

BREW_ANALYTICS=$(echo "${1}" | jq -r '.["brew-analytics"]')
BREW_ANALYTICS=$(echo "${1}" | jq -r 'try .["brew-analytics"]')
if [[ -z "${BREW_ANALYTICS}" || "${BREW_ANALYTICS}" == "null" ]]; then
BREW_ANALYTICS=true
fi
Expand Down
16 changes: 8 additions & 8 deletions modules/chezmoi/chezmoi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ if [[ $DEBUG == true ]]; then
fi

# The repository with your chezmoi dotfiles. (default: null)
DOTFILE_REPOSITORY=$(echo "$1" | jq -r '.["repository"]') # (string)
DOTFILE_REPOSITORY=$(echo "$1" | jq -r 'try .["repository"]') # (string)
# The chezmoi repository branch to use.
DOTFILE_BRANCH=$(echo "$1" | jq -r '.["branch"]')
DOTFILE_BRANCH=$(echo "$1" | jq -r 'try .["branch"]')
if [[ -n "${DOTFILE_BRANCH}" && "${DOTFILE_BRANCH}" != "null" ]]; then
INIT_BRANCH_FLAG="--branch ${DOTFILE_BRANCH}"
else
Expand All @@ -36,7 +36,7 @@ fi
#
# To turn on lingering for a given user, run the following commmand with sudo:
# 'sudo loginctl enable-linger <username>'
ALL_USERS=$(echo "$1" | jq -r '.["all-users"]') # (boolean)
ALL_USERS=$(echo "$1" | jq -r 'try .["all-users"]') # (boolean)
if [[ -z $ALL_USERS || $ALL_USERS == "null" ]]; then
ALL_USERS=true
fi
Expand All @@ -45,32 +45,32 @@ 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" | jq -r '.["run-every"]') # (string)
RUN_EVERY=$(echo "$1" | jq -r 'try .["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" | jq -r '.["wait-after-boot"]') # (string)
WAIT_AFTER_BOOT=$(echo "$1" | jq -r 'try .["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" | jq -r '.["disable-init"]') # (boolean)
DISABLE_INIT=$(echo "$1" | jq -r 'try .["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" | jq -r '.["disable-update"]') # (boolean)
DISABLE_UPDATE=$(echo "$1" | jq -r 'try .["disable-update"]') # (boolean)
if [[ -z $DISABLE_UPDATE || $DISABLE_UPDATE == "null" ]]; then
DISABLE_UPDATE=false
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" | jq -r '.["file-conflict-policy"]') # (string)
FILE_CONFLICT_POLICY=$(echo "$1" | jq -r 'try .["file-conflict-policy"]') # (string)
if [[ -z $FILE_CONFLICT_POLICY || $FILE_CONFLICT_POLICY == "null" ]]; then
FILE_CONFLICT_POLICY="skip"
fi
Expand Down
32 changes: 16 additions & 16 deletions modules/default-flatpaks/v1/default-flatpaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ configure_flatpak_repo () {
CONFIG_FILE=$1
INSTALL_LEVEL=$2
REPO_INFO="/usr/share/bluebuild/default-flatpaks/$INSTALL_LEVEL/repo-info.yml"
get_json_array INSTALL "try .$INSTALL_LEVEL.install[]" "$CONFIG_FILE"
get_json_array INSTALL "try .["$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=$(jq -r '.["repo-url"]' "$REPO_INFO")
CONFIG_NAME=$(jq -r '.["repo-name"]' "$REPO_INFO")
CONFIG_TITLE=$(jq -r '.["repo-title"]' "$REPO_INFO")
CONFIG_URL=$(jq -r 'try .["repo-url"]' "$REPO_INFO")
CONFIG_NAME=$(jq -r 'try .["repo-name"]' "$REPO_INFO")
CONFIG_TITLE=$(jq -r 'try .["repo-title"]' "$REPO_INFO")
else
CONFIG_URL="null"
CONFIG_NAME="null"
CONFIG_TITLE="null"
fi

echo "Configuring $INSTALL_LEVEL repo in $REPO_INFO"
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"]')
REPO_URL=$(echo "$CONFIG_FILE" | jq -r 'try .["$INSTALL_LEVEL.repo-url"]')
REPO_NAME=$(echo "$CONFIG_FILE" | jq -r 'try .["$INSTALL_LEVEL.repo-name"]')
REPO_TITLE=$(echo "$CONFIG_FILE" | jq -r 'try .["$INSTALL_LEVEL.repo-title"]')

# If repo-name isn't configured, use flathub as fallback
# Checked separately from URL to allow custom naming
Expand Down Expand Up @@ -85,8 +85,8 @@ configure_lists () {
INSTALL_LEVEL=$2
INSTALL_LIST="/usr/share/bluebuild/default-flatpaks/$INSTALL_LEVEL/install"
REMOVE_LIST="/usr/share/bluebuild/default-flatpaks/$INSTALL_LEVEL/remove"
get_json_array INSTALL "try .$INSTALL_LEVEL.install[]" "$CONFIG_FILE"
get_json_array REMOVE "try .$INSTALL_LEVEL.remove[]" "$CONFIG_FILE"
get_json_array INSTALL "try .["$INSTALL_LEVEL.install"][]" "$CONFIG_FILE"
get_json_array REMOVE "try .["$INSTALL_LEVEL.remove"][]" "$CONFIG_FILE"

echo "Creating $INSTALL_LEVEL Flatpak install list at $INSTALL_LIST"
if [[ ${#INSTALL[@]} -gt 0 ]]; then
Expand All @@ -107,21 +107,21 @@ configure_lists () {

check_flatpak_id_validity_from_flathub () {
if [[ -f "/usr/share/bluebuild/default-flatpaks/system/repo-info.yml" ]]; then
SYSTEM_FLATHUB_REPO=$(jq -r '.["repo-url"]' "/usr/share/bluebuild/default-flatpaks/system/repo-info.yml")
SYSTEM_FLATHUB_REPO=$(jq -r 'try .["repo-url"]' "/usr/share/bluebuild/default-flatpaks/system/repo-info.yml")
else
SYSTEM_FLATHUB_REPO=""
fi
if [[ -f "/usr/share/bluebuild/default-flatpaks/user/repo-info.yml" ]]; then
USER_FLATHUB_REPO=$(jq -r '.["repo-url"]' "/usr/share/bluebuild/default-flatpaks/user/repo-info.yml")
USER_FLATHUB_REPO=$(jq -r 'try .["repo-url"]' "/usr/share/bluebuild/default-flatpaks/user/repo-info.yml")
else
USER_FLATHUB_REPO=""
fi
FLATHUB_REPO_LINK="https://dl.flathub.org/repo/flathub.flatpakrepo"
URL="https://flathub.org/apps"
CONFIG_FILE="${1}"
INSTALL_LEVEL="${2}"
get_json_array INSTALL "try .$INSTALL_LEVEL.install[]" "${CONFIG_FILE}"
get_json_array REMOVE "try .$INSTALL_LEVEL.remove[]" "${CONFIG_FILE}"
get_json_array INSTALL "try .["$INSTALL_LEVEL.install"][]" "${CONFIG_FILE}"
get_json_array REMOVE "try .["$INSTALL_LEVEL.remove"][]" "${CONFIG_FILE}"
if [[ "${SYSTEM_FLATHUB_REPO}" == "${FLATHUB_REPO_LINK}" ]] || [[ "${USER_FLATHUB_REPO}" == "${FLATHUB_REPO_LINK}" ]]; then
echo "Safe-checking if ${INSTALL_LEVEL} flatpak IDs are typed correctly. If test fails, build also fails"
if [[ ${#INSTALL[@]} -gt 0 ]]; then
Expand Down Expand Up @@ -155,7 +155,7 @@ systemctl enable -f system-flatpak-setup.timer
systemctl enable -f --global user-flatpak-setup.timer

# Check that `system` is present before configuring. Also copy template list files before writing Flatpak IDs.
if [[ ! $(echo "$1" | jq -r '.["system"]') == "null" ]]; then
if [[ ! $(echo "$1" | jq -r 'try .["system"]') == "null" ]]; then
configure_flatpak_repo "$1" "system"
if [ ! -f "/usr/share/bluebuild/default-flatpaks/system/install" ]; then
cp -r "$MODULE_DIRECTORY"/default-flatpaks/config/system/install /usr/share/bluebuild/default-flatpaks/system/install
Expand All @@ -167,7 +167,7 @@ if [[ ! $(echo "$1" | jq -r '.["system"]') == "null" ]]; then
fi

# Check that `user` is present before configuring. Also copy template list files before writing Flatpak IDs.
if [[ ! $(echo "$1" | jq -r '.["user"]') == "null" ]]; then
if [[ ! $(echo "$1" | jq -r 'try .["user"]') == "null" ]]; then
configure_flatpak_repo "$1" "user"
if [ ! -f "/usr/share/bluebuild/default-flatpaks/user/install" ]; then
cp -r "$MODULE_DIRECTORY"/default-flatpaks/config/user/install /usr/share/bluebuild/default-flatpaks/user/install
Expand All @@ -183,7 +183,7 @@ check_flatpak_id_validity_from_flathub "${1}" "system"
check_flatpak_id_validity_from_flathub "${1}" "user"

echo "Configuring default-flatpaks notifications"
NOTIFICATIONS=$(echo "$1" | jq -r '.["notify"]')
NOTIFICATIONS=$(echo "$1" | jq -r 'try .["notify"]')
CONFIG_NOTIFICATIONS="/usr/share/bluebuild/default-flatpaks/notifications"
cp -r "${MODULE_DIRECTORY}/default-flatpaks/config/notifications" "${CONFIG_NOTIFICATIONS}"
if [[ -z "${NOTIFICATIONS}" ]] || [[ "${NOTIFICATIONS}" == "null" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions modules/default-flatpaks/v1/system-flatpak-setup
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ check_internet_connection() {
}

REPO_INFO="/usr/share/bluebuild/default-flatpaks/system/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)
REPO_URL=$(jq -r 'try .["repo-url"]' $REPO_INFO)
REPO_NAME=$(jq -r 'try .["repo-name"]' $REPO_INFO)
REPO_TITLE=$(jq -r 'try .["repo-title"]' $REPO_INFO)

# Opt out of and remove Fedora's system flatpak repos
FLATPAK_SYSTEM_REMOTES=($(flatpak --system remotes))
Expand Down
6 changes: 3 additions & 3 deletions modules/default-flatpaks/v1/user-flatpak-setup
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ check_internet_connection() {
}

REPO_INFO="/usr/share/bluebuild/default-flatpaks/user/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)
REPO_URL=$(jq -r 'try .["repo-url"]' $REPO_INFO)
REPO_NAME=$(jq -r 'try .["repo-name"]' $REPO_INFO)
REPO_TITLE=$(jq -r 'try .["repo-title"]' $REPO_INFO)

# Remove Fedora's flatpak user repos, if they exist
FLATPAK_USER_REMOTES=($(flatpak --user remotes))
Expand Down
6 changes: 3 additions & 3 deletions modules/files/files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [[ ${#FILES[@]} -gt 0 ]]; then
echo "Adding files to image"
for pair in "${FILES[@]}"; do
# Support for legacy recipe format to satisfy transition period to new source/destination recipe format
if [[ $(echo $pair | jq -r '.["source"]') == "null" || -z $(echo $pair | jq -r '.["source"]') ]] && [[ $(echo $pair | jq -r '.["destination"]') == "null" || -z $(echo $pair | jq -r '.["destination"]') ]]; then
if [[ $(echo $pair | jq -r 'try .["source"]') == "null" || -z $(echo $pair | jq -r 'try .["source"]') ]] && [[ $(echo $pair | jq -r 'try .["destination"]') == "null" || -z $(echo $pair | jq -r 'try .["destination"]') ]]; then
echo "ATTENTION: You are using the legacy module recipe format"
echo " It is advised to switch to new module recipe format,"
echo " which contains 'source' & 'destination' YAML keys"
Expand All @@ -28,8 +28,8 @@ if [[ ${#FILES[@]} -gt 0 ]]; then
FILE="$PWD/$(echo $pair | jq -r 'to_entries | .[0].key')"
DEST=$(echo $pair | jq -r 'to_entries | .[0].value')
else
FILE="$PWD/$(echo $pair | jq -r '.["source"]')"
DEST=$(echo $pair | jq -r '.["destination"]')
FILE="$PWD/$(echo $pair | jq -r 'try .["source"]')"
DEST=$(echo $pair | jq -r 'try .["destination"]')
fi
if [ -d "$FILE" ]; then
if [ ! -d "$DEST" ]; then
Expand Down
4 changes: 2 additions & 2 deletions modules/justfiles/justfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -euo pipefail

get_json_array CONFIG_SELECTION 'try .include[]' "$1"
VALIDATE="$(echo "$1" | jq -r '.["validate"]')"
get_json_array CONFIG_SELECTION 'try .["include"][]' "$1"
VALIDATE="$(echo "$1" | jq -r 'try .["validate"]')"

IMPORT_FILE="/usr/share/ublue-os/just/60-custom.just"
CONFIG_FOLDER="${CONFIG_DIRECTORY}/justfiles"
Expand Down
2 changes: 1 addition & 1 deletion modules/rpm-ostree/rpm-ostree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ if [[ ${#REPLACE[@]} -gt 0 ]]; then
for REPLACEMENT in "${REPLACE[@]}"; do

# Get repository
REPO=$(echo "${REPLACEMENT}" | jq -r '.["from-repo"]')
REPO=$(echo "${REPLACEMENT}" | jq -r 'try .["from-repo"]')
REPO="${REPO//%OS_VERSION%/${OS_VERSION}}"

# Ensure repository is provided
Expand Down
2 changes: 1 addition & 1 deletion modules/yafti/yafti.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fi

YAFTI_FILE="${FIRSTBOOT_DATA}/yafti.yml"

get_json_array FLATPAKS 'try .custom-flatpaks[]' "$1"
get_json_array FLATPAKS 'try .["custom-flatpaks"][]' "$1"
if [[ ${#FLATPAKS[@]} -gt 0 ]]; then
echo "Adding Flatpaks to yafti.yml"
sed -i '/^ Custom:/,/^ / s/description: .*/description: "Flatpaks suggested by the image maintainer."/' "${YAFTI_FILE}"
Expand Down

0 comments on commit ebfdd8f

Please sign in to comment.