-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·121 lines (105 loc) · 3.42 KB
/
install.sh
File metadata and controls
executable file
·121 lines (105 loc) · 3.42 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
#!/bin/bash
OS=""
ARCH=""
BASE_URL="https://github.com/Privado-Inc/privado-cli/releases/latest/download/privado-"
REPO_URL="https://github.com/Privado-Inc/privado-cli/"
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 $REPO_URL for more information."
exit 1
fi
mkdir -p $HOME/.privado/bin
if [[ "$OS" == "windows" ]]; then
echo "Downloading binary:"
curl -L "$BASE_URL$OS-$ARCH.zip" -o /tmp/privado-$OS-$ARCH.zip
echo "Downloading binary MD5:"
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
echo "Downloading binary:"
curl -L "$BASE_URL$OS-$ARCH.tar.gz" -o /tmp/privado-$OS-$ARCH.tar.gz
echo "Downloading binary MD5:"
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
WHO_AM_I=$(whoami)
if [[ "$WHO_AM_I" == "root" ]]; then
cp $HOME/.privado/bin/privado /usr/local/bin/privado
chmod 755 /usr/local/bin/privado
echo "Installation is complete! Run 'privado' to use Privado CLI"
else
DEFAULT_PROFILE_PATH="$HOME/.bashrc"
NO_FILE=""
for EACH_PROFILE in ".profile" ".bash_profile" ".zprofile" ".zshrc"
do
if [[ -f $HOME/$EACH_PROFILE ]]; then
cat $HOME/$EACH_PROFILE | grep -q "/.privado" || echo "export PATH=\$PATH:$HOME/.privado/bin" >> $HOME/$EACH_PROFILE
NO_FILE="true"
fi
done
if [[ "$NO_FILE" == "" ]] || [[ "$OS" == "linux" ]]; then
cat $DEFAULT_PROFILE_PATH | grep -q "/.privado" || echo "export PATH=\$PATH:$HOME/.privado/bin" >> $DEFAULT_PROFILE_PATH
fi
echo "Installation is complete! Please open a new session and run 'privado' to use Privado CLI"
fi
}
function checkDocker {
docker ps > /dev/null 2>&1
EXIT_CODE=$?
if [[ "$EXIT_CODE" != "0" ]]; then
echo "> Preflight checks failed!"
echo "> Either Docker is not installed, not running, or you do not have appropriate permissions to use the same. Please retry this script with sudo privileges."
exit
fi
}
function preFlightChecks {
checkDocker
}
function cleanup {
rm -f /tmp/privado-*
}
findOS
findArch
preFlightChecks
downloadAndInstallLatestVersion
cleanup