Skip to content

Commit 7169f6c

Browse files
committed
lando will now install in ~/.lando/bin by default
1 parent 0ce0ad3 commit 7169f6c

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

.github/workflows/pr-windows-script-replacer-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ jobs:
5555
}
5656
5757
if (-not (lando version | Select-String -Pattern "${{ matrix.old-version }}")) {
58-
throw "Error: lando is not the version we expect!"
58+
$reported = lando version
59+
throw "Error: lando is not the version we expect! expected ${{ matrix.version}} but found $reported"
5960
}
6061
6162
- name: Replace Lando with setup-script

setup-lando.sh

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ set -u
7676

7777
# configuration things at the top for QOL
7878
LANDO_DEFAULT_MV="3"
79+
LANDO_BINDIR="$HOME/.lando/bin"
80+
LANDO_DATADIR="${XDG_DATA_HOME:-$HOME/.data}/lando"
7981
LANDO_TMPDIR=${TMPDIR:-/tmp}
8082
MACOS_OLDEST_SUPPORTED="12.0"
8183
REQUIRED_CURL_VERSION="7.41.0"
@@ -164,12 +166,15 @@ get_installer_os
164166
# @TODO: dest based on lmv
165167
ARCH="${LANDO_INSTALLER_ARCH:-"$INSTALLER_ARCH"}"
166168
DEBUG="${LANDO_INSTALLER_DEBUG:-${RUNNER_DEBUG:-}}"
167-
DEST="${LANDO_INSTALLER_DEST:-/usr/local/bin}"
169+
DEST="${LANDO_INSTALLER_DEST:-$HOME/.lando/bin}"
168170
FAT="${LANDO_INSTALLER_FAT:-0}"
169171
OS="${LANDO_INSTALLER_OS:-"$INSTALLER_OS"}"
170172
SUDO="${LANDO_INSTALLER_SUDO:-1}"
171173
SETUP="${LANDO_INSTALLER_SETUP:-1}"
174+
SYMLINKER="${LANDO_BINDIR}/lando"
172175
VERSION="${LANDO_VERSION:-${LANDO_INSTALLER_VERSION:-stable}}"
176+
177+
# preserve originals OPTZ
173178
ORIGOPTS="$*"
174179

175180
usage() {
@@ -268,7 +273,6 @@ if [[ "$DEBUG" == "1" ]]; then
268273
LANDO_DEBUG="--debug"
269274
fi;
270275

271-
272276
# redefine this one
273277
abort() {
274278
printf "${tty_red}ERROR${tty_reset}: %s\n" "$(chomp "$1")" >&2
@@ -803,10 +807,12 @@ fi
803807
# LANDO
804808
LANDO="${DEST}/lando"
805809
LANDO_TMPFILE="${LANDO_TMPDIR}/${RANDOM}"
810+
HIDDEN_LANDO="${LANDO_DATADIR}/${VERSION}/lando"
806811

807812
# Create directories if we need to
808813
if [[ ! -d "$DEST" ]]; then auto_exec mkdir -p "$DEST"; fi
809814
if [[ ! -d "$LANDO_TMPDIR" ]]; then auto_exec mkdir -p "$LANDO_TMPDIR"; fi
815+
if [[ ! -d "$LANDO_BINDIR" ]]; then execute mkdir -p "$LANDO_BINDIR"; fi
810816

811817
# download lando
812818
log "${tty_magenta}downloading${tty_reset} ${tty_bold}${URL}${tty_reset} to ${tty_bold}${LANDO}${tty_reset}"
@@ -821,17 +827,20 @@ auto_exec curl \
821827
auto_exec chmod +x "${LANDO_TMPFILE}"
822828
execute "${LANDO_TMPFILE}" version >/dev/null
823829

824-
# if we get here we should be good to move it to its final destination
830+
# if dest = symlinker then we need to actually mv 2 LANDO_DATADIR
825831
# NOTE: we use mv here instead of cp because of https://developer.apple.com/forums/thread/130313
826-
auto_exec mv -f "${LANDO_TMPFILE}" "${LANDO}"
832+
if [[ "$LANDO" == "$SYMLINKER" ]]; then
833+
execute mkdir -p "${LANDO_DATADIR}/${VERSION}"
834+
execute mv -f "$LANDO_TMPFILE" "$HIDDEN_LANDO"
835+
execute ln -sf "$HIDDEN_LANDO" "$SYMLINKER"
836+
else
837+
auto_exec mv -f "$LANDO_TMPFILE" "$LANDO"
838+
auto_exec ln -sf "$LANDO" "$SYMLINKER"
839+
fi
827840

828841
# if lando 3 then we need to do some other cleanup things
829842
# @TODO: is there an equivalent on lando 4?
830843
if [[ $LMV == '3' ]]; then
831-
# ensure dirz
832-
execute mkdir -p "$HOME/.lando/bin"
833-
# force symlink landobin to ensure PATH primacy as best we can
834-
execute ln -sf "${LANDO}" "$HOME/.lando/bin/lando"
835844
# remove preexisting lando core so this one can also assert primacy
836845
execute rm -rf "$HOME/.lando/plugins/@lando/core"
837846
# clean
@@ -851,11 +860,18 @@ if [[ "$SETUP" == "1" ]]; then
851860
fi
852861

853862
# shell env
854-
log "${tty_blue}adding${tty_reset} ${tty_bold}${DEST}${tty_reset} to ${tty_bold}PATH${tty_reset}"
855-
execute "${LANDO}" shellenv --add "${LANDO_DEBUG-}"
863+
execute "${LANDO}" shellenv --add "${LANDO_DEBUG-}" > /dev/null
856864

857-
# TODO: print better messages for different situations eg ensure setup
858-
log "${tty_green}success!${tty_reset} ${tty_bold}lando${tty_reset} is now installed!"
865+
# sucess message here
866+
log "${tty_green}success!${tty_reset} ${tty_magenta}lando${tty_reset} is now installed!"
867+
868+
# if we cannot invoke lando then print shellenv message
869+
if \
870+
! execute lando version >/dev/null \
871+
|| [[ "$(readlink -f $(which lando))" != "$LANDO" && "$(readlink -f $(which lando))" != "$HIDDEN_LANDO" ]]; then
872+
log
873+
log "${tty_magenta}Start a new terminal session${tty_reset} or run ${tty_magenta}eval \"\$(${LANDO} shellenv)\"${tty_reset} to use lando"
874+
fi
859875

860876
# FIN!
861877
exit 0

0 commit comments

Comments
 (0)