-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·124 lines (106 loc) · 3.67 KB
/
install.sh
File metadata and controls
executable file
·124 lines (106 loc) · 3.67 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
#!/bin/sh
# install.sh — Installs the incipit binary from GitHub releases.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/urmzd/incipit/main/install.sh | sh
#
# Environment variables:
# INCIPIT_VERSION — version to install (e.g. "v1.0.0"); defaults to latest
# INCIPIT_INSTALL_DIR — installation directory; defaults to $HOME/.local/bin
set -eu
REPO="urmzd/incipit"
# curl with optional auth — uses GH_TOKEN or GITHUB_TOKEN if set.
gh_curl() {
token="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
if [ -n "$token" ]; then
curl -fsSL -H "Authorization: token $token" "$@"
else
curl -fsSL "$@"
fi
}
main() {
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Linux)
case "$arch" in
x86_64) target="x86_64-unknown-linux-musl" ;;
aarch64) target="aarch64-unknown-linux-musl" ;;
*) err "Unsupported Linux architecture: $arch" ;;
esac
;;
Darwin)
case "$arch" in
x86_64) target="x86_64-apple-darwin" ;;
arm64) target="aarch64-apple-darwin" ;;
*) err "Unsupported macOS architecture: $arch" ;;
esac
;;
MINGW*|MSYS*|CYGWIN*|Windows_NT)
err "Windows is not supported by this installer. Download a binary from https://github.com/$REPO/releases/latest"
;;
*)
err "Unsupported operating system: $os"
;;
esac
if [ -n "${INCIPIT_VERSION:-}" ]; then
tag="$INCIPIT_VERSION"
else
tag=$(gh_curl "https://api.github.com/repos/$REPO/releases/latest" \
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')
if [ -z "$tag" ]; then
err "Failed to fetch latest release tag"
fi
fi
artifact="incipit-${target}"
url="https://github.com/$REPO/releases/download/${tag}/${artifact}"
install_dir="${INCIPIT_INSTALL_DIR:-$HOME/.local/bin}"
mkdir -p "$install_dir"
echo "Downloading incipit $tag for $target..."
gh_curl "$url" -o "$install_dir/incipit"
chmod +x "$install_dir/incipit"
echo "Installed incipit to $install_dir/incipit"
# Initialize: download bundled templates and create config
echo "Initializing templates..."
"$install_dir/incipit" init --version "$tag"
case ":$PATH:" in
*":$install_dir:"*) ;;
*) add_to_path "$install_dir" ;;
esac
}
add_to_path() {
install_dir="$1"
case "$(basename "$SHELL")" in
zsh) profile="$HOME/.zshrc" ;;
bash)
if [ -f "$HOME/.bashrc" ]; then
profile="$HOME/.bashrc"
else
profile="$HOME/.profile"
fi
;;
fish) profile="$HOME/.config/fish/config.fish" ;;
*) profile="$HOME/.profile" ;;
esac
if [ "$(basename "$SHELL")" = "fish" ]; then
if ! grep -q "$install_dir" "$profile" 2>/dev/null; then
mkdir -p "$(dirname "$profile")"
echo "" >> "$profile"
echo "# Added by incipit installer" >> "$profile"
echo "set -Ux fish_user_paths $install_dir \$fish_user_paths" >> "$profile"
echo "Added $install_dir to $profile"
echo "Restart your shell or run: source $profile"
fi
elif [ -n "$profile" ] && ! grep -q "$install_dir" "$profile" 2>/dev/null; then
echo "" >> "$profile"
echo "# Added by incipit installer" >> "$profile"
echo "export PATH=\"$install_dir:\$PATH\"" >> "$profile"
echo "Added $install_dir to $profile"
echo "Restart your shell or run: source $profile"
fi
}
err() {
echo "Error: $1" >&2
exit 1
}
main