aboutsummaryrefslogtreecommitdiff
path: root/contrib/guix/libexec/prelude.bash
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-03-17 12:36:55 -0400
committerCarl Dong <contact@carldong.me>2021-04-05 11:00:21 -0400
commit7753357a7bae98ec775c707b9dec4cea1e945802 (patch)
tree81eb95d504fb71a062c068f1def14298c45b4485 /contrib/guix/libexec/prelude.bash
parente5b49a01f5d0f631e7f08f86ca8a2c2b8213319f (diff)
guix: Add source-able bash prelude and utils
Diffstat (limited to 'contrib/guix/libexec/prelude.bash')
-rw-r--r--contrib/guix/libexec/prelude.bash60
1 files changed, 60 insertions, 0 deletions
diff --git a/contrib/guix/libexec/prelude.bash b/contrib/guix/libexec/prelude.bash
new file mode 100644
index 0000000000..33a319012c
--- /dev/null
+++ b/contrib/guix/libexec/prelude.bash
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+export LC_ALL=C
+set -e -o pipefail
+
+# shellcheck source=../../shell/realpath.bash
+source contrib/shell/realpath.bash
+
+# shellcheck source=../../shell/git-utils.bash
+source contrib/shell/git-utils.bash
+
+################
+# Required non-builtin commands should be invokable
+################
+
+check_tools() {
+ for cmd in "$@"; do
+ if ! command -v "$cmd" > /dev/null 2>&1; then
+ echo "ERR: This script requires that '$cmd' is installed and available in your \$PATH"
+ exit 1
+ fi
+ done
+}
+
+check_tools cat env readlink dirname basename git
+
+################
+# We should be at the top directory of the repository
+################
+
+same_dir() {
+ local resolved1 resolved2
+ resolved1="$(bash_realpath "${1}")"
+ resolved2="$(bash_realpath "${2}")"
+ [ "$resolved1" = "$resolved2" ]
+}
+
+if ! same_dir "${PWD}" "$(git_root)"; then
+cat << EOF
+ERR: This script must be invoked from the top level of the git repository
+
+Hint: This may look something like:
+ env FOO=BAR ./contrib/guix/guix-<blah>
+
+EOF
+exit 1
+fi
+
+################
+# Set common variables
+################
+
+VERSION="${VERSION:-$(git_head_version)}"
+DISTNAME="${DISTNAME:-bitcoin-${VERSION}}"
+
+version_base_prefix="${PWD}/guix-build-"
+VERSION_BASE="${version_base_prefix}${VERSION}" # TOP
+
+DISTSRC_BASE="${DISTSRC_BASE:-${VERSION_BASE}}"
+
+OUTDIR_BASE="${OUTDIR_BASE:-${VERSION_BASE}/output}"