From 571a260007685afd7e995a40dec881cab34c44e8 Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Tue, 21 Jul 2026 23:22:04 +0530 Subject: [PATCH 1/9] Added install-capi.sh --- crates/ekore_capi/install-capi.sh | 133 ++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 crates/ekore_capi/install-capi.sh diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh new file mode 100755 index 000000000..fd240929f --- /dev/null +++ b/crates/ekore_capi/install-capi.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +# WARNING: do not commit changes to this file unless you've checked it against +# `shellcheck` (https://www.shellcheck.net/); run `shellcheck install-capi.sh` +# to make sure this script is POSIX shell compatible; we cannot rely on bash +# being present + +set -eu + +prefix= +version= +target= + +while [ $# -gt 0 ]; do + case $1 in + --version) + version=$2 + shift + shift + ;; + --version=*) + version=${1#--version=} + shift + ;; + --prefix) + prefix=$2 + shift + shift + ;; + --prefix=*) + prefix=${1#--prefix=} + shift + ;; + --target) + target=$2 + shift + shift + ;; + --target=*) + target=${1#--target=} + shift + ;; + *) + echo "Error: argument '$1' unknown" + exit 1 + ;; + esac +done + +if [ -z "${target}" ]; then + case $(uname -m):$(uname -s) in + arm64:Darwin) + target=macos-aarch64;; + x86_64:Darwin) + target=macos-x86_64;; + aarch64:Linux) + target=linux-aarch64;; + x86_64:Linux) + target=linux-x86_64;; + *) + echo "Error: unknown target, uname = '$(uname -a)'" + exit 1;; + esac +fi + +# if no prefix is given, prompt for one +if [ -z "${prefix}" ]; then + # read from stdin (`<&1`), even if piped into a shell + printf "Enter installation path: " + read -r <&1 prefix + echo +fi + +# we need the absolute path; use `eval` to expand possible tilde `~` +eval mkdir -p "${prefix}" +eval cd "${prefix}" +prefix=$(pwd) +cd - >/dev/null + +# if no version is given, use the latest version tag +if [ -z "${version}" ]; then + version=$(curl -s -o /dev/null -w '%{redirect_url}' \ + "https://github.com/NNPDF/eko/releases/latest" | sed 's:.*/tag/::') +fi + +url="https://github.com/NNPDF/eko/releases/download/${version}/ekore_capi-${version}-${target}.tar.gz" + +echo "prefix: '${prefix}'" +echo "target: '${target}'" +echo "version: '${version}'" +echo "URL: '${url}'" + +curl -s -LJ "${url}" | tar xzf - -C "${prefix}" + +# Patch the pkg-config file +sed "s:prefix=/:prefix=${prefix}/:" "${prefix}"/lib/pkgconfig/ekore_capi.pc > \ + "${prefix}"/lib/pkgconfig/ekore_capi.pc.new +mv "${prefix}"/lib/pkgconfig/ekore_capi.pc.new "${prefix}"/lib/pkgconfig/ekore_capi.pc + +pcbin= + +if command -v pkg-config >/dev/null; then + pcbin=$(command -v pkg-config) +elif command -v pkgconf >/dev/null; then + pcbin=$(command -v pkgconf) +else + echo + echo "Error: neither \`pkg-config\` nor \`pkgconf\` found. At least one is needed for the CAPI to be found" + exit 1 +fi + +# check whether the library can be found +if "${pcbin}" --exists ekore_capi; then + found_prefix=$(cd "$("${pcbin}" --variable=prefix ekore_capi)" && pwd) + + if [ "${prefix}" != "${found_prefix}" ]; then + echo + echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set." + echo "It appears a different installation of Ekore C-API is found:" + echo + echo " ${found_prefix}" + echo + echo "Remove this installation or reorder your PKG_CONFIG_PATH" + fi +else + echo + echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set." + echo "Try adding" + echo + echo " export PKG_CONFIG_PATH=${prefix}/lib/pkgconfig:\"\${PKG_CONFIG_PATH:-}\"" + echo + echo "to your shell configuration file" +fi From 65153f98556e4ae1734a8ce5a3e236706e123c1b Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Tue, 21 Jul 2026 23:34:27 +0530 Subject: [PATCH 2/9] Added curl tags fsSL --- crates/ekore_capi/install-capi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index fd240929f..bc11484b7 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -90,7 +90,7 @@ echo "target: '${target}'" echo "version: '${version}'" echo "URL: '${url}'" -curl -s -LJ "${url}" | tar xzf - -C "${prefix}" +curl -fsSL "${url}" | tar xzf - -C "${prefix}" # Patch the pkg-config file sed "s:prefix=/:prefix=${prefix}/:" "${prefix}"/lib/pkgconfig/ekore_capi.pc > \ From a62c9e48b75d60a417df199c659b185b18ef6be2 Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Tue, 21 Jul 2026 23:56:16 +0530 Subject: [PATCH 3/9] Added telling error messages --- crates/ekore_capi/install-capi.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index bc11484b7..b65e33140 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -14,6 +14,10 @@ target= while [ $# -gt 0 ]; do case $1 in --version) + if [ $# -lt 2 ]; then + echo "Error: --version requires a value" >&2 + exit 1 + fi version=$2 shift shift @@ -23,6 +27,10 @@ while [ $# -gt 0 ]; do shift ;; --prefix) + if [ $# -lt 2 ]; then + echo "Error: --prefix requires a value" >&2 + exit 1 + fi prefix=$2 shift shift @@ -32,6 +40,10 @@ while [ $# -gt 0 ]; do shift ;; --target) + if [ $# -lt 2 ]; then + echo "Error: --target requires a value" >&2 + exit 1 + fi target=$2 shift shift @@ -41,7 +53,7 @@ while [ $# -gt 0 ]; do shift ;; *) - echo "Error: argument '$1' unknown" + echo "Error: argument '$1' unknown" >&2 exit 1 ;; esac From d6ee5a5fd6794a03bf936e0a26223dc06420184b Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Wed, 22 Jul 2026 00:10:53 +0530 Subject: [PATCH 4/9] Added TTY input --- crates/ekore_capi/install-capi.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index b65e33140..570f46c25 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -77,10 +77,14 @@ fi # if no prefix is given, prompt for one if [ -z "${prefix}" ]; then - # read from stdin (`<&1`), even if piped into a shell - printf "Enter installation path: " - read -r <&1 prefix - echo + if [ -r /dev/tty ]; then + printf "Enter installation path: " + IFS= read -r prefix &2 + exit 1 + fi fi # we need the absolute path; use `eval` to expand possible tilde `~` From de6aad06c4a10f5857946304897a5b640ba19d0f Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Wed, 22 Jul 2026 00:19:18 +0530 Subject: [PATCH 5/9] Fixed ~ expansion --- crates/ekore_capi/install-capi.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index 570f46c25..0568ebe14 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -87,9 +87,10 @@ if [ -z "${prefix}" ]; then fi fi -# we need the absolute path; use `eval` to expand possible tilde `~` -eval mkdir -p "${prefix}" -eval cd "${prefix}" +# we need the absolute path; expand a leading "~" (POSIX) and canonicalize +case ${prefix} in "~"|"~/"*) prefix=${HOME}${prefix#\~};; esac +mkdir -p "${prefix}" +cd "${prefix}" prefix=$(pwd) cd - >/dev/null From 3dec9694bf8c717e53f48786b4eecd20639ef45f Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Wed, 22 Jul 2026 00:31:43 +0530 Subject: [PATCH 6/9] Fixed special characters in sed --- crates/ekore_capi/install-capi.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index 0568ebe14..aa4d17e68 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -110,8 +110,8 @@ echo "URL: '${url}'" curl -fsSL "${url}" | tar xzf - -C "${prefix}" # Patch the pkg-config file -sed "s:prefix=/:prefix=${prefix}/:" "${prefix}"/lib/pkgconfig/ekore_capi.pc > \ - "${prefix}"/lib/pkgconfig/ekore_capi.pc.new +escaped_prefix=$(printf %s "${prefix}" | sed 's:[\\/&]:\\&:g') +sed "s:prefix=/:prefix=${escaped_prefix}/:" "${prefix}/lib/pkgconfig/ekore_capi.pc" > "${prefix}/lib/pkgconfig/ekore_capi.pc.new" mv "${prefix}"/lib/pkgconfig/ekore_capi.pc.new "${prefix}"/lib/pkgconfig/ekore_capi.pc pcbin= From d22eb0f07ad4a76126e76c0e5803169360118623 Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Thu, 30 Jul 2026 23:38:20 +0530 Subject: [PATCH 7/9] Handled broken downloads --- crates/ekore_capi/install-capi.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index aa4d17e68..ded2cd578 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -107,7 +107,18 @@ echo "target: '${target}'" echo "version: '${version}'" echo "URL: '${url}'" -curl -fsSL "${url}" | tar xzf - -C "${prefix}" +tmp_dir=$(mktemp -d) +tarball="${tmp_dir}/ekore_capi.tar.gz" + +if curl -fsSL "${url}" -o "${tarball}"; then + tar xzf "${tarball}" -C "${prefix}" +else + echo "Error: Failed to download the file." >&2 + rm -rf "${tmp_dir}" + exit 1 +fi + +rm -rf "${tmp_dir}" # Patch the pkg-config file escaped_prefix=$(printf %s "${prefix}" | sed 's:[\\/&]:\\&:g') From e1b8231cf8385f965f9ab94cabee577e0a6b07cd Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Thu, 30 Jul 2026 23:49:57 +0530 Subject: [PATCH 8/9] Fixed shellcheck error --- crates/ekore_capi/install-capi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index ded2cd578..ff56fc0f1 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -88,7 +88,7 @@ if [ -z "${prefix}" ]; then fi # we need the absolute path; expand a leading "~" (POSIX) and canonicalize -case ${prefix} in "~"|"~/"*) prefix=${HOME}${prefix#\~};; esac +case ${prefix} in "~"|"$HOME/"*) prefix=${HOME}${prefix#\~};; esac mkdir -p "${prefix}" cd "${prefix}" prefix=$(pwd) From 8746000985fe3af77f85eca5acc36fb050525912 Mon Sep 17 00:00:00 2001 From: AkshatRai07 Date: Sun, 2 Aug 2026 11:51:24 +0530 Subject: [PATCH 9/9] Added trap and extract dir --- crates/ekore_capi/install-capi.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ekore_capi/install-capi.sh b/crates/ekore_capi/install-capi.sh index ff56fc0f1..dfcf92aac 100755 --- a/crates/ekore_capi/install-capi.sh +++ b/crates/ekore_capi/install-capi.sh @@ -108,18 +108,19 @@ echo "version: '${version}'" echo "URL: '${url}'" tmp_dir=$(mktemp -d) +trap 'rm -rf "${tmp_dir}"' EXIT tarball="${tmp_dir}/ekore_capi.tar.gz" +extract_dir="${tmp_dir}/extract" if curl -fsSL "${url}" -o "${tarball}"; then - tar xzf "${tarball}" -C "${prefix}" + mkdir -p "${extract_dir}" + tar xzf "${tarball}" -C "${extract_dir}" + cp -R "${extract_dir}"/* "${prefix}/" else echo "Error: Failed to download the file." >&2 - rm -rf "${tmp_dir}" exit 1 fi -rm -rf "${tmp_dir}" - # Patch the pkg-config file escaped_prefix=$(printf %s "${prefix}" | sed 's:[\\/&]:\\&:g') sed "s:prefix=/:prefix=${escaped_prefix}/:" "${prefix}/lib/pkgconfig/ekore_capi.pc" > "${prefix}/lib/pkgconfig/ekore_capi.pc.new"