-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·185 lines (151 loc) · 5.09 KB
/
install.sh
File metadata and controls
executable file
·185 lines (151 loc) · 5.09 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
set -euo pipefail
# The following script is adapted from the bun.sh install script
# Licensed under the MIT License (https://github.com/oven-sh/bun/blob/main/LICENSE.md)
platform=$(uname -ms)
# Invoke the ps1 script if on Windows
if [[ ${OS:-} = Windows_NT ]]; then
if [[ $platform != MINGW64* ]]; then
powershell -c "irm https://apify.com/install-cli.ps1|iex"
exit $?
fi
fi
# Reset
Color_Off=''
# Regular Colors
Red=''
Dim='' # White
if [[ -t 1 ]]; then
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Dim='\033[0;2m' # White
fi
error() {
echo -e "${Red}error${Color_Off}:" "$@" >&2
exit 1
}
info() {
echo -e "${Dim}$@ ${Color_Off}"
}
if [[ $# -gt 1 ]]; then
error 'Too many arguments, only 1 is allowed. The first can be a specific tag of Apify CLI to install. (e.g. "0.28.0")'
fi
# Check if curl is available
if ! command -v curl &>/dev/null; then
error "curl is required but not installed. Please install curl and try again."
fi
case $platform in
'Darwin x86_64')
target=darwin-x64
;;
'Darwin arm64')
target=darwin-aarch64
;;
'Linux aarch64' | 'Linux arm64')
target=linux-aarch64
;;
'MINGW64'*'ARM64'* | 'MINGW64'*'aarch64'*)
target=windows-aarch64
;;
'MINGW64'*)
target=windows-x64
;;
'Linux riscv64')
error 'Not supported on riscv64'
;;
'Linux x86_64' | *)
target=linux-x64
;;
esac
case "$target" in
'linux'*)
if [ -f /etc/alpine-release ]; then
target="$target-musl"
fi
;;
esac
if [[ $target = darwin-x64 ]]; then
# Is this process running in Rosetta?
# redirect stderr to devnull to avoid error message when not running in Rosetta
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
target=darwin-arm64
info "Your shell is running in Rosetta 2. Downloading Apify and Actor CLI for $target instead"
fi
fi
# If AVX2 isn't supported, use the -baseline build
case "$target" in
'darwin-x64'*)
if [[ $(sysctl -a | grep machdep.cpu | grep AVX2) == '' ]]; then
target="$target-baseline"
fi
;;
'linux-x64'*)
# If AVX2 isn't supported, use the -baseline build
if [[ $(cat /proc/cpuinfo | grep avx2) = '' ]]; then
target="$target-baseline"
fi
;;
esac
# Function to fetch latest version from GitHub API
fetch_latest_version() {
local api_url="https://api.github.com/repos/apify/apify-cli/releases/latest"
local response=$(curl -s "$api_url")
if [ $? -ne 0 ]; then
error "Failed to fetch latest version from GitHub API"
fi
# Extract tag_name and strip 'v' prefix
local version=$(echo "$response" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/' | sed 's/^v//')
if [ -z "$version" ]; then
error "Failed to parse version from GitHub API response"
fi
echo "$version"
}
executable_names=("apify" "actor")
if [[ $# = 0 || $1 = "latest" ]]; then
version=$(fetch_latest_version)
else
version=$1
# Validate version format
if [[ ! $version =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-beta\.[0-9]+)?$ ]]; then
error "Invalid version format: $version. Expected format: x.y.z or x.y.z-beta.n (with optional 'v' prefix)"
fi
# Trim 'v' prefix if present
version=${version#v}
fi
# Function to construct download URL
construct_download_url() {
local cli_name="$1"
local edition="$2"
echo "https://github.com/apify/apify-cli/releases/download/v${version}/${cli_name}-${version}-${edition}"
}
install_env=APIFY_CLI_INSTALL
install_dir=${!install_env:-$HOME/.apify}
bin_dir=$install_dir/bin
if [[ ! -d $bin_dir ]]; then
mkdir -p "$bin_dir" ||
error "Failed to create install directory \"$bin_dir\""
fi
for executable_name in "${executable_names[@]}"; do
download_url=$(construct_download_url "$executable_name" "$target")
output_filename="${executable_name}"
info "Downloading $executable_name bundle for version $version and target $target"
curl --fail --location --progress-bar --output "$bin_dir/$output_filename" "$download_url" ||
error "Failed to download $executable_name bundle for version $version and target $target (might not exist for this platform/arch combination)"
chmod +x "$bin_dir/$output_filename" ||
error "Failed to set permissions on $executable_name executable"
# Alias apify to apify-cli, as npm does (because otherwise npx apify-cli wouldn't work)
if [[ $executable_name = "apify" ]]; then
cp "$bin_dir/$output_filename" "$bin_dir/apify-cli"
fi
done
# Invoke the CLI to handle shell integrations nicely
# When running the script via `curl xxx | bash`, stdin is the script that gets consumed by bash.
# If stdin is not a tty and we have a readable /dev/tty, tell Node.js to open /dev/tty itself
# (shell-level redirects don't support raw mode properly for Node.js/Inquirer).
if ! [ -t 0 ] && [ -r /dev/tty ]; then
PROVIDED_INSTALL_DIR="$install_dir" FINAL_BIN_DIR="$bin_dir" APIFY_OPEN_TTY=1 "$bin_dir/apify" install
else
PROVIDED_INSTALL_DIR="$install_dir" FINAL_BIN_DIR="$bin_dir" "$bin_dir/apify" install
fi