-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
114 lines (104 loc) · 3.91 KB
/
install.sh
File metadata and controls
114 lines (104 loc) · 3.91 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
#!/usr/bin/env bash
# Install flow: download → launcher + PATH → setup (deps, config, WhatsApp link, bot runs).
# New shell is created only after setup.js exits (user presses Ctrl+C to stop the bot).
# Code lives in ~/.local/share/cowcode (fixed path); state in ~/.cowcode. Same idea as OpenClaw.
set -e
POST_INSTALL_CMD=
[ "$1" = "-c" ] && [ -n "${2:-}" ] && POST_INSTALL_CMD="$2"
BRANCH="${COWCODE_BRANCH:-master}"
TARBALL="https://github.com/bishwashere/cowCode/archive/refs/heads/${BRANCH}.tar.gz"
EXTRACTED="cowCode-${BRANCH}"
# Fixed install path — no path dependency (like OpenClaw global install)
INSTALL_DIR="${COWCODE_INSTALL_DIR:-$HOME/.local/share/cowcode}"
BIN_DIR="$HOME/.local/bin"
echo ""
echo " Welcome to cowCode — WhatsApp bot with your own LLM"
echo " ------------------------------------------------"
echo ""
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
echo " ► Downloading..."
curl -fsSL "$TARBALL" -o "$WORK/archive.tar.gz"
tar xzf "$WORK/archive.tar.gz" -C "$WORK"
echo " ✓ Done."
echo ""
echo " ► Installing to $INSTALL_DIR ..."
mkdir -p "$INSTALL_DIR"
rsync -a --exclude=node_modules "$WORK/$EXTRACTED/" "$INSTALL_DIR/" 2>/dev/null || cp -R "$WORK/$EXTRACTED/"* "$INSTALL_DIR/"
cd "$INSTALL_DIR"
echo " ✓ Code installed."
echo ""
# Launcher: fixed path only (like OpenClaw — run cowcode from anywhere)
mkdir -p "$BIN_DIR"
cat > "$BIN_DIR/cowcode" << LAUNCHER
#!/usr/bin/env bash
export COWCODE_INSTALL_DIR="$INSTALL_DIR"
exec node "$INSTALL_DIR/cli.js" "\$@"
LAUNCHER
chmod +x "$BIN_DIR/cowcode"
echo " ► Launcher installed: $BIN_DIR/cowcode"
PATH_LINE='export PATH="$HOME/.local/bin:$PATH"'
ADDED_PATH=0
add_path_to() {
local f="$1"
[ -f "$f" ] || touch "$f" 2>/dev/null || return 0
grep -q '.local/bin' "$f" 2>/dev/null && return 0
echo "" >> "$f"
echo "# cowCode" >> "$f"
echo "$PATH_LINE" >> "$f"
echo " ► Added ~/.local/bin to PATH in $f"
ADDED_PATH=1
}
if ! command -v cowcode >/dev/null 2>&1; then
add_path_to "${ZDOTDIR:-$HOME}/.zshrc"
add_path_to "${ZDOTDIR:-$HOME}/.zprofile"
add_path_to "$HOME/.bashrc"
add_path_to "$HOME/.profile"
[ "$ADDED_PATH" = 1 ] && echo " ► Open a new terminal, or run: source ~/.zshrc (then run: cowcode moo start)"
fi
echo ""
echo " ► Setting up (dependencies + config)..."
if [ -n "$POST_INSTALL_CMD" ]; then
# Non-interactive: just install deps so cowcode can run when we exec with -c
(cd "$INSTALL_DIR" && (pnpm install --silent 2>/dev/null || npm install --silent 2>/dev/null || true))
echo " ✓ Dependencies ready."
else
echo " (You will link WhatsApp in a moment. When you are done and want to stop the bot, press Ctrl+C.)"
echo ""
# Ignore Ctrl+C in this script so we always reach the exec (new shell) after setup exits
trap '' INT
if [ -t 0 ]; then
node setup.js || true
elif [ -e /dev/tty ]; then
node setup.js < /dev/tty || true
else
echo " No terminal. Run: cd $INSTALL_DIR && node setup.js"
fi
trap - INT
echo ""
echo " ------------------------------------------------"
# Start daemon in background (no new terminal); user can close this window.
export PATH="$BIN_DIR:$PATH"
export COWCODE_INSTALL_DIR="$INSTALL_DIR"
if "$BIN_DIR/cowcode" moo start; then
echo " ► Bot is running in the background. You can close this terminal."
echo " ► To see logs: cowcode logs"
else
echo " To start the bot later: cowcode moo start"
fi
echo ""
exit 0
fi
echo ""
echo " ------------------------------------------------"
echo " To start the bot: cowcode moo start"
echo " (or from this folder: npm start)"
echo ""
# When -c was passed: run that command in the new shell and exit
if [ -n "$POST_INSTALL_CMD" ]; then
echo " ► Running in new shell: $POST_INSTALL_CMD"
exec "${SHELL:-/bin/zsh}" -l -c "$POST_INSTALL_CMD"
elif [ "$ADDED_PATH" = 1 ] && [ -t 0 ]; then
echo " ► Starting a new shell so cowcode works in this terminal..."
exec "${SHELL:-/bin/zsh}" -l
fi