mirror of
https://github.com/coder/code-server.git
synced 2026-05-26 15:13:28 +00:00
Improved install.sh flags
This commit is contained in:
181
install.sh
181
install.sh
@@ -1,51 +1,59 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# code-server's automatic install script.
|
||||
# See https://github.com/cdr/code-server/blob/master/doc/install.md
|
||||
|
||||
usage() {
|
||||
cli="$0"
|
||||
arg0="$0"
|
||||
if [ "$0" = sh ]; then
|
||||
cli="curl -fsSL https://code-server.dev/install.sh | sh -s --"
|
||||
arg0="curl -fsSL https://code-server.dev/install.sh | sh -s --"
|
||||
else
|
||||
curl_usage="The latest script is available at https://code-server.dev/install.sh"
|
||||
curl_usage="The latest script is available at https://code-server.dev/install.sh
|
||||
"
|
||||
fi
|
||||
|
||||
cat << EOF
|
||||
Installs code-server for Linux or macOS.
|
||||
Installs code-server for Linux and macOS.
|
||||
It tries to use the system package manager if possible.
|
||||
After successful installation it explains how to start using code-server.
|
||||
${curl_usage-}
|
||||
|
||||
Usage:
|
||||
|
||||
$cli [--dry-run] [--version X.X.X] [--static <install-prefix>=~/.local]
|
||||
$arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local]
|
||||
|
||||
--dry-run Echo the commands for the install process without running them.
|
||||
|
||||
--version Install a specific version instead of the latest release.
|
||||
|
||||
--static Install a static release into ~/.local
|
||||
|
||||
The release will be unarchived into ~/.local/lib/code-server.X.X.X
|
||||
and the binary symlinked into ~/.local/bin/code-server.
|
||||
Add ~/.local/bin to your \$PATH to use it.
|
||||
|
||||
To install system wide pass ---static=/usr/local
|
||||
--dry-run
|
||||
Echo the commands for the install process without running them.
|
||||
--version X.X.X
|
||||
Install a specific version instead of the latest.
|
||||
--method [detect | archive]
|
||||
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.
|
||||
- archive installs a static release archive into ~/.local
|
||||
Add ~/.local/bin to your \$PATH to use it.
|
||||
--prefix <dir>
|
||||
Sets the prefix used by static release archives. Defaults to ~/.local
|
||||
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
|
||||
|
||||
- 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.
|
||||
- For Arch Linux it will install the AUR package.
|
||||
- For any unrecognized Linux operating system it will install the latest static
|
||||
release into ~/.local
|
||||
- Add ~/.local/bin to your \$PATH to run code-server.
|
||||
|
||||
- For macOS it will install the Homebrew package.
|
||||
- If Homebrew is not installed it will install the latest static release
|
||||
into ~/.local
|
||||
- Add ~/.local/bin to your \$PATH to run code-server.
|
||||
|
||||
- If ran on an architecture with no binary releases, it will install the
|
||||
npm package with yarn or npm.
|
||||
- We only have binary releases for amd64 and arm64 presently.
|
||||
|
||||
It will cache all downloaded assets into ~/.cache/code-server
|
||||
|
||||
More installation docs are at https://github.com/cdr/code-server/blob/master/doc/install.md
|
||||
EOF
|
||||
}
|
||||
@@ -60,10 +68,9 @@ echo_latest_version() {
|
||||
echo_static_postinstall() {
|
||||
echo
|
||||
cat << EOF
|
||||
Static release has been installed into $STATIC_INSTALL_PREFIX/lib/code-server-$VERSION
|
||||
|
||||
Static release has been installed into $ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION
|
||||
Please extend your path to use code-server:
|
||||
PATH="$STATIC_INSTALL_PREFIX/bin:\$PATH"
|
||||
PATH="$ARCHIVE_INSTALL_PREFIX/bin:\$PATH"
|
||||
Then you can run:
|
||||
code-server
|
||||
EOF
|
||||
@@ -86,8 +93,8 @@ main() {
|
||||
|
||||
unset \
|
||||
DRY_RUN \
|
||||
STATIC \
|
||||
STATIC_INSTALL_PREFIX \
|
||||
METHOD \
|
||||
ARCHIVE_INSTALL_PREFIX \
|
||||
SKIP_ECHO \
|
||||
VERSION \
|
||||
OPTIONAL
|
||||
@@ -97,16 +104,19 @@ main() {
|
||||
--dry-run)
|
||||
DRY_RUN=1
|
||||
;;
|
||||
--static)
|
||||
STATIC=1
|
||||
if [ "${2-}" ]; then
|
||||
STATIC_INSTALL_PREFIX="$(OPTIONAL=1 parse_arg "$@")"
|
||||
shift
|
||||
fi
|
||||
--method)
|
||||
METHOD="$(parse_arg "$@")"
|
||||
shift
|
||||
;;
|
||||
--static=*)
|
||||
STATIC=1
|
||||
STATIC_INSTALL_PREFIX="$(OPTIONAL=1 parse_arg "$@")"
|
||||
--method=*)
|
||||
METHOD="$(parse_arg "$@")"
|
||||
;;
|
||||
--prefix)
|
||||
ARCHIVE_INSTALL_PREFIX="$(parse_arg "$@")"
|
||||
shift
|
||||
;;
|
||||
--prefix=*)
|
||||
ARCHIVE_INSTALL_PREFIX="$(parse_arg "$@")"
|
||||
;;
|
||||
--version)
|
||||
VERSION="$(parse_arg "$@")"
|
||||
@@ -115,7 +125,7 @@ main() {
|
||||
--version=*)
|
||||
VERSION="$(parse_arg "$@")"
|
||||
;;
|
||||
-h | --help)
|
||||
-h | --h | -help | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
@@ -130,7 +140,13 @@ main() {
|
||||
done
|
||||
|
||||
VERSION="${VERSION-$(echo_latest_version)}"
|
||||
STATIC_INSTALL_PREFIX="${STATIC_INSTALL_PREFIX-$HOME/.local}"
|
||||
METHOD="${METHOD-detect}"
|
||||
if [ "$METHOD" != detect ] && [ "$METHOD" != archive ]; then
|
||||
echoerr "Unknown install method \"$METHOD\""
|
||||
echoerr "Run with --help to see usage."
|
||||
exit 1
|
||||
fi
|
||||
ARCHIVE_INSTALL_PREFIX="${ARCHIVE_INSTALL_PREFIX-$HOME/.local}"
|
||||
|
||||
OS="$(os)"
|
||||
if [ ! "$OS" ]; then
|
||||
@@ -142,11 +158,12 @@ main() {
|
||||
|
||||
ARCH="$(arch)"
|
||||
if [ ! "$ARCH" ]; then
|
||||
if [ "${STATIC-}" ]; then
|
||||
if [ "$METHOD" = archive ]; then
|
||||
echoerr "No static releases available for the architecture $(uname -m)."
|
||||
echoerr "Please rerun without the --static flag to install from npm."
|
||||
echoerr 'Please rerun without the "--method archive" flag to install from npm.'
|
||||
exit 1
|
||||
fi
|
||||
echo "No precompiled releases for $(uname -m)."
|
||||
install_npm
|
||||
return
|
||||
fi
|
||||
@@ -154,8 +171,8 @@ main() {
|
||||
CACHE_DIR="$(echo_cache_dir)"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
if [ "${STATIC-}" ]; then
|
||||
install_static
|
||||
if [ "$METHOD" = archive ]; then
|
||||
install_archive
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -170,10 +187,11 @@ main() {
|
||||
install_rpm
|
||||
;;
|
||||
arch)
|
||||
install_arch
|
||||
install_aur
|
||||
;;
|
||||
*)
|
||||
install_static
|
||||
echo "Unsupported package manager."
|
||||
install_archive
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -212,36 +230,43 @@ fetch() {
|
||||
URL="$1"
|
||||
FILE="$2"
|
||||
|
||||
echo "+ Downloading $URL"
|
||||
|
||||
if [ -e "$FILE" ]; then
|
||||
echo
|
||||
echo "+ Using cached $FILE from $URL"
|
||||
echo "+ Using cached $FILE"
|
||||
return
|
||||
fi
|
||||
|
||||
SKIP_ECHO=1
|
||||
sh_c curl \
|
||||
-#fL \
|
||||
-Ro "$FILE.incomplete" \
|
||||
-o "$FILE.incomplete" \
|
||||
-C - \
|
||||
"$URL"
|
||||
SKIP_ECHO=1 sh_c mv "$FILE.incomplete" "$FILE"
|
||||
sh_c mv "$FILE.incomplete" "$FILE"
|
||||
unset SKIP_ECHO
|
||||
|
||||
echo "+ Downloaded into $FILE"
|
||||
}
|
||||
|
||||
install_macos() {
|
||||
if command_exists brew; then
|
||||
echo "Installing from Homebrew."
|
||||
echo
|
||||
|
||||
sh_c brew install code-server
|
||||
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Homebrew is not installed so installing static release."
|
||||
echo "Homebrew not installed."
|
||||
|
||||
install_static
|
||||
install_archive
|
||||
}
|
||||
|
||||
install_deb() {
|
||||
echo "Installing v$VERSION deb package from GitHub releases."
|
||||
echo
|
||||
|
||||
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server_${VERSION}_$ARCH.deb" "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
|
||||
sudo_sh_c dpkg -i "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
|
||||
@@ -251,6 +276,7 @@ install_deb() {
|
||||
|
||||
install_rpm() {
|
||||
echo "Installing v$VERSION rpm package from GitHub releases."
|
||||
echo
|
||||
|
||||
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$ARCH.rpm" "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
|
||||
sudo_sh_c rpm -i "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
|
||||
@@ -260,65 +286,67 @@ install_rpm() {
|
||||
|
||||
install_aur() {
|
||||
echo "Installing from the AUR."
|
||||
echo
|
||||
|
||||
fetch "https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz" "$CACHE_DIR/code-server-aur.tar.gz"
|
||||
|
||||
prev_dir="$PWD"
|
||||
tmp_dir="$(mktemp -d)"
|
||||
(
|
||||
cd "$tmp_dir"
|
||||
SKIP_ECHO=1 sh_c tar -xzf "$CACHE_DIR/code-server-aur.tar.gz" --strip-components 1
|
||||
sh_c makepkg -si
|
||||
)
|
||||
cd "$tmp_dir"
|
||||
|
||||
echo "+ Downloading PKGBUILD from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz"
|
||||
SKIP_ECHO=1 sh_c 'curl -fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xz --strip-components 1'
|
||||
unset SKIP_ECHO
|
||||
echo "+ Downloaded into $tmp_dir"
|
||||
sh_c makepkg -si
|
||||
|
||||
cd "$prev_dir"
|
||||
rm -Rf "$tmp_dir"
|
||||
|
||||
echo_systemd_postinstall
|
||||
}
|
||||
|
||||
install_static() {
|
||||
STATIC_INSTALL_PREFIX=${STATIC_INSTALL_PREFIX-/usr/local/lib}
|
||||
|
||||
install_archive() {
|
||||
echo "Installing static release v$VERSION"
|
||||
echo
|
||||
|
||||
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"
|
||||
|
||||
if [ ! -d "$STATIC_INSTALL_PREFIX" ]; then
|
||||
echo
|
||||
echoerr "Static release install prefix $STATIC_INSTALL_PREFIX does not exist"
|
||||
exit 1
|
||||
fi
|
||||
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"
|
||||
|
||||
sh_c="sh_c"
|
||||
if [ ! -w "$STATIC_INSTALL_PREFIX" ]; then
|
||||
if [ ! -w "$ARCHIVE_INSTALL_PREFIX" ]; then
|
||||
sh_c="sudo_sh_c"
|
||||
fi
|
||||
SKIP_ECHO=1 sh_c mkdir -p "$STATIC_INSTALL_PREFIX/lib" "$STATIC_INSTALL_PREFIX/bin"
|
||||
|
||||
if [ -e "$STATIC_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then
|
||||
SKIP_ECHO=1 sh_c mkdir -p "$ARCHIVE_INSTALL_PREFIX/lib" "$ARCHIVE_INSTALL_PREFIX/bin"
|
||||
unset SKIP_ECHO
|
||||
|
||||
if [ -e "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then
|
||||
echo
|
||||
echoerr "code-server-$VERSION is already installed at $STATIC_INSTALL_PREFIX/lib/code-server-$VERSION"
|
||||
echoerr "Please remove it to reinstall."
|
||||
exit 1
|
||||
echo "code-server-$VERSION is already installed at $ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION"
|
||||
echo "Remove it to reinstall."
|
||||
exit 0
|
||||
fi
|
||||
"$sh_c" tar -C "$STATIC_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
|
||||
"$sh_c" mv -f "$STATIC_INSTALL_PREFIX/lib/code-server-$VERSION-$OS-$ARCH" "$STATIC_INSTALL_PREFIX/lib/code-server-$VERSION"
|
||||
"$sh_c" tar -C "$ARCHIVE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
|
||||
"$sh_c" mv -f "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION-$OS-$ARCH" "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION"
|
||||
"$sh_c" ln -fs "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION/bin/code-server" "$ARCHIVE_INSTALL_PREFIX/bin/code-server"
|
||||
|
||||
echo_static_postinstall
|
||||
}
|
||||
|
||||
install_npm() {
|
||||
echoerr "No precompiled releases for $(uname -m)."
|
||||
if command_exists yarn; then
|
||||
echo "Installing with yarn."
|
||||
echo
|
||||
sh_c yarn global add code-server --unsafe-perm
|
||||
return
|
||||
elif command_exists npm; then
|
||||
echo "Installing with npm."
|
||||
echo
|
||||
sh_c npm install -g code-server --unsafe-perm
|
||||
return
|
||||
fi
|
||||
echoerr
|
||||
echo
|
||||
echoerr "Please install npm or yarn to install code-server!"
|
||||
echoerr "You will need at least node v12 and a few C build dependencies."
|
||||
echoerr "You will need at least node v12 and a few C dependencies."
|
||||
echoerr "See the docs https://github.com/cdr/code-server#yarn-npm"
|
||||
exit 1
|
||||
}
|
||||
@@ -402,7 +430,6 @@ command_exists() {
|
||||
|
||||
sh_c() {
|
||||
if [ ! "${SKIP_ECHO-}" ]; then
|
||||
echo
|
||||
echo "+ $*"
|
||||
fi
|
||||
if [ ! "${DRY_RUN-}" ]; then
|
||||
@@ -421,7 +448,7 @@ sudo_sh_c() {
|
||||
echo
|
||||
echoerr "This script needs to run the following command as root."
|
||||
echoerr " $*"
|
||||
echoerr "Please run this script as root or install sudo or su."
|
||||
echoerr "Please install sudo or su."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user