@@ -18,13 +18,26 @@ usage()
18
18
echo " "
19
19
}
20
20
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
+
21
34
# Return value of the latest published release on GitHub, with no heading "v" (e.g., "0.7.0")
22
35
get_latest_release ()
23
36
{
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
28
41
}
29
42
30
43
PREFIX=" $HOME /.local"
51
64
52
65
set -u # error on use of undefined variable
53
66
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 )
55
75
SOURCE_URL=" https://github.com/fortran-lang/fpm/releases/download/v${LATEST_RELEASE} /fpm-${LATEST_RELEASE} .F90"
56
76
BOOTSTRAP_DIR=" build/bootstrap"
77
+
57
78
if [ -z ${FC+x} ]; then
58
79
FC=" gfortran"
59
80
fi
63
84
64
85
mkdir -p $BOOTSTRAP_DIR
65
86
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
-
75
87
$FETCH $SOURCE_URL > $BOOTSTRAP_DIR /fpm.F90
76
88
77
89
SAVEDIR=" $( pwd) "
0 commit comments