summaryrefslogtreecommitdiff
path: root/build_files/build.sh
blob: 23e86cb4e5fa9349f4ed597da082eb68bdcb141e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash

set -ouex pipefail

case "${BASE_IMAGE:-}" in
  ghcr.io/ublue-os/bazzite-deck:* | ghcr.io/ublue-os/bazzite-deck@*)
    ;;
  *)
    echo "AeroCore OS only supports bazzite-deck BASE_IMAGE values for HTPC game-mode builds: ${BASE_IMAGE:-<unset>}" >&2
    exit 1
    ;;
esac

# Copy the contents of system_files/ of the git repo to /
cp -avf "/ctx/system_files"/. /

# Apply configured Flatpak mirrors to existing installations as well as new
# remotes created from flathub.flatpakrepo during first boot.
systemctl enable aerocore-flatpak-mirror.service

# Keep Bazzite's game mode news hook unchanged; select the matching feed branch.
NEWS_HOOK_CONFIG=/etc/gamemode-news-hook.conf
if [[ ! -f "${NEWS_HOOK_CONFIG}" ]]; then
  echo "Unable to locate game mode news hook config: ${NEWS_HOOK_CONFIG}" >&2
  exit 1
fi
NEWS_BRANCH="${IMAGE_BRANCH:-stable}"
case "${NEWS_BRANCH}" in
  testing|unstable) ;;
  *) NEWS_BRANCH=stable ;;
esac
NEWS_FEED_URL="https://git.mirror.aerocore.com.cn/AeroCore-IO/aerocore-os-gamemode-news/plain/announcements.json?h=${NEWS_BRANCH}"
sed -i \
  "s|^github = .*|github = ${NEWS_FEED_URL}|" \
  "${NEWS_HOOK_CONFIG}"
grep -Fxq \
  "github = ${NEWS_FEED_URL}" \
  "${NEWS_HOOK_CONFIG}"

# Bazzite's Kinoite/Plasma desktop shortcut used to start a privileged
# return-to-gamemode.service.  Current Bazzite invokes the user-session entry
# point directly; keep the shortcut correct when the base image still ships
# the legacy Exec= line.
RETURN_TO_GAMING_DESKTOP="/etc/skel/Desktop/Return.desktop"
if [[ -f "${RETURN_TO_GAMING_DESKTOP}" ]]; then
  sed -i 's|^Exec=.*|Exec=/usr/bin/return-to-gamemode|' "${RETURN_TO_GAMING_DESKTOP}"
fi

# ujust loads explicit imports, not every fragment in the just/ directory.
# Preserve upstream recipes and register our overlay after copying its files.
AEROCORE_DECKY_IMPORT='import "/usr/share/ublue-os/just/92-aerocore-decky-mirror.just"'
if ! grep -Fxq "${AEROCORE_DECKY_IMPORT}" /usr/share/ublue-os/justfile; then
  printf '\n%s\n' "${AEROCORE_DECKY_IMPORT}" >> /usr/share/ublue-os/justfile
fi
# Fail the image build if the public entry point cannot resolve the recipe.
ujust --show setup-decky-mirror >/dev/null

install_regular_file() {
  local source_file="$1"
  local destination_file="$2"

  # Several Bazzite branding paths are symlinks.  cp follows an existing
  # destination symlink, which leaves the name Plasma resolves untouched.
  # Replace the link itself so the final immutable image owns this exact path.
  rm -f -- "${destination_file}"
  install -Dm0644 -- "${source_file}" "${destination_file}"
}

# KDE's Deck presets use distributor-logo-steamdeck.svg for the Kickoff
# launcher.  In the Bazzite base image that name (and the related aliases)
# may already exist as links to the upstream distributor-logo.svg.  Install
# the AeroCore asset explicitly after the general overlay so the final image
# cannot silently retain the upstream Bazzite logo.
AEROCORE_DISTRIBUTOR_LOGO="/ctx/system_files/usr/share/icons/hicolor/scalable/places/distributor-logo.svg"
AEROCORE_ICON_DIR="/usr/share/icons/hicolor/scalable/places"
mkdir -p "${AEROCORE_ICON_DIR}"
for icon_name in \
  distributor-logo.svg \
  distributor-logo-steamdeck.svg \
  bazzite-logo.svg \
  start-here.svg; do
  install_regular_file "${AEROCORE_DISTRIBUTOR_LOGO}" "${AEROCORE_ICON_DIR}/${icon_name}"
done

# Use a downstream-specific, non-upstream icon name for Plasma's launcher.
install_regular_file \
  "/ctx/system_files/usr/share/pixmaps/bazzite-logo-le.svg" \
  "/usr/share/icons/hicolor/scalable/apps/aerocore-logo.svg"

# KDE's About System KCM loads this path from kcm-about-distrorc.  The base
# image may provide it as a symlink, so replace the directory entry itself or
# the KCM can continue rendering the upstream Bazzite logo.
install_regular_file \
  "/ctx/system_files/usr/share/pixmaps/system-logo-white.png" \
  "/usr/share/pixmaps/system-logo-white.png"

# Game Mode's Vapor splash asset is an upstream symlink on current Bazzite
# images, while VGUI is a regular file.  Replace both exact paths explicitly.
for look_and_feel in com.valve.vapor.desktop com.valve.vgui.desktop; do
  install_regular_file \
    "/ctx/system_files/usr/share/plasma/look-and-feel/${look_and_feel}/contents/splash/images/bazzite_logo.svgz" \
    "/usr/share/plasma/look-and-feel/${look_and_feel}/contents/splash/images/bazzite_logo.svgz"
done

# Steam's Game Mode transitions load these four assets directly.  They are
# symlinks in some upstream layers, so replace their directory entries just
# like the Plasma splash assets above.
for animation in \
  bazzite.webm \
  bazzite-oled.webm \
  bazzite-suspend.webm \
  bazzite-suspend-oled.webm; do
  install_regular_file \
    "/ctx/system_files/usr/share/ublue-os/bazzite/${animation}" \
    "/usr/share/ublue-os/bazzite/${animation}"
done

gtk-update-icon-cache -f /usr/share/icons/hicolor || true

# The Plasma launcher resolves the standard start-here name from both scalable
# and per-size places directories.  Populate every existing Bazzite icon size
# in the installed payload, not only in the live installer image.
for icon_dir in /usr/share/icons/hicolor/*; do
  [[ -d "${icon_dir}" ]] || continue
  source_icon="${icon_dir}/bazzite-logo-icon.png"
  if [[ -f "${source_icon}" ]]; then
    mkdir -p "${icon_dir}/apps" "${icon_dir}/places"
    cp -f "${source_icon}" "${icon_dir}/places/start-here.png"
    cp -f "${source_icon}" "${icon_dir}/apps/fedora-logo-icon.png"
  fi
done

if ! cmp -s "${AEROCORE_DISTRIBUTOR_LOGO}" "${AEROCORE_ICON_DIR}/distributor-logo.svg"; then
  echo "AeroCore distributor logo was not installed into the image" >&2
  exit 1
fi

# Default HDMI-CEC to putting the TV into standby when the system sleeps.
# `ujust toggle-cec-sleep enable` changes this same setting at runtime.  Keep
# the default in the base image's config so users do not need to run the
# command manually after a fresh install; the runtime command can still
# change it later.
CEC_CONFIG=/etc/default/cec-control
if [[ -f "${CEC_CONFIG}" ]]; then
  if grep -q '^CEC_ONSLEEP_STANDBY=' "${CEC_CONFIG}"; then
    sed -i 's/^CEC_ONSLEEP_STANDBY=.*/CEC_ONSLEEP_STANDBY=true/' "${CEC_CONFIG}"
  else
    printf '%s\n' 'CEC_ONSLEEP_STANDBY=true' >> "${CEC_CONFIG}"
  fi
fi

configure_mirrors() {
mkdir -p /etc/environment.d

if [[ -n "${FLATPAK_REMOTE_URL:-}" || -n "${HOMEBREW_BOTTLE_DOMAIN:-}" || -n "${HOMEBREW_API_DOMAIN:-}" ]]; then
  : > /etc/environment.d/99-aerocore-mirrors.conf
fi

if [[ -n "${FLATPAK_REMOTE_URL:-}" ]]; then
  printf '%s\n' "FLATPAK_REMOTE_URL=${FLATPAK_REMOTE_URL}" >> /etc/environment.d/99-aerocore-mirrors.conf
  mirror_utils=/usr/libexec/bazzite-mirror-utils.sh
  flatpak_repo=/etc/flatpak/remotes.d/flathub.flatpakrepo
  expected_flatpak_url="${FLATPAK_REMOTE_URL%/}/"
  mirror_updated=false

  if [[ -r "${mirror_utils}" ]] && bash "${mirror_utils}" update_flathub_repo_url "${FLATPAK_REMOTE_URL}"; then
    mirror_updated=true
  fi

  # Keep mirror configuration best-effort. If Bazzite's helper is absent or
  # cannot update the definition, update its Url field directly as a fallback.
  if [[ "${mirror_updated}" != true && -w "${flatpak_repo}" ]]; then
    temp_repo="$(mktemp)"
    if awk -v url="${expected_flatpak_url}" '
      BEGIN { updated = 0 }
      /^Url=/ { print "Url=" url; updated = 1; next }
      { print }
      END { if (!updated) print "Url=" url }
    ' "${flatpak_repo}" > "${temp_repo}" && mv "${temp_repo}" "${flatpak_repo}"; then
      mirror_updated=true
    else
      rm -f "${temp_repo}"
    fi
  fi

  if [[ "${mirror_updated}" == true ]]; then
    echo "Configured Flathub mirror: ${expected_flatpak_url}"
  else
    echo "Warning: could not configure Flathub mirror ${expected_flatpak_url}; keeping the existing repo definition." >&2
  fi
fi

if [[ -n "${HOMEBREW_BOTTLE_DOMAIN:-}" || -n "${HOMEBREW_API_DOMAIN:-}" ]]; then
  mkdir -p /etc/skel/.config/environment.d
  : > /etc/skel/.config/environment.d/99-aerocore-mirrors.conf
fi

if [[ -n "${HOMEBREW_BOTTLE_DOMAIN:-}" ]]; then
  printf '%s\n' "HOMEBREW_BOTTLE_DOMAIN=${HOMEBREW_BOTTLE_DOMAIN}" | tee -a /etc/environment.d/99-aerocore-mirrors.conf /etc/skel/.config/environment.d/99-aerocore-mirrors.conf >/dev/null
fi

if [[ -n "${HOMEBREW_API_DOMAIN:-}" ]]; then
  printf '%s\n' "HOMEBREW_API_DOMAIN=${HOMEBREW_API_DOMAIN}" | tee -a /etc/environment.d/99-aerocore-mirrors.conf /etc/skel/.config/environment.d/99-aerocore-mirrors.conf >/dev/null
fi

find /etc/environment.d /etc/skel/.config/environment.d -name 99-aerocore-mirrors.conf -type f -exec chmod 0644 {} + 2>/dev/null || true
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
  configure_mirrors
fi

/ctx/install-instruments.sh
/ctx/patch-bazzite-deck-identity.sh
/ctx/patch-bazzite-rollback-helper.sh
/ctx/patch-bazzite-os-branch-select.sh