Files

144 lines
5.5 KiB
Bash
Raw Permalink Normal View History

2026-09-25 17:32:12 +03:00
#!/usr/bin/env bash
#
# build.sh — build & install lxpanel with the Erisian/Unix-time Digital Clock.
#
# Target: Gentoo Linux (out-of-tree source build). The same script works on any
# autotools-based distro; only the emerge convenience list is Gentoo-specific.
#
# The build:
# 1. verifies build dependencies (pkg-config; optionally `emerge`s them),
# 2. downloads lxpanel at the EXACT commit the patch was generated against,
# 3. applies erisian-time.patch (idempotent),
# 4. runs autogen.sh + configure + make, and (optionally) `make install`.
#
# Usage:
# ./build.sh # build & install to /usr (default)
# ./build.sh --deps # also `emerge` the required ebuilds first
# ./build.sh --prefix=/opt/lxpanel
# ./build.sh --no-install # build only, do not install
# ./build.sh --clean # re-download the source fresh
#
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$HERE"
# Prefer system build tools: a foreign toolchain earlier in PATH (e.g. a
# linuxbrew gcc/ld) can break the final link. On a clean Gentoo this is a no-op.
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# --- pinned upstream commit (erisian-time.patch was generated against this) --
COMMIT=4dec3d0d3d8f9e2a9d14dd1b099d378289b67db4
SRC_URL="https://codeload.github.com/lxde/lxpanel/tar.gz/${COMMIT}"
SRC_TAR="lxpanel-src.tar.gz"
SRC_DIR="lxpanel-${COMMIT}"
PATCH=erisian-time.patch
PREFIX=/usr
DO_DEPS=0
DO_INSTALL=1
DO_CLEAN=0
for arg in "$@"; do
case "$arg" in
--deps) DO_DEPS=1 ;;
--no-install) DO_INSTALL=0 ;;
--clean) DO_CLEAN=1 ;;
--prefix=*) PREFIX="${arg#--prefix=}" ;;
*) echo "Unknown option: $arg (see header)"; exit 1 ;;
esac
done
# run priv-privileged commands with sudo only when not root
if [ "$(id -u)" = 0 ]; then SUDO=""; else SUDO="sudo"; fi
# --- 1. dependencies --------------------------------------------------------
# pkg-config modules that configure.ac requires for the GTK3 (default) build.
REQUIRED_PC=(gtk+-3.0 libfm-gtk3 libwnck-3.0 keybinder-3.0 glib-2.0 x11)
OPTIONAL_PC=(libmenu-cache) # without: menu routines are disabled (warning)
# Gentoo ebuilds providing the above + the default dynamic-plugin deps.
# (best-effort; the pkg-config checks below are the authoritative gate)
EBUILDS=(
sys-devel/autoconf sys-devel/automake sys-devel/libtool sys-apps/intltool
dev-libs/glib x11-libs/gtk+ gnome-extra/libfm-gtk gnome-libs/libwnck
x11-libs/keybinder gnome-extra/libmenu-cache x11-libs/libX11
net-misc/curl dev-libs/libxml2 net-wireless/libiw media-libs/alsa-lib
)
if [ "$DO_DEPS" = 1 ]; then
echo ">> Installing dependencies via emerge ..."
$SUDO emerge -av "${EBUILDS[@]}"
fi
echo ">> Checking dependencies (pkg-config) ..."
missing=0
for m in "${REQUIRED_PC[@]}"; do
if pkg-config --exists "$m" 2>/dev/null; then echo " [ok] $m"
else echo " [MISS] $m"; missing=1; fi
done
for m in "${OPTIONAL_PC[@]}"; do
if pkg-config --exists "$m" 2>/dev/null; then echo " [ok] $m"
else echo " [opt] $m (menu support will be disabled)"; fi
done
if [ "$missing" = 1 ]; then
echo; echo "Missing required dependencies — install the ebuilds above (or rerun with --deps)."
exit 1
fi
# --- 2. source (pinned commit) ---------------------------------------------
if [ "$DO_CLEAN" = 1 ]; then rm -rf "$SRC_DIR" "$SRC_TAR"; fi
if [ ! -d "$SRC_DIR" ]; then
echo ">> Downloading lxpanel @ ${COMMIT:0:7} ..."
curl -fsSL -o "$SRC_TAR" "$SRC_URL"
tar xf "$SRC_TAR"
fi
cd "$SRC_DIR"
# --- 3. apply the Erisian patch (idempotent) --------------------------------
if grep -q "dclock_expand_codes" plugins/dclock.c; then
echo ">> ${PATCH} already applied — skipping."
else
echo ">> Applying ${PATCH} ..."
patch -p1 < "$HERE/$PATCH"
fi
# --- 4. build --------------------------------------------------------------
# Auto-disable dynamic plugins whose optional deps are absent, so the build
# succeeds on a minimal system. The Erisian clock (plugins/dclock.c) is a
# built-in plugin compiled into lxpanel itself and is ALWAYS built.
EXCLUDES=""
if ! command -v curl-config >/dev/null 2>&1 || ! pkg-config --exists libxml-2.0 2>/dev/null; then
EXCLUDES="${EXCLUDES},-weather"; echo " [note] weather plugin disabled (need: net-misc/curl, dev-libs/libxml2)"
fi
if [ ! -e /usr/include/iwlib.h ] && [ ! -e /usr/include/linux/iwlib.h ]; then
EXCLUDES="${EXCLUDES},-netstat"; echo " [note] netstat plugin disabled (need: net-wireless/libiw)"
fi
WITH_PLUGINS_OPT=""
[ -n "$EXCLUDES" ] && WITH_PLUGINS_OPT="--with-plugins=all${EXCLUDES}"
echo ">> autogen.sh ..."
sh ./autogen.sh
# GTK3 is NOT the configure default (upstream defaults to gtk+-2.0), so
# --enable-gtk3=yes is required for the modern gtk+-3.0 build.
echo ">> configure --enable-gtk3=yes --prefix=$PREFIX $WITH_PLUGINS_OPT"
./configure --enable-gtk3=yes --prefix="$PREFIX" $WITH_PLUGINS_OPT
echo ">> make ..."
make
if [ "$DO_INSTALL" = 1 ]; then
echo ">> make install ..."
$SUDO make install
fi
echo
if [ "$DO_INSTALL" = 1 ]; then
echo ">> Done. lxpanel installed under $PREFIX."
else
echo ">> Done. (built only — not installed)"
fi
echo " Configure the Digital Clock (Clock Format) with the Erisian/unix codes, e.g.:"
echo " %eY.%eE.%ed %eh:%em:%es %ew"
echo " Codes: %eY year / %ey short-year / %eS season / %eE season# / %ed day"
echo " %eh:%em:%es hour:min:sec / %ew weekday / %ut unix time"
echo " St Tib's day (leap year): %ed=tib, %ew=St. Tib's Day"