sibling requirements

This commit is contained in:
David Young
2026-10-20 06:21:18 -06:00
parent b7c7b6f6e8
commit 1a8bdda0aa
8 changed files with 142 additions and 37 deletions
+67 -15
View File
@@ -7,6 +7,7 @@ export HAMPACK_DIR
CONF_FILE="${HAMPACK_COMPILE_CONF:-$HAMPACK_DIR/compile.conf}"
TMP_DIR="/tmp/hampack-build"
VERSION_FILE="$HOME/.local/state/HamPack/.installed_versions"
FAILED=()
# Get the installed version of an app
get_installed_version() {
@@ -131,31 +132,71 @@ install_desktop() {
echo " Desktop file installed."
}
# Find the tag for a version, named either "1.2.3" or "v1.2.3". Prints nothing
# if the repo has no tags at all; fails if it has tags but none for the version.
find_version_tag() {
local git_url="$1"
local version="$2"
local tags
tags=$(git ls-remote --tags --refs "$git_url" | sed 's|.*refs/tags/||') || return 1
[ -z "$tags" ] && return 0
local tag
for tag in "$version" "v$version"; do
if grep -qxF "$tag" <<< "$tags"; then
echo "$tag"
return 0
fi
done
return 1
}
# Fetch source via git or wget
fetch_source() {
local app="$1"
local git_url="$2"
local wget_url="$3"
local version="$4"
local ref="$5"
local src_dir="$TMP_DIR/$app"
rm -rf "$src_dir"
mkdir -p "$src_dir"
if [ -n "$git_url" ]; then
echo " Cloning $git_url..."
git clone "$git_url" "$src_dir"
if [ -n "$git_url" ] && [ -n "$ref" ]; then
echo " Cloning $git_url at $ref..."
git clone "$git_url" "$src_dir" || return 1
git -C "$src_dir" -c advice.detachedHead=false checkout "$ref" || return 1
elif [ -n "$git_url" ]; then
local tag=""
if [ -n "$version" ]; then
if ! tag=$(find_version_tag "$git_url" "$version"); then
echo " Error: no tag $version or v$version in $git_url"
return 1
fi
fi
if [ -n "$tag" ]; then
echo " Cloning $git_url at $tag..."
git -c advice.detachedHead=false clone --branch "$tag" "$git_url" "$src_dir" || return 1
else
echo " $git_url has no tags; cloning the default branch..."
git clone "$git_url" "$src_dir" || return 1
fi
elif [ -n "$wget_url" ]; then
echo " Downloading $wget_url..."
local filename="${wget_url##*/}"
local filepath="$TMP_DIR/$filename"
wget -q "$wget_url" -O "$filepath"
wget -q "$wget_url" -O "$filepath" || return 1
echo " Extracting $filename..."
case "$filename" in
*.zip)
unzip -q "$filepath" -d "$src_dir"
unzip -q "$filepath" -d "$src_dir" || return 1
# If the zip extracted into a single subdirectory, flatten it
local contents
contents=$(ls -1 "$src_dir")
@@ -169,24 +210,24 @@ fetch_source() {
fi
;;
*.tar.gz|*.tgz)
tar -xzf "$filepath" -C "$src_dir" --strip-components=1
tar -xzf "$filepath" -C "$src_dir" --strip-components=1 || return 1
;;
*.tar.bz2)
tar -xjf "$filepath" -C "$src_dir" --strip-components=1
tar -xjf "$filepath" -C "$src_dir" --strip-components=1 || return 1
;;
*.tar.xz)
tar -xJf "$filepath" -C "$src_dir" --strip-components=1
tar -xJf "$filepath" -C "$src_dir" --strip-components=1 || return 1
;;
*)
echo " Error: unknown file type for $filename"
exit 1
return 1
;;
esac
rm -f "$filepath"
else
echo " Error: no git or wget URL specified for $app"
exit 1
return 1
fi
}
@@ -224,6 +265,7 @@ process_app() {
local version="$6"
local desktop="$7"
local gui="$8"
local ref="$9"
echo ""
echo "=== $app ==="
@@ -247,7 +289,11 @@ process_app() {
return
fi
fetch_source "$app" "$git_url" "$wget_url"
if ! fetch_source "$app" "$git_url" "$wget_url" "$version" "$ref"; then
echo " Error: could not fetch $app source, skipping."
FAILED+=("$app")
return
fi
run_steps "$app" "$steps"
install_desktop "$desktop"
save_installed_version "$app" "$version"
@@ -260,17 +306,17 @@ process_app() {
# Parse compile.conf and process each app
process_conf() {
local app="" git_url="" wget_url="" install_path="" steps="" version="" desktop="" gui=""
local app="" git_url="" wget_url="" install_path="" steps="" version="" desktop="" gui="" ref=""
while IFS= read -r line || [ -n "$line" ]; do
[[ -z "$line" || "$line" == \#* ]] && continue
if [[ "$line" =~ ^\[(.+)\]$ ]]; then
if [ -n "$app" ]; then
process_app "$app" "$git_url" "$wget_url" "$install_path" "$steps" "$version" "$desktop" "$gui"
process_app "$app" "$git_url" "$wget_url" "$install_path" "$steps" "$version" "$desktop" "$gui" "$ref"
fi
app="${BASH_REMATCH[1]}"
git_url="" wget_url="" install_path="" steps="" version="" desktop="" gui=""
git_url="" wget_url="" install_path="" steps="" version="" desktop="" gui="" ref=""
continue
fi
@@ -279,6 +325,7 @@ process_conf() {
case "$key" in
git) git_url="$(eval echo "$value")" ;;
ref) ref="$value" ;;
wget) wget_url="$(eval echo "$value")" ;;
install) install_path="$(eval echo "$value")" ;;
steps) steps="$value" ;;
@@ -291,7 +338,7 @@ process_conf() {
# Process the last app in the file
if [ -n "$app" ]; then
process_app "$app" "$git_url" "$wget_url" "$install_path" "$steps" "$version" "$desktop" "$gui"
process_app "$app" "$git_url" "$wget_url" "$install_path" "$steps" "$version" "$desktop" "$gui" "$ref"
fi
}
@@ -315,4 +362,9 @@ echo ""
echo "Cleaning up..."
rm -rf "$TMP_DIR"
if (( ${#FAILED[@]} > 0 )); then
echo "Failed to install: ${FAILED[*]}"
exit 1
fi
echo "All done."