-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
executable file
·158 lines (131 loc) · 6.55 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
#!/bin/sh
# This script is for installing the latest version of Turso CLI on your machine.
set -e
# Terminal ANSI escape codes.
reset="\033[0m"
bright_blue="${reset}\033[34;1m"
probe_arch() {
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="x86_64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*) printf "Architecture ${ARCH} is not supported by this installation script\n"; exit 1 ;;
esac
}
probe_os() {
OS=$(uname -s)
case $OS in
Darwin) OS="Darwin" ;;
Linux) OS="Linux" ;;
*) printf "Operating system ${OS} is not supported by this installation script\n"; exit 1 ;;
esac
}
print_logo() {
printf "${bright_blue}
.: .:
.\$\$. \$\$: .\$\$\$: \$\$\$^ \$\$: ~\$^
.\$\$\$!:\$\$\$ .\$\$\$\$~ .\$\$\$\$^ !\$\$~^\$\$\$~
\$\$\$\$\$\$ .\$\$\$\$\$~ .\$\$\$\$\$^ \$\$\$\$\$\$:
!\$\$\$\$\$\$\$\$\$\$~ .\$\$\$\$\$\$\$\$\$\$\$
:\$\$\$\$\$\$\$\$~ .\$\$\$\$\$\$\$\$!
.\$\$\$\$\$\$\$\$~ .\$\$\$\$\$\$\$\$^
.\$\$\$\$\$\$\$\$! ~\$! :\$\$. :\$\$\$\$\$\$\$\$^
\$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$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
"\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$"
\$\$\$\$\$~\$\$\$\$\$^\$\$\$\$\$~\$\$\$\$\$\$~\$\$\$\$:
\$\$^ .\$\$\$ \$\$\$: ~\$\$^ .\$\$^
.. : : :. :
${reset}
"
}
detect_profile() {
local DETECTED_PROFILE
DETECTED_PROFILE=''
local SHELLTYPE
SHELLTYPE="$(basename "/$SHELL")"
if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "$SHELLTYPE" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ "$SHELLTYPE" = "fish" ]; then
DETECTED_PROFILE="$HOME/.config/fish/conf.d/turso.fish"
fi
if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -d "$HOME/.config/fish" ]; then
DETECTED_PROFILE="$HOME/.config/fish/conf.d/turso.fish"
fi
fi
if [ ! -z "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE"
fi
}
update_profile() {
PROFILE_FILE=$(detect_profile)
if [[ -n "$PROFILE_FILE" ]]; then
if ! grep -q "\.turso" $PROFILE_FILE; then
printf "\n${bright_blue}Updating profile ${reset}$PROFILE_FILE\n"
printf "\n# Turso\nexport PATH=\"$INSTALL_DIRECTORY:\$PATH\"\n" >> $PROFILE_FILE
printf "\nTurso will be available when you open a new terminal.\n"
printf "If you want to make Turso available in this terminal, please run:\n"
printf "\nsource $PROFILE_FILE\n"
fi
else
printf "\n${bright_blue}Unable to detect profile file location. ${reset}Please add the following to your profile file:\n"
printf "\nexport PATH=\"$INSTALL_DIRECTORY:\$PATH\"\n"
fi
}
printf "\nWelcome to the Turso installer!\n"
print_logo
probe_arch
probe_os
URL_PREFIX="https://github.com/chiselstrike/homebrew-tap/releases/latest/download/"
TARGET="${OS}_$ARCH"
printf "${bright_blue}Downloading ${reset}$TARGET ...\n"
URL="$URL_PREFIX/homebrew-tap_$TARGET.tar.gz"
DOWNLOAD_FILE=$(mktemp -t turso.XXXXXXXXXX)
curl --progress-bar -L "$URL" -o "$DOWNLOAD_FILE"
INSTALL_DIRECTORY="$HOME/.turso"
printf "\n${bright_blue}Installing to ${reset}$INSTALL_DIRECTORY\n"
mkdir -p $INSTALL_DIRECTORY
tar -C $INSTALL_DIRECTORY -zxf $DOWNLOAD_FILE turso
rm -f $DOWNLOAD_FILE
update_profile
printf "\nTurso CLI installed!\n\n"
printf "If you are a new user, you can sign up with ${bright_blue}turso auth signup${reset}.\n\n"
printf "If you already have an account, please login with ${bright_blue}turso auth login${reset}.\n\n"
$INSTALL_DIRECTORY/turso auth signup