-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·72 lines (63 loc) · 1.74 KB
/
install.sh
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
#!/bin/bash
# Detect OS
OS="unknown"
case "$(uname)" in
"Darwin")
OS="macos"
;;
"Linux")
OS="linux"
;;
"MINGW"*|"MSYS"*|"CYGWIN"*)
OS="windows"
;;
esac
# Configuration
SCRIPT_NAME="git-commit.sh"
if [ "$OS" = "windows" ]; then
SCRIPT_DIR="$USERPROFILE/git-commit-ai"
EXECUTABLE_NAME="cmai.sh"
else
SCRIPT_DIR="$HOME/git-commit-ai"
EXECUTABLE_NAME="cmai"
fi
CONFIG_DIR="${HOME:-$USERPROFILE}/.config/git-commit-ai"
# Debug function
debug_log() {
echo "Install Script > $1"
}
# Check if script is being run with sudo (skip on Windows)
if [ "$OS" != "windows" ] && [ "$EUID" -eq 0 ]; then
echo "Please do not run this script with sudo. Run as a regular user."
exit 1
fi
# Create directory for the script
debug_log "Creating script directory"
mkdir -p "$SCRIPT_DIR"
# Copy the git-commit.sh script to the directory
debug_log "Copying git-commit script"
cp "$(dirname "$0")/$SCRIPT_NAME" "$SCRIPT_DIR/$SCRIPT_NAME"
chmod +x "$SCRIPT_DIR/$SCRIPT_NAME"
# Handle executable installation
if [ "$OS" = "windows" ]; then
# On Windows, we rely on PATH
cp "$SCRIPT_DIR/$SCRIPT_NAME" "$SCRIPT_DIR/$EXECUTABLE_NAME"
else
# Create symbolic link on Unix systems
debug_log "Creating symbolic link"
sudo ln -sf "$SCRIPT_DIR/$SCRIPT_NAME" "/usr/local/bin/$EXECUTABLE_NAME"
fi
# Ensure config directory exists
debug_log "Ensuring config directory exists"
mkdir -p "$CONFIG_DIR"
if [ "$OS" != "windows" ]; then
chmod 700 "$CONFIG_DIR"
fi
# Add instructions for API key
echo "Installation complete!"
echo "To set up your OpenRouter API key, run:"
echo "cmai <your_openrouter_api_key>"
echo ""
echo "Usage:"
echo "- Stage your git changes"
echo "- Run 'cmai' to generate a commit message"