Files
firmware/bin/common.sh
T
Oleksandr Shyshatskyi 4415905fb3 Initial commit: USB-installable custom firmware builder for Creator 5
Builds a modified FlashForge update package that the printer installs by
itself from a USB stick, reusing FlashForge's own updater rather than a
parallel one.

Integration is a single file: /usr/prog/PROGRAM/software/firmwareExe is
replaced with a shell script. Everything funnels through that binary, so
app_startup.sh, rcS and the init chain stay completely stock. The genuine
binary is kept as firmwareExe.stock and remains the default UI.

Key findings from the stock firmware, each enforced by a test:
- components named *.tar.xz are PLAIN tar; the installer runs bare `tar -xvf`
- the .tgz is DES3-encrypted plain tar, not gzip
- nothing in init starts Klipper -- firmwareExe runs start.sh, so replacing
  the UI without S70klipper leaves a printer that cannot move
- the installer wipes the software dir before run.sh, so an uninstall package
  must ship the genuine firmwareExe rather than back one up
- ssh already works: stock ships dropbear + an enabled S50dropbear, only the
  root password is missing

Brick-safety is designed in, not bolted on: a five-rung profile ladder
starting with a probe that changes nothing, a container-based simulation that
actually runs the installer and asserts the printer would still boot, an
uninstall round-trip test, and a SAFE-MODE latch for UI crash loops.

75 checks pass. Not yet run on hardware.
2026-08-22 21:48:56 +03:00

31 lines
1022 B
Bash

# Sourced by every script in bin/. Resolves the repo root, loads config.env
# and the selected profile, and exports the feature flags.
#
# Profile selection, in order of precedence:
# PROFILE=web ./bin/build.sh environment
# ./bin/build.sh --profile web argument (parsed by the caller)
# PROFILE in config.env default
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/.." && pwd)"
cd "$ROOT"
if [ ! -f config.env ]; then
if [ -f config.env.example ]; then
echo "no config.env -- copy config.env.example and edit the paths:" >&2
echo " cp config.env.example config.env" >&2
fi
exit 1
fi
# shellcheck disable=SC1091
. ./config.env
PROFILE="${PROFILE:-${DEFAULT_PROFILE:-full}}"
if [ -f "profiles/$PROFILE.env" ]; then
# shellcheck disable=SC1090
. "profiles/$PROFILE.env"
else
echo "unknown profile '$PROFILE' (have: $(ls profiles/*.env 2>/dev/null | xargs -n1 basename 2>/dev/null | sed 's/\.env$//' | tr '\n' ' '))" >&2
exit 1
fi
WORK="${WORK:-work}"