diskOS installer: initial public beta
Flashes the diskOS custom UI onto the FiiO Snowsky Disc over Ingenic mask-ROM USB, building the image from your own stock firmware. Runs from source via install.sh.
This commit is contained in:
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
# diskOS installer - one-time setup.
|
||||
#
|
||||
# Creates a local Python virtual environment (.venv) next to this script and installs the two
|
||||
# pip dependencies (pyusb, pycryptodome) into it. After this you run the tool with ./diskos-installer.
|
||||
#
|
||||
# What this does NOT install (they come from your system, not from us):
|
||||
# - Python 3 itself (install via your OS package manager if missing)
|
||||
# - Tk/tkinter (only needed for the GRAPHICAL installer; CLI works without it)
|
||||
# - libusb-1.0 (needed to talk to the device in mask-ROM mode)
|
||||
# The script checks for these and tells you exactly what to install if any are missing.
|
||||
set -eu
|
||||
|
||||
HERE=$(CDPATH= cd "$(dirname "$0")" && pwd)
|
||||
cd "$HERE"
|
||||
|
||||
# Do NOT run this as root. The installer keeps per-user state and a saved recovery image under your
|
||||
# home directory; running setup as root would create them root-owned and in the wrong place.
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
echo "error: don't run install.sh as root (no sudo). Run it as your normal user;" >&2
|
||||
echo " only the one-time udev rule needs root (see README, 'USB permissions')." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Scratch file for capturing venv-creation errors: created private + removed on exit, never a
|
||||
# fixed /tmp path (a predictable name in a world-writable dir invites a symlink attack).
|
||||
ERRTMP=$(mktemp "${TMPDIR:-/tmp}/diskos_venv.XXXXXX") || { echo "error: mktemp failed" >&2; exit 1; }
|
||||
trap 'rm -f "$ERRTMP"' EXIT INT TERM
|
||||
|
||||
# ---- locate a usable Python 3 -------------------------------------------------
|
||||
PY=""
|
||||
for c in python3 python; do
|
||||
if command -v "$c" >/dev/null 2>&1; then
|
||||
if "$c" -c 'import sys; sys.exit(0 if sys.version_info[:2] >= (3, 8) else 1)' 2>/dev/null; then
|
||||
PY=$(command -v "$c"); break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ -z "$PY" ]; then
|
||||
echo "error: Python 3.8+ not found." >&2
|
||||
echo " Debian/Ubuntu: sudo apt install python3 python3-venv" >&2
|
||||
echo " Fedora: sudo dnf install python3" >&2
|
||||
echo " macOS: brew install python3 (or install from python.org)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "==> using $("$PY" --version 2>&1) at $PY"
|
||||
|
||||
# ---- create the venv ----------------------------------------------------------
|
||||
if [ ! -x "$HERE/.venv/bin/python" ] && [ ! -x "$HERE/.venv/Scripts/python.exe" ]; then
|
||||
echo "==> creating virtual environment in .venv/"
|
||||
if ! "$PY" -m venv "$HERE/.venv" 2>"$ERRTMP"; then
|
||||
echo "error: could not create the virtual environment:" >&2
|
||||
sed 's/^/ /' "$ERRTMP" >&2 2>/dev/null || true
|
||||
echo " Debian/Ubuntu often needs: sudo apt install python3-venv" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "==> reusing existing .venv/"
|
||||
fi
|
||||
VENV_PY="$HERE/.venv/bin/python"
|
||||
[ -x "$VENV_PY" ] || VENV_PY="$HERE/.venv/Scripts/python.exe" # windows layout
|
||||
|
||||
# ---- install pinned dependencies ---------------------------------------------
|
||||
echo "==> installing dependencies (pyusb, pycryptodome)"
|
||||
"$VENV_PY" -m pip install --upgrade pip >/dev/null 2>&1 || true
|
||||
"$VENV_PY" -m pip install -r "$HERE/requirements.txt"
|
||||
|
||||
# ---- capability checks (warn, do not fail) -----------------------------------
|
||||
echo "==> checking optional system components"
|
||||
|
||||
# Tk (GUI only). A venv inherits the base interpreter's tkinter, so this reflects the system Python.
|
||||
if "$VENV_PY" -c 'import tkinter' 2>/dev/null; then
|
||||
echo " ok: tkinter present - the graphical installer will work"
|
||||
else
|
||||
echo " note: tkinter NOT found - the GRAPHICAL installer will not run (the CLI still works)."
|
||||
echo " To enable the GUI, install your system's Tk package, then re-run this script:"
|
||||
echo " Debian/Ubuntu: sudo apt install python3-tk"
|
||||
echo " Fedora: sudo dnf install python3-tkinter"
|
||||
echo " macOS: brew install python-tk (or use python.org's Python, which bundles Tk)"
|
||||
fi
|
||||
|
||||
# libusb-1.0 backend for pyusb (needed to see the device in mask-ROM mode).
|
||||
if "$VENV_PY" -c 'import ctypes.util,sys; sys.exit(0 if ctypes.util.find_library("usb-1.0") else 1)' 2>/dev/null; then
|
||||
echo " ok: libusb-1.0 present - device detection will work"
|
||||
else
|
||||
echo " note: libusb-1.0 NOT found - the tool cannot detect the device until you install it:"
|
||||
echo " Debian/Ubuntu: sudo apt install libusb-1.0-0"
|
||||
echo " Fedora: sudo dnf install libusbx"
|
||||
echo " macOS: brew install libusb"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Setup complete. Run the installer with:"
|
||||
echo " ./diskos-installer doctor # check host + tools + device"
|
||||
echo " ./diskos-installer gui # graphical installer (needs tkinter)"
|
||||
echo " ./diskos-installer --help # all commands"
|
||||
Reference in New Issue
Block a user