2020-05-20 11:50:16 +03:00
|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
|
2020-05-22 22:38:03 +03:00
|
|
|
# code-server's automatic install script.
|
|
|
|
# See https://github.com/cdr/code-server/blob/master/doc/install.md
|
|
|
|
|
2020-05-20 11:50:16 +03:00
|
|
|
usage() {
|
2020-05-22 22:38:03 +03:00
|
|
|
arg0="$0"
|
2020-05-21 23:45:31 +03:00
|
|
|
if [ "$0" = sh ]; then
|
2020-05-22 22:38:03 +03:00
|
|
|
arg0="curl -fsSL https://code-server.dev/install.sh | sh -s --"
|
2020-05-21 23:45:31 +03:00
|
|
|
else
|
2020-05-28 00:46:55 +03:00
|
|
|
not_curl_usage="The latest script is available at https://code-server.dev/install.sh
|
2020-05-22 22:38:03 +03:00
|
|
|
"
|
2020-05-21 23:45:31 +03:00
|
|
|
fi
|
2020-05-22 22:38:03 +03:00
|
|
|
|
2020-05-28 00:01:33 +03:00
|
|
|
cath << EOF
|
2020-06-13 17:56:50 +03:00
|
|
|
Installs code-server for Linux, macOS and FreeBSD.
|
2020-05-22 05:16:16 +03:00
|
|
|
It tries to use the system package manager if possible.
|
|
|
|
After successful installation it explains how to start using code-server.
|
2020-10-09 22:33:58 +03:00
|
|
|
|
|
|
|
Pass in user@host to install code-server on user@host over ssh.
|
|
|
|
The remote host must have internet access.
|
2020-05-28 00:46:55 +03:00
|
|
|
${not_curl_usage-}
|
2020-05-21 23:45:31 +03:00
|
|
|
Usage:
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-10-09 22:33:58 +03:00
|
|
|
$arg0 [--dry-run] [--version X.X.X] [--method detect] \
|
2020-10-22 00:05:58 +03:00
|
|
|
[--prefix ~/.local] [--rsh ssh] [user@host]
|
2020-05-22 22:38:03 +03:00
|
|
|
|
|
|
|
--dry-run
|
|
|
|
Echo the commands for the install process without running them.
|
2020-10-09 22:33:58 +03:00
|
|
|
|
2020-05-22 22:38:03 +03:00
|
|
|
--version X.X.X
|
|
|
|
Install a specific version instead of the latest.
|
2020-10-09 22:33:58 +03:00
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
--method [detect | standalone]
|
2020-05-22 22:38:03 +03:00
|
|
|
Choose the installation method. Defaults to detect.
|
|
|
|
- detect detects the system package manager and tries to use it.
|
|
|
|
Full reference on the process is further below.
|
2020-05-27 23:39:17 +03:00
|
|
|
- standalone installs a standalone release archive into ~/.local
|
2020-05-22 22:38:03 +03:00
|
|
|
Add ~/.local/bin to your \$PATH to use it.
|
2020-10-09 22:33:58 +03:00
|
|
|
|
2020-05-22 22:38:03 +03:00
|
|
|
--prefix <dir>
|
2020-05-27 23:39:17 +03:00
|
|
|
Sets the prefix used by standalone release archives. Defaults to ~/.local
|
2020-05-22 22:38:03 +03:00
|
|
|
The release is unarchived into ~/.local/lib/code-server-X.X.X
|
|
|
|
and the binary symlinked into ~/.local/bin/code-server
|
|
|
|
To install system wide pass ---prefix=/usr/local
|
2020-05-22 06:53:02 +03:00
|
|
|
|
2020-10-22 00:05:58 +03:00
|
|
|
--rsh <bin>
|
|
|
|
Specifies the remote shell for remote installation. Defaults to ssh.
|
|
|
|
|
2020-05-22 05:16:16 +03:00
|
|
|
- For Debian, Ubuntu and Raspbian it will install the latest deb package.
|
|
|
|
- For Fedora, CentOS, RHEL and openSUSE it will install the latest rpm package.
|
2020-05-21 22:17:02 +03:00
|
|
|
- For Arch Linux it will install the AUR package.
|
2020-05-27 23:39:17 +03:00
|
|
|
- For any unrecognized Linux operating system it will install the latest standalone
|
2020-05-22 05:16:16 +03:00
|
|
|
release into ~/.local
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
- For macOS it will install the Homebrew package.
|
2020-05-27 23:39:17 +03:00
|
|
|
- If Homebrew is not installed it will install the latest standalone release
|
2020-05-22 05:16:16 +03:00
|
|
|
into ~/.local
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-06-13 17:56:50 +03:00
|
|
|
- For FreeBSD, it will install the npm package with yarn or npm.
|
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
- If ran on an architecture with no releases, it will install the
|
2020-05-22 05:16:16 +03:00
|
|
|
npm package with yarn or npm.
|
2020-05-27 23:39:17 +03:00
|
|
|
- We only have releases for amd64 and arm64 presently.
|
2020-05-27 23:48:11 +03:00
|
|
|
- The npm package builds the native modules on postinstall.
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-22 22:38:03 +03:00
|
|
|
It will cache all downloaded assets into ~/.cache/code-server
|
|
|
|
|
2020-05-22 06:53:02 +03:00
|
|
|
More installation docs are at https://github.com/cdr/code-server/blob/master/doc/install.md
|
2020-05-20 11:50:16 +03:00
|
|
|
EOF
|
2020-05-21 22:17:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
echo_latest_version() {
|
2020-05-21 23:45:31 +03:00
|
|
|
# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
|
|
|
|
version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/cdr/code-server/releases/latest)"
|
2020-06-03 00:22:24 +03:00
|
|
|
version="${version#https://github.com/cdr/code-server/releases/tag/}"
|
|
|
|
version="${version#v}"
|
2020-05-21 22:17:02 +03:00
|
|
|
echo "$version"
|
2020-05-20 11:50:16 +03:00
|
|
|
}
|
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
echo_standalone_postinstall() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh
|
|
|
|
cath << EOF
|
2020-05-27 23:39:17 +03:00
|
|
|
Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION
|
2020-05-20 11:50:16 +03:00
|
|
|
Please extend your path to use code-server:
|
2020-05-27 23:39:17 +03:00
|
|
|
PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH"
|
2020-05-20 11:50:16 +03:00
|
|
|
Then you can run:
|
|
|
|
code-server
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_systemd_postinstall() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh
|
|
|
|
cath << EOF
|
2020-05-20 11:50:16 +03:00
|
|
|
To have systemd start code-server now and restart on boot:
|
2020-08-28 19:21:00 +03:00
|
|
|
sudo systemctl enable --now code-server@\$USER
|
2020-05-20 11:50:16 +03:00
|
|
|
Or, if you don't want/need a background service you can run:
|
|
|
|
code-server
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2020-05-21 22:17:02 +03:00
|
|
|
if [ "${TRACE-}" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset \
|
|
|
|
DRY_RUN \
|
2020-05-22 22:38:03 +03:00
|
|
|
METHOD \
|
2020-05-27 23:39:17 +03:00
|
|
|
STANDALONE_INSTALL_PREFIX \
|
2020-05-21 22:17:02 +03:00
|
|
|
VERSION \
|
2020-10-09 22:33:58 +03:00
|
|
|
OPTIONAL \
|
|
|
|
ALL_FLAGS \
|
2020-10-22 00:05:58 +03:00
|
|
|
RSH_ARGS \
|
|
|
|
RSH
|
2020-05-21 22:17:02 +03:00
|
|
|
|
2020-10-09 22:33:58 +03:00
|
|
|
ALL_FLAGS=""
|
2020-05-21 22:17:02 +03:00
|
|
|
while [ "$#" -gt 0 ]; do
|
2020-10-09 22:33:58 +03:00
|
|
|
case "$1" in
|
|
|
|
-*)
|
|
|
|
ALL_FLAGS="${ALL_FLAGS} $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
case "$1" in
|
|
|
|
--dry-run)
|
|
|
|
DRY_RUN=1
|
|
|
|
;;
|
2020-05-22 22:38:03 +03:00
|
|
|
--method)
|
|
|
|
METHOD="$(parse_arg "$@")"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--method=*)
|
|
|
|
METHOD="$(parse_arg "$@")"
|
2020-05-21 22:17:02 +03:00
|
|
|
;;
|
2020-05-22 22:38:03 +03:00
|
|
|
--prefix)
|
2020-05-27 23:39:17 +03:00
|
|
|
STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")"
|
2020-05-22 22:38:03 +03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--prefix=*)
|
2020-05-27 23:39:17 +03:00
|
|
|
STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")"
|
2020-05-21 22:17:02 +03:00
|
|
|
;;
|
|
|
|
--version)
|
|
|
|
VERSION="$(parse_arg "$@")"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--version=*)
|
|
|
|
VERSION="$(parse_arg "$@")"
|
|
|
|
;;
|
2020-10-22 00:05:58 +03:00
|
|
|
--rsh)
|
|
|
|
RSH="$(parse_arg "$@")"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--rsh=*)
|
|
|
|
RSH="$(parse_arg "$@")"
|
|
|
|
;;
|
2020-05-22 22:38:03 +03:00
|
|
|
-h | --h | -help | --help)
|
2020-05-21 22:17:02 +03:00
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-10-09 22:33:58 +03:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
# We remove the -- added above.
|
|
|
|
ALL_FLAGS="${ALL_FLAGS% --}"
|
2020-10-22 00:00:20 +03:00
|
|
|
RSH_ARGS="$*"
|
2020-10-09 22:33:58 +03:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr "Unknown flag $1"
|
|
|
|
echoerr "Run with --help to see usage."
|
|
|
|
exit 1
|
|
|
|
;;
|
2020-10-09 22:33:58 +03:00
|
|
|
*)
|
2020-10-22 00:00:20 +03:00
|
|
|
RSH_ARGS="$*"
|
2020-10-09 22:33:58 +03:00
|
|
|
break
|
|
|
|
;;
|
2020-05-20 11:50:16 +03:00
|
|
|
esac
|
2020-05-21 22:17:02 +03:00
|
|
|
|
|
|
|
shift
|
2020-05-20 11:50:16 +03:00
|
|
|
done
|
2020-05-21 22:17:02 +03:00
|
|
|
|
2020-10-22 00:00:20 +03:00
|
|
|
if [ "${RSH_ARGS-}" ]; then
|
2020-10-22 08:43:22 +03:00
|
|
|
RSH="${RSH-ssh}"
|
2020-10-22 00:05:58 +03:00
|
|
|
echoh "Installing remotely with $RSH $RSH_ARGS"
|
|
|
|
curl -fsSL https://code-server.dev/install.sh | prefix "$RSH_ARGS" "$RSH" "$RSH_ARGS" sh -s -- "$ALL_FLAGS"
|
2020-10-09 22:33:58 +03:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
VERSION="${VERSION-$(echo_latest_version)}"
|
2020-05-22 22:38:03 +03:00
|
|
|
METHOD="${METHOD-detect}"
|
2020-05-27 23:39:17 +03:00
|
|
|
if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then
|
2020-05-22 22:38:03 +03:00
|
|
|
echoerr "Unknown install method \"$METHOD\""
|
|
|
|
echoerr "Run with --help to see usage."
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-27 23:39:17 +03:00
|
|
|
STANDALONE_INSTALL_PREFIX="${STANDALONE_INSTALL_PREFIX-$HOME/.local}"
|
2020-05-20 11:50:16 +03:00
|
|
|
|
|
|
|
OS="$(os)"
|
|
|
|
if [ ! "$OS" ]; then
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr "Unsupported OS $(uname)."
|
2020-05-20 11:50:16 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
distro_name
|
|
|
|
|
|
|
|
ARCH="$(arch)"
|
|
|
|
if [ ! "$ARCH" ]; then
|
2020-05-27 23:39:17 +03:00
|
|
|
if [ "$METHOD" = standalone ]; then
|
2020-06-13 17:56:50 +03:00
|
|
|
echoerr "No precompiled releases for $(uname -m)."
|
2020-05-27 23:39:17 +03:00
|
|
|
echoerr 'Please rerun without the "--method standalone" flag to install from npm.'
|
2020-05-20 11:50:16 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "No precompiled releases for $(uname -m)."
|
2020-05-20 11:50:16 +03:00
|
|
|
install_npm
|
2020-05-22 06:53:02 +03:00
|
|
|
return
|
2020-05-20 11:50:16 +03:00
|
|
|
fi
|
|
|
|
|
2020-06-13 17:56:50 +03:00
|
|
|
if [ "$OS" = "freebsd" ]; then
|
|
|
|
if [ "$METHOD" = standalone ]; then
|
|
|
|
echoerr "No precompiled releases available for $OS."
|
|
|
|
echoerr 'Please rerun without the "--method standalone" flag to install from npm.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echoh "No precompiled releases available for $OS."
|
|
|
|
install_npm
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-05-21 22:34:34 +03:00
|
|
|
CACHE_DIR="$(echo_cache_dir)"
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
if [ "$METHOD" = standalone ]; then
|
|
|
|
install_standalone
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$(distro)" in
|
|
|
|
macos)
|
|
|
|
install_macos
|
|
|
|
;;
|
|
|
|
ubuntu | debian | raspbian)
|
|
|
|
install_deb
|
|
|
|
;;
|
|
|
|
centos | fedora | rhel | opensuse)
|
|
|
|
install_rpm
|
|
|
|
;;
|
|
|
|
arch)
|
2020-05-22 22:38:03 +03:00
|
|
|
install_aur
|
2020-05-20 11:50:16 +03:00
|
|
|
;;
|
|
|
|
*)
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Unsupported package manager."
|
2020-05-27 23:39:17 +03:00
|
|
|
install_standalone
|
2020-05-20 11:50:16 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
parse_arg() {
|
|
|
|
case "$1" in
|
|
|
|
*=*)
|
2020-05-27 22:48:03 +03:00
|
|
|
# Remove everything after first equal sign.
|
|
|
|
opt="${1%%=*}"
|
|
|
|
# Remove everything before first equal sign.
|
2020-05-21 22:17:02 +03:00
|
|
|
optarg="${1#*=}"
|
2020-05-21 23:45:31 +03:00
|
|
|
if [ ! "$optarg" ] && [ ! "${OPTIONAL-}" ]; then
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr "$opt requires an argument"
|
|
|
|
echoerr "Run with --help to see usage."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "$optarg"
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
2020-05-21 22:17:02 +03:00
|
|
|
;;
|
|
|
|
esac
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
case "${2-}" in
|
2020-05-21 23:45:31 +03:00
|
|
|
"" | -*)
|
2020-05-21 22:17:02 +03:00
|
|
|
if [ ! "${OPTIONAL-}" ]; then
|
|
|
|
echoerr "$1 requires an argument"
|
|
|
|
echoerr "Run with --help to see usage."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$2"
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
2020-05-20 11:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fetch() {
|
|
|
|
URL="$1"
|
|
|
|
FILE="$2"
|
|
|
|
|
|
|
|
if [ -e "$FILE" ]; then
|
2020-06-05 01:19:47 +03:00
|
|
|
echoh "+ Reusing $FILE"
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-06-05 01:19:47 +03:00
|
|
|
sh_c mkdir -p "$CACHE_DIR"
|
2020-05-20 11:50:16 +03:00
|
|
|
sh_c curl \
|
|
|
|
-#fL \
|
2020-05-22 22:38:03 +03:00
|
|
|
-o "$FILE.incomplete" \
|
2020-05-20 11:50:16 +03:00
|
|
|
-C - \
|
|
|
|
"$URL"
|
2020-05-22 22:38:03 +03:00
|
|
|
sh_c mv "$FILE.incomplete" "$FILE"
|
2020-05-20 11:50:16 +03:00
|
|
|
}
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
install_macos() {
|
|
|
|
if command_exists brew; then
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Installing from Homebrew."
|
|
|
|
echoh
|
2020-05-21 22:17:02 +03:00
|
|
|
|
|
|
|
sh_c brew install code-server
|
|
|
|
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Homebrew not installed."
|
2020-05-21 22:17:02 +03:00
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
install_standalone
|
2020-05-21 22:17:02 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 11:50:16 +03:00
|
|
|
install_deb() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Installing v$VERSION deb package from GitHub releases."
|
|
|
|
echoh
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-27 06:15:44 +03:00
|
|
|
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server_${VERSION}_$ARCH.deb" \
|
|
|
|
"$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
|
2020-05-20 11:50:16 +03:00
|
|
|
sudo_sh_c dpkg -i "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
|
|
|
|
|
|
|
|
echo_systemd_postinstall
|
|
|
|
}
|
|
|
|
|
|
|
|
install_rpm() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Installing v$VERSION rpm package from GitHub releases."
|
|
|
|
echoh
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-27 06:15:44 +03:00
|
|
|
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$ARCH.rpm" \
|
|
|
|
"$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
|
2020-05-20 11:50:16 +03:00
|
|
|
sudo_sh_c rpm -i "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
|
|
|
|
|
|
|
|
echo_systemd_postinstall
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
install_aur() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Installing from the AUR."
|
|
|
|
echoh
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-28 00:46:55 +03:00
|
|
|
sh_c mkdir -p "$CACHE_DIR/code-server-aur"
|
|
|
|
sh_c "curl -#fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xzC $CACHE_DIR/code-server-aur --strip-components 1"
|
|
|
|
echo "+ cd $CACHE_DIR/code-server-aur"
|
|
|
|
if [ ! "${DRY_RUN-}" ]; then
|
|
|
|
cd "$CACHE_DIR/code-server-aur"
|
|
|
|
fi
|
2020-05-27 22:48:03 +03:00
|
|
|
sh_c makepkg -si
|
2020-05-20 11:50:16 +03:00
|
|
|
|
|
|
|
echo_systemd_postinstall
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
install_standalone() {
|
2020-05-28 03:38:29 +03:00
|
|
|
echoh "Installing standalone release archive v$VERSION from GitHub releases."
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-22 22:38:03 +03:00
|
|
|
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" \
|
|
|
|
"$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
|
2020-05-20 11:50:16 +03:00
|
|
|
|
|
|
|
sh_c="sh_c"
|
2020-05-27 23:39:17 +03:00
|
|
|
if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then
|
2020-05-20 11:50:16 +03:00
|
|
|
sh_c="sudo_sh_c"
|
|
|
|
fi
|
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
if [ -e "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh
|
|
|
|
echoh "code-server-$VERSION is already installed at $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION"
|
|
|
|
echoh "Remove it to reinstall."
|
2020-05-22 22:38:03 +03:00
|
|
|
exit 0
|
2020-05-21 22:34:34 +03:00
|
|
|
fi
|
2020-05-27 22:48:03 +03:00
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
"$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/lib" "$STANDALONE_INSTALL_PREFIX/bin"
|
|
|
|
"$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
|
|
|
|
"$sh_c" mv -f "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION-$OS-$ARCH" "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION"
|
|
|
|
"$sh_c" ln -fs "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION/bin/code-server" "$STANDALONE_INSTALL_PREFIX/bin/code-server"
|
2020-05-20 11:50:16 +03:00
|
|
|
|
2020-05-27 23:39:17 +03:00
|
|
|
echo_standalone_postinstall
|
2020-05-20 11:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
install_npm() {
|
|
|
|
if command_exists yarn; then
|
2020-05-27 22:48:03 +03:00
|
|
|
sh_c="sh_c"
|
|
|
|
if [ ! -w "$(yarn global bin)" ]; then
|
|
|
|
sh_c="sudo_sh_c"
|
|
|
|
fi
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Installing with yarn."
|
|
|
|
echoh
|
2020-05-27 22:48:03 +03:00
|
|
|
"$sh_c" yarn global add code-server --unsafe-perm
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
|
|
|
elif command_exists npm; then
|
2020-05-27 22:48:03 +03:00
|
|
|
sh_c="sh_c"
|
|
|
|
if [ ! -w "$(npm config get prefix)" ]; then
|
|
|
|
sh_c="sudo_sh_c"
|
|
|
|
fi
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "Installing with npm."
|
|
|
|
echoh
|
2020-05-27 22:48:03 +03:00
|
|
|
"$sh_c" npm install -g code-server --unsafe-perm
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
|
|
|
fi
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr "Please install npm or yarn to install code-server!"
|
2020-05-22 22:38:03 +03:00
|
|
|
echoerr "You will need at least node v12 and a few C dependencies."
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr "See the docs https://github.com/cdr/code-server#yarn-npm"
|
2020-05-20 11:50:16 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
os() {
|
|
|
|
case "$(uname)" in
|
|
|
|
Linux)
|
|
|
|
echo linux
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
echo macos
|
|
|
|
;;
|
2020-06-13 17:56:50 +03:00
|
|
|
FreeBSD)
|
|
|
|
echo freebsd
|
|
|
|
;;
|
2020-05-20 11:50:16 +03:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# distro prints the detected operating system including linux distros.
|
|
|
|
#
|
|
|
|
# Example outputs:
|
|
|
|
# - macos
|
|
|
|
# - debian, ubuntu, raspbian
|
|
|
|
# - centos, fedora, rhel, opensuse
|
|
|
|
# - alpine
|
|
|
|
# - arch
|
2020-06-13 17:56:50 +03:00
|
|
|
# - freebsd
|
2020-05-20 11:50:16 +03:00
|
|
|
#
|
|
|
|
# Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120.
|
|
|
|
distro() {
|
2020-06-13 17:56:50 +03:00
|
|
|
if [ "$OS" = "macos" ] || [ "$OS" = "freebsd" ]; then
|
|
|
|
echo "$OS"
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-05-21 23:45:31 +03:00
|
|
|
if [ -f /etc/os-release ]; then
|
|
|
|
(
|
|
|
|
. /etc/os-release
|
|
|
|
case "$ID" in opensuse-*)
|
|
|
|
# opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
|
|
|
|
echo "opensuse"
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "$ID"
|
|
|
|
)
|
2020-05-20 11:50:16 +03:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# os_name prints a pretty human readable name for the OS/Distro.
|
|
|
|
distro_name() {
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
echo "macOS v$(sw_vers -productVersion)"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-05-21 23:45:31 +03:00
|
|
|
if [ -f /etc/os-release ]; then
|
2020-05-20 11:50:16 +03:00
|
|
|
(
|
|
|
|
. /etc/os-release
|
|
|
|
echo "$PRETTY_NAME"
|
|
|
|
)
|
2020-05-21 23:45:31 +03:00
|
|
|
return
|
2020-05-20 11:50:16 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Prints something like: Linux 4.19.0-9-amd64
|
|
|
|
uname -sr
|
|
|
|
}
|
|
|
|
|
|
|
|
arch() {
|
|
|
|
case "$(uname -m)" in
|
|
|
|
aarch64)
|
|
|
|
echo arm64
|
|
|
|
;;
|
|
|
|
x86_64)
|
|
|
|
echo amd64
|
|
|
|
;;
|
2020-06-13 17:56:50 +03:00
|
|
|
amd64) # FreeBSD.
|
|
|
|
echo amd64
|
|
|
|
;;
|
2020-05-20 11:50:16 +03:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
command_exists() {
|
2020-10-09 22:33:58 +03:00
|
|
|
command -v "$@" > /dev/null
|
2020-05-20 11:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sh_c() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "+ $*"
|
2020-05-20 11:50:16 +03:00
|
|
|
if [ ! "${DRY_RUN-}" ]; then
|
|
|
|
sh -c "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
sudo_sh_c() {
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
|
|
|
sh_c "$@"
|
|
|
|
elif command_exists sudo; then
|
|
|
|
sh_c "sudo $*"
|
|
|
|
elif command_exists su; then
|
|
|
|
sh_c "su -c '$*'"
|
|
|
|
else
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr "This script needs to run the following command as root."
|
|
|
|
echoerr " $*"
|
2020-05-22 22:38:03 +03:00
|
|
|
echoerr "Please install sudo or su."
|
2020-05-20 11:50:16 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
echo_cache_dir() {
|
2020-05-20 11:50:16 +03:00
|
|
|
if [ "${XDG_CACHE_HOME-}" ]; then
|
|
|
|
echo "$XDG_CACHE_HOME/code-server"
|
|
|
|
elif [ "${HOME-}" ]; then
|
|
|
|
echo "$HOME/.cache/code-server"
|
|
|
|
else
|
|
|
|
echo "/tmp/code-server-cache"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh() {
|
|
|
|
echo "$@" | humanpath
|
2020-05-27 22:48:03 +03:00
|
|
|
}
|
|
|
|
|
2020-05-28 00:01:33 +03:00
|
|
|
cath() {
|
2020-05-27 22:48:03 +03:00
|
|
|
humanpath
|
|
|
|
}
|
|
|
|
|
2020-05-21 22:17:02 +03:00
|
|
|
echoerr() {
|
2020-05-28 00:01:33 +03:00
|
|
|
echoh "$@" >&2
|
2020-05-21 22:17:02 +03:00
|
|
|
}
|
|
|
|
|
2020-05-28 00:46:55 +03:00
|
|
|
# humanpath replaces all occurances of " $HOME" with " ~"
|
|
|
|
# and all occurances of '"$HOME' with the literal '"$HOME'.
|
2020-05-27 22:48:03 +03:00
|
|
|
humanpath() {
|
2020-05-28 00:46:55 +03:00
|
|
|
sed "s# $HOME# ~#g; s#\"$HOME#\"\$HOME#g"
|
2020-05-27 22:48:03 +03:00
|
|
|
}
|
|
|
|
|
2020-10-09 22:33:58 +03:00
|
|
|
# We need to make sure we exit with a non zero exit if the command fails.
|
|
|
|
# /bin/sh does not support -o pipefail unfortunately.
|
|
|
|
prefix() {
|
|
|
|
PREFIX="$1"
|
|
|
|
shift
|
|
|
|
fifo="$(mktemp -d)/fifo"
|
|
|
|
mkfifo "$fifo"
|
|
|
|
sed -e "s#^#$PREFIX: #" "$fifo" &
|
|
|
|
"$@" > "$fifo" 2>&1
|
|
|
|
}
|
|
|
|
|
2020-05-20 11:50:16 +03:00
|
|
|
main "$@"
|