Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·109 lines (90 loc) · 3.38 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·109 lines (90 loc) · 3.38 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
#!/bin/sh
# else-bot 一键安装。
#
# curl -fsSL https://github.com/narcilee7/else/raw/refs/heads/master/install.sh | sh
#
# 装完会:放好 `else` 二进制、准备 runtime 目录、注册后台常驻服务,
# 然后跑一次 `else doctor` 告诉你现在的状态。
set -eu
REPO="${ELSE_REPO:-narcilee7/else}"
VERSION="${ELSE_VERSION:-latest}"
INSTALL_DIR="${ELSE_INSTALL_DIR:-$HOME/.local/bin}"
say() { printf '\033[36m==>\033[0m %s\n' "$1"; }
warn() { printf '\033[33m!!\033[0m %s\n' "$1" >&2; }
die() { printf '\033[31mxx\033[0m %s\n' "$1" >&2; exit 1; }
# —— 平台 ——
os="$(uname -s)"
case "$os" in
Darwin) os_target="apple-darwin" ;;
Linux) os_target="unknown-linux-gnu" ;;
*) die "不支持的系统:$os" ;;
esac
arch="$(uname -m)"
case "$arch" in
arm64 | aarch64) arch_target="aarch64" ;;
x86_64 | amd64) arch_target="x86_64" ;;
*) die "不支持的架构:$arch" ;;
esac
target="$arch_target-unknown-linux-gnu"
if [ "$os" = "Darwin" ]; then
target="$arch_target-apple-darwin"
fi
# —— 版本 ——
if [ "$VERSION" = "latest" ]; then
say "查找最新版本…"
VERSION="$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p' | head -n 1)"
[ -n "$VERSION" ] || die "找不到最新版本,请用 ELSE_VERSION 指定"
fi
asset="else-$target.tar.gz"
url="https://github.com/$REPO/releases/download/v$VERSION/$asset"
checksums_url="https://github.com/$REPO/releases/download/v$VERSION/SHA256SUMS"
say "下载 else-bot ${VERSION} (${target})…"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT INT TERM
curl -fsSL "$url" -o "$tmp/$asset" || die "下载失败:$url"
curl -fsSL "$checksums_url" -o "$tmp/SHA256SUMS" || die "下载校验和失败:$checksums_url"
expected="$(awk -v asset="$asset" '$2 == asset { print $1 }' "$tmp/SHA256SUMS")"
[ -n "$expected" ] || die "SHA256SUMS 中没有 $asset"
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "$tmp/$asset" | awk '{ print $1 }')"
else
actual="$(shasum -a 256 "$tmp/$asset" | awk '{ print $1 }')"
fi
[ "$actual" = "$expected" ] || die "$asset 校验失败"
say "解压…"
tar -xzf "$tmp/$asset" -C "$tmp"
# —— 安装 ——
source_binary="$tmp/else-bot"
[ -x "$source_binary" ] || source_binary="$tmp/else-cli"
[ -x "$source_binary" ] || source_binary="$tmp/else"
[ -x "$source_binary" ] || die "压缩包中找不到 else-bot"
mkdir -p "$INSTALL_DIR"
if [ -w "$INSTALL_DIR" ]; then
install -m 0755 "$source_binary" "$INSTALL_DIR/else-bot"
ln -sf else-bot "$INSTALL_DIR/else-cli"
ln -sf else-bot "$INSTALL_DIR/else"
else
say "需要写入权限,用 sudo 安装到 $INSTALL_DIR"
sudo install -m 0755 "$source_binary" "$INSTALL_DIR/else-bot"
sudo ln -sf else-bot "$INSTALL_DIR/else-cli"
sudo ln -sf else-bot "$INSTALL_DIR/else"
fi
say "已安装:$INSTALL_DIR/else-bot"
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*) warn "$INSTALL_DIR 不在 PATH 里。把它加进 shell 配置:"
warn " export PATH=\"$INSTALL_DIR:\$PATH\"" ;;
esac
# —— 初始化 ——
if [ -x "$INSTALL_DIR/else-bot" ]; then
"$INSTALL_DIR/else-bot" onboard || warn "初始化没完全成功,先看看 else-bot doctor 的输出"
echo
"$INSTALL_DIR/else-bot" doctor || true
fi
cat <<'EOF'
装好了。
else-bot 打开终端界面
else-bot brief 看今天要你管的事
else-bot doctor 检查运行状态
EOF