-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
86 lines (80 loc) · 2.5 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
#!/bin/sh
# Written by @nedimf (nedimcodes) 2021
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
GLOBAL_DIR="mystery-release"
#check_if_dir_exists
check_if_dir_exists(){
pwd=$(pwd)
if [ -d "$pwd/$GLOBAL_DIR" ]
then
return 0
else
return 1
fi
}
#export downloaded archive
export_tar(){
echo "Exporting... 📦"
tar xvzf mystery_$1_darwin_$2.tar.gz
cd mystery
cp mystery /usr/local/bin/mystery
#test if mystery installed successfully by calling mystery --version, clears output
mystery --version > /dev/null 2>&1;
status=$?
if [[ status -eq 0 ]]
then
echo "Mystery CLI has been ${GREEN}successfully${NC} installed ✅\nLaunch by typing: ${YELLOW}mystery${NC} in your terminal"
else
echo "${RED}Mystery CLI failed to install. Copy above log and open new issue${NC}\nOpen: https://github.com/asilvr/mystery/issues/new/choose"
fi
}
#download latest release
download(){
if check_if_dir_exists; then
cd $GLOBAL_DIR
else
mkdir $GLOBAL_DIR
cd $GLOBAL_DIR
fi
arch_name=$1
#Download latest release
tag_version=$(curl -s https://api.github.com/repos/asilvr/mystery/releases/latest | grep "tag_name" | cut -d : -f 2,3 | tr -d \" | tr -d \,)
echo "${GREEN}Downloading mystery $tag_version${NC}"
package_link=$(curl -s https://api.github.com/repos/asilvr/mystery/releases/latest | grep "browser_download_url.*_$arch_name.tar.gz" | cut -d : -f 2,3 | tr -d \")
package_name=mystery_${tag_version//" "}_darwin_$1.tar.gz
if [[ -z tag_version ]]
then
echo "${RED}Error: Github isn't available, please turn off all of your proxies${NC}"
exit 1
else
curl -L $package_link > $package_name --silent
fi
if [[ $? -eq 0 ]]
then
export_tar $tag_version $arch_name
else
echo "${RED}Error: Mystery CLI failed to install!${NC}"
fi
}
#check of OS type and return values accordingly
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "${RED}Mystery has no Linux release build${NC}"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OS
arch_name="$(uname -m)"
if [ "${arch_name}" = "x86_64" ]; then
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then
echo "Unknown architecture: ${arch_name}, most likely Rosseta 2"
else
download "amd64"
fi
elif [ "${arch_name}" = "arm64" ]; then
download "arm64"
else
echo "Unknown architecture: ${arch_name}"
fi
fi