|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Tell build process to exit if there are any errors. |
| 4 | +set -euxo pipefail |
| 5 | + |
| 6 | +MODULE_DIRECTORY="${MODULE_DIRECTORY:-"/tmp/modules"}" |
| 7 | + |
| 8 | +FIRSTBOOT_DATA="/usr/share/ublue-os/firstboot" |
| 9 | + |
| 10 | +mkdir -p "$FIRSTBOOT_DATA/launcher/" |
| 11 | + |
| 12 | +# doesn't overwrite user's yafti.yml |
| 13 | +cp --update=none "$MODULE_DIRECTORY/yafti/yafti.yml" "$FIRSTBOOT_DATA/yafti.yml" |
| 14 | +cp -r "$MODULE_DIRECTORY/yafti/launcher/" "$FIRSTBOOT_DATA" |
| 15 | + |
| 16 | +FIRSTBOOT_SCRIPT="${FIRSTBOOT_DATA}/launcher/login-profile.sh" |
| 17 | +PROFILED_DIR="/etc/profile.d" |
| 18 | +FIRSTBOOT_LINK="${PROFILED_DIR}/ublue-firstboot.sh" |
| 19 | + |
| 20 | +# Install yafti |
| 21 | +YAFTI_REPO="https://github.com/fiftydinar/Yafti-AppImage" |
| 22 | +ARCH="$(uname -m)" |
| 23 | +VER=$(basename $(curl -Ls -o /dev/null -w %{url_effective} "$YAFTI_REPO"/releases/latest)) |
| 24 | +curl -fLs --create-dirs "$YAFTI_REPO/releases/download/${VER}/Android_Tools-${VER%@*}-anylinux-${ARCH}.AppImage" -o /usr/bin/yafti |
| 25 | +chmod +x /usr/bin/yafti |
| 26 | + |
| 27 | +# If the profile.d directory doesn't exist, create it |
| 28 | +if [ ! -d "${PROFILED_DIR}" ]; then |
| 29 | + mkdir -p "${PROFILED_DIR}" |
| 30 | +fi |
| 31 | + |
| 32 | +# Create symlink to our profile script, which creates the per-user "autorun yafti" links. |
| 33 | +if [ -f "${FIRSTBOOT_SCRIPT}" ]; then |
| 34 | + ln -sf "${FIRSTBOOT_SCRIPT}" "${FIRSTBOOT_LINK}" |
| 35 | +fi |
| 36 | + |
| 37 | +YAFTI_FILE="${FIRSTBOOT_DATA}/yafti.yml" |
| 38 | + |
| 39 | +get_json_array FLATPAKS 'try .["custom-flatpaks"][]' "${1}" |
| 40 | +if [[ ${#FLATPAKS[@]} -gt 0 ]]; then |
| 41 | + echo "Adding Flatpaks to yafti.yml" |
| 42 | + sed -i -e '/- Boatswain for Streamdeck: com.feaneron.Boatswain/a \ |
| 43 | + Custom:\n description: Flatpaks suggested by the image maintainer.\n default: true' "${YAFTI_FILE}" |
| 44 | + |
| 45 | + for pkg in "${FLATPAKS[@]}"; do |
| 46 | + echo "Adding to yafti: ${pkg}" |
| 47 | + sed -i '/^[[:space:]]*Custom:/ { |
| 48 | + n; n; n; |
| 49 | + i\ |
| 50 | + - REPLACEMEHERE |
| 51 | + }' "${YAFTI_FILE}" |
| 52 | + sed -i "s/ - REPLACEMEHERE/ - ${pkg}/g" "${YAFTI_FILE}" |
| 53 | + done |
| 54 | +fi |
0 commit comments