Files
eden/tools/cpm/common.sh
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1004 B
Bash
Raw Normal View History

#!/bin/sh -e
# SPDX-FileCopyrightText: Copyright 2026 crueter
2025-12-31 17:16:46 +01:00
# SPDX-License-Identifier: LGPL-3.0-or-later
2026-06-26 02:22:04 +02:00
: "${CPM_SOURCE_CACHE:=$PWD/.cache/cpm}"
: "${CPMUTIL_PATCH_DIR:=$PWD/.patch}"
2026-06-26 02:22:04 +02:00
# TODO: cache cpmfile defs?
cmd_exists() {
command -v "$1" >/dev/null 2>&1
}
2025-12-31 17:16:46 +01:00
must_install() {
for cmd in "$@"; do
2026-06-26 02:22:04 +02:00
cmd_exists "$cmd" || { echo "-- $cmd must be installed" && exit 1; }
done
}
2026-06-26 02:22:04 +02:00
# Random integer between 100000 and 999999
_randint() {
awk 'BEGIN { srand(); print int(100000 + rand() * 900000) }'
}
2025-10-20 03:43:15 +02:00
2026-06-26 02:22:04 +02:00
# Use mktemp if available, use a local temp dir otherwise
make_temp_dir() {
if cmd_exists mktemp; then
mktemp -d
else
TMP="$PWD/.cpm/tmp-$(_randint)"
mkdir -p "$TMP"
echo "$TMP"
fi
}
2026-06-26 02:22:04 +02:00
# must_install jq find mktemp tar 7z unzip sha512sum git patch curl
2026-06-26 02:22:04 +02:00
if [ ! -s cpmfile.json ]; then
# TODO: actually make it a no-op
echo "-- Warning: cpmfile.json does not exist or is empty, most commands will be no-ops"
else
LIBS=$(jq -j 'keys_unsorted | join(" ")' cpmfile.json)
export LIBS
fi