From 323a1f3234c902159ae4e8ac74e276076c67cd59 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 16 Apr 2024 10:46:25 -0800 Subject: [PATCH] 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. --- ci/build/npm-postinstall.sh | 37 ++++++++++++++++++++++++++----------- docs/android.md | 2 +- docs/npm.md | 8 ++++---- docs/termux.md | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index 0dac63b3e..0f99a0449 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -51,6 +51,18 @@ symlink_bin_script() { cd "$oldpwd" } +command_exists() { + if [ ! "$1" ]; then return 1; fi + command -v "$@" > /dev/null +} + +is_root() { + if command_exists id && [ "$(id -u)" = 0 ]; then + return 0 + fi + return 1 +} + OS="$(os)" main() { @@ -75,17 +87,20 @@ main() { exit 1 fi - case "${npm_config_user_agent-}" in npm*) - # We are running under npm. - if [ "${npm_config_unsafe_perm-}" != "true" ]; then - echo "Please pass --unsafe-perm to npm to install code-server" - echo "Otherwise the postinstall script does not have permissions to run" - echo "See https://docs.npmjs.com/misc/config#unsafe-perm" - echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm" - exit 1 - fi - ;; - esac + # Under npm, if we are running as root, we need --unsafe-perm otherwise + # post-install scripts will not have sufficient permissions to do their thing. + if is_root; then + case "${npm_config_user_agent-}" in npm*) + if [ "${npm_config_unsafe_perm-}" != "true" ]; then + echo "Please pass --unsafe-perm to npm to install code-server" + echo "Otherwise post-install scripts will not have permissions to run" + echo "See https://docs.npmjs.com/misc/config#unsafe-perm" + echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm" + exit 1 + fi + ;; + esac + fi if ! vscode_install; then echo "You may not have the required dependencies to build the native modules." diff --git a/docs/android.md b/docs/android.md index 9479276e0..8107be873 100644 --- a/docs/android.md +++ b/docs/android.md @@ -18,7 +18,7 @@ nvm install 18 nvm use 18 ``` -8. Install code-server globally on device with: `npm install --global code-server --unsafe-perm` +8. Install code-server globally on device with: `npm install --global code-server` 9. Run code-server with `code-server` 10. Access on localhost:8080 in your browser diff --git a/docs/npm.md b/docs/npm.md index 12064e3b0..4f3341249 100644 --- a/docs/npm.md +++ b/docs/npm.md @@ -92,7 +92,7 @@ Installing code-server requires all of the [prerequisites for VS Code developmen Next, install code-server with: ```bash -npm install --global code-server --unsafe-perm +npm install --global code-server code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` @@ -112,7 +112,7 @@ For help and additional troubleshooting, see [#1397](https://github.com/coder/co After adding the dependencies for your OS, install the code-server package globally: ```bash -npm install --global code-server --unsafe-perm +npm install --global code-server code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` @@ -144,8 +144,8 @@ To debug installation issues, install with `npm`: ```shell # Uninstall -npm uninstall --global --unsafe-perm code-server > /dev/null 2>&1 +npm uninstall --global code-server > /dev/null 2>&1 # Install with logging -npm install --loglevel verbose --global --unsafe-perm code-server +npm install --loglevel verbose --global code-server ``` diff --git a/docs/termux.md b/docs/termux.md index 491f16a4a..d6ea8c7bb 100644 --- a/docs/termux.md +++ b/docs/termux.md @@ -70,7 +70,7 @@ code-server --auth none 7. If already installed then use the following command for upgradation. ``` -npm update --global code-server --unsafe-perm +npm update --global code-server ``` ## Upgrade