forked from Privado-Inc/privado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·91 lines (80 loc) · 2.59 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
#!/bin/bash
OS=""
ARCH=""
BASE_URL="https://github.com/Privado-Inc/privado/releases/download/latest/privado-"
function findOS {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="darwin"
elif [[ "$OSTYPE" == "msys" ]]; then
OS="windows"
else
echo "Unsupported OS"
exit 10
fi
}
function findArch {
ARCH_STR=$(uname -m)
if [[ "$ARCH_STR" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$ARCH_STR" == "arm64" ]]; then
ARCH="arm64"
else
echo "Unsupported Architecture"
exit 10
fi
}
function downloadAndInstallLatestVersion {
if [[ "$OS" == "" || "$ARCH" == "" ]]; then
echo "Unsupported OS or Arch type. Please visit https://privado.ai/cli for more information."
exit 1
fi
mkdir -p $HOME/.privado/bin
if [[ "$OS" == "windows" ]]; then
curl -L "$BASE_URL$OS-$ARCH.zip" -o /tmp/privado-$OS-$ARCH.zip
curl -L "$BASE_URL$OS-$ARCH.zip.md5" -o /tmp/privado-$OS-$ARCH.zip.md5
MD5_ACTUAL=$(certutil -hashfile /tmp/privado-$OS-$ARCH.zip MD5 | head -n2 | tail -n1)
MD5_EXPECTED=$(cat /tmp/privado-$OS-$ARCH.zip.md5)
else
curl -L "$BASE_URL$OS-$ARCH.tar.gz" -o /tmp/privado-$OS-$ARCH.tar.gz
curl -L "$BASE_URL$OS-$ARCH.tar.gz.md5" -o /tmp/privado-$OS-$ARCH.tar.gz.md5
if [[ "$OS" == "linux" ]]; then
MD5_ACTUAL=$(md5sum /tmp/privado-$OS-$ARCH.tar.gz | awk '{print $1}')
else
MD5_ACTUAL=$(md5 /tmp/privado-$OS-$ARCH.tar.gz | awk '{print $4}')
fi
MD5_EXPECTED=$(cat /tmp/privado-$OS-$ARCH.tar.gz.md5)
fi
if [[ "$MD5_EXPECTED" != "$MD5_ACTUAL" ]]; then
echo "Error in downloading the file. Please retry"
exit 10
fi
if [[ "$OS" == "windows" ]]; then
unzip -o /tmp/privado-$OS-$ARCH.zip -d $HOME/.privado/bin
elif [[ "$OS" == "darwin" ]]; then
tar -xf /tmp/privado-$OS-$ARCH.tar.gz -C $HOME/.privado/bin
else
tar -xf /tmp/privado-$OS-$ARCH.tar.gz -C $HOME/.privado/bin
fi
PROFILE_PATH="$HOME/.bashrc"
NO_FILE=""
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
do
if [[ -f $HOME/$EACH_PROFILE ]]; then
cat $HOME/$EACH_PROFILE | grep "/.privado" || echo "export PATH=\$PATH:$HOME/.privado/bin" >> $HOME/$EACH_PROFILE
PROFILE_PATH=$HOME/$EACH_PROFILE
NO_FILE="true"
break
fi
done
if [[ "$NO_FILE" == "" ]]; then
echo "export PATH=\$PATH:$HOME/.privado/bin" >> $PROFILE_PATH
fi
echo "Installation is complete. Please open a new session or run the command"
echo ". $PROFILE_PATH"
echo "In your existing session"
}
findOS
findArch
downloadAndInstallLatestVersion