forked from appwrite/sdk-for-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
197 lines (158 loc) Β· 6.05 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/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
APPWRITE_CLI_IMAGE_NAME=appwrite/cli
# Appwrite CLI image version
APPWRITE_CLI_IMAGE_VERSION=0.13.1
# sudo is required to copy executable to APPWRITE_INSTALL_DIR for linux
USE_SUDO="false"
# 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
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86_64) ARCH="amd64";;
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"
}
performChecks() {
echo "[2/4] Performing Checks ..."
# Check if docker is installed
printf "${GREEN}π¦ Checking if docker is installed ... ${NC}\n"
if ! command -v docker &> /dev/null; then
printf "${RED}β Docker could not be found. Please install docker for your OS from https://docs.docker.com/get-docker/ and try again.${NC}\n"
exit 1
fi
printSuccess
# Check if the Docker Daemon is running
printf "${GREEN}πβ Checking if docker daemon is running ... ${NC}\n"
rep=$(curl -s --unix-socket /var/run/docker.sock http://ping > /dev/null)
status=$?
if [ "$status" == "7" ]; then
printf "${RED}β The docker daemon is not operational. Make sure that docker is running and try again.${NC} \n"
exit 1
fi
printSuccess
}
install() {
echo "[3/4] Starting installation ..."
# Fetch the Appwrite CLI Image.
printf "${GREEN}π³ Pulling docker image ... ${NC}\n"
out=$(docker pull "$APPWRITE_CLI_IMAGE_NAME:$APPWRITE_CLI_IMAGE_VERSION")
if [[ $out != *"Image is up to date"* ]] && [[ $out != *"Downloaded newer image"* ]]; then
printf "${RED}β Failed to fetch docker image. Exiting ... ${NC}\n"
exit 1
fi
printSuccess
echo '#!/bin/bash
allowList=(version help init client account avatars database functions health locale storage teams users)
if [[ -z $1 ]]; then
set -- "$@" help
fi
# Check if the command is in the allowList
if [[ ! " ${allowList[@]} " =~ " ${1} " ]]; then
printf "\nLooks like a crazy hamster πΉ flipped a bit.\n\nUse appwrite help for a list of supported commands.\n"
exit 1
fi
# https://stackoverflow.com/a/30655982/2299554
for x in "${@}" ; do
# try to figure out if quoting was required for the $x
if [[ "$x" != "${x%[[:space:]]*}" ]]; then
x="\""$x"\""
fi
x="${x// /%20}"
_args=$_args" "$x
done
bash -c "docker run -i --rm --volume appwrite-cli:/usr/local/code/app/.preferences/ --volume \"$PWD\":/usr/local/code/files:rw --network host '$APPWRITE_CLI_IMAGE_NAME:$APPWRITE_CLI_IMAGE_VERSION' $_args" ' > $APPWRITE_TEMP_NAME
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() {
echo "π§Ή Cleaning up mess ... "
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
printf "π€ May the force be with you. \n"
echo "π To get started with Appwrite CLI, please visit https://appwrite.io/docs/command-line"
}
# Installation Starts here
greeting
getSystemInfo
performChecks
install
installCompleted