Skip to content

Commit 5efb9e0

Browse files
authored
Install script: fix query latest release from GitHub on missing curl (#839)
1 parent f8c901c commit 5efb9e0

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

install.sh

100755100644
Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ usage()
1818
echo ""
1919
}
2020

21+
# Return a download command
22+
get_fetch_command()
23+
{
24+
if command -v curl > /dev/null 2>&1; then
25+
echo "curl -L"
26+
elif command -v wget > /dev/null 2>&1; then
27+
echo "wget -O -"
28+
else
29+
echo "No download mechanism found. Install curl or wget first."
30+
return 1
31+
fi
32+
}
33+
2134
# Return value of the latest published release on GitHub, with no heading "v" (e.g., "0.7.0")
2235
get_latest_release()
2336
{
24-
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
25-
grep '"tag_name":' | # Get tag line
26-
sed -E 's/.*"([^"]+)".*/\1/' | # Pluck JSON value
27-
sed -E 's/^v//' # Remove heading "v" if present
37+
$2 "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
38+
grep '"tag_name":' | # Get tag line
39+
sed -E 's/.*"([^"]+)".*/\1/' | # Pluck JSON value
40+
sed -E 's/^v//' # Remove heading "v" if present
2841
}
2942

3043
PREFIX="$HOME/.local"
@@ -51,9 +64,17 @@ done
5164

5265
set -u # error on use of undefined variable
5366

54-
LATEST_RELEASE=$(get_latest_release "fortran-lang/fpm")
67+
# Get download command
68+
FETCH=$(get_fetch_command)
69+
if [ $? -ne 0 ]; then
70+
echo "No download mechanism found. Install curl or wget first."
71+
exit 1
72+
fi
73+
74+
LATEST_RELEASE=$(get_latest_release "fortran-lang/fpm" $FETCH)
5575
SOURCE_URL="https://github.com/fortran-lang/fpm/releases/download/v${LATEST_RELEASE}/fpm-${LATEST_RELEASE}.F90"
5676
BOOTSTRAP_DIR="build/bootstrap"
77+
5778
if [ -z ${FC+x} ]; then
5879
FC="gfortran"
5980
fi
@@ -63,15 +84,6 @@ fi
6384

6485
mkdir -p $BOOTSTRAP_DIR
6586

66-
if command -v curl > /dev/null 2>&1; then
67-
FETCH="curl -L"
68-
elif command -v wget > /dev/null 2>&1; then
69-
FETCH="wget -O -"
70-
else
71-
echo "No download mechanism found. Install curl or wget first."
72-
exit 1
73-
fi
74-
7587
$FETCH $SOURCE_URL > $BOOTSTRAP_DIR/fpm.F90
7688

7789
SAVEDIR="$(pwd)"

0 commit comments

Comments
 (0)