Disallow running as root without --user-data-dir

This commit adds the --user-data-dir argument which allows a custom data dir
for Chromium's user data. This is useful when running as root on Linux since
the root user does not have read or write permissions for the ~/.config/Code
dir.

Part of #3068
This commit is contained in:
Daniel Imms
2016-04-06 16:31:36 -07:00
parent 78dcfe10d8
commit 6456f85788
3 changed files with 29 additions and 1 deletions

View File

@@ -3,6 +3,23 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
ARGS=$@
# If root, ensure that --user-data-dir is specified
if [ "$(id -u)" = "0" ]; then
while test $# -gt 0
do
if [[ $1 == --user-data-dir=* ]]; then
DATA_DIR_SET=1
fi
shift
done
if [ -z $DATA_DIR_SET ]; then
echo "It is recommended to start vscode as a normal user. To run as root, you must specify an alternate user data directory with the --user-data-dir argument." 1>&2
exit 1
fi
fi
if [ ! -L $0 ]; then
# if path is not a symlink, find relatively
VSCODE_PATH="$(dirname $0)/.."
@@ -15,7 +32,8 @@ else
VSCODE_PATH="/usr/share/@@NAME@@"
fi
fi
ELECTRON="$VSCODE_PATH/@@NAME@@"
CLI="$VSCODE_PATH/resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" $ARGS
exit $?