Build a small command-line utility in /app/ that updates Grafana data to reflect Linkerd DevStats branding.
What to implement
A executable script (preferred name: grafana_linkerd_setup.sh) in /app/ that performs two main actions:
Branding text update (optional)
When run with the environment variable SKIPVIM unset, recursively scan textual files under the directory pointed to by GRAFANA_DATA and update branding references from Grafana to Linkerd DevStats. The exact wording used by the test isn’t required to be known here, but the goal is to replace Grafana mentions present in UI text with Linkerd DevStats branding.
If SKIPVIM is set, skip this textual replacement step.
Icon and logo replacement
Replace a specific set of UI assets in GRAFANA_DATA/public/img with Linkerd-provided assets stored in /app/grafana/img/.
For each destination file, preserve a backup if one does not already exist:
Create a backup: copy the current destination to destination.bak using non-destructive semantics (do not overwrite an existing backup).
Overwrite the destination with the corresponding Linkerd asset from the source directory. If the copy fails, exit non-zero.
Exact destination mappings to implement in GRAFANA_DATA/public/img:
GRAFANA_DATA: path to the Grafana data directory to modify (must exist and be writable).
SKIPVIM (optional): if set (any value), skip the branding text replacement step.
Source assets:
Provided Linkerd assets must be present in /app/grafana/img/ (linkerd.svg and linkerd32.png).
Outputs
Modified Grafana data directory (the one pointed to by GRAFANA_DATA) with:
Branding text updated to reflect Linkerd DevStats (when SKIPVIM is not set).
Replaced icons/logos in public/img as described, with backups created as destination.bak where appropriate.
Console output should end with a line containing OK to indicate success.
File locations and naming
Script location: /app/grafana_linkerd_setup.sh
Source assets: /app/grafana/img/
Expect to find linkerd.svg and linkerd32.png there.
Target assets: under the Grafana data directory:
grafana_icon.svg
grafana_com_auth_icon.svg
grafana_net_logo.svg
fav32.png
fav16.png
fav_dark_16.png
fav_dark_32.png
Backups: destination.bak files should be created next to each destination when updating, but only if the backup does not already exist (to avoid overwriting existing backups).
Behavior notes
If GRAFANA_DATA does not exist or is not writable, exit non-zero with a clear error message.
If any required source asset is missing in /app/grafana/img/, fail with a non-zero exit and a descriptive error.
The script should be POSIX-compatible (bash) and robust to repeated runs (idempotent for idempotent parts, e.g., backups won’t be overwritten if already present).
Example usage
export GRAFANA_DATA=/path/to/grafana
./grafana_linkerd_setup.sh
To skip the branding text replacement step:
export SKIPVIM=1
./grafana_linkerd_setup.sh
Note
Focus on implementing the described functionality at /app/ without exposing the test’s internal logic. Ensure the tool behaves deterministically as described above.