-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·110 lines (91 loc) · 3.08 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
# This script should be run via curl:
# sh -c "$(curl -fsSL https://fpm.dev/install.sh)"
# or via wget
# sh -c "$(wget -qO- https://fastn.dev/install.sh)"
# The [ -t 1 ] check only works when the function is not called from
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
# function at the top level to always return false when stdout is not
# a tty.
if [ -t 1 ]; then
is_tty() {
true
}
else
is_tty() {
false
}
fi
command_exists() {
command -v "$@" >/dev/null 2>&1
}
setup_colors() {
if ! is_tty; then
FMT_RED=""
FMT_GREEN=""
FMT_YELLOW=""
FMT_BLUE=""
FMT_BOLD=""
FMT_RESET=""
else
FMT_RED=$(printf '\033[31m')
FMT_GREEN=$(printf '\033[32m')
FMT_YELLOW=$(printf '\033[33m')
FMT_BLUE=$(printf '\033[34m')
FMT_BOLD=$(printf '\033[1m')
FMT_RESET=$(printf '\033[0m')
fi
}
setup() {
# Parse arguments
while [ $# -gt 0 ]; do
case $1 in
--pre-release) PRE_RELEASE=true ;;
--controller) CONTROLLER=true;;
esac
shift
done
if [[ $PRE_RELEASE ]]; then
URL="https://api.github.com/repos/ftd-lang/fastn/releases"
echo "Downloading the latest pre-release binaries"
else
URL="https://api.github.com/repos/ftd-lang/fastn/releases/latest"
echo "Downloading the latest production ready binaries"
fi
DESTINATION_PATH="/usr/local/bin"
if [ -d "$DESTINATION_PATH" ]; then
DESTINATION_PATH=$DESTINATION_PATH
else
DESTINATION_PATH="${HOME}/.fastn/bin"
mkdir -p $DESTINATION_PATH
fi
if [[ $CONTROLLER ]]; then
curl -s $URL | grep ".*\/releases\/download\/.*\/fastn_controller_linux.*" | head -2 | cut -d : -f 2,3 | tee /dev/tty | xargs -I % curl -O -J -L %
mv fastn_controller_linux_musl_x86_64 "${DESTINATION_PATH}/fastn"
mv fastn_controller_linux_musl_x86_64.d "${DESTINATION_PATH}/fastn.d"
elif [[ "$OSTYPE" == "darwin"* ]]; then
curl -s $URL | grep ".*\/releases\/download\/.*\/fastn_macos.*" | head -1 | cut -d : -f 2,3 | tee /dev/tty | xargs -I % curl -O -J -L %
mv fastn_macos_x86_64 "${DESTINATION_PATH}/fastn"
else
curl -s $URL | grep ".*\/releases\/download\/.*\/fastn_linux.*" | head -2 | cut -d : -f 2,3 | tee /dev/tty | xargs -I % curl -O -J -L %
mv fastn_linux_musl_x86_64 "${DESTINATION_PATH}/fastn"
mv fastn_linux_musl_x86_64.d "${DESTINATION_PATH}/fastn.d"
fi
chmod +x "${DESTINATION_PATH}/fastn"*
if ! [[ $DESTINATION_PATH == "/usr/local/bin" ]]; then
cat <<EOF
Unable to create a binary link for your system. Please add the following to your .bashrc/.zshrc file
${FMT_GREEN}PATH="\$PATH:${DESTINATION_PATH}"${FMT_RESET}
and reload the configuration/restart the terminal session
EOF
fi
}
main() {
setup_colors
if ! command_exists curl; then
echo "${FMT_RED}curl command not found. Please install the curl utility and execute the script once again${FMT_RESET}"
exit 1
fi
setup "$@"
}
main "$@"