Skip to content

Commit 323a1f3

Browse files
committed
Only require unsafe-perm if you are root
Remove it from the docs, as the error message should be sufficient and it seems weird to recommend unsafe-perm by default.
1 parent b8d830b commit 323a1f3

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

ci/build/npm-postinstall.sh

+26-11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ symlink_bin_script() {
5151
cd "$oldpwd"
5252
}
5353

54+
command_exists() {
55+
if [ ! "$1" ]; then return 1; fi
56+
command -v "$@" > /dev/null
57+
}
58+
59+
is_root() {
60+
if command_exists id && [ "$(id -u)" = 0 ]; then
61+
return 0
62+
fi
63+
return 1
64+
}
65+
5466
OS="$(os)"
5567

5668
main() {
@@ -75,17 +87,20 @@ main() {
7587
exit 1
7688
fi
7789

78-
case "${npm_config_user_agent-}" in npm*)
79-
# We are running under npm.
80-
if [ "${npm_config_unsafe_perm-}" != "true" ]; then
81-
echo "Please pass --unsafe-perm to npm to install code-server"
82-
echo "Otherwise the postinstall script does not have permissions to run"
83-
echo "See https://docs.npmjs.com/misc/config#unsafe-perm"
84-
echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm"
85-
exit 1
86-
fi
87-
;;
88-
esac
90+
# Under npm, if we are running as root, we need --unsafe-perm otherwise
91+
# post-install scripts will not have sufficient permissions to do their thing.
92+
if is_root; then
93+
case "${npm_config_user_agent-}" in npm*)
94+
if [ "${npm_config_unsafe_perm-}" != "true" ]; then
95+
echo "Please pass --unsafe-perm to npm to install code-server"
96+
echo "Otherwise post-install scripts will not have permissions to run"
97+
echo "See https://docs.npmjs.com/misc/config#unsafe-perm"
98+
echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm"
99+
exit 1
100+
fi
101+
;;
102+
esac
103+
fi
89104

90105
if ! vscode_install; then
91106
echo "You may not have the required dependencies to build the native modules."

docs/android.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ nvm install 18
1818
nvm use 18
1919
```
2020

21-
8. Install code-server globally on device with: `npm install --global code-server --unsafe-perm`
21+
8. Install code-server globally on device with: `npm install --global code-server`
2222
9. Run code-server with `code-server`
2323
10. Access on localhost:8080 in your browser
2424

docs/npm.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Installing code-server requires all of the [prerequisites for VS Code developmen
9292
Next, install code-server with:
9393

9494
```bash
95-
npm install --global code-server --unsafe-perm
95+
npm install --global code-server
9696
code-server
9797
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
9898
```
@@ -112,7 +112,7 @@ For help and additional troubleshooting, see [#1397](https://github.com/coder/co
112112
After adding the dependencies for your OS, install the code-server package globally:
113113

114114
```bash
115-
npm install --global code-server --unsafe-perm
115+
npm install --global code-server
116116
code-server
117117
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
118118
```
@@ -144,8 +144,8 @@ To debug installation issues, install with `npm`:
144144

145145
```shell
146146
# Uninstall
147-
npm uninstall --global --unsafe-perm code-server > /dev/null 2>&1
147+
npm uninstall --global code-server > /dev/null 2>&1
148148

149149
# Install with logging
150-
npm install --loglevel verbose --global --unsafe-perm code-server
150+
npm install --loglevel verbose --global code-server
151151
```

docs/termux.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ code-server --auth none
7070
7. If already installed then use the following command for upgradation.
7171

7272
```
73-
npm update --global code-server --unsafe-perm
73+
npm update --global code-server
7474
```
7575

7676
## Upgrade

0 commit comments

Comments
 (0)