Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·136 lines (127 loc) · 5.26 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·136 lines (127 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
# Install the latest Lectern release for this machine.
#
# curl -fsSL https://raw.githubusercontent.com/JeremiahM37/lectern/main/install.sh | sh
#
# Picks the archive for this OS/CPU from the latest GitHub release, verifies
# it against the release's checksums.txt, and installs `lectern` into
# ~/.local/bin (LECTERN_INSTALL_DIR overrides — set it to /usr/local/bin
# yourself if you want it system-wide; sudo only runs if that dir needs it).
# Set LECTERN_VERSION=vX.Y.Z to pin a release. Safe to re-run: it always
# overwrites with the requested version and touches nothing else.
#
# LECTERN_RELEASE_BASE overrides where archives/checksums are fetched from
# (tests point this at a local fixture server); leave it unset otherwise.
set -eu
repo="JeremiahM37/lectern"
name="lectern"
version="${LECTERN_VERSION:-latest}"
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux|darwin) ;;
mingw*|msys*|cygwin*)
echo "On Windows use PowerShell: irm https://raw.githubusercontent.com/$repo/main/install.ps1 | iex" >&2
exit 1
;;
*) echo "unsupported OS: $os" >&2; exit 1 ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "unsupported CPU: $(uname -m)" >&2; exit 1 ;;
esac
if [ -n "${LECTERN_RELEASE_BASE:-}" ]; then
base="$LECTERN_RELEASE_BASE"
elif [ "$version" = latest ]; then
base="https://github.com/$repo/releases/latest/download"
else
base="https://github.com/$repo/releases/download/$version"
fi
archive="${name}_${os}_${arch}.tar.gz"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
echo "Downloading $archive ($version)…"
curl -fsSL -o "$tmp/$archive" "$base/$archive"
curl -fsSL -o "$tmp/checksums.txt" "$base/checksums.txt"
want=$(grep " $archive\$" "$tmp/checksums.txt" | cut -d' ' -f1)
if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$tmp/$archive" | cut -d' ' -f1)
else got=$(shasum -a 256 "$tmp/$archive" | cut -d' ' -f1); fi
if [ -z "$want" ] || [ "$want" != "$got" ]; then
echo "checksum mismatch for $archive" >&2
exit 1
fi
tar xzf "$tmp/$archive" -C "$tmp"
dir="${LECTERN_INSTALL_DIR:-$HOME/.local/bin}"
mkdir -p "$dir"
if [ -w "$dir" ]; then
install -m 755 "$tmp/$name" "$dir/.$name.next"
mv -f "$dir/.$name.next" "$dir/$name"
else
echo "Installing to $dir needs sudo."
sudo install -m 755 "$tmp/$name" "$dir/$name"
fi
echo "Installed $("$dir/$name" version | head -1) to $dir/$name"
# PATH: a fresh ~/.local/bin is often not on it (never on macOS), and then
# the next command the user types fails. Name the exact line and file, and
# with consent add it. LECTERN_MODIFY_PATH=1 adds it without asking, 0 never.
on_path=0
case ":$PATH:" in *":$dir:"*) on_path=1 ;; esac
if [ "$on_path" = 0 ]; then
path_line="export PATH=\"$dir:\$PATH\""
case "$(basename "${SHELL:-sh}")" in
zsh) rc="$HOME/.zshrc" ;;
bash) if [ "$os" = darwin ]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi ;;
fish) rc="$HOME/.config/fish/config.fish"; path_line="fish_add_path $dir" ;;
*) rc="$HOME/.profile" ;;
esac
answer="${LECTERN_MODIFY_PATH:-}"
if grep -qsF "$dir" "$rc"; then
answer=already
elif [ -z "$answer" ] && [ -t 1 ] && (: </dev/tty) 2>/dev/null; then
# curl | sh: stdin is the script, so ask the terminal itself.
printf '\n%s is not on your PATH. Add it in %s? [Y/n] ' "$dir" "$rc"
read -r answer </dev/tty || answer=n
case "$answer" in [nN]*) answer=0 ;; *) answer=1 ;; esac
fi
case "$answer" in
already) echo "$rc already adds $dir to PATH; open a new terminal to use it." ;;
1|y|yes)
mkdir -p "$(dirname "$rc")"
printf '\n# Added by the Lectern installer\n%s\n' "$path_line" >>"$rc"
echo "Added $dir to PATH in $rc. Open a new terminal, or run now: $path_line" ;;
*) echo "To run lectern by name, add this line to $rc, then open a new terminal:"
echo " $path_line" ;;
esac
fi
# distro_install NAME prints the exact command for whatever package manager
# this machine has, so a missing prerequisite is one copy-paste away instead
# of a trip to search engine + docs.
distro_install() {
pkg="$1"
if [ "$os" = darwin ]; then
if command -v brew >/dev/null 2>&1; then echo " brew install $pkg"
else echo " install Homebrew (https://brew.sh), then: brew install $pkg"; fi
return
fi
if command -v apt-get >/dev/null 2>&1; then echo " sudo apt-get update && sudo apt-get install -y $pkg"
elif command -v dnf >/dev/null 2>&1; then echo " sudo dnf install -y $pkg"
elif command -v yum >/dev/null 2>&1; then echo " sudo yum install -y $pkg"
elif command -v pacman >/dev/null 2>&1; then echo " sudo pacman -S --noconfirm $pkg"
elif command -v zypper >/dev/null 2>&1; then echo " sudo zypper install -y $pkg"
elif command -v apk >/dev/null 2>&1; then echo " sudo apk add $pkg"
else echo " install $pkg with your system's package manager"; fi
}
missing=""
if ! command -v git >/dev/null 2>&1; then
echo ""
echo "git is missing — every project and task worktree needs it:"
distro_install git
missing="$missing git"
fi
if [ "$on_path" = 1 ]; then run="$name"; else run="$dir/$name"; fi
echo ""
if [ -n "$missing" ]; then
echo "Next: install the missing tool(s) above (${missing# }), then run '$run up'."
else
echo "Next: run '$run up' — it starts Lectern and opens your browser, ready to start an agent."
fi