Skip to content

feat: add a page to showcase the local installation script #16122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 15, 2025
Prev Previous commit
Next Next commit
Merge branch 'main' into lilac/local-cli-install-page
  • Loading branch information
aslilac committed Jan 14, 2025
commit b35e8778306ae14155e2d2f95adab51a1fa2f93a
6 changes: 3 additions & 3 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func New(opts *Options) *Handler {

handler.installScript, err = parseInstallScript(opts.SiteFS, opts.BuildInfo)
if err != nil {
_ = xerrors.Errorf("install.sh will be unavailable: %w", err)
_, _ = fmt.Fprintf(os.Stderr, "install.sh will be unavailable: %v", err.Error())
}

return handler
Expand Down Expand Up @@ -222,8 +222,8 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
// If the asset does not exist, this will return a 404.
h.handler.ServeHTTP(rw, r)
return
// If requesting the install.sh script, fill in the template with the
// appropriate hostname and version info.
// If requesting the install.sh script, respond with the preprocessed version
// which contains the correct hostname and version information.
case reqFile == "install.sh":
if h.installScript == nil {
http.NotFound(rw, r)
Expand Down
30 changes: 18 additions & 12 deletions site/static/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ set -eu
# See https://github.com/coder/coder#install
#
# To run:
# curl -L {{ .Origin }}/install.sh | sh
# curl -fsSL "{{ .Origin }}/install.sh" | sh

usage() {
arg0="$0"
if [ "$0" = sh ]; then
arg0="curl -fsSL {{ .Origin }}/install.sh | sh -s --"
arg0="curl -fsSL \"{{ .Origin }}/install.sh\" | sh -s --"
else
not_curl_usage="The latest script is available at {{ .Origin }}/install.sh
"
Expand Down Expand Up @@ -121,11 +121,12 @@ main() {

unset \
DRY_RUN \
OPTIONAL \
ORIGIN \
ALL_FLAGS \
RSH_ARGS \
RSH

ORIGIN="{{ .Origin }}"
ALL_FLAGS=""

while [ "$#" -gt 0 ]; do
Expand All @@ -139,6 +140,13 @@ main() {
--dry-run)
DRY_RUN=1
;;
--origin)
ORIGIN="$(parse_arg "$@")"
shift
;;
--origin=*)
ORIGIN="$(parse_arg "$@")"
;;
--prefix)
STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")"
shift
Expand Down Expand Up @@ -188,7 +196,7 @@ main() {
if [ "${RSH_ARGS-}" ]; then
RSH="${RSH-ssh}"
echoh "Installing remotely with $RSH $RSH_ARGS"
curl -fsSL "{{ .Origin }}/install.sh" | prefix "$RSH_ARGS" "$RSH" "$RSH_ARGS" sh -s -- "$ALL_FLAGS"
curl -fsSL "$ORIGIN/install.sh" | prefix "$RSH_ARGS" "$RSH" "$RSH_ARGS" sh -s -- "$ALL_FLAGS"
return
fi

Expand Down Expand Up @@ -223,7 +231,7 @@ parse_arg() {
opt="${1%%=*}"
# Remove everything before first equal sign.
optarg="${1#*=}"
if [ ! "$optarg" ] && [ ! "${OPTIONAL-}" ]; then
if [ ! "$optarg" ]; then
echoerr "$opt requires an argument"
echoerr "Run with --help to see usage."
exit 1
Expand All @@ -235,11 +243,9 @@ parse_arg() {

case "${2-}" in
"" | -*)
if [ ! "${OPTIONAL-}" ]; then
echoerr "$1 requires an argument"
echoerr "Run with --help to see usage."
exit 1
fi
echoerr "$1 requires an argument"
echoerr "Run with --help to see usage."
exit 1
;;
*)
echo "$2"
Expand Down Expand Up @@ -267,12 +273,12 @@ fetch() {
}

install_standalone() {
echoh "Installing coder-$OS-$ARCH {{ .Version }} from {{ .Origin }}."
echoh "Installing coder-$OS-$ARCH {{ .Version }} from $ORIGIN."
echoh

BINARY_FILE="$CACHE_DIR/coder-${OS}-${ARCH}-{{ .Version }}"

fetch "{{ .Origin }}/bin/coder-${OS}-${ARCH}" "$BINARY_FILE"
fetch "$ORIGIN/bin/coder-${OS}-${ARCH}" "$BINARY_FILE"

# -w only works if the directory exists so try creating it first. If this
# fails we can ignore the error as the -w check will then swap us to sudo.
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.