Skip to content

Commit b8dce0f

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 48c8032 commit b8dce0f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.github/workflows/installer.yml

Lines changed: 24 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,29 @@ 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 Node.js v14
36+
uses: actions/setup-node@v2
37+
with:
38+
node-version: "14"
39+
40+
- name: Install curl
41+
run: apk add curl
42+
43+
- name: Add user
44+
run: adduser coder --disabled-password
45+
46+
# Standalone should work without root.
47+
- name: Test standalone to a non-existent prefix
48+
run: su coder -c "./install.sh --method standalone --prefix /tmp/does/not/yet/exist"
49+
2750
macos:
2851
name: Test installer on macOS
2952
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)