Files
2026-10-13 16:01:34 +08:00

77 lines
1.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 从 git.yumee.top 克隆并安装 pouch 到 ~/.pouch
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/common/help.sh"
usage() {
cat <<'EOF'
用法: pouch-install
从 https://git.yumee.top/laily/.pouch 克隆到 ~/.pouch,
并运行仓库内 install.sh 安装 CLI。
~/.pouch 已是 pouch 仓库时跳过克隆,直接跑 install.sh。
路径已占用且不是 pouch 仓库时拒绝覆盖。
选项:
-h, --help 显示此帮助
EOF
}
dotfile_help_requested "${1:-}" && dotfile_show_help
set -euo pipefail
POUCH_DIR="${HOME}/.pouch"
POUCH_URL="https://git.yumee.top/laily/.pouch"
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo -e "${RED}缺少命令: $1${NC}" >&2
exit 1
fi
}
is_pouch_repo() {
[ -d "$POUCH_DIR/skills" ] && [ -f "$POUCH_DIR/install.sh" ]
}
need_cmd git
need_cmd python3
if [ -e "$POUCH_DIR" ] || [ -L "$POUCH_DIR" ]; then
if is_pouch_repo; then
echo -e "${GREEN}${POUCH_DIR} 已存在,跳过克隆${NC}"
else
echo -e "${RED}${POUCH_DIR} 已存在且不是 pouch 仓库,拒绝覆盖${NC}" >&2
exit 1
fi
else
echo -e "${YELLOW}正在克隆 ${POUCH_URL} 到 ${POUCH_DIR}...${NC}"
git clone "$POUCH_URL" "$POUCH_DIR"
echo -e "${GREEN}已克隆到 ${POUCH_DIR}${NC}"
fi
if ! is_pouch_repo; then
echo -e "${RED}${POUCH_DIR} 缺少 skills/ 或 install.sh,仓库可能不完整${NC}" >&2
exit 1
fi
echo -e "${YELLOW}正在运行 ${POUCH_DIR}/install.sh...${NC}"
bash "$POUCH_DIR/install.sh"
export PATH="${HOME}/.local/bin:${PATH}"
if command -v pouch >/dev/null 2>&1; then
echo -e "${GREEN}pouch 安装成功: $(command -v pouch)${NC}"
else
echo -e "${YELLOW}pouch 已写入 ~/.local/bin,当前会话请执行:${NC}"
echo ' export PATH="$HOME/.local/bin:$PATH"'
fi