Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ec85eba

Browse files
committedMay 27, 2020
Add auto install script
1 parent 1494000 commit ec85eba

File tree

9 files changed

+376
-28
lines changed

9 files changed

+376
-28
lines changed
 

‎README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For a full setup and walkthrough, please see [./doc/guide.md](./doc/guide.md).
1818
### Debian, Ubuntu
1919

2020
```bash
21-
curl -OL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server_3.3.1_amd64.deb
21+
curl -fOL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server_3.3.1_amd64.deb
2222
sudo dpkg -i code-server_3.3.1_amd64.deb
2323
systemctl --user enable --now code-server
2424
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
@@ -27,7 +27,7 @@ systemctl --user enable --now code-server
2727
### Fedora, CentOS, Red Hat, SUSE
2828

2929
```bash
30-
curl -OL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server-3.3.1-amd64.rpm
30+
curl -fOL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server-3.3.1-amd64.rpm
3131
sudo rpm -i code-server-3.3.1-amd64.rpm
3232
systemctl --user enable --now code-server
3333
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
@@ -103,10 +103,10 @@ Add the code-server `bin` directory to your `$PATH` to easily execute `code-serv
103103
Here is an example script for installing and using a static `code-server` release on Linux:
104104

105105
```bash
106-
curl -L https://github.com/cdr/code-server/releases/download/v3.3.1/code-server-3.3.1-linux-amd64.tar.gz \
107-
| sudo tar -C /usr/local -xz
108-
sudo mv /usr/local/code-server-3.3.1-linux-amd64 /usr/local/code-server-3.3.1
109-
PATH="/usr/local/code-server-3.3.1/bin:$PATH"
106+
curl -fL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server-3.3.1-linux-amd64.tar.gz \
107+
| sudo tar -C /usr/local/lib -xz
108+
sudo mv /usr/local/lib/code-server-3.3.1-linux-amd64 /usr/local/lib/code-server-3.3.1
109+
PATH="/usr/local/lib/code-server-3.3.1/bin:$PATH"
110110
code-server
111111
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
112112
```

‎ci/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ Any file or directory in this subdirectory should be documented here.
1414

1515
Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub) installed.
1616

17-
1. Update the version of code-server in `package.json` and README.md/guide.md install examples and make a PR.
17+
1. Update the version of code-server and make a PR.
18+
1. Update in `package.json`
19+
2. [README.md](../README.md) and [guide.md](../doc/guide.md) install examples
20+
3. [install.sh](../install.sh)
1821
2. GitHub actions will generate the `npm-package`, `release-packages` and `release-images` artifacts.
1922
3. Run `yarn release:github-draft` to create a GitHub draft release from the template with
2023
the updated version.

‎ci/container/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ RUN apt-get update
66
RUN apt-get install -y curl gnupg
77

88
# Installs node.
9-
RUN curl -sSL https://deb.nodesource.com/setup_14.x | bash - && \
9+
RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
1010
apt-get install -y nodejs
1111

1212
# Installs yarn.
13-
RUN curl -sSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
13+
RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
1414
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
1515
apt-get update && apt-get install -y yarn
1616

@@ -28,23 +28,23 @@ RUN apt-get install -y git rsync unzip
2828

2929
# We need latest jq from debian buster for date support.
3030
RUN ARCH="$(dpkg --print-architecture)" && \
31-
curl -sSOL http://http.us.debian.org/debian/pool/main/libo/libonig/libonig5_6.9.1-1_$ARCH.deb && \
31+
curl -fsSOL http://http.us.debian.org/debian/pool/main/libo/libonig/libonig5_6.9.1-1_$ARCH.deb && \
3232
dpkg -i libonig*.deb && \
33-
curl -sSOL http://http.us.debian.org/debian/pool/main/j/jq/libjq1_1.5+dfsg-2+b1_$ARCH.deb && \
33+
curl -fsSOL http://http.us.debian.org/debian/pool/main/j/jq/libjq1_1.5+dfsg-2+b1_$ARCH.deb && \
3434
dpkg -i libjq*.deb && \
35-
curl -sSOL http://http.us.debian.org/debian/pool/main/j/jq/jq_1.5+dfsg-2+b1_$ARCH.deb && \
35+
curl -fsSOL http://http.us.debian.org/debian/pool/main/j/jq/jq_1.5+dfsg-2+b1_$ARCH.deb && \
3636
dpkg -i jq*.deb && rm *.deb
3737

3838
# Installs shellcheck.
3939
# Unfortunately coredumps on debian:8 so disabled for now.
40-
#RUN curl -sSL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.$(uname -m).tar.xz | \
40+
#RUN curl -fsSL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.$(uname -m).tar.xz | \
4141
# tar -xJ && \
4242
# mv shellcheck*/shellcheck /usr/local/bin && \
4343
# rm -R shellcheck*
4444

4545
# Install Go dependencies
4646
RUN ARCH="$(dpkg --print-architecture)" && \
47-
curl -sSL "https://dl.google.com/go/go1.14.3.linux-$ARCH.tar.gz" | tar -C /usr/local -xz
47+
curl -fsSL "https://dl.google.com/go/go1.14.3.linux-$ARCH.tar.gz" | tar -C /usr/local -xz
4848
ENV PATH=/usr/local/go/bin:/root/go/bin:$PATH
4949
ENV GO111MODULE=on
5050
RUN go get mvdan.cc/sh/v3/cmd/shfmt

‎ci/container/arm64/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ RUN apt-get update
66
RUN apt-get install -y curl gnupg
77

88
# Installs node.
9-
RUN curl -sSL https://deb.nodesource.com/setup_14.x | bash - && \
9+
RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
1010
apt-get install -y nodejs
1111

1212
# Installs yarn.
13-
RUN curl -sSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
13+
RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
1414
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
1515
apt-get update && apt-get install -y yarn
1616

@@ -24,27 +24,27 @@ RUN apt-get install -y build-essential \
2424
RUN apt-get install -y gettext-base
2525

2626
# Misc build dependencies.
27-
RUN apt-get install -y git rsync
27+
RUN apt-get install -y git rsync unzip
2828

2929
# We need latest jq from debian buster for date support.
3030
RUN ARCH="$(dpkg --print-architecture)" && \
31-
curl -sSOL http://http.us.debian.org/debian/pool/main/libo/libonig/libonig5_6.9.1-1_$ARCH.deb && \
31+
curl -fsSOL http://http.us.debian.org/debian/pool/main/libo/libonig/libonig5_6.9.1-1_$ARCH.deb && \
3232
dpkg -i libonig*.deb && \
33-
curl -sSOL http://http.us.debian.org/debian/pool/main/j/jq/libjq1_1.5+dfsg-2+b1_$ARCH.deb && \
33+
curl -fsSOL http://http.us.debian.org/debian/pool/main/j/jq/libjq1_1.5+dfsg-2+b1_$ARCH.deb && \
3434
dpkg -i libjq*.deb && \
35-
curl -sSOL http://http.us.debian.org/debian/pool/main/j/jq/jq_1.5+dfsg-2+b1_$ARCH.deb && \
35+
curl -fsSOL http://http.us.debian.org/debian/pool/main/j/jq/jq_1.5+dfsg-2+b1_$ARCH.deb && \
3636
dpkg -i jq*.deb && rm *.deb
3737

3838
# Installs shellcheck.
3939
# Unfortunately coredumps on debian:8 so disabled for now.
40-
#RUN curl -sSL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.$(uname -m).tar.xz | \
40+
#RUN curl -fsSL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.$(uname -m).tar.xz | \
4141
# tar -xJ && \
4242
# mv shellcheck*/shellcheck /usr/local/bin && \
4343
# rm -R shellcheck*
4444

4545
# Install Go dependencies
4646
RUN ARCH="$(dpkg --print-architecture)" && \
47-
curl -sSL "https://dl.google.com/go/go1.14.3.linux-$ARCH.tar.gz" | tar -C /usr/local -xz
47+
curl -fsSL "https://dl.google.com/go/go1.14.3.linux-$ARCH.tar.gz" | tar -C /usr/local -xz
4848
ENV PATH=/usr/local/go/bin:/root/go/bin:$PATH
4949
ENV GO111MODULE=on
5050
RUN go get mvdan.cc/sh/v3/cmd/shfmt

‎ci/dev/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ main() {
99
tsc --noEmit
1010
# See comment in ./ci/container/Dockerfile
1111
if [[ ! ${CI-} ]]; then
12-
shellcheck -e SC2046,SC2164,SC2154 $(git ls-files "*.sh")
12+
shellcheck -e SC2046,SC2164,SC2154,SC1091 $(git ls-files "*.sh")
1313
fi
1414
}
1515

‎ci/lib.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ curl() {
5656
# This will contain the artifacts we want.
5757
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
5858
get_artifacts_url() {
59-
curl -sSL 'https://api.github.com/repos/cdr/code-server/actions/workflows/ci.yaml/runs?status=success&event=push' | jq -r ".workflow_runs[] | select(.head_sha == \"$(git rev-parse HEAD)\") | .artifacts_url" | head -n 1
59+
curl -fsSL 'https://api.github.com/repos/cdr/code-server/actions/workflows/ci.yaml/runs?status=success&event=push' | jq -r ".workflow_runs[] | select(.head_sha == \"$(git rev-parse HEAD)\") | .artifacts_url" | head -n 1
6060
}
6161

6262
# Grabs the artifact's download url.
6363
# https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
6464
get_artifact_url() {
6565
local artifact_name="$1"
66-
curl -sSL "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
66+
curl -fsSL "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
6767
}
6868

6969
# Uses the above two functions to download a artifact into a directory.
@@ -74,7 +74,7 @@ download_artifact() {
7474
local tmp_file
7575
tmp_file="$(mktemp)"
7676

77-
curl -sSL "$(get_artifact_url "$artifact_name")" > "$tmp_file"
77+
curl -fsSL "$(get_artifact_url "$artifact_name")" > "$tmp_file"
7878
unzip -q -o "$tmp_file" -d "$dst"
7979
rm "$tmp_file"
8080
}

‎ci/release-container/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RUN adduser --gecos '' --disabled-password coder && \
2828
echo "coder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd
2929

3030
RUN ARCH="$(dpkg --print-architecture)" && \
31-
curl -sSL "https://github.com/boxboat/fixuid/releases/download/v0.4.1/fixuid-0.4.1-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - && \
31+
curl -fsSL "https://github.com/boxboat/fixuid/releases/download/v0.4.1/fixuid-0.4.1-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - && \
3232
chown root:root /usr/local/bin/fixuid && \
3333
chmod 4755 /usr/local/bin/fixuid && \
3434
mkdir -p /etc/fixuid && \

‎doc/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SSH into your instance and run the appropriate commands documented in [README.md
8282
Assuming Debian:
8383

8484
```bash
85-
curl -OL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server_3.3.1_amd64.deb
85+
curl -fOL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server_3.3.1_amd64.deb
8686
sudo dpkg -i code-server_3.3.1_amd64.deb
8787
systemctl --user enable --now code-server
8888
# Now code-server is running at http://127.0.0.1:8080

‎install.sh

Lines changed: 345 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
VERSION=3.3.1
5+
6+
usage() {
7+
cat << EOF
8+
$0 [-d] [-s] [-p <static-install-prefix>]
9+
10+
Installs code-server on any macOS or Linux system.
11+
12+
If ran on Ubuntu, Debian or Raspbian then the GitHub releases v$VERSION
13+
deb package will be fetched and installed.
14+
15+
If ran on Fedora, CentOS, RHEL or openSUSE then the GitHub releases v$VERSION
16+
rpm package will be fetched and installed.
17+
18+
If ran on macOS and Homebrew is installed then the Homebrew code-server
19+
package will be installed. However, if Homebrew is not installed then
20+
v$VERSION of the macOS static release will be installed
21+
into /usr/local/lib/code-server-$VERSION.
22+
23+
If ran on Arch Linux, then the code-server AUR package will be installed.
24+
25+
If ran on an unsupported architecture the npm package will be installed
26+
with yarn or npm. Only amd64 and arm64 are currently supported.
27+
28+
If ran on any other Linux distro, v$VERSION of the linux static release
29+
will be installed into /usr/local/lib/code-server-$VERSION.
30+
31+
-d Enables a dry run where where the steps that would have taken place
32+
are printed but do not actually execute.
33+
34+
-s Forces the installation of a static release into /usr/local/lib/code-server-$VERSION
35+
Set the -p flag to change the installation prefix from /usr/local/lib
36+
37+
-p Sets the installation prefix for a static release install.
38+
EOF
39+
exit 1
40+
}
41+
42+
echo_static_postinstall() {
43+
echo
44+
cat << EOF
45+
Static release has been installed into $STATIC_INSTALL_PREFIX/code-server-$VERSION
46+
Please extend your path to use code-server:
47+
PATH="$STATIC_INSTALL_PREFIX/code-server-$VERSION/bin:\$PATH"
48+
Then you can run:
49+
code-server
50+
EOF
51+
}
52+
53+
echo_systemd_postinstall() {
54+
echo
55+
cat << EOF
56+
To have systemd start code-server now and restart on boot:
57+
systemctl --user enable --now code-server
58+
Or, if you don't want/need a background service you can run:
59+
code-server
60+
EOF
61+
}
62+
63+
main() {
64+
unset DRY_RUN STATIC STATIC_INSTALL_PREFIX SKIP_LOG
65+
while getopts ":dsp:h" opt; do
66+
case "$opt" in
67+
d) DRY_RUN=1 ;;
68+
s) STATIC=1 ;;
69+
p) STATIC_INSTALL_PREFIX="$OPTARG" ;;
70+
h | ?) usage ;;
71+
esac
72+
done
73+
shift $((OPTIND - 1))
74+
75+
OS="$(os)"
76+
if [ ! "$OS" ]; then
77+
echo "Unsupported OS $(uname)."
78+
exit 1
79+
fi
80+
81+
distro_name
82+
83+
ARCH="$(arch)"
84+
if [ ! "$ARCH" ]; then
85+
if [ "${STATIC-}" ]; then
86+
echo "No static releases available for the architecture $(uname -m)."
87+
echo "Please rerun without the -s flag to install from npm."
88+
exit 1
89+
fi
90+
install_npm
91+
exit 0
92+
fi
93+
94+
CACHE_DIR="$(cache_dir)"
95+
mkdir -p "$CACHE_DIR"
96+
97+
if [ "${STATIC-}" ]; then
98+
install_static
99+
return
100+
fi
101+
102+
case "$(distro)" in
103+
macos)
104+
install_macos
105+
;;
106+
ubuntu | debian | raspbian)
107+
install_deb
108+
;;
109+
centos | fedora | rhel | opensuse)
110+
install_rpm
111+
;;
112+
arch)
113+
install_arch
114+
;;
115+
*)
116+
install_static
117+
;;
118+
119+
esac
120+
}
121+
122+
install_macos() {
123+
if command_exists brew; then
124+
echo "Installing from Homebrew."
125+
126+
sh_c brew install code-server
127+
128+
return
129+
fi
130+
131+
echo "Homebrew is not installed so installing static release."
132+
133+
install_static
134+
}
135+
136+
fetch() {
137+
URL="$1"
138+
FILE="$2"
139+
140+
if [ -e "$FILE" ]; then
141+
echo
142+
echo "+ Using cached $FILE from $URL"
143+
return
144+
fi
145+
146+
sh_c curl \
147+
-#fL \
148+
-Ro "$FILE.incomplete" \
149+
-C - \
150+
"$URL"
151+
mv "$FILE.incomplete" "$FILE"
152+
}
153+
154+
install_deb() {
155+
echo "Installing v$VERSION deb package from GitHub releases."
156+
157+
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server_${VERSION}_$ARCH.deb" "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
158+
sudo_sh_c dpkg -i "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
159+
160+
echo_systemd_postinstall
161+
}
162+
163+
install_rpm() {
164+
echo "Installing v$VERSION rpm package from GitHub releases."
165+
166+
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$ARCH.rpm" "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
167+
sudo_sh_c rpm -i "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
168+
169+
echo_systemd_postinstall
170+
}
171+
172+
install_arch() {
173+
echo "Installing from the AUR."
174+
175+
fetch "https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz" "$CACHE_DIR/code-server-aur.tar.gz"
176+
177+
tmp_dir="$(mktemp -d)"
178+
(
179+
cd "$tmp_dir"
180+
tar -xzf "$CACHE_DIR/code-server-aur.tar.gz" --strip-components 1
181+
sh_c makepkg -si
182+
)
183+
rm -Rf "$tmp_dir"
184+
185+
echo_systemd_postinstall
186+
}
187+
188+
install_static() {
189+
STATIC_INSTALL_PREFIX=${STATIC_INSTALL_PREFIX-/usr/local/lib}
190+
191+
echo "Installing static release v$VERSION"
192+
193+
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
194+
195+
if [ ! -d "$STATIC_INSTALL_PREFIX" ]; then
196+
echo
197+
echo "Static release install prefix $STATIC_INSTALL_PREFIX does not exist"
198+
exit 1
199+
fi
200+
201+
sh_c="sh_c"
202+
if [ ! -w "$STATIC_INSTALL_PREFIX" ]; then
203+
sh_c="sudo_sh_c"
204+
fi
205+
206+
"$sh_c" tar -C "$STATIC_INSTALL_PREFIX" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
207+
# In case previously installed.
208+
SKIP_LOG=1 "$sh_c" rm -Rf "$STATIC_INSTALL_PREFIX/code-server-$VERSION"
209+
"$sh_c" mv -f "$STATIC_INSTALL_PREFIX/code-server-$VERSION-$OS-$ARCH" "$STATIC_INSTALL_PREFIX/code-server-$VERSION"
210+
211+
echo_static_postinstall
212+
}
213+
214+
install_npm() {
215+
echo "No precompiled releases for $(uname -m)."
216+
if command_exists yarn; then
217+
echo "Installing with yarn."
218+
sh_c yarn global add code-server --unsafe-perm
219+
return
220+
elif command_exists npm; then
221+
echo "Installing with npm."
222+
sh_c npm install -g code-server --unsafe-perm
223+
return
224+
fi
225+
echo
226+
echo "Please install npm or yarn to install code-server!"
227+
echo "You will need at least node v12 and a few C build dependencies."
228+
echo "See the docs https://github.com/cdr/code-server#yarn-npm"
229+
exit 1
230+
}
231+
232+
os() {
233+
case "$(uname)" in
234+
Linux)
235+
echo linux
236+
;;
237+
Darwin)
238+
echo macos
239+
;;
240+
esac
241+
}
242+
243+
# distro prints the detected operating system including linux distros.
244+
#
245+
# Example outputs:
246+
# - macos
247+
# - debian, ubuntu, raspbian
248+
# - centos, fedora, rhel, opensuse
249+
# - alpine
250+
# - arch
251+
#
252+
# Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120.
253+
distro() {
254+
if [ "$(uname)" = "Darwin" ]; then
255+
echo "macos"
256+
return
257+
fi
258+
259+
if [ ! -f /etc/os-release ]; then
260+
return
261+
fi
262+
263+
(
264+
. /etc/os-release
265+
case "$ID" in opensuse-*)
266+
# opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
267+
echo "opensuse"
268+
return
269+
;;
270+
esac
271+
272+
echo "$ID"
273+
)
274+
}
275+
276+
# os_name prints a pretty human readable name for the OS/Distro.
277+
distro_name() {
278+
if [ "$(uname)" = "Darwin" ]; then
279+
echo "macOS v$(sw_vers -productVersion)"
280+
return
281+
fi
282+
283+
if [ ! -f /etc/os-release ]; then
284+
(
285+
. /etc/os-release
286+
echo "$PRETTY_NAME"
287+
)
288+
fi
289+
290+
# Prints something like: Linux 4.19.0-9-amd64
291+
uname -sr
292+
}
293+
294+
arch() {
295+
case "$(uname -m)" in
296+
aarch64)
297+
echo arm64
298+
;;
299+
x86_64)
300+
echo amd64
301+
;;
302+
esac
303+
}
304+
305+
command_exists() {
306+
command -v "$@" > /dev/null 2>&1
307+
}
308+
309+
sh_c() {
310+
if [ ! "${SKIP_LOG-}" ]; then
311+
echo
312+
echo "+ $*"
313+
fi
314+
if [ ! "${DRY_RUN-}" ]; then
315+
sh -c "$*"
316+
fi
317+
}
318+
319+
sudo_sh_c() {
320+
if [ "$(id -u)" = 0 ]; then
321+
sh_c "$@"
322+
elif command_exists sudo; then
323+
sh_c "sudo $*"
324+
elif command_exists su; then
325+
sh_c "su -c '$*'"
326+
else
327+
echo
328+
echo "This script needs to run the following command as root."
329+
echo " $*"
330+
echo "Please run this script as root or install sudo or su."
331+
exit 1
332+
fi
333+
}
334+
335+
cache_dir() {
336+
if [ "${XDG_CACHE_HOME-}" ]; then
337+
echo "$XDG_CACHE_HOME/code-server"
338+
elif [ "${HOME-}" ]; then
339+
echo "$HOME/.cache/code-server"
340+
else
341+
echo "/tmp/code-server-cache"
342+
fi
343+
}
344+
345+
main "$@"

0 commit comments

Comments
 (0)
Please sign in to comment.