Files
ff-logo/bootstrap-fastfetch.sh
2026-08-31 07:58:12 -07:00

145 lines
5.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Bootstrap fastfetch with image support (chafa + ImageMagick)
# Builds from source so that --logo-type chafa/kitty works.
# Usage: ./bootstrap-fastfetch.sh
FASTFETCH_VER="2.62.1"
SRC_DIR="/tmp/fastfetch-src"
# ── Platform detection ─────────────────────────────────────────────────────────
MACOS=0
[[ "$(uname)" == "Darwin" ]] && MACOS=1
# ── Already installed from source? ────────────────────────────────────────────
# A source build goes to /usr/local/bin. Check if it's there AND has image support.
if command -v fastfetch &>/dev/null; then
FF_PATH=$(command -v fastfetch)
if [[ "$FF_PATH" == /usr/local/* ]]; then
if fastfetch --list-features 2>/dev/null | grep -qi 'chafa\|imagemagick'; then
echo "fastfetch is already built from source with image support."
exit 0
else
echo "fastfetch at $FF_PATH lacks image support — rebuilding..."
fi
else
echo "Installed fastfetch at $FF_PATH lacks source-build image support — rebuilding..."
fi
fi
echo "Building fastfetch $FASTFETCH_VER with image support..."
# ── Install build dependencies ─────────────────────────────────────────────────
if command -v brew &>/dev/null; then
brew install git cmake ninja chafa imagemagick
brew unlink fastfetch 2>/dev/null || true
elif command -v pacman &>/dev/null; then
sudo pacman -S --needed --noconfirm \
git base-devel cmake ninja chafa imagemagick
elif command -v apt &>/dev/null; then
sudo apt-get update -qq
sudo apt-get install -y \
git build-essential cmake ninja-build pkg-config \
libchafa-dev \
libmagickcore-dev libmagickwand-dev
else
echo "Unsupported package manager." >&2
echo "Install manually: git cmake ninja chafa imagemagick (dev headers)" >&2
exit 1
fi
# ── CPU count ──────────────────────────────────────────────────────────────────
if [[ $MACOS -eq 1 ]]; then
JOBS=$(sysctl -n hw.logicalcpu)
else
JOBS=$(nproc)
fi
# ── Clone source ───────────────────────────────────────────────────────────────
rm -rf "$SRC_DIR"
git clone --depth 1 --branch "$FASTFETCH_VER" \
https://github.com/fastfetch-cli/fastfetch.git "$SRC_DIR"
# ── Linux: patch sonames if the installed version doesn't match what fastfetch
# expects at runtime. Libraries live in multiarch dirs on Debian/Ubuntu
# (/usr/lib/x86_64-linux-gnu/ etc.) so we use ldconfig -p to locate them. ──
patch_soname() {
local libname="$1" # e.g. libchafa
local old_so="$2" # e.g. so.0
local new_so="$3" # e.g. so.1
# Find the real path of the old soname via the ldconfig cache
local old_path
old_path=$(ldconfig -p 2>/dev/null \
| grep -F "${libname}.${old_so}" \
| awk '{print $NF}' | head -1)
if [[ -z "$old_path" ]]; then
return 0 # old soname not present — nothing to patch
fi
local lib_dir new_path
lib_dir=$(dirname "$old_path")
new_path="${lib_dir}/${libname}.${new_so}"
if [[ ! -f "$new_path" ]] && [[ ! -L "$new_path" ]]; then
echo "Patching ${libname} soname (${old_so} → ${new_so}) in $lib_dir ..."
sudo ln -sf "$(basename "$old_path")" "$new_path"
sudo ldconfig
fi
}
if [[ $MACOS -eq 0 ]]; then
# chafa: Debian 12 ships libchafa.so.0; some fastfetch builds dlopen so.1
patch_soname libchafa so.0 so.1
# ImageMagick 7 soname bump (not present on Debian stable which ships IM6)
if pkg-config --exists MagickCore-7.Q16HDRI 2>/dev/null; then
patch_soname libMagickCore-7.Q16HDRI so.10 so.11
patch_soname libMagickWand-7.Q16HDRI so.10 so.11
fi
fi
# ── CMake configuration ────────────────────────────────────────────────────────
CMAKE_EXTRA_FLAGS=""
if [[ $MACOS -eq 1 ]]; then
BREW_PREFIX="$(brew --prefix)"
CMAKE_EXTRA_FLAGS="-DChafa_DIR=${BREW_PREFIX}/opt/chafa/lib/cmake/chafa \
-DCMAKE_PREFIX_PATH=${BREW_PREFIX}/opt/chafa:${BREW_PREFIX}/opt/imagemagick \
-DImageMagick_ROOT=${BREW_PREFIX}/opt/imagemagick"
fi
# shellcheck disable=SC2086 # word-split intended for CMAKE_EXTRA_FLAGS
cmake -S "$SRC_DIR" -B "$SRC_DIR/build" \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_VULKAN=OFF \
$CMAKE_EXTRA_FLAGS
cmake --build "$SRC_DIR/build" -j"$JOBS"
sudo cmake --install "$SRC_DIR/build" --prefix /usr/local
# ── macOS: symlink brew libs into /usr/local/lib so fastfetch's dlopen finds them
if [[ $MACOS -eq 1 ]]; then
BREW_PREFIX="$(brew --prefix)"
sudo mkdir -p /usr/local/lib
sudo ln -sf "${BREW_PREFIX}/opt/chafa/lib/libchafa.dylib" \
/usr/local/lib/libchafa.dylib
IM_LIB="${BREW_PREFIX}/opt/imagemagick/lib"
sudo ln -sf "${IM_LIB}/libMagickWand-7.Q16HDRI.dylib" \
/usr/local/lib/libMagickWand-7.Q16HDRI.dylib
sudo ln -sf "${IM_LIB}/libMagickCore-7.Q16HDRI.dylib" \
/usr/local/lib/libMagickCore-7.Q16HDRI.dylib
echo "Symlinked chafa + imagemagick into /usr/local/lib"
fi
echo
echo "Done — fastfetch with image support installed at /usr/local/bin/fastfetch"
fastfetch --list-features 2>/dev/null | grep -i 'chafa\|imagemagick' \
&& echo "Image support confirmed." \
|| echo "Warning: image features not listed — check cmake output above."