forked from Cohesible/synapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·182 lines (145 loc) · 4.27 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
#!/usr/bin/env bash
set -euo pipefail
# This script is based on Bun's install script
if [[ ${OS:-} = Windows_NT ]]; then
echo 'error: install synapse using Windows Subsystem for Linux or use the Powershell script'
exit 1
fi
Color_Off=''
Red=''
Green=''
Dim=''
if [[ -t 1 ]]; then
Color_Off='\033[0m'
Red='\033[0;31m'
Green='\033[0;32m'
Dim='\033[0;2m'
fi
error() {
echo -e "${Red}error${Color_Off}:" "$@" >&2
exit 1
}
info() {
echo -e "${Dim}$@ ${Color_Off}"
}
info_log() {
echo -e "${Dim}$@ ${Color_Off}" >&2
}
success() {
echo -e "${Green}$@ ${Color_Off}"
}
# Used for script generation
DownloadUrl=''
if [ -n "$DownloadUrl" ]; then
set -- "$DownloadUrl" "$@"
fi
InstallToProfile=${SYNAPSE_INSTALL_TO_PROFILE:-true}
install_dir=${SYNAPSE_INSTALL:-$HOME/.synapse}
app_dir=$install_dir/app
if [[ ! -d "$app_dir" ]]; then
mkdir -p "$app_dir" ||
error "Failed to create install directory \"$app_dir\""
fi
get_target() {
case $(uname -ms) in
'Darwin x86_64')
# Is this process running in Rosetta?
# redirect stderr to devnull to avoid error message when not running in Rosetta
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
info_log "Your shell is running in Rosetta 2. Downloading synapse for $target instead"
echo darwin-aarch64
else
echo darwin-x64
fi
;;
'Darwin arm64')
echo darwin-aarch64
;;
'Linux aarch64' | 'Linux arm64')
error "ARM on Linux is not supported yet" # FIXME
echo linux-aarch64
;;
'Linux x86_64' | *)
echo linux-x64
;;
esac
}
install_from_archive() {
strip=0
case $(basename $1) in
*.xz ) flags=-Jxf;;
*.gz|*.tgz ) flags=-zxf;;
*.zip )
strip=1
flags=-zxf
;;
esac
tar --strip=$strip $flags "$1" -C "$app_dir" || error 'Failed to extract synapse'
sea="$app_dir/bin/synapse"
if [[ -f "$sea" ]]; then
node=$sea
else
node="$app_dir/bin/node"
fi
chmod +x "$node"
if [ "$InstallToProfile" = true ]; then
shell=${SHELL:-sh}
"$node" "$app_dir/dist/install.js" "$install_dir" "$app_dir" $(basename "$shell")
else
info 'Skipping profile install'
"$node" "$app_dir/dist/install.js" "$install_dir" "$app_dir"
fi
installedVersion=$("$install_dir"/bin/synapse --version)
success "Installed $installedVersion"
}
install_from_github() {
target=$(get_target)
if [[ "$target" =~ ^darwin ]]; then
tarball_basename=synapse-$target.zip
else
tarball_basename=synapse-$target.tgz
fi
GITHUB=${GITHUB-"https://github.com"}
github_repo="$GITHUB/Cohesible/synapse"
if [[ $# = 0 ]]; then
synapse_uri=$github_repo/releases/latest/download/$tarball_basename
else
info "Installing requested version $1"
synapse_uri=$github_repo/releases/download/$1/$tarball_basename
fi
tarball_path=$app_dir/$tarball_basename
curl --fail --location --progress-bar --output "$tarball_path" "$synapse_uri" ||
error "Failed to download synapse from \"$synapse_uri\""
install_from_archive "$tarball_path"
rm -r "$tarball_path"
}
if [[ $# -gt 0 ]]; then
if [[ $# -gt 1 ]]; then
install_dir="$2"
app_dir="$install_dir/app"
if [[ ! -d "$app_dir" ]]; then
mkdir -p "$app_dir" ||
error "Failed to create install directory \"$app_dir\""
fi
fi
if [[ "$1" =~ ^https: ]]; then
target=$(get_target)
if [[ "$target" =~ ^darwin ]]; then
tarball_basename=synapse-$target.zip
else
tarball_basename=synapse-$target.tgz
fi
tarball_path=$app_dir/$tarball_basename
curl --fail --location --progress-bar --output "$tarball_path" "$1" || error "Failed to download synapse from \"$1\""
install_from_archive "$tarball_path"
rm -r "$tarball_path"
elif [[ "$1" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
install_from_github $1
elif [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
install_from_github "v$1"
else
install_from_archive $1
fi
exit 0
fi
install_from_github