-
Notifications
You must be signed in to change notification settings - Fork 26
/
install.sh
157 lines (127 loc) Β· 4.7 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
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
#!/bin/bash
## <script src="/dist/scripts/cli-bash.js"></script>
## <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/themes/prism-okaidia.min.css" rel="stylesheet" />
## <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/components/prism-core.min.js" data-manual></script>
## <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/components/prism-bash.min.js"></script>
## <style>body {color: #272822; background-color: #272822; font-size: 0.8em;} </style>
# Love open-source, dev-tooling and passionate about code as much as we do?
# ---
# We're always looking for awesome hackers like you to join our 100% remote team!
# Check and see if you find any relevant position @ https://appwrite.io/company/careers π©βπ» π
# (and let us know you found this message...)
# This script contains hidden JS code to allow better readability and syntax highlighting
# You can use "View source" of this page to see the full script.
# Appwrite CLI location
APPWRITE_INSTALL_DIR="/usr/local/bin"
# Appwrite CLI Executable name
APPWRITE_EXECUTABLE_NAME=appwrite
# Appwrite executable file path
APPWRITE_EXECUTABLE_FILEPATH="$APPWRITE_INSTALL_DIR/$APPWRITE_EXECUTABLE_NAME"
# Appwrite CLI temp name
APPWRITE_TEMP_NAME=temp-$(date +%s)
# Appwrite CLI image name
GITHUB_REPOSITORY_NAME=appwrite/sdk-for-cli
# sudo is required to copy executable to APPWRITE_INSTALL_DIR for linux
USE_SUDO="false"
OS=""
ARCH=""
# Add some color to life
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
greeting() {
echo -e "${RED}"
cat << "EOF"
_ _ _ ___ __ _____
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
//_\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
|_| |_|
EOF
echo -e "${NC}\n"
echo "π₯ Welcome to the Appwrite CLI install shield π‘"
}
getSystemInfo() {
echo "[1/4] Getting System Info ..."
ARCH=$(uname -m)
case $ARCH in
i386|i686) ARCH="x64" ;;
x86_64) ARCH="x64";;
armv6*) ARCH="arm64" ;;
armv7*) ARCH="arm64" ;;
aarch64*) ARCH="arm64" ;;
esac
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
# Need root access if its a linux system
if [ "$OS" == "linux" ] && [ "$APPWRITE_INSTALL_DIR" == "/usr/local/bin" ]; then
USE_SUDO="true"
fi
# Need root access if its Apple Silicon
if [ "$OS" == "darwin" ] && [[ "$(uname -a)" = *ARM64* ]]; then
USE_SUDO="true"
fi
printf "${GREEN}\nOS : $OS \nARCH : $ARCH \nREQUIRES ROOT : $USE_SUDO\n\n${NC}"
}
runAsRoot() {
local CMD="$*"
if [ $EUID -ne 0 -a $USE_SUDO = "true" ]; then
CMD="sudo $CMD"
fi
$CMD
}
printSuccess() {
printf "${GREEN}β
Done ... ${NC}\n\n"
}
downloadBinary() {
echo "[2/4] Downloading executable for $OS ($ARCH) ..."
GITHUB_LATEST_VERSION="6.1.0"
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
printf "${GREEN}π¦ Downloading Appwrite CLI $GITHUB_LATEST_VERSION ... ${NC}\n"
res=$(curl -s $GITHUB_URL)
if [[ "$res" == *"Not Found"* ]]; then
printf "${RED}β Couldn't find executable for $OS ($ARCH). Please contact the Appwrite team ${NC} \n"
exit 1
fi
curl -L -o $APPWRITE_TEMP_NAME $GITHUB_URL
printSuccess
}
install() {
echo "[3/4] Installing ..."
printf "${GREEN}π§ Setting Permissions ${NC}\n"
chmod +x $APPWRITE_TEMP_NAME
if [ $? -ne 0 ]; then
printf "${RED}β Failed to set permissions ... ${NC}\n"
exit 1
fi
printSuccess
printf "${GREEN}π Copying temporary file to $APPWRITE_EXECUTABLE_FILEPATH ... ${NC}\n"
runAsRoot cp $APPWRITE_TEMP_NAME $APPWRITE_EXECUTABLE_FILEPATH
if [ $? -ne 0 ]; then
printf "${RED}β Failed to copy temporary file to $APPWRITE_EXECUTABLE_FILEPATH ... ${NC}\n"
exit 1
fi
printSuccess
}
cleanup() {
printf "${GREEN}π§Ή Cleaning up mess ... ${NC}\n"
rm $APPWRITE_TEMP_NAME
if [ $? -ne 0 ]; then
printf "${RED}β Failed to remove temporary file ... ${NC}\n"
exit 1
fi
printSuccess
}
installCompleted() {
echo "[4/4] Wrapping up installation ... "
cleanup
echo "π To get started with Appwrite CLI, please visit https://appwrite.io/docs/command-line"
echo "As first step, you can login to your Appwrite account using 'appwrite login'"
}
# Installation Starts here
greeting
getSystemInfo
downloadBinary
install
installCompleted