Skip to content

Commit 46d1d72

Browse files
authored
Create install
1 parent cb1f405 commit 46d1d72

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

install

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Install script to install fn
5+
6+
version="0.3.26"
7+
8+
command_exists() {
9+
command -v "$@" > /dev/null 2>&1
10+
}
11+
12+
case "$(uname -m)" in
13+
*64)
14+
;;
15+
*)
16+
echo >&2 'Error: you are not using a 64bit platform.'
17+
echo >&2 'Functions CLI currently only supports 64bit platforms.'
18+
exit 1
19+
;;
20+
esac
21+
22+
if command_exists fn ; then
23+
echo >&2 'Warning: "fn" command appears to already exist.'
24+
echo >&2 'If you are just upgrading your functions cli client, ignore this and wait a few seconds.'
25+
echo >&2 'You may press Ctrl+C now to abort this process.'
26+
( set -x; sleep 5 )
27+
fi
28+
29+
user="$(id -un 2>/dev/null || true)"
30+
31+
sh_c='sh -c'
32+
if [ "$user" != 'root' ]; then
33+
if command_exists sudo; then
34+
sh_c='sudo -E sh -c'
35+
elif command_exists su; then
36+
sh_c='su -c'
37+
else
38+
echo >&2 'Error: this installer needs the ability to run commands as root.'
39+
echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
40+
exit 1
41+
fi
42+
fi
43+
44+
curl=''
45+
if command_exists curl; then
46+
curl='curl -sSL -o'
47+
elif command_exists wget; then
48+
curl='wget -qO'
49+
elif command_exists busybox && busybox --list-modules | grep -q wget; then
50+
curl='busybox wget -qO'
51+
else
52+
echo >&2 'Error: this installer needs the ability to run wget or curl.'
53+
echo >&2 'We are unable to find either "wget" or "curl" available to make this happen.'
54+
exit 1
55+
fi
56+
57+
url='https://github.com/fnproject/cli/releases/download'
58+
59+
# perform some very rudimentary platform detection
60+
case "$(uname)" in
61+
Linux)
62+
$sh_c "$curl /usr/local/bin/fn $url/$version/fn_linux"
63+
$sh_c "chmod +x /usr/local/bin/fn"
64+
fn --version
65+
exit 0
66+
;;
67+
Darwin)
68+
$sh_c "$curl /usr/local/bin/fn $url/$version/fn_mac"
69+
$sh_c "chmod +x /usr/local/bin/fn"
70+
fn --version
71+
exit 0
72+
;;
73+
WindowsNT)
74+
$sh_c "$curl $url/$version/fn.exe"
75+
# TODO how to make executable? chmod?
76+
fn.exe --version
77+
exit 0
78+
;;
79+
esac
80+
81+
cat >&2 <<'EOF'
82+
83+
Either your platform is not easily detectable or is not supported by this
84+
installer script (yet - PRs welcome! [fn/install]).
85+
Please visit the following URL for more detailed installation instructions:
86+
87+
https://github.com/fnproject/fn
88+
89+
EOF
90+
exit 1

0 commit comments

Comments
 (0)