mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-17 22:13:17 +08:00
🎄 Sync 2026-11-14 17:29:54
This commit is contained in:
1 parent
00efd4e7cf
commit
4e24fe7535
123 files changed
+26051
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Concatenate styles/NN-*.css into htdocs/luci-static/carbon/carbon.css.
|
||||
|
||||
python3 -I scripts/build-css.py write carbon.css
|
||||
python3 -I scripts/build-css.py --check CI: fail if carbon.css is stale
|
||||
|
||||
carbon.css is committed so every install path (SDK, installer, .ipk, demo)
|
||||
ships one stylesheet request without a build step. Edit the files in styles/.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
SOURCES = ROOT / 'styles'
|
||||
TARGET = ROOT / 'htdocs' / 'luci-static' / 'carbon' / 'carbon.css'
|
||||
BANNER = '/* Generated by scripts/build-css.py from styles/*.css. Do not edit. */\n\n'
|
||||
|
||||
|
||||
def build():
|
||||
files = sorted(SOURCES.glob('[0-9][0-9]-*.css'))
|
||||
if not files or files[0].name != '00-header.css':
|
||||
raise SystemExit('styles/00-header.css must exist and sort first')
|
||||
parts = [f.read_text(encoding='utf-8') for f in files]
|
||||
return parts[0] + BANNER + ''.join(parts[1:])
|
||||
|
||||
|
||||
def main(check):
|
||||
text = build()
|
||||
current = TARGET.read_text(encoding='utf-8') if TARGET.exists() else None
|
||||
if check:
|
||||
if current != text:
|
||||
print('carbon.css is stale: run python3 -I scripts/build-css.py', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
if current != text:
|
||||
TARGET.write_text(text, encoding='utf-8')
|
||||
print('wrote', TARGET.relative_to(ROOT))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main('--check' in sys.argv))
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Package the static preview and the actual theme assets for GitHub Pages."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
OUTPUT = ROOT / "dist" / "demo"
|
||||
THEME_PREFIX = "../htdocs/luci-static/carbon/"
|
||||
VERSION = (ROOT / "root" / "usr" / "share" / "carbon" / "version").read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
def build():
|
||||
# Clean only the generated demo directory, never a symlink or an external path.
|
||||
if OUTPUT.is_symlink() or OUTPUT.resolve() != ROOT.resolve() / "dist" / "demo":
|
||||
raise RuntimeError(f"Unsafe demo output directory: {OUTPUT}")
|
||||
if OUTPUT.exists():
|
||||
shutil.rmtree(OUTPUT)
|
||||
OUTPUT.mkdir(parents=True)
|
||||
for name in ("index.html", "login.html", "form.html", "lang.js", "mock.js", "demo.js", "demo.css"):
|
||||
content = (ROOT / "preview" / name).read_text(encoding="utf-8")
|
||||
if name.endswith(".html"):
|
||||
content = content.replace(THEME_PREFIX, "assets/carbon/")
|
||||
# Same cache-busting version parameter the theme header adds.
|
||||
content = content.replace('assets/carbon/carbon.js"', f'assets/carbon/carbon.js?v={VERSION}"')
|
||||
(OUTPUT / name).write_text(content, encoding="utf-8")
|
||||
assets = OUTPUT / "assets" / "carbon"
|
||||
assets.mkdir(parents=True)
|
||||
for name in ("carbon.css", "carbon.js", "brands.js", "logo.svg"):
|
||||
shutil.copyfile(ROOT / "htdocs" / "luci-static" / "carbon" / name, assets / name)
|
||||
shutil.copytree(ROOT / "htdocs" / "luci-static" / "carbon" / "i18n", assets / "i18n")
|
||||
shutil.copyfile(ROOT / "LICENSE", OUTPUT / "LICENSE")
|
||||
(OUTPUT / ".nojekyll").touch()
|
||||
print(f"Built Carbon demo: {OUTPUT}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
build()
|
||||
Executable
+86
@@ -0,0 +1,86 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Build carbon-install.sh — a single self-extracting installer for opkg and
|
||||
# apk based OpenWrt / ImmortalWrt (LuCI 23.05+).
|
||||
#
|
||||
# Usage: sh scripts/build-installer.sh [output-dir] [--ipk FILE] [--apk FILE] [--key FILE]
|
||||
# --ipk .ipk to embed for opkg (default: built with scripts/build-ipk.sh)
|
||||
# --apk signed .apk to embed for apk systems (release builds). Without it,
|
||||
# apk systems fall back to copying files (no online updates).
|
||||
# --key public key that verifies --apk (default: keys/carbon-apk.pem)
|
||||
#
|
||||
# The --files payload is taken from the .ipk, so both install modes ship
|
||||
# exactly the same theme files.
|
||||
#
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
OUT=''
|
||||
IPK=''
|
||||
APK=''
|
||||
KEY="$ROOT/keys/carbon-apk.pem"
|
||||
die() { echo "build-installer: $*" >&2; exit 1; }
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--ipk) [ "$#" -ge 2 ] || die "--ipk needs a file"; IPK=$2; shift 2 ;;
|
||||
--apk) [ "$#" -ge 2 ] || die "--apk needs a file"; APK=$2; shift 2 ;;
|
||||
--key) [ "$#" -ge 2 ] || die "--key needs a file"; KEY=$2; shift 2 ;;
|
||||
-*) die "unknown option $1" ;;
|
||||
*) OUT=$1; shift ;;
|
||||
esac
|
||||
done
|
||||
OUT=${OUT:-"$ROOT/dist"}
|
||||
VER=$(sed -n 's/^PKG_VERSION:=//p' "$ROOT/Makefile")
|
||||
REL=$(sed -n 's/^PKG_RELEASE:=//p' "$ROOT/Makefile")
|
||||
FULLVER="$VER-r$REL"
|
||||
mkdir -p "$OUT" && OUT=$(cd "$OUT" && pwd) # absolute: later steps run from a temp dir
|
||||
TARGET="$OUT/carbon-install.sh"
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/carbon-inst.XXXXXX")
|
||||
cleanup() { [ -n "$WORK" ] && [ -d "$WORK" ] && rm -r "$WORK"; }
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
PAYLOAD="$WORK/payload"
|
||||
mkdir -p "$PAYLOAD/pkg" "$PAYLOAD/files"
|
||||
|
||||
if [ -z "$IPK" ]; then
|
||||
sh "$ROOT/scripts/build-ipk.sh" "$WORK/ipk" >/dev/null
|
||||
IPK=$(ls "$WORK"/ipk/*.ipk)
|
||||
fi
|
||||
[ -s "$IPK" ] || die "missing .ipk: $IPK"
|
||||
[ -s "$KEY" ] || die "missing public key: $KEY"
|
||||
|
||||
ipk_version=$(tar -xzOf "$IPK" ./control.tar.gz | tar -xzOf - ./control | sed -n 's/^Version: //p')
|
||||
[ -n "$ipk_version" ] || die "cannot read the .ipk version"
|
||||
[ "$ipk_version" = "$FULLVER" ] || echo "build-installer: note: .ipk is $ipk_version, Makefile is $FULLVER" >&2
|
||||
cp "$IPK" "$PAYLOAD/pkg/luci-theme-carbon.ipk"
|
||||
printf '%s\n' "$ipk_version" > "$PAYLOAD/pkg/opkg.version"
|
||||
tar -xzOf "$IPK" ./data.tar.gz | tar -xzf - -C "$PAYLOAD/files" ./www ./usr
|
||||
|
||||
if [ -n "$APK" ]; then
|
||||
[ -s "$APK" ] || die "missing .apk: $APK"
|
||||
apk_version=$(basename "$APK" | sed -n 's/^luci-theme-carbon-\([0-9][^/]*-r[0-9]*\)\.apk$/\1/p')
|
||||
[ -n "$apk_version" ] || die "expected luci-theme-carbon-VERSION-rN.apk, got $(basename "$APK")"
|
||||
cp "$APK" "$PAYLOAD/pkg/luci-theme-carbon.apk"
|
||||
printf '%s\n' "$apk_version" > "$PAYLOAD/pkg/apk.version"
|
||||
else
|
||||
echo "build-installer: no --apk given; apk systems will fall back to copying files" >&2
|
||||
fi
|
||||
cp "$KEY" "$PAYLOAD/pkg/carbon-apk.pem"
|
||||
|
||||
if tar --version 2>/dev/null | grep -q 'GNU tar'; then
|
||||
TAROPTS="--format=ustar --owner=0 --group=0 --numeric-owner"
|
||||
else
|
||||
export COPYFILE_DISABLE=1
|
||||
TAROPTS="--format ustar --uid 0 --gid 0 --uname root --gname root --no-xattrs --no-mac-metadata"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
(cd "$PAYLOAD" && tar $TAROPTS -czf "$WORK/payload.tar.gz" ./pkg ./files)
|
||||
|
||||
sed "s/@VERSION@/$FULLVER/" "$ROOT/scripts/installer-head.sh" > "$TARGET"
|
||||
printf '__CARBON_PAYLOAD__\n' >> "$TARGET"
|
||||
cat "$WORK/payload.tar.gz" >> "$TARGET"
|
||||
chmod 0755 "$TARGET"
|
||||
|
||||
echo "Built $TARGET ($(du -k "$TARGET" | cut -f1) KB; ipk $ipk_version${APK:+, apk $apk_version})"
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Build luci-theme-carbon_<version>_all.ipk without the OpenWrt SDK.
|
||||
#
|
||||
# The theme is architecture independent (CSS/JS/templates only), so a
|
||||
# plain tar-based .ipk works on every OpenWrt 23.05 / 24.10 device that
|
||||
# uses opkg. For OpenWrt 25.x (apk) build with the SDK and the Makefile.
|
||||
#
|
||||
# Usage: sh scripts/build-ipk.sh [output-dir]
|
||||
#
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
OUT=${1:-"$ROOT/dist"}
|
||||
PKG=luci-theme-carbon
|
||||
VER=$(sed -n 's/^PKG_VERSION:=//p' "$ROOT/Makefile")
|
||||
REL=$(sed -n 's/^PKG_RELEASE:=//p' "$ROOT/Makefile")
|
||||
FULLVER="$VER-r$REL"
|
||||
mkdir -p "$OUT" && OUT=$(cd "$OUT" && pwd) # absolute: later steps run from a temp dir
|
||||
IPK="$OUT/${PKG}_${FULLVER}_all.ipk"
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/carbon-ipk.XXXXXX")
|
||||
cleanup() { [ -n "$WORK" ] && [ -d "$WORK" ] && rm -r "$WORK"; }
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
DATA="$WORK/data"
|
||||
CTRL="$WORK/control"
|
||||
mkdir -p "$DATA/www" "$DATA/usr/share/ucode/luci" "$CTRL" "$OUT"
|
||||
|
||||
# --- payload (same layout luci.mk produces) -------------------------------
|
||||
cp -R "$ROOT/htdocs/." "$DATA/www/"
|
||||
cp -R "$ROOT/ucode/." "$DATA/usr/share/ucode/luci/"
|
||||
cp -R "$ROOT/root/." "$DATA/"
|
||||
chmod 0755 "$DATA/etc/uci-defaults/30_luci-theme-carbon"
|
||||
chmod 0755 "$DATA/usr/libexec/rpcd/luci.carbon_update"
|
||||
find "$DATA" -name '.DS_Store' -exec rm {} +
|
||||
|
||||
SIZE=$(du -sk "$DATA" | cut -f1)
|
||||
|
||||
# --- control files --------------------------------------------------------
|
||||
cat > "$CTRL/control" <<EOF
|
||||
Package: $PKG
|
||||
Version: $FULLVER
|
||||
Depends: luci-base, curl, ca-bundle, flock
|
||||
Source: $PKG
|
||||
SourceName: $PKG
|
||||
License: Apache-2.0
|
||||
Section: luci
|
||||
URL: https://github.com/openwrt/luci
|
||||
Architecture: all
|
||||
Installed-Size: $((SIZE * 1024))
|
||||
Description: Carbon - an Apple-style LuCI theme for everyday users.
|
||||
Simple / Pro navigation, chart based dashboard, dark mode, mobile layout.
|
||||
EOF
|
||||
|
||||
cat > "$CTRL/postinst" <<'EOF'
|
||||
#!/bin/sh
|
||||
[ -n "${IPKG_INSTROOT:-}" ] && exit 0
|
||||
if [ -f /etc/uci-defaults/30_luci-theme-carbon ]; then
|
||||
( . /etc/uci-defaults/30_luci-theme-carbon ) && rm -f /etc/uci-defaults/30_luci-theme-carbon
|
||||
fi
|
||||
rm -f /tmp/luci-indexcache* 2>/dev/null
|
||||
rm -rf /tmp/luci-modulecache 2>/dev/null
|
||||
/etc/init.d/rpcd reload 2>/dev/null
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
cat > "$CTRL/postrm" <<'EOF'
|
||||
#!/bin/sh
|
||||
if [ "${PKG_UPGRADE:-}" = 1 ] || [ "${1:-}" = upgrade ]; then exit 0; fi
|
||||
[ -n "${IPKG_INSTROOT:-}" ] && exit 0
|
||||
uci -q delete luci.themes.Carbon
|
||||
if [ "$(uci -q get luci.main.mediaurlbase)" = "/luci-static/carbon" ]; then
|
||||
if [ -d /www/luci-static/bootstrap ]; then
|
||||
uci set luci.main.mediaurlbase=/luci-static/bootstrap
|
||||
else
|
||||
uci -q delete luci.main.mediaurlbase
|
||||
fi
|
||||
fi
|
||||
uci commit luci
|
||||
rm -f /etc/config/carbon
|
||||
rm -rf /www/luci-static/carbon/custom
|
||||
rmdir /www/luci-static/carbon 2>/dev/null
|
||||
rm -f /tmp/luci-indexcache* 2>/dev/null
|
||||
/etc/init.d/rpcd reload 2>/dev/null
|
||||
exit 0
|
||||
EOF
|
||||
chmod 0755 "$CTRL/postinst" "$CTRL/postrm"
|
||||
echo "2.0" > "$WORK/debian-binary"
|
||||
|
||||
# --- pack (gzip'd tar of tars, like OpenWrt's ipkg-build) -----------------
|
||||
if tar --version 2>/dev/null | grep -q 'GNU tar'; then
|
||||
TAROPTS="--format=gnu --owner=0 --group=0 --numeric-owner --sort=name"
|
||||
else
|
||||
# bsdtar (macOS): strip resource forks / xattrs, force root ownership
|
||||
export COPYFILE_DISABLE=1
|
||||
TAROPTS="--format ustar --uid 0 --gid 0 --uname root --gname root --no-xattrs --no-mac-metadata"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
(cd "$DATA" && tar $TAROPTS -czf "$WORK/data.tar.gz" .)
|
||||
# shellcheck disable=SC2086
|
||||
(cd "$CTRL" && tar $TAROPTS -czf "$WORK/control.tar.gz" .)
|
||||
# shellcheck disable=SC2086
|
||||
(cd "$WORK" && tar $TAROPTS -czf "$IPK" ./debian-binary ./data.tar.gz ./control.tar.gz)
|
||||
|
||||
echo "Built $IPK ($(du -k "$IPK" | cut -f1) KB)"
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# The Makefile is the single version source. root/usr/share/carbon/version is
|
||||
# its packaged copy; the theme header and carbon.js read it at runtime.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
ver="$(sed -n 's/^PKG_VERSION:=//p' Makefile)-r$(sed -n 's/^PKG_RELEASE:=//p' Makefile)"
|
||||
if [ "$(cat root/usr/share/carbon/version)" != "$ver" ]; then
|
||||
echo "root/usr/share/carbon/version must contain $ver" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -rnE '\?v=[0-9]|C\.version *= *.[0-9]' ucode htdocs; then
|
||||
echo "Hard-coded theme version found; read it from /usr/share/carbon/version instead" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "version $ver"
|
||||
Executable
+217
@@ -0,0 +1,217 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate htdocs/luci-static/carbon/brands.js — brand icons + device
|
||||
recognition data for the dashboard's "Connected Devices" list.
|
||||
|
||||
Sources (downloaded into a cache dir, nothing is executed from them):
|
||||
* Simple Icons (CC0 1.0) https://simpleicons.org — brand glyph paths
|
||||
* IEEE MA-L OUI registry https://standards-oui.ieee.org/oui/oui.csv
|
||||
|
||||
Usage: python3 -I scripts/gen-brands.py [cache-dir]
|
||||
"""
|
||||
import base64
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
SI_VERSION = "16.37.0"
|
||||
SI_BASE = f"https://cdn.jsdelivr.net/npm/simple-icons@{SI_VERSION}"
|
||||
OUI_URL = "https://standards-oui.ieee.org/oui/oui.csv"
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
OUT = os.path.join(ROOT, "htdocs", "luci-static", "carbon", "brands.js")
|
||||
CACHE = sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, ".cache", "brands")
|
||||
|
||||
# key: (display name, avatar style, OUI organisation regex or None)
|
||||
# avatar style: ("icon", simple-icons slug, bg, fg)
|
||||
# ("mono", letter, bg, fg)
|
||||
# ("glyph", carbon icon name, bg)
|
||||
# bg/fg may be CSS values; "INV" = inverted neutral (dark on light theme,
|
||||
# light on dark theme) for brands whose colour is black or white.
|
||||
BRANDS = {
|
||||
"apple": ("Apple", ("icon", "apple", "INV"), r"^Apple, Inc"),
|
||||
"xiaomi": ("Xiaomi", ("icon", "xiaomi", "#FF6900"), r"Xiaomi"),
|
||||
"huawei": ("Huawei", ("icon", "huawei", "#FF0000"), r"Huawei|HUAWEI"),
|
||||
"honor": ("Honor", ("mono", "H", "INV"), r"Honor Device"),
|
||||
"samsung": ("Samsung", ("mono", "S", "#1428A0"), r"^Samsung Electronics"),
|
||||
"oppo": ("OPPO", ("mono", "O", "#2D683D"), r"Oppo|OPPO"),
|
||||
"vivo": ("vivo", ("mono", "v", "#415FFF"), r"vivo Mobile"),
|
||||
"oneplus": ("OnePlus", ("icon", "oneplus", "#F5010C"), r"OnePlus"),
|
||||
"realme": ("realme", ("mono", "r", "#FFC915", "#1d1d1f"), r"Realme"),
|
||||
"meizu": ("Meizu", ("icon", "meizu", "#FF4132"), None),
|
||||
"google": ("Google", ("icon", "google", "#4285F4"), r"^Google"),
|
||||
"android": ("Android", ("icon", "android", "#3DDC84"), None),
|
||||
"amazon": ("Amazon", ("glyph", "speaker", "#FF9900"), r"^Amazon"),
|
||||
"nintendo": ("Nintendo", ("glyph", "gamepad", "#E60012"), r"Nintendo"),
|
||||
"playstation": ("PlayStation", ("icon", "playstation", "#0070D1"), r"Sony Interactive"),
|
||||
"sony": ("Sony", ("mono", "S", "INV"), r"^Sony"),
|
||||
"microsoft": ("Microsoft", ("glyph", "pc", "#737373"), r"^Microsoft"),
|
||||
"windows": ("Windows", ("glyph", "pc", "#0078D4"), None),
|
||||
"lenovo": ("Lenovo", ("mono", "L", "#E2231A"), r"Lenovo"),
|
||||
"dell": ("Dell", ("icon", "dell", "#007DB8"), r"^Dell"),
|
||||
"hp": ("HP", ("icon", "hp", "#0096D6"), r"^HP |^Hewlett Packard|^HP Inc"),
|
||||
"asus": ("ASUS", ("mono", "A", "INV"), r"ASUSTek"),
|
||||
"tplink": ("TP-Link", ("icon", "tplink", "#4ACBD6"), r"TP-LINK|TP-Link"),
|
||||
"raspberrypi": ("Raspberry Pi", ("icon", "raspberrypi", "#A22846"), r"Raspberry Pi"),
|
||||
"synology": ("Synology", ("mono", "S", "#3A3A3C"), r"Synology"),
|
||||
"espressif": ("Espressif", ("icon", "espressif", "#E7352C"), r"Espressif"),
|
||||
"lg": ("LG", ("icon", "lg", "#A50034"), r"^LG Electronics"),
|
||||
"roku": ("Roku", ("mono", "R", "#662D91"), r"^Roku"),
|
||||
"dji": ("DJI", ("icon", "dji", "INV"), r"DJI"),
|
||||
"ubiquiti": ("Ubiquiti", ("icon", "ubiquiti", "#0559C9"), r"Ubiquiti"),
|
||||
"philipshue": ("Philips Hue", ("icon", "philipshue", "#0065D3"), r"Signify|Philips Lighting"),
|
||||
"zte": ("ZTE", ("mono", "Z", "#0081CC"), r"^zte|ZTE Corporation"),
|
||||
"tcl": ("TCL", ("mono", "T", "#E4002B"), r"^TCL"),
|
||||
"hisense": ("Hisense", ("mono", "H", "#00A99D"), r"Hisense"),
|
||||
"midea": ("Midea", ("mono", "M", "#03B0EF"), r"Midea (Group|Air|Electric)"),
|
||||
"haier": ("Haier", ("mono", "H", "#005AAB"), r"Haier"),
|
||||
# Wi-Fi chip vendors: no brand shown, only a "computer" hint
|
||||
"_pc": (None, ("glyph", "pc", None), r"^Intel Corporate|^Liteon|^AzureWave|^Realtek"),
|
||||
}
|
||||
|
||||
# Hostname rules, first match wins: (regex, brand key or None, device type)
|
||||
HOST_RULES = [
|
||||
(r"iphone", "apple", "phone"),
|
||||
(r"ipad", "apple", "tablet"),
|
||||
(r"macbook|imac|mac-?mini|mac-?pro|mac-?studio|^mac\b", "apple", "pc"),
|
||||
(r"apple-?tv|appletv", "apple", "tv"),
|
||||
(r"homepod", "apple", "speaker"),
|
||||
(r"apple-?watch|ipod|airport|apple", "apple", None),
|
||||
(r"redmi|xiaomi|^mi[-_ ]|^mi\d|poco|mijia|miwifi|xiaoai|zhimi|chuangmi|yeelink|lumi-|roborock|dreame|viomi|mibox|mitv", "xiaomi", None),
|
||||
(r"honor", "honor", "phone"),
|
||||
(r"huawei|matebook|matepad|harmony", "huawei", None),
|
||||
(r"samsung|galaxy|^sm-[a-z]\d", "samsung", None),
|
||||
(r"oneplus", "oneplus", "phone"),
|
||||
(r"realme|^rmx\d", "realme", "phone"),
|
||||
(r"oppo|^cph\d|^pd[a-z]m\d", "oppo", "phone"),
|
||||
(r"vivo|iqoo", "vivo", "phone"),
|
||||
(r"meizu", "meizu", "phone"),
|
||||
(r"pixel|chromecast|google|nest-?(hub|mini|audio|wifi)", "google", None),
|
||||
(r"echo|kindle|fire-?tv|amazon|alexa", "amazon", None),
|
||||
(r"nintendo", "nintendo", "game"),
|
||||
(r"playstation|^ps[345]\b|^ps[345]-", "playstation", "game"),
|
||||
(r"xbox", "microsoft", "game"),
|
||||
(r"^desktop-|^laptop-|^win-|windows|surface", "windows", "pc"),
|
||||
(r"bravia", "sony", "tv"),
|
||||
(r"lenovo|thinkpad|thinkbook|legion|yoga", "lenovo", "pc"),
|
||||
(r"dell|xps|inspiron|latitude|optiplex", "dell", "pc"),
|
||||
(r"^hp[-_]|hewlett|laserjet|deskjet|officejet|envy|pavilion|elitebook", "hp", None),
|
||||
(r"asus|rog-|zenbook|vivobook", "asus", None),
|
||||
(r"tp-?link|^tl-|deco", "tplink", None),
|
||||
(r"raspberry|^rpi|raspi", "raspberrypi", "pc"),
|
||||
(r"synology|diskstation|^ds\d{3}", "synology", "nas"),
|
||||
(r"^esp[-_]|esp32|esp8266|tasmota|espressif", "espressif", "iot"),
|
||||
(r"lgwebos|^lg[-_]", "lg", "tv"),
|
||||
(r"roku", "roku", "tv"),
|
||||
(r"dji", "dji", None),
|
||||
(r"unifi|ubnt|ubiquiti", "ubiquiti", None),
|
||||
(r"hue-?bridge|philips-?hue", "philipshue", "iot"),
|
||||
(r"hisense|vidaa", "hisense", "tv"),
|
||||
(r"tcl", "tcl", "tv"),
|
||||
(r"midea", "midea", "iot"),
|
||||
(r"haier", "haier", "iot"),
|
||||
(r"zte", "zte", None),
|
||||
(r"^android|android-", "android", "phone"),
|
||||
# brandless device types
|
||||
(r"printer|epson|canon|brother", None, "printer"),
|
||||
(r"camera|ipcam|^ipc|ezviz|hikvision|imou|xiaovv", None, "camera"),
|
||||
(r"tv\b|-tv|tv-|电视", None, "tv"),
|
||||
(r"speaker|sonos", None, "speaker"),
|
||||
(r"phone|手机", None, "phone"),
|
||||
(r"pad\b|tablet|平板", None, "tablet"),
|
||||
(r"nas\b", None, "nas"),
|
||||
(r"pc\b|desktop|laptop|notebook|电脑", None, "pc"),
|
||||
]
|
||||
|
||||
|
||||
def fetch(url, dest):
|
||||
if os.path.exists(dest):
|
||||
return dest
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "carbon-theme-build"})
|
||||
with urllib.request.urlopen(req, timeout=120) as r, open(dest, "wb") as f:
|
||||
f.write(r.read())
|
||||
return dest
|
||||
|
||||
|
||||
def main():
|
||||
os.makedirs(CACHE, exist_ok=True)
|
||||
|
||||
# --- icons -----------------------------------------------------------
|
||||
paths = {}
|
||||
for key, (_, style, _) in BRANDS.items():
|
||||
if style[0] != "icon":
|
||||
continue
|
||||
slug = style[1]
|
||||
svg = open(fetch(f"{SI_BASE}/icons/{slug}.svg", os.path.join(CACHE, slug + ".svg")), encoding="utf-8").read()
|
||||
m = re.search(r'<path d="([^"]+)"', svg)
|
||||
if not m:
|
||||
sys.exit(f"no path in {slug}.svg")
|
||||
paths[key] = m.group(1)
|
||||
|
||||
# --- OUI -------------------------------------------------------------
|
||||
oui_csv = fetch(OUI_URL, os.path.join(CACHE, "oui.csv"))
|
||||
rules = [(k, re.compile(v[2])) for k, v in BRANDS.items() if v[2]]
|
||||
prefixes = {k: set() for k, _ in rules}
|
||||
with open(oui_csv, encoding="utf-8", errors="replace") as f:
|
||||
for row in csv.DictReader(f):
|
||||
if row.get("Registry") != "MA-L":
|
||||
continue
|
||||
org = row.get("Organization Name", "")
|
||||
for k, rx in rules:
|
||||
if rx.search(org):
|
||||
prefixes[k].add(row["Assignment"].strip().upper())
|
||||
break
|
||||
|
||||
oui = {}
|
||||
for k, s in prefixes.items():
|
||||
if not s:
|
||||
continue
|
||||
raw = b"".join(bytes.fromhex(p) for p in sorted(s))
|
||||
oui[k] = base64.b64encode(raw).decode("ascii")
|
||||
|
||||
# --- emit ------------------------------------------------------------
|
||||
brands = {}
|
||||
for key, (name, style, _) in BRANDS.items():
|
||||
b = {"n": name}
|
||||
kind = style[0]
|
||||
bg = style[2] if len(style) > 2 else None
|
||||
if bg == "INV":
|
||||
b["inv"] = 1
|
||||
elif bg:
|
||||
b["bg"] = bg
|
||||
if kind == "icon":
|
||||
b["p"] = paths[key]
|
||||
elif kind == "mono":
|
||||
b["m"] = style[1]
|
||||
if len(style) > 3:
|
||||
b["fg"] = style[3]
|
||||
else:
|
||||
b["g"] = style[1]
|
||||
brands[key] = b
|
||||
|
||||
host = [[rx, k, t] for rx, k, t in HOST_RULES]
|
||||
|
||||
js = (
|
||||
"/*!\n"
|
||||
" * Carbon — brand data for the connected-devices list (generated by scripts/gen-brands.py).\n"
|
||||
f" * Brand glyphs: Simple Icons {SI_VERSION} (CC0 1.0). All trademarks belong to their owners.\n"
|
||||
" * MAC prefixes: IEEE Registration Authority MA-L registry.\n"
|
||||
" */\n"
|
||||
"(function (C) {\n"
|
||||
"\t'use strict';\n"
|
||||
f"\tC.BRAND_DATA = {json.dumps({'brands': brands, 'host': host, 'oui': oui}, separators=(',', ':'), ensure_ascii=False)};\n"
|
||||
"\tif (typeof C.onBrands === 'function') C.onBrands();\n"
|
||||
"})(window.Carbon = window.Carbon || {});\n"
|
||||
)
|
||||
with open(OUT, "w", encoding="utf-8") as f:
|
||||
f.write(js)
|
||||
|
||||
total = sum(len(s) for s in prefixes.values())
|
||||
print(f"wrote {OUT}: {len(js) // 1024} KB, {len(brands)} brands, {len(paths)} icons, {total} OUI prefixes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Extract Carbon's theme strings and compile po/<lang>/carbon.po catalogues.
|
||||
|
||||
python3 -I scripts/gen-i18n.py regenerate pot, merge po files, write JS
|
||||
python3 -I scripts/gen-i18n.py --check CI: fail if anything is stale or untranslated
|
||||
|
||||
Sources use t('…') / tr('…') / N_('…') with single-quoted literals. The po files
|
||||
are standard gettext, so the OpenWrt SDK (luci.mk) also builds them into
|
||||
luci-i18n-carbon-<lang> packages. Release packages bundle the compiled
|
||||
catalogues as htdocs/luci-static/carbon/i18n/<lc>.js, which the theme header
|
||||
loads for the active LuCI language.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
PO_DIR = ROOT / 'po'
|
||||
POT = PO_DIR / 'templates' / 'carbon.pot'
|
||||
OUT_DIR = ROOT / 'htdocs' / 'luci-static' / 'carbon' / 'i18n'
|
||||
SOURCES = [
|
||||
'htdocs/luci-static/carbon/carbon.js',
|
||||
'htdocs/luci-static/resources/menu-carbon.js',
|
||||
'htdocs/luci-static/resources/view/system/carbon-update.js',
|
||||
]
|
||||
MENU_JSON = ['root/usr/share/luci/menu.d/luci-theme-carbon.json']
|
||||
# Same short names luci.mk uses for lmo files (LUCI_LC_ALIAS).
|
||||
ALIAS = {'zh_Hans': 'zh-cn', 'zh_Hant': 'zh-tw', 'pt_BR': 'pt-br', 'nb_NO': 'no', 'sr_Latn': 'sr'}
|
||||
CALL = re.compile(r"(?<![\w$.])(?:C\.)?(?:t|tr|N_)\(\s*'((?:[^'\\\n]|\\.)*)'")
|
||||
PLACEHOLDER = re.compile(r'%[sd]')
|
||||
|
||||
|
||||
def js_unescape(text):
|
||||
return re.sub(r'\\(.)', lambda m: {'n': '\n', 't': '\t'}.get(m.group(1), m.group(1)), text)
|
||||
|
||||
|
||||
def extract():
|
||||
found = {}
|
||||
# File-only references (like xgettext --add-location=file): editing a source
|
||||
# does not rewrite every catalogue just because line numbers moved.
|
||||
for rel in SOURCES:
|
||||
for line in (ROOT / rel).read_text(encoding='utf-8').splitlines():
|
||||
for match in CALL.finditer(line):
|
||||
found.setdefault(js_unescape(match.group(1)), []).append(rel)
|
||||
for rel in MENU_JSON:
|
||||
for node in json.loads((ROOT / rel).read_text(encoding='utf-8')).values():
|
||||
if node.get('title'):
|
||||
found.setdefault(node['title'], []).append(rel)
|
||||
return found
|
||||
|
||||
|
||||
def po_escape(text):
|
||||
return text.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\t', '\\t')
|
||||
|
||||
|
||||
def po_unescape(text):
|
||||
return re.sub(r'\\(.)', lambda m: {'n': '\n', 't': '\t'}.get(m.group(1), m.group(1)), text)
|
||||
|
||||
|
||||
def parse_po(path):
|
||||
"""Minimal gettext reader: msgid/msgstr pairs, multi-line strings, no plurals."""
|
||||
entries, current, field = {}, {}, None
|
||||
|
||||
def flush():
|
||||
if 'msgid' in current and current['msgid'] != '' and 'msgctxt' not in current:
|
||||
entries[current['msgid']] = current.get('msgstr', '')
|
||||
current.clear()
|
||||
|
||||
for raw in path.read_text(encoding='utf-8').splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith('#'):
|
||||
if not line and current:
|
||||
flush()
|
||||
field = None
|
||||
continue
|
||||
match = re.match(r'(msgctxt|msgid|msgstr)\s+"(.*)"$', line)
|
||||
if match:
|
||||
if match.group(1) in ('msgid', 'msgctxt') and 'msgstr' in current:
|
||||
flush()
|
||||
field = match.group(1)
|
||||
current[field] = po_unescape(match.group(2))
|
||||
elif line.startswith('"') and field:
|
||||
current[field] += po_unescape(line[1:-1])
|
||||
flush()
|
||||
return entries
|
||||
|
||||
|
||||
def render_po(msgids, refs, translations, header):
|
||||
out = [header.rstrip('\n'), '']
|
||||
for msgid in msgids:
|
||||
for ref in refs.get(msgid, []):
|
||||
out.append('#: ' + ref)
|
||||
out.append(f'msgid "{po_escape(msgid)}"')
|
||||
out.append(f'msgstr "{po_escape(translations.get(msgid, ""))}"')
|
||||
out.append('')
|
||||
return '\n'.join(out)
|
||||
|
||||
|
||||
def po_header(lang=None):
|
||||
lines = ['msgid ""', 'msgstr ""', '"Content-Type: text/plain; charset=UTF-8\\n"']
|
||||
if lang:
|
||||
lines.append(f'"Language: {lang}\\n"')
|
||||
return '\n'.join(lines) + '\n'
|
||||
|
||||
|
||||
def render_js(lang, msgids, translations):
|
||||
body = ',\n'.join('\t' + json.dumps(k, ensure_ascii=False) + ': ' + json.dumps(translations[k], ensure_ascii=False)
|
||||
for k in msgids if translations.get(k))
|
||||
return ('/* Generated by scripts/gen-i18n.py from po/%s/carbon.po. Do not edit. */\n'
|
||||
'(window.Carbon = window.Carbon || {}).I18N = {\n%s\n};\n') % (lang, body)
|
||||
|
||||
|
||||
def main(check):
|
||||
found = extract()
|
||||
msgids = sorted(found, key=str.casefold)
|
||||
refs = {k: sorted(set(v)) for k, v in found.items()}
|
||||
outputs = {POT: render_po(msgids, refs, {}, po_header())}
|
||||
problems = []
|
||||
languages = sorted(d.name for d in PO_DIR.iterdir() if d.is_dir() and d.name != 'templates')
|
||||
for lang in languages:
|
||||
po = PO_DIR / lang / 'carbon.po'
|
||||
translations = parse_po(po) if po.exists() else {}
|
||||
for msgid in msgids:
|
||||
value = translations.get(msgid, '')
|
||||
if not value:
|
||||
problems.append(f'{lang}: untranslated: {msgid!r}')
|
||||
elif PLACEHOLDER.findall(value) != PLACEHOLDER.findall(msgid):
|
||||
problems.append(f'{lang}: placeholders differ: {msgid!r} -> {value!r}')
|
||||
outputs[po] = render_po(msgids, refs, translations, po_header(lang))
|
||||
outputs[OUT_DIR / (ALIAS.get(lang, lang.lower().replace('_', '-')) + '.js')] = render_js(lang, msgids, translations)
|
||||
|
||||
stale = [p for p, text in outputs.items() if not p.exists() or p.read_text(encoding='utf-8') != text]
|
||||
expected = {p for p in outputs if p.parent == OUT_DIR}
|
||||
orphans = [p for p in OUT_DIR.glob('*.js') if p not in expected] if OUT_DIR.exists() else []
|
||||
if check:
|
||||
for path in stale:
|
||||
problems.append(f'stale: {path.relative_to(ROOT)} (run scripts/gen-i18n.py)')
|
||||
for path in orphans:
|
||||
problems.append(f'orphan catalogue: {path.relative_to(ROOT)}')
|
||||
for line in problems:
|
||||
print('::error::' + line if '--github' in sys.argv else line, file=sys.stderr)
|
||||
return 1 if problems else 0
|
||||
for path in stale:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(outputs[path], encoding='utf-8')
|
||||
print('wrote', path.relative_to(ROOT))
|
||||
for path in orphans:
|
||||
path.unlink()
|
||||
print('removed', path.relative_to(ROOT))
|
||||
for line in problems:
|
||||
print('warning:', line, file=sys.stderr)
|
||||
print(f'{len(msgids)} strings, languages: {", ".join(languages) or "none"}')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main('--check' in sys.argv))
|
||||
Executable
+285
@@ -0,0 +1,285 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Carbon theme installer for OpenWrt / ImmortalWrt (LuCI 23.05 and later).
|
||||
#
|
||||
# sh carbon-install.sh install or upgrade
|
||||
# sh carbon-install.sh --trust-key also trust Carbon's APK key for LuCI package uploads
|
||||
# sh carbon-install.sh --files only copy files (no package record, no online updates)
|
||||
# sh carbon-install.sh uninstall remove the theme
|
||||
#
|
||||
# The installer embeds the release's signed .apk, its .ipk and Carbon's public
|
||||
# key, and installs through the system package manager (apk or opkg), so
|
||||
# System → Carbon Theme Settings can update the theme later. The APK signature
|
||||
# is verified with the embedded key in a private key directory: /etc/apk/keys
|
||||
# and signature checks stay untouched unless --trust-key is given. Missing
|
||||
# dependencies come from the firmware's own package feeds. If a native install
|
||||
# is impossible (e.g. offline without dependencies), the theme files are copied
|
||||
# instead and online updates stay disabled.
|
||||
#
|
||||
set -e
|
||||
|
||||
VERSION="@VERSION@"
|
||||
PKG=luci-theme-carbon
|
||||
ROOT="${CARBON_ROOT:-}" # tests only: alternate root with stub tools on PATH
|
||||
DEPS="${CARBON_DEPS-luci-base curl ca-bundle flock}" # tests only: override the dependency list
|
||||
# Files written by the --files mode (and by installers before v1.1.3).
|
||||
FILE_PATHS="
|
||||
/www/luci-static/carbon
|
||||
/www/luci-static/resources/menu-carbon.js
|
||||
/www/luci-static/resources/carbon
|
||||
/www/luci-static/resources/view/system/carbon-update.js
|
||||
/usr/share/ucode/luci/template/themes/carbon
|
||||
/usr/share/rpcd/acl.d/luci-theme-carbon.json
|
||||
/usr/share/rpcd/acl.d/luci-theme-carbon-update.json
|
||||
/usr/share/luci/menu.d/luci-theme-carbon.json
|
||||
/usr/share/carbon
|
||||
/usr/libexec/rpcd/luci.carbon_update
|
||||
/lib/upgrade/keep.d/luci-theme-carbon
|
||||
"
|
||||
# User data under the theme directory: the custom logo. Kept when a script-only
|
||||
# install becomes a package; removed on uninstall.
|
||||
CUSTOM_DIR=/www/luci-static/carbon/custom
|
||||
|
||||
say() { printf '%s\n' "$*"; }
|
||||
warn() { printf 'WARNING: %s\n' "$*" >&2; }
|
||||
die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
usage() {
|
||||
say "Usage: sh $0 [install|uninstall] [--trust-key] [--files]"
|
||||
say " install install or upgrade Carbon $VERSION through apk/opkg (default)"
|
||||
say " --trust-key also add Carbon's public key to /etc/apk/keys for LuCI uploads"
|
||||
say " --files copy files only; online updates are not available"
|
||||
say " uninstall remove the theme"
|
||||
}
|
||||
|
||||
WORK=''
|
||||
cleanup() { [ -z "$WORK" ] || rm -rf "$WORK"; }
|
||||
trap cleanup EXIT
|
||||
trap 'exit 1' HUP INT TERM
|
||||
|
||||
unpack() {
|
||||
line=$(awk '/^__CARBON_PAYLOAD__$/ { print NR + 1; exit 0 }' "$0")
|
||||
[ -n "$line" ] || die "embedded payload not found (file damaged? run it as: sh carbon-install.sh)"
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/carbon-install.XXXXXX") || die "cannot create a temporary directory"
|
||||
tail -n +"$line" "$0" | tar -xzf - -C "$WORK" || die "failed to unpack the installer (file damaged?)"
|
||||
}
|
||||
|
||||
have_uci() { command -v uci >/dev/null 2>&1; }
|
||||
|
||||
refresh_luci() {
|
||||
[ -n "$ROOT" ] && return 0
|
||||
rm -f /tmp/luci-indexcache* 2>/dev/null || true
|
||||
rm -rf /tmp/luci-modulecache 2>/dev/null || true
|
||||
[ -x /etc/init.d/rpcd ] && /etc/init.d/rpcd reload >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
manager() {
|
||||
if command -v apk >/dev/null 2>&1 && [ -f "$ROOT/etc/apk/world" ]; then echo apk
|
||||
elif command -v opkg >/dev/null 2>&1; then echo opkg
|
||||
fi
|
||||
}
|
||||
|
||||
# Installed version of a package, empty when it is not registered.
|
||||
pkg_version() {
|
||||
case "$1" in
|
||||
apk) apk list --installed "$2" 2>/dev/null | sed -n "s/^$2-\([0-9][^ ]*\) .*/\1/p" | head -n 1 ;;
|
||||
opkg) opkg status "$2" 2>/dev/null | awk '/^Version: / {v=$2} /^Status: .* installed$/ {ok=1} END {if (ok) print v}' ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Prints <, = or > comparing version $2 with $3.
|
||||
version_cmp() {
|
||||
case "$1" in
|
||||
apk) apk version -t "$2" "$3" 2>/dev/null ;;
|
||||
opkg)
|
||||
if opkg compare-versions "$2" '<<' "$3"; then echo '<'
|
||||
elif opkg compare-versions "$2" '=' "$3"; then echo '='
|
||||
else echo '>'; fi ;;
|
||||
esac
|
||||
}
|
||||
|
||||
remove_files() {
|
||||
for p in $FILE_PATHS; do
|
||||
if [ "$p" = /www/luci-static/carbon ] && [ "${1:-}" != all ] && [ -d "${ROOT}${CUSTOM_DIR}" ]; then
|
||||
find "${ROOT}${p}" -mindepth 1 -maxdepth 1 ! -name custom -exec rm -rf {} \;
|
||||
else
|
||||
rm -rf "${ROOT}${p}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install_files() {
|
||||
say "Copying theme files ..."
|
||||
mkdir -p "$ROOT/"
|
||||
cp -a "$WORK/files/." "$ROOT/" || die "failed to copy theme files"
|
||||
}
|
||||
|
||||
# Native install through apk/opkg. Returns non-zero when the caller should
|
||||
# fall back to copying files; exits on a signature failure.
|
||||
install_native() {
|
||||
mgr=$1
|
||||
case "$mgr" in
|
||||
apk) ext=apk ;;
|
||||
opkg) ext=ipk ;;
|
||||
*) warn "neither apk nor opkg was found"; return 1 ;;
|
||||
esac
|
||||
pkg="$WORK/pkg/$PKG.$ext"
|
||||
[ -s "$pkg" ] || { warn "this installer contains no .$ext package for $mgr"; return 1; }
|
||||
target=$(cat "$WORK/pkg/$mgr.version")
|
||||
current=$(pkg_version "$mgr" "$PKG")
|
||||
reinstall=0
|
||||
if [ -n "$current" ]; then
|
||||
case "$(version_cmp "$mgr" "$target" "$current")" in
|
||||
'<') say "Carbon $current is newer than this installer ($target); keeping it."; return 0 ;;
|
||||
'=') reinstall=1 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ "$mgr" = apk ]; then
|
||||
mkdir -p "$WORK/keys"
|
||||
cp "$WORK/pkg/carbon-apk.pem" "$WORK/keys/carbon-apk.pem"
|
||||
apk --keys-dir "$WORK/keys" --repositories-file /dev/null --no-network verify "$pkg" >/dev/null 2>&1 ||
|
||||
die "APK signature verification failed. Nothing was installed; download carbon-install.sh again."
|
||||
fi
|
||||
|
||||
missing=''
|
||||
for dep in $DEPS; do
|
||||
[ -n "$(pkg_version "$mgr" "$dep")" ] || missing="$missing $dep"
|
||||
done
|
||||
if [ -n "$missing" ]; then
|
||||
say "Installing dependencies from the firmware feeds:$missing"
|
||||
case "$mgr" in
|
||||
apk) apk update >/dev/null 2>&1 || true; apk add $missing ;;
|
||||
opkg) opkg update >/dev/null 2>&1 || true; opkg install $missing ;;
|
||||
esac || { warn "could not install$missing (check internet access and the package feeds)"; return 1; }
|
||||
fi
|
||||
|
||||
# Files from a script-only install are owned by no package; let the package own them.
|
||||
[ -n "$current" ] || remove_files
|
||||
|
||||
say "Installing $PKG $target with $mgr ..."
|
||||
case "$mgr" in
|
||||
apk) apk --keys-dir "$WORK/keys" --repositories-file /dev/null --no-network add "$pkg" ;;
|
||||
opkg)
|
||||
if [ "$reinstall" = 1 ]; then opkg install --force-reinstall "$pkg"
|
||||
else opkg install "$pkg"; fi ;;
|
||||
esac || { warn "$mgr could not install $PKG"; return 1; }
|
||||
|
||||
[ "$(pkg_version "$mgr" "$PKG")" = "$target" ] || { warn "$mgr does not report $PKG $target as installed"; return 1; }
|
||||
return 0
|
||||
}
|
||||
|
||||
trust_key() {
|
||||
[ "$1" = apk ] || { warn "--trust-key only applies to apk based firmware"; return 0; }
|
||||
mkdir -p "$ROOT/etc/apk/keys"
|
||||
cp "$WORK/pkg/carbon-apk.pem" "$ROOT/etc/apk/keys/carbon-apk.pem"
|
||||
chmod 644 "$ROOT/etc/apk/keys/carbon-apk.pem"
|
||||
say "Trusted Carbon's APK key for LuCI package uploads: /etc/apk/keys/carbon-apk.pem"
|
||||
}
|
||||
|
||||
activate() {
|
||||
have_uci || return 0
|
||||
{
|
||||
uci set luci.themes.Carbon=/luci-static/carbon &&
|
||||
uci set luci.main.mediaurlbase=/luci-static/carbon &&
|
||||
uci commit luci
|
||||
} || warn "could not select the Carbon theme; choose it in System → System → Language and Style"
|
||||
}
|
||||
|
||||
do_install() {
|
||||
if [ -z "$ROOT" ]; then
|
||||
[ "$(id -u)" = 0 ] || die "please run as root"
|
||||
fi
|
||||
[ -f "$ROOT/usr/share/ucode/luci/template/header.ut" ] || \
|
||||
die "LuCI with ucode templates (OpenWrt 23.05 or later) is required"
|
||||
|
||||
unpack
|
||||
say "Installing Carbon theme $VERSION ..."
|
||||
mgr=$(manager)
|
||||
native=0
|
||||
if [ "$FILES_ONLY" != 1 ]; then
|
||||
if install_native "$mgr"; then
|
||||
native=1
|
||||
elif [ -n "$mgr" ] && [ -n "$(pkg_version "$mgr" "$PKG")" ]; then
|
||||
# Never copy files over a registered package; the installed version keeps working.
|
||||
die "the upgrade failed; Carbon $(pkg_version "$mgr" "$PKG") remains installed. See the messages above."
|
||||
else
|
||||
warn "falling back to copying files. The theme works, but online updates stay"
|
||||
warn "disabled until Carbon is installed with apk/opkg (run this installer again later)."
|
||||
fi
|
||||
elif [ -n "$mgr" ] && [ -n "$(pkg_version "$mgr" "$PKG")" ]; then
|
||||
die "Carbon is installed with $mgr; upgrade it without --files"
|
||||
fi
|
||||
[ "$native" = 1 ] || install_files
|
||||
[ "$TRUST_KEY" != 1 ] || [ -z "$mgr" ] || trust_key "$mgr"
|
||||
activate
|
||||
refresh_luci
|
||||
|
||||
say ""
|
||||
if [ "$native" = 1 ]; then
|
||||
say "Done. Carbon is installed with $mgr and is now the active theme."
|
||||
say "Online updates: System → Carbon Theme Settings."
|
||||
else
|
||||
say "Done. Carbon files were copied and Carbon is now the active theme."
|
||||
fi
|
||||
say "Refresh the LuCI page, then log out and back in once so the"
|
||||
say "dashboard and updater permissions take effect."
|
||||
}
|
||||
|
||||
do_uninstall() {
|
||||
say "Removing Carbon theme ..."
|
||||
mgr=$(manager)
|
||||
current=''
|
||||
[ -z "$mgr" ] || current=$(pkg_version "$mgr" "$PKG")
|
||||
if [ -n "$current" ]; then
|
||||
say "Removing $PKG $current with $mgr ..."
|
||||
case "$mgr" in
|
||||
apk) apk del "$PKG" ;;
|
||||
opkg) opkg remove "$PKG" ;;
|
||||
esac || die "$mgr could not remove $PKG"
|
||||
fi
|
||||
remove_files all
|
||||
rm -rf "${ROOT}${CUSTOM_DIR}"
|
||||
rm -f "$ROOT/etc/config/carbon"
|
||||
|
||||
if have_uci; then
|
||||
uci -q delete luci.themes.Carbon || true
|
||||
if [ "$(uci -q get luci.main.mediaurlbase)" = "/luci-static/carbon" ]; then
|
||||
fallback=""
|
||||
for t in bootstrap argon material openwrt-2020; do
|
||||
if [ -d "$ROOT/www/luci-static/$t" ]; then fallback="/luci-static/$t"; break; fi
|
||||
done
|
||||
if [ -n "$fallback" ]; then
|
||||
uci set luci.main.mediaurlbase="$fallback"
|
||||
else
|
||||
uci -q delete luci.main.mediaurlbase || true
|
||||
fi
|
||||
fi
|
||||
uci commit luci || true
|
||||
fi
|
||||
|
||||
refresh_luci
|
||||
[ ! -f "$ROOT/etc/apk/keys/carbon-apk.pem" ] || say "Carbon's APK key stays trusted; remove /etc/apk/keys/carbon-apk.pem to revoke it."
|
||||
say "Done. Refresh the LuCI page."
|
||||
}
|
||||
|
||||
ACTION=install
|
||||
FILES_ONLY=0
|
||||
TRUST_KEY=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
install|upgrade) ACTION=install ;;
|
||||
uninstall|remove) ACTION=uninstall ;;
|
||||
--files) FILES_ONLY=1 ;;
|
||||
--trust-key) TRUST_KEY=1 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) usage; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$ACTION" in
|
||||
install) do_install ;;
|
||||
uninstall) do_uninstall ;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* Minify the theme's static assets in place, for release packaging only.
|
||||
*
|
||||
* node scripts/minify.mjs [package-root] (default: repository root)
|
||||
*
|
||||
* CI runs this on a disposable checkout before building packages. Sources in
|
||||
* git stay readable. LuCI view modules ('require …' directives, top-level
|
||||
* return) are not touched.
|
||||
*/
|
||||
import { readFileSync, writeFileSync, readdirSync, existsSync } from 'node:fs';
|
||||
import { join, resolve, relative } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { transform } from 'esbuild';
|
||||
|
||||
const root = resolve(process.argv[2] || fileURLToPath(new URL('..', import.meta.url)));
|
||||
const media = join(root, 'htdocs/luci-static/carbon');
|
||||
const i18n = join(media, 'i18n');
|
||||
const files = [
|
||||
join(media, 'carbon.css'),
|
||||
join(media, 'carbon.js'),
|
||||
join(media, 'brands.js'),
|
||||
...(existsSync(i18n) ? readdirSync(i18n).filter((f) => f.endsWith('.js')).map((f) => join(i18n, f)) : [])
|
||||
];
|
||||
|
||||
let before = 0, after = 0;
|
||||
for (const file of files) {
|
||||
const source = readFileSync(file, 'utf8');
|
||||
const { code, warnings } = await transform(source, {
|
||||
loader: file.endsWith('.css') ? 'css' : 'js',
|
||||
minify: true,
|
||||
legalComments: 'inline',
|
||||
charset: 'utf8'
|
||||
});
|
||||
if (warnings.length)
|
||||
throw new Error(relative(root, file) + ': ' + warnings.map((w) => w.text).join('; '));
|
||||
writeFileSync(file, code);
|
||||
before += Buffer.byteLength(source);
|
||||
after += Buffer.byteLength(code);
|
||||
console.log(relative(root, file).padEnd(44), String(Buffer.byteLength(source)).padStart(7), '→', String(Buffer.byteLength(code)).padStart(7));
|
||||
}
|
||||
console.log('total'.padEnd(44), String(before).padStart(7), '→', String(after).padStart(7), `(${Math.round((1 - after / before) * 100)}% smaller)`);
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Assemble the GitHub release body.
|
||||
#
|
||||
# sh scripts/release-notes.sh TAG [owner/repo] > notes.md
|
||||
#
|
||||
# docs/releases/TAG.md and docs/releases/install.md are each written in two
|
||||
# sections, "## English" and "## 简体中文". The body is every language once,
|
||||
# start to finish:
|
||||
#
|
||||
# ## English (TAG.md English section, then install.md English section)
|
||||
# ---
|
||||
# ## 简体中文 (TAG.md 简体中文 section, then install.md 简体中文 section)
|
||||
#
|
||||
# Release notes from before v1.2 (no "## English" heading) are printed
|
||||
# unchanged above both sections. RELEASE_NOTES_DIR overrides docs/releases.
|
||||
#
|
||||
set -eu
|
||||
|
||||
TAG=${1:?usage: sh scripts/release-notes.sh TAG [owner/repo]}
|
||||
REPO=${2:-mrjoechen/luci-theme-carbon}
|
||||
DIR=${RELEASE_NOTES_DIR:-$(cd "$(dirname "$0")/.." && pwd)/docs/releases}
|
||||
NOTES="$DIR/$TAG.md"
|
||||
INSTALL="$DIR/install.md"
|
||||
EN='English'
|
||||
ZH='简体中文'
|
||||
|
||||
printf '%s\n' "$REPO" | grep -Eq '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$' || { echo "invalid repository: $REPO" >&2; exit 1; }
|
||||
printf '%s\n' "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$' || { echo "invalid tag: $TAG" >&2; exit 1; }
|
||||
|
||||
has_section() { grep -qx "## $2" "$1"; }
|
||||
# Body of "## NAME" up to the next "## " heading, without surrounding blank lines.
|
||||
section() {
|
||||
awk -v want="## $2" '
|
||||
/^## / { on = ($0 == want); next }
|
||||
on { lines[++n] = $0 }
|
||||
END {
|
||||
first = 1; while (first <= n && lines[first] == "") first++
|
||||
last = n; while (last >= first && lines[last] == "") last--
|
||||
for (i = first; i <= last; i++) print lines[i]
|
||||
}' "$1"
|
||||
}
|
||||
|
||||
for lang in "$EN" "$ZH"; do
|
||||
has_section "$INSTALL" "$lang" || { echo "$INSTALL: missing section ## $lang" >&2; exit 1; }
|
||||
done
|
||||
|
||||
notes_lang=0
|
||||
if [ -f "$NOTES" ] && has_section "$NOTES" "$EN"; then
|
||||
has_section "$NOTES" "$ZH" || { echo "$NOTES: missing section ## $ZH" >&2; exit 1; }
|
||||
notes_lang=1
|
||||
elif [ -f "$NOTES" ]; then
|
||||
cat "$NOTES"
|
||||
printf '\n---\n\n'
|
||||
fi
|
||||
|
||||
for lang in "$EN" "$ZH"; do
|
||||
[ "$lang" = "$EN" ] || printf '\n---\n\n'
|
||||
printf '## %s\n\n' "$lang"
|
||||
if [ "$notes_lang" = 1 ]; then
|
||||
section "$NOTES" "$lang"
|
||||
printf '\n'
|
||||
fi
|
||||
section "$INSTALL" "$lang" | sed "s#@REPOSITORY@#$REPO#g"
|
||||
done
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
# Sign APK v3 files and require verification with the intended public key.
|
||||
# Usage: sh scripts/sign-apk.sh PRIVATE_KEY PUBLIC_KEY PACKAGE.apk [...]
|
||||
set -eu
|
||||
|
||||
[ "$#" -ge 3 ] || { echo "Usage: $0 PRIVATE_KEY PUBLIC_KEY PACKAGE.apk [...]" >&2; exit 1; }
|
||||
private_key=$1
|
||||
public_key=$2
|
||||
shift 2
|
||||
[ -s "$private_key" ] && [ -s "$public_key" ] || { echo "Signing key is missing" >&2; exit 1; }
|
||||
command -v apk >/dev/null 2>&1 || { echo "apk-tools 3 is required" >&2; exit 1; }
|
||||
|
||||
umask 077
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT HUP INT TERM
|
||||
mkdir "$work/keys"
|
||||
cp "$public_key" "$work/keys/carbon-apk.pem"
|
||||
|
||||
for package in "$@"; do
|
||||
[ -s "$package" ] || { echo "APK file is missing: $package" >&2; exit 1; }
|
||||
case "$package" in *.apk) ;; *) echo "Expected an .apk file: $package" >&2; exit 1 ;; esac
|
||||
# Keep the input intact if signing fails. adbsign alone is not a verification.
|
||||
cp "$package" "$work/package.apk"
|
||||
# The SDK input is unsigned. This flag is only for reading it while signing;
|
||||
# verification and router installation must never use it.
|
||||
apk adbsign --allow-untrusted --reset-signatures --sign-key "$private_key" "$work/package.apk"
|
||||
apk --keys-dir "$work/keys" --repositories-file /dev/null --no-network verify "$work/package.apk"
|
||||
cat "$work/package.apk" > "$package"
|
||||
printf 'Signed and verified: %s\n' "$package"
|
||||
done
|
||||
Reference in new issue
Block a user