-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·171 lines (143 loc) · 5.42 KB
/
install.sh
File metadata and controls
executable file
·171 lines (143 loc) · 5.42 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
# mole installer — https://getkaze.dev/mole/install.sh
# Usage: curl -fsSL https://getkaze.dev/mole/install.sh | sudo bash
set -euo pipefail
BINARY_NAME="mole"
RELEASES_BASE="https://github.com/getkaze/mole/releases"
# Install directory: always ~/.local/bin (user-writable, enables self-update without sudo).
REAL_USER="${SUDO_USER:-$(whoami)}"
REAL_HOME=$(eval echo "~${REAL_USER}")
if [ "$(id -u)" = "0" ]; then
INSTALL_DIR="${REAL_HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
chown "$REAL_USER" "$INSTALL_DIR"
else
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
# ── color helpers ──────────────────────────────────────────────────────────────
bold=$(tput bold 2>/dev/null || true)
reset=$(tput sgr0 2>/dev/null || true)
green=$(tput setaf 2 2>/dev/null || true)
red=$(tput setaf 1 2>/dev/null || true)
info() { echo "${bold}==>${reset} $*"; }
ok() { echo "${green} ✓${reset} $*"; }
fail() { echo "${red}error:${reset} $*" >&2; exit 1; }
# ── sanity checks ─────────────────────────────────────────────────────────────
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$OS" in
linux) ;;
darwin) ;;
*) fail "unsupported OS: $OS (supported: linux, darwin)" ;;
esac
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*) fail "unsupported architecture: $ARCH" ;;
esac
# Config directory
CONFIG_DIR="/etc/mole"
# Detect MOLE_VERSION (optional — defaults to latest)
VERSION="${MOLE_VERSION:-}"
if [ -z "$VERSION" ]; then
info "fetching latest version"
VERSION="$(curl -fsSL -o /dev/null -w '%{url_effective}' "${RELEASES_BASE}/latest" 2>/dev/null || true)"
VERSION="${VERSION##*/}"
[ -n "$VERSION" ] && [ "$VERSION" != "latest" ] || fail "could not fetch latest version from ${RELEASES_BASE}/latest"
VERSION="$(echo "$VERSION" | tr -d '[:space:]')"
fi
DOWNLOAD_URL="${RELEASES_BASE}/download/${VERSION}/${BINARY_NAME}-${OS}-${ARCH}"
# ── download binary ────────────────────────────────────────────────────────────
info "installing mole ${VERSION} (${OS}/${ARCH})"
TMP="$(mktemp)"
trap 'rm -f "$TMP"' EXIT
if command -v curl &>/dev/null; then
curl -fsSL "$DOWNLOAD_URL" -o "$TMP"
elif command -v wget &>/dev/null; then
wget -qO "$TMP" "$DOWNLOAD_URL"
else
fail "curl or wget is required"
fi
chmod +x "$TMP"
mv "$TMP" "${INSTALL_DIR}/${BINARY_NAME}"
ok "binary installed to ${INSTALL_DIR}/${BINARY_NAME}"
# ── create config directory ───────────────────────────────────────────────────
info "setting up config directory (${CONFIG_DIR})"
mkdir -p "${CONFIG_DIR}"
if [ ! -f "${CONFIG_DIR}/mole.yaml" ]; then
cat > "${CONFIG_DIR}/mole.yaml" <<'YAML'
# Mole — AI-powered PR reviewer
# Docs: https://getkaze.dev/mole/docs
github:
app_id: 0
private_key_path: /etc/mole/github-app.pem
webhook_secret: ""
llm:
api_key: ""
review_model: "claude-sonnet-4-6"
deep_review_model: "claude-opus-4-6"
pricing:
claude-sonnet-4-6: [3.00, 15.00]
claude-opus-4-6: [15.00, 75.00]
mysql:
host: localhost
port: 3306
database: mole
user: mole
password: ""
valkey:
host: localhost
port: 6379
server:
port: 8080
worker:
count: 3
log:
level: info
dashboard:
github_client_id: ""
github_client_secret: ""
session_secret: ""
base_url: "http://localhost:8080"
allowed_org: ""
YAML
ok "created default mole.yaml"
else
ok "mole.yaml already exists, skipping"
fi
# ── ownership ──────────────────────────────────────────────────────────────────
# Give the calling (non-root) user ownership so mole can self-update without sudo.
if [ "$(id -u)" = "0" ] && [ -n "${SUDO_USER:-}" ]; then
chown -R "${SUDO_USER}" "${CONFIG_DIR}"
chown "${SUDO_USER}" "${INSTALL_DIR}/${BINARY_NAME}"
ok "ownership set to ${SUDO_USER} (self-update enabled)"
fi
# ── done ───────────────────────────────────────────────────────────────────────
echo ""
echo "${bold}mole ${VERSION} installed successfully!${reset}"
# Check if install dir is in PATH
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "${bold}Note:${reset} ${INSTALL_DIR} is not in your PATH."
echo " Add it to your shell profile:"
echo ""
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
;;
esac
echo ""
echo "Next steps:"
echo " 1. Edit ${CONFIG_DIR}/mole.yaml with your credentials"
echo " 2. Copy your GitHub App private key to ${CONFIG_DIR}/github-app.pem"
echo " 3. Ensure MySQL and Valkey are running"
echo ""
echo "Quick start:"
echo " mole migrate # run database migrations"
echo " mole health # check MySQL, Valkey, GitHub connectivity"
echo " mole serve # start the server"
echo ""
echo "Docs: https://getkaze.dev/mole/docs"