Skip to content

Commit ed3e60d

Browse files
committed
Avoid root when prefix is writable
Previously if the prefix was non-existent we would switch to root even if the user does have the permissions to create the directory. Fixes #3585
1 parent d922e15 commit ed3e60d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.github/workflows/installer.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
ubuntu:
15-
name: Test installer on ubuntu
15+
name: Test installer on Ubuntu
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout repo
@@ -24,6 +24,24 @@ jobs:
2424
- name: Test code-server
2525
run: yarn test:standalone-release code-server
2626

27+
alpine:
28+
name: Test installer on Alpine
29+
runs-on: ubuntu-latest
30+
container: "alpine:3.14"
31+
steps:
32+
- name: Checkout repo
33+
uses: actions/checkout@v2
34+
35+
- name: Install curl
36+
run: apk add curl
37+
38+
- name: Add user
39+
run: adduser coder --disabled-password
40+
41+
# Standalone should work without root.
42+
- name: Test standalone to a non-existent prefix
43+
run: su coder -c "./install.sh --method standalone --prefix /tmp/does/not/yet/exist"
44+
2745
macos:
2846
name: Test installer on macOS
2947
runs-on: macos-latest

install.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ main() {
132132
unset \
133133
DRY_RUN \
134134
METHOD \
135-
STANDALONE_INSTALL_PREFIX \
136135
OPTIONAL \
137136
ALL_FLAGS \
138137
RSH_ARGS \
@@ -381,6 +380,10 @@ install_standalone() {
381380
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" \
382381
"$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
383382

383+
# -w only works if the directory exists so try creating it first. If this
384+
# fails we can ignore the error as the -w check will then swap us to sudo.
385+
sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2> /dev/null || true
386+
384387
sh_c="sh_c"
385388
if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then
386389
sh_c="sudo_sh_c"

0 commit comments

Comments
 (0)