2020-05-13 10:17:34 +02:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
set -eu
|
|
|
|
|
2022-08-04 18:03:28 +02:00
|
|
|
# Copied from ../lib.sh.
|
|
|
|
arch() {
|
|
|
|
cpu="$(uname -m)"
|
|
|
|
case "$cpu" in
|
|
|
|
aarch64) cpu=arm64 ;;
|
|
|
|
x86_64) cpu=amd64 ;;
|
2021-05-10 18:26:39 +02:00
|
|
|
esac
|
2022-08-04 18:03:28 +02:00
|
|
|
echo "$cpu"
|
2021-05-10 18:26:39 +02:00
|
|
|
}
|
|
|
|
|
2022-08-04 18:03:28 +02:00
|
|
|
# Copied from ../lib.sh except we do not rename Darwin since the cloud agent
|
|
|
|
# uses "darwin" in the release names and we do not need to detect Alpine.
|
|
|
|
os() {
|
|
|
|
osname=$(uname | tr '[:upper:]' '[:lower:]')
|
|
|
|
case $osname in
|
|
|
|
cygwin* | mingw*) osname="windows" ;;
|
|
|
|
esac
|
|
|
|
echo "$osname"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a symlink at $2 pointing to $1 on any platform. Anything that
|
|
|
|
# currently exists at $2 will be deleted.
|
|
|
|
symlink() {
|
|
|
|
source="$1"
|
|
|
|
dest="$2"
|
|
|
|
rm -rf "$dest"
|
|
|
|
case $OS in
|
|
|
|
windows) mklink /J "$dest" "$source" ;;
|
|
|
|
*) ln -s "$source" "$dest" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# VS Code bundles some modules into an asar which is an archive format that
|
|
|
|
# works like tar. It then seems to get unpacked into node_modules.asar.
|
|
|
|
#
|
|
|
|
# I don't know why they do this but all the dependencies they bundle already
|
|
|
|
# exist in node_modules so just symlink it. We have to do this since not only
|
|
|
|
# Code itself but also extensions will look specifically in this directory for
|
|
|
|
# files (like the ripgrep binary or the oniguruma wasm).
|
|
|
|
symlink_asar() {
|
|
|
|
symlink node_modules node_modules.asar
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make a symlink at bin/$1/$3 pointing to the platform-specific version of the
|
|
|
|
# script in $2. The extension of the link will be .cmd for Windows otherwise it
|
|
|
|
# will be whatever is in $4 (or no extension if $4 is not set).
|
|
|
|
symlink_bin_script() {
|
|
|
|
oldpwd="$(pwd)"
|
|
|
|
cd "bin/$1"
|
|
|
|
source="$2"
|
|
|
|
dest="$3"
|
|
|
|
ext="${4-}"
|
|
|
|
case $OS in
|
|
|
|
windows) symlink "$source.cmd" "$dest.cmd" ;;
|
|
|
|
darwin | macos) symlink "$source-darwin.sh" "$dest$ext" ;;
|
|
|
|
*) symlink "$source-linux.sh" "$dest$ext" ;;
|
|
|
|
esac
|
|
|
|
cd "$oldpwd"
|
|
|
|
}
|
|
|
|
|
|
|
|
ARCH="${NPM_CONFIG_ARCH:-$(arch)}"
|
|
|
|
OS="$(os)"
|
|
|
|
|
2022-02-04 23:52:42 +01:00
|
|
|
# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
|
|
|
|
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
|
|
|
|
export npm_config_build_from_source=true
|
2021-05-10 18:26:39 +02:00
|
|
|
|
2020-05-13 10:17:34 +02:00
|
|
|
main() {
|
2020-05-15 03:37:58 +02:00
|
|
|
# Grabs the major version of node from $npm_config_user_agent which looks like
|
|
|
|
# yarn/1.21.1 npm/? node/v14.2.0 darwin x64
|
|
|
|
major_node_version=$(echo "$npm_config_user_agent" | sed -n 's/.*node\/v\([^.]*\).*/\1/p')
|
2021-06-01 19:19:03 +02:00
|
|
|
|
|
|
|
if [ -n "${FORCE_NODE_VERSION:-}" ]; then
|
|
|
|
echo "WARNING: Overriding required Node.js version to v$FORCE_NODE_VERSION"
|
|
|
|
echo "This could lead to broken functionality, and is unsupported."
|
|
|
|
echo "USE AT YOUR OWN RISK!"
|
|
|
|
fi
|
|
|
|
|
2022-05-04 23:58:49 +02:00
|
|
|
if [ "$major_node_version" -ne "${FORCE_NODE_VERSION:-16}" ]; then
|
|
|
|
echo "ERROR: code-server currently requires node v16."
|
2021-06-01 19:19:03 +02:00
|
|
|
if [ -n "$FORCE_NODE_VERSION" ]; then
|
|
|
|
echo "However, you have overrided the version check to use v$FORCE_NODE_VERSION."
|
|
|
|
fi
|
2020-05-15 03:37:58 +02:00
|
|
|
echo "We have detected that you are on node v$major_node_version"
|
2021-06-01 19:19:03 +02:00
|
|
|
echo "You can override this version check by setting \$FORCE_NODE_VERSION,"
|
|
|
|
echo "but configurations that do not use the same node version are unsupported."
|
2020-05-15 03:37:58 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-13 11:06:11 +02:00
|
|
|
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
|
|
|
|
|
2021-10-28 22:27:17 +02:00
|
|
|
mkdir -p ./lib
|
|
|
|
|
2022-02-01 17:45:19 +01:00
|
|
|
if curl -fsSL "https://github.com/coder/cloud-agent/releases/latest/download/cloud-agent-$OS-$ARCH" -o ./lib/coder-cloud-agent; then
|
2020-11-02 23:47:09 +01:00
|
|
|
chmod +x ./lib/coder-cloud-agent
|
|
|
|
else
|
|
|
|
echo "Failed to download cloud agent; --link will not work"
|
|
|
|
fi
|
2020-10-12 08:09:48 +02:00
|
|
|
|
2022-08-22 23:07:57 +02:00
|
|
|
if ! vscode_install; then
|
2020-05-13 11:06:11 +02:00
|
|
|
echo "You may not have the required dependencies to build the native modules."
|
2022-05-11 23:39:57 +02:00
|
|
|
echo "Please see https://github.com/coder/code-server/blob/main/docs/npm.md"
|
2020-05-13 11:06:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-06-01 19:19:03 +02:00
|
|
|
|
|
|
|
if [ -n "${FORCE_NODE_VERSION:-}" ]; then
|
|
|
|
echo "WARNING: The required Node.js version was overriden to v$FORCE_NODE_VERSION"
|
|
|
|
echo "This could lead to broken functionality, and is unsupported."
|
|
|
|
echo "USE AT YOUR OWN RISK!"
|
|
|
|
fi
|
2020-05-13 10:17:34 +02:00
|
|
|
}
|
|
|
|
|
2022-08-22 23:07:57 +02:00
|
|
|
install_with_yarn_or_npm() {
|
|
|
|
# NOTE@edvincent: We want to keep using the package manager that the end-user was using to install the package.
|
|
|
|
# This also ensures that when *we* run `yarn` in the development process, the yarn.lock file is used.
|
|
|
|
case "${npm_config_user_agent-}" in
|
|
|
|
npm*)
|
|
|
|
if [ -f "yarn.lock" ]; then
|
|
|
|
echo "yarn.lock file present, running in development mode. use yarn to install code-server!"
|
|
|
|
exit 1
|
|
|
|
else
|
2022-09-06 22:34:34 +02:00
|
|
|
# HACK: NPM's use of semver doesn't like resolving some peerDependencies that vscode (upstream) brings in the form of pre-releases.
|
|
|
|
# The legacy behavior doesn't complain about pre-releases being used, falling back to that for now.
|
|
|
|
# See https://github.com//pull/5071
|
2022-09-06 20:03:27 +02:00
|
|
|
npm install --unsafe-perm --legacy-peer-deps --omit=dev
|
2022-08-22 23:07:57 +02:00
|
|
|
fi
|
|
|
|
;;
|
2022-12-07 23:04:50 +01:00
|
|
|
yarn*)
|
|
|
|
if [ -f "yarn.lock" ]; then
|
|
|
|
yarn --production --frozen-lockfile --no-default-rc
|
|
|
|
else
|
|
|
|
echo "yarn.lock file not present, not running in development mode. use npm to install code-server!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2022-08-22 23:07:57 +02:00
|
|
|
*)
|
|
|
|
echo "Could not determine which package manager is being used to install code-server"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
vscode_install() {
|
2022-03-15 03:37:29 +01:00
|
|
|
echo 'Installing Code dependencies...'
|
|
|
|
cd lib/vscode
|
2022-08-22 23:07:57 +02:00
|
|
|
install_with_yarn_or_npm
|
2020-12-17 22:16:04 +01:00
|
|
|
|
2021-05-12 23:46:29 +02:00
|
|
|
symlink_asar
|
2022-08-04 18:03:28 +02:00
|
|
|
symlink_bin_script remote-cli code code-server
|
|
|
|
symlink_bin_script helpers browser browser .sh
|
2020-12-17 22:16:04 +01:00
|
|
|
|
2020-05-19 03:30:24 +02:00
|
|
|
cd extensions
|
2022-08-22 23:07:57 +02:00
|
|
|
install_with_yarn_or_npm
|
2020-05-19 03:30:24 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 10:17:34 +02:00
|
|
|
main "$@"
|