Files
lxs/lxs.sh
T

54 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# LXS - platform dispatcher (POSIX side)
# Description: Thin shim kept at the repo root so the documented install URL
# and the /usr/local/bin/lxs symlink stay stable while the real
# implementation lives in linux/lxs.sh.
# Repo: https://git.hyko.cx/hykocx/lxs
# License: MIT
LXS_REPO_URL="${LXS_REPO_URL:-https://git.hyko.cx/hykocx/lxs}"
LXS_BRANCH="${LXS_BRANCH:-main}"
export LXS_RAW_BASE="${LXS_RAW_BASE:-${LXS_REPO_URL}/raw/branch/${LXS_BRANCH}}"
# Platform sub-tree to dispatch into. Only linux/ ships today; the darwin
# branch is here so a macos/ tree drops in without touching this file.
case "$(uname -s 2>/dev/null)" in
Linux) LXS_PLATFORM_DIR="linux" ;;
Darwin) LXS_PLATFORM_DIR="macos" ;;
*) LXS_PLATFORM_DIR="linux" ;;
esac
# Locate a sibling <platform>/lxs.sh (repo checkout or installed layout).
_lxs_self_dir=""
if [ -n "${BASH_SOURCE[0]:-}" ]; then
_lxs_resolved=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null) \
|| _lxs_resolved=$(realpath "${BASH_SOURCE[0]}" 2>/dev/null) \
|| _lxs_resolved="${BASH_SOURCE[0]}"
[ -f "$_lxs_resolved" ] && _lxs_self_dir=$(dirname "$_lxs_resolved")
unset _lxs_resolved
fi
if [ -n "$_lxs_self_dir" ] && [ -f "${_lxs_self_dir}/${LXS_PLATFORM_DIR}/lxs.sh" ]; then
exec bash "${_lxs_self_dir}/${LXS_PLATFORM_DIR}/lxs.sh" "$@"
fi
# No files on disk — we were piped from curl. Fetch the platform entrypoint.
if ! command -v curl >/dev/null 2>&1; then
echo "lxs: curl is required to bootstrap ${LXS_PLATFORM_DIR}/lxs.sh" >&2
exit 1
fi
_lxs_tmp=$(mktemp "/tmp/lxs.entrypoint.XXXXXX.sh") || exit 1
if ! curl -fsSL -H "Cache-Control: no-cache" \
-o "$_lxs_tmp" "${LXS_RAW_BASE}/${LXS_PLATFORM_DIR}/lxs.sh"; then
echo "lxs: failed to fetch ${LXS_RAW_BASE}/${LXS_PLATFORM_DIR}/lxs.sh" >&2
rm -f "$_lxs_tmp"
exit 1
fi
bash "$_lxs_tmp" "$@"
_lxs_rc=$?
rm -f "$_lxs_tmp"
exit $_lxs_rc