-
Notifications
You must be signed in to change notification settings - Fork 0
/
streak.sh
executable file
·175 lines (135 loc) · 4.29 KB
/
streak.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
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
#!/bin/bash
#- StreakCLI -------------------------------------------------------------------
#- https://github.com/AstroStreakNet/streak ------------------------------------
#- HELPER FUNCTIONS ------------------------------------------------------------
export INSTALL_PATH="/opt/streak"
export BIN="$INSTALL_PATH/bin"
CHECK_MISSING () {
command -v "$1" > /dev/null 2>&1 && return
# $2 = essential requirement
# true = error. terminate if not found
# false = warning. just show missing
if [ $2 = true ]; then
echo -e "\033[31mError 401:\033[0m $1 is not installed."
echo "Please install \"$1\" to proceed and make sure it's in \$PATH"
exit 1;
else
echo -e "\033[33mWarning 401:\033[0m $1 is not installed."
echo "Program usage is limited due to missing package: \"$1\""
fi
}
INSTALL_STREAK() {
CHECK_MISSING "git" true # to pull the project and keep it updated
CHECK_MISSING "tar" true # to untar source files
CHECK_MISSING "grep" true # to search through local .FITS
# direct build link
RELEASE="https://api.github.com/repos/AstroStreakNet/streak/releases/latest"
# get system architecture and OS
OS=$(uname -s)
ARCH=$(uname -m)
# determine binary to download
case "$OS" in
Darwin)
case "$ARCH" in
arm64) BINARY="darwin-arm" ;;
x86_64) BINARY="darwin-intel" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
;;
Linux)
case "$ARCH" in
aarch64) BINARY="linux-arm" ;;
x86_64) BINARY="linux-x86" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac
BIN_URL=$(curl --silent "$RELEASE" | grep "$BINARY" | cut -d '"' -f 4)
if [ -z "$BIN_URL" ]; then
echo "Binary not found for $BINARY"
exit 1
fi
# download and extract the source archive
SOURCE_URL=$(curl --silent "$RELEASE" | grep "source.tar.gz" | cut -d '"' -f 4)
if [ -z "$SOURCE_URL" ]; then
echo "Source archive not found"
exit 1
fi
echo "Binary URL: $BIN_URL"
echo "Source URL: $SOURCE_URL"
# create installation path
echo "Login as super user to complete the installation."
sudo mkdir -p "$INSTALL_PATH"
# save installation media
curl -L -o "$INSTALL_PATH/bin" "$BIN_URL" # streak binary
curl -L -o "$INSTALL_PATH/source.tar.gz" "$SOURCE_URL" # source archive
# untar source files
tar -xzf "$INSTALL_PATH/source.tar.gz" -C "$INSTALL_PATH/"
echo "Installed StreakCLI Successfully!"
}
#- CHECK INSTALL ---------------------------------------------------------------
# xargs is required to process input passed as pipes. It's optional when usecase
# is strictly
# $ streak upload [commands]
#
# but is necessary for trying commands as-
# $ find . -type f | streal upload
CHECK_MISSING "xargs" false
# required to download selected images, and program files
CHECK_MISSING "curl" true
# required to search through fits header data and make comparisions
CHECK_MISSING "bc" true
# optional dependency. useful within various subcommands
CHECK_MISSING "fzf" false
# check installation path
if [ -d "$INSTALL_PATH" ]; then
scripts=(
"bin" # program binary
"debug.sh" "print.sh" "grepfind.sh" # more control
"upload.sh" "download.sh" "browse.sh" # binary wrapper
)
for file in "${scripts[@]}"; do
if [ ! -f "$INSTALL_PATH/$file" ]; then
echo -e "\033[31mError 400:\033[0m Installation appears to be broken."
echo "Fixing install... this should only take a moment."
INSTALL_STREAK
fi
done
else
"$INSTALL_PATH/print.sh" "PROMPT_NEW"
INSTALL_STREAK
fi
#- DEPENDENCIES ----------------------------------------------------------------
# script calls very commonly required in various different scripts
export PRINT_ERROR="$INSTALL_PATH/print.sh ERROR"
export PRINT_WARNING="$INSTALL_PATH/print.sh WARN"
#- RUN STREAK ------------------------------------------------------------------
CMD=$1
shift
ARGS="$@"
if [ ! -t 0 ]; then ARGS+=" $(xargs)"; fi
case "$CMD" in
"--help" | "-h" | "help")
"$INSTALL_PATH/print.sh" "PROMPT_HELP"
;;
"upload" | "u")
"$INSTALL_PATH/upload.sh" $ARGS
;;
"browse" | "b")
"$INSTALL_PATH/browse.sh" $ARGS
;;
"download" | "d")
"$INSTALL_PATH/download.sh" $ARGS
;;
"debug" | "x" | "whatis")
"$INSTALL_PATH/debug.sh" $ARGS
;;
*)
$PRINT_ERROR 100 "Invalid usage $CMD"
"$INSTALL_PATH/print.sh" "PROMPT_HELP"
;;
esac