@@ -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+
5466OS=" $( os) "
5567
5668main () {
@@ -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."
0 commit comments