first commit

This commit is contained in:
2026-11-04 09:43:05 -07:00
commit c33736775b
25 changed files with 2056 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
#!/bin/bash
#
# Purpose : Paths, settings and helpers shared by coredesktop-dev's scripts
# The deployed copy: the machine's running CoreDesktop, which update pulls
COREDESKTOP="$HOME/.local/share/coredesktop"
CONFIG_DIR="$HOME/.config/coredesktop-dev"
CONFIG="$CONFIG_DIR/config"
# First line after the shebang of the pre-push hook this project installs, so it
# never overwrites or removes a hook someone else wrote
HOOK_MARKER="# Installed by coredesktop-dev; remove with: coredesktop-dev hooks remove"
die() {
echo "$*" >&2
exit 1
}
confirm() {
local answer
read -rp "$1 [y/N] " answer
[[ "$answer" == [yY]* ]]
}
# Sets WORKING_COPY from the settings file (empty if there is none)
load_config() {
WORKING_COPY=""
# shellcheck source=/dev/null
[ -f "$CONFIG" ] && source "$CONFIG"
return 0
}
save_config() {
mkdir -p "$CONFIG_DIR"
printf 'WORKING_COPY=%q\n' "$1" > "$CONFIG"
}
# True if DIR is the deployed copy, however it's spelled
is_deployed_copy() {
[ -e "$1" ] && [ "$(realpath "$1")" = "$(realpath "$COREDESKTOP" 2> /dev/null)" ]
}
# True if DIR is the top of a git clone of CoreDesktop
is_coredesktop_clone() {
[ -d "$1" ] \
&& [ "$(git -C "$1" rev-parse --show-toplevel 2> /dev/null)" = "$(realpath "$1")" ] \
&& [ -f "$1/update" ] && [ -d "$1/updates.d" ]
}
# Load the settings and stop unless they point at a CoreDesktop clone
require_working_copy() {
load_config
[ -n "$WORKING_COPY" ] \
|| die "No working copy is set. Run $(sibling_dir)/install.sh, or: sibling add <coredesktop-dev url>"
is_coredesktop_clone "$WORKING_COPY" \
|| die "The working copy, $WORKING_COPY, isn't a clone of CoreDesktop (set in $CONFIG)."
}
in_flatpak() {
[ -f /.flatpak-info ] || [ -n "${FLATPAK_ID:-}" ]
}
# This project's folder
sibling_dir() {
cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd
}