-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·197 lines (171 loc) · 4.13 KB
/
install.sh
File metadata and controls
executable file
·197 lines (171 loc) · 4.13 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
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
set -euo pipefail
# Debugging output
# set -x
show_help() {
echo "Funnel Installation Script"
echo
echo "Usage:"
echo " $0 [version] [install_path] # Install Funnel (default: latest version to \$HOME/.local/bin)"
echo " $0 --list # List available versions"
echo " $0 --help # Show this help"
echo " $0 --version <version> # Specify version to install"
echo " $0 --dest <install_path> # Specify installation path (default: \$HOME/.local/bin)"
}
list_tags() {
RELEASES_URL="https://api.github.com/repos/ohsu-comp-bio/funnel/releases"
# Get all releases and extract tag names
RELEASES_JSON=$(curl -s "$RELEASES_URL")
echo "$RELEASES_JSON" | grep '"tag_name":' | cut -d '"' -f 4 | head -20 | while read -r tag; do
echo "$tag"
done
}
# Global variables
# TODO: Move to respective functions?
VERSION=""
RELEASE_URL=""
ASSETS=""
OS=""
ARCH=""
TAR_FILE=""
CHECKSUM_FILE=""
DEST=""
# Arguments
while [[ $# -gt 0 ]]; do
case $1 in
--list | -l)
list_tags
exit 0
;;
--help | -h)
show_help
exit 0
;;
--version | -v)
VERSION="$2"
shift
shift
;;
--dest | -d)
# Deprecated flag
DEST="$2"
shift
shift
;;
-*)
echo "Unknown option: $1"
show_help
exit 1
;;
*)
# Handle positional arguments
if [ -z "$VERSION" ]; then
VERSION="$1"
elif [ -z "$DEST" ]; then
DEST="$1"
else
echo "Too many arguments: $1"
show_help
exit 1
fi
shift
;;
esac
done
get_release_url() {
if [ -z "$VERSION" ]; then
echo "No version specified. Fetching the latest release..."
RELEASE_URL="https://api.github.com/repos/ohsu-comp-bio/funnel/releases/latest"
VERSION=$(curl -s $RELEASE_URL | grep '"tag_name":' | cut -d '"' -f 4)
else
echo "Fetching release for version $VERSION..."
RELEASE_URL="https://api.github.com/repos/ohsu-comp-bio/funnel/releases/tags/$VERSION"
fi
}
get_os_arch() {
# OS/Arch
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
if [ "$ARCH" == "x86_64" ]; then
ARCH="amd64"
elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
ARCH="arm64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
}
get_assets() {
# Fetch the release assets URLs
RELEASE_JSON=$(curl -s $RELEASE_URL)
if echo "$RELEASE_JSON" | grep -q '"status": "404"'; then
echo "Release $VERSION not found."
echo
echo "Available versions:"
list_tags
exit 1
fi
ASSETS=$(echo "$RELEASE_JSON" | grep "browser_download_url" | cut -d '"' -f 4)
if [ -z "$ASSETS" ]; then
echo "No assets found for release $VERSION. Exiting..."
exit 1
fi
}
download() {
TAR_FILE="funnel-${OS}-${ARCH}"
# Download the tar.gz file and checksums.txt for the detected OS and Arch
echo "Downloading Funnel $VERSION for $OS $ARCH..."
for asset in $ASSETS; do
asset_name=$(basename "$asset")
# Binary (tar.gz)
if [[ "$asset" == *"${TAR_FILE}"* && "$asset" == *.tar.gz ]]; then
TAR_URL="$asset"
TAR_NAME="$asset_name"
echo " ➜ $TAR_NAME"
curl -L --progress-bar -o "$TAR_NAME" "$TAR_URL"
# Checksums
elif [[ "$asset_name" == *checksums* ]]; then
CHECKSUM_FILE="$asset_name"
echo " ➜ $CHECKSUM_FILE"
curl -L --progress-bar -o "$CHECKSUM_FILE" "$asset"
fi
done
}
verify() {
# Verify checksum
echo "Verifying checksum..."
CHECKSUM_EXPECTED=$(grep $TAR_NAME $CHECKSUM_FILE | awk '{print $1}')
CHECKSUM_ACTUAL=$(shasum -a 256 $TAR_NAME | awk '{print $1}')
if [ "$CHECKSUM_EXPECTED" != "$CHECKSUM_ACTUAL" ]; then
echo "Checksum verification failed for $TAR_NAME. Exiting..."
exit 1
fi
}
install() {
# Extract and install the package
echo "Extracting the package..."
tar -xzf $TAR_NAME
# Determine where to install the Funnel binary
if [ -z "$DEST" ]; then
DEST=$HOME/.local/bin
fi
echo "Installing Funnel to $DEST..."
mkdir -p $DEST
mv funnel $DEST
# Clean up
rm $TAR_NAME $CHECKSUM_FILE
echo "Installation successful: $DEST/funnel"
echo
$DEST/funnel version
echo
echo "Run '$DEST/funnel --help' for more info"
}
main() {
get_release_url
get_os_arch
get_assets
download
verify
install
}
main