-
Notifications
You must be signed in to change notification settings - Fork 8
Added install-capi.sh #553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AkshatRai07
wants to merge
9
commits into
master
Choose a base branch
from
capi-installer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
571a260
Added install-capi.sh
AkshatRai07 65153f9
Added curl tags fsSL
AkshatRai07 a62c9e4
Added telling error messages
AkshatRai07 d6ee5a5
Added TTY input
AkshatRai07 de6aad0
Fixed ~ expansion
AkshatRai07 3dec969
Fixed special characters in sed
AkshatRai07 d22eb0f
Handled broken downloads
AkshatRai07 e1b8231
Fixed shellcheck error
AkshatRai07 8746000
Added trap and extract dir
AkshatRai07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| #!/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) | ||
| if [ $# -lt 2 ]; then | ||
| echo "Error: --version requires a value" >&2 | ||
| exit 1 | ||
| fi | ||
| version=$2 | ||
| shift | ||
| shift | ||
| ;; | ||
| --version=*) | ||
| version=${1#--version=} | ||
| shift | ||
| ;; | ||
| --prefix) | ||
| if [ $# -lt 2 ]; then | ||
| echo "Error: --prefix requires a value" >&2 | ||
| exit 1 | ||
| fi | ||
| prefix=$2 | ||
| shift | ||
| shift | ||
| ;; | ||
|
AkshatRai07 marked this conversation as resolved.
|
||
| --prefix=*) | ||
| prefix=${1#--prefix=} | ||
| shift | ||
| ;; | ||
| --target) | ||
| if [ $# -lt 2 ]; then | ||
| echo "Error: --target requires a value" >&2 | ||
| exit 1 | ||
| fi | ||
| target=$2 | ||
| shift | ||
| shift | ||
| ;; | ||
|
AkshatRai07 marked this conversation as resolved.
|
||
| --target=*) | ||
| target=${1#--target=} | ||
| shift | ||
| ;; | ||
| *) | ||
| echo "Error: argument '$1' unknown" >&2 | ||
| 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 | ||
| if [ -r /dev/tty ]; then | ||
| printf "Enter installation path: " | ||
| IFS= read -r prefix </dev/tty | ||
| echo | ||
| else | ||
| echo "Error: cannot prompt for --prefix (no TTY available); pass --prefix explicitly" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # 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 | ||
|
|
||
| # 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 -fsSL "${url}" | tar xzf - -C "${prefix}" | ||
|
AkshatRai07 marked this conversation as resolved.
Outdated
|
||
|
|
||
| # 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" | ||
| mv "${prefix}"/lib/pkgconfig/ekore_capi.pc.new "${prefix}"/lib/pkgconfig/ekore_capi.pc | ||
|
|
||
|
AkshatRai07 marked this conversation as resolved.
|
||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.