-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
172 lines (145 loc) · 5.4 KB
/
install.sh
File metadata and controls
172 lines (145 loc) · 5.4 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
172
#!/bin/bash
#
# mmerd - Mermaid ERD Generator Installation Script
# Automatically generates Entity Relationship Diagrams from SQL files
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Installation directory
INSTALL_DIR="$HOME/.local/bin"
echo -e "${BLUE}╔══════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ mmerd Installation Script ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════╝${NC}"
echo
# Check for required dependencies
check_dependency() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}✗ $1 is not installed${NC}"
return 1
else
echo -e "${GREEN}✓ $1 is installed${NC}"
return 0
fi
}
echo -e "${YELLOW}Checking dependencies...${NC}"
# Check for Node.js and npm
if ! check_dependency "node"; then
echo -e "${RED}Node.js is required. Please install it first:${NC}"
echo " Ubuntu/Debian: sudo apt-get install nodejs"
echo " macOS: brew install node"
echo " Or visit: https://nodejs.org/"
exit 1
fi
if ! check_dependency "npm"; then
echo -e "${RED}npm is required. Please install Node.js which includes npm.${NC}"
exit 1
fi
# Check for mermaid-cli
if ! check_dependency "mmdc"; then
echo -e "${YELLOW}Installing mermaid-cli globally...${NC}"
npm install -g @mermaid-js/mermaid-cli
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install mermaid-cli. You may need to use sudo:${NC}"
echo " sudo npm install -g @mermaid-js/mermaid-cli"
exit 1
fi
echo -e "${GREEN}✓ mermaid-cli installed successfully${NC}"
else
echo -e "${GREEN}✓ mermaid-cli is already installed${NC}"
fi
# Create installation directory if it doesn't exist
if [ ! -d "$INSTALL_DIR" ]; then
echo -e "${YELLOW}Creating installation directory: $INSTALL_DIR${NC}"
mkdir -p "$INSTALL_DIR"
fi
# Check if PATH includes $HOME/.local/bin
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo -e "${YELLOW}Adding $HOME/.local/bin to PATH...${NC}"
# Detect shell and update appropriate config file
if [ -n "$BASH_VERSION" ]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo -e "${GREEN}✓ Added to ~/.bashrc${NC}"
echo -e "${YELLOW} Run 'source ~/.bashrc' to update current session${NC}"
elif [ -n "$ZSH_VERSION" ]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
echo -e "${GREEN}✓ Added to ~/.zshrc${NC}"
echo -e "${YELLOW} Run 'source ~/.zshrc' to update current session${NC}"
else
echo -e "${YELLOW}Please add the following to your shell configuration:${NC}"
echo ' export PATH="$HOME/.local/bin:$PATH"'
fi
fi
# Install mmerd scripts
echo -e "${YELLOW}Installing mmerd scripts...${NC}"
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Copy scripts to installation directory
for script in mmerd mmviz; do
if [ -f "$SCRIPT_DIR/bin/$script" ]; then
cp "$SCRIPT_DIR/bin/$script" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$script"
echo -e "${GREEN}✓ Installed $script${NC}"
else
echo -e "${RED}✗ $script not found in $SCRIPT_DIR/bin/${NC}"
fi
done
# Create mmsvg script
cat > "$INSTALL_DIR/mmsvg" << 'EOF'
#!/bin/bash
# mmsvg: Generate SVG (vector, scalable) from .mermaid file
if [ -z "$1" ]; then
echo "Usage: mmsvg <file.mermaid>"
exit 1
fi
input_file="$1"
output_file="${input_file%.mermaid}.svg"
echo "🎨 Generating SVG from $input_file..."
mmdc -i "$input_file" -o "$output_file" -b white
if [ $? -eq 0 ]; then
echo "✓ Created: $output_file"
echo "🖼️ Opening diagram..."
xdg-open "$output_file" 2>/dev/null || open "$output_file" 2>/dev/null || echo "Please open $output_file manually"
else
echo "✗ Failed to generate diagram"
exit 1
fi
EOF
chmod +x "$INSTALL_DIR/mmsvg"
echo -e "${GREEN}✓ Installed mmsvg${NC}"
# Create an alias for mmview
cat > "$INSTALL_DIR/mmview" << 'EOF'
#!/bin/bash
# mmview: Quick view any image file
if [ -z "$1" ]; then
echo "Usage: mmview <image-file>"
exit 1
fi
xdg-open "$1" 2>/dev/null || open "$1" 2>/dev/null || echo "Please open $1 manually"
EOF
chmod +x "$INSTALL_DIR/mmview"
echo -e "${GREEN}✓ Installed mmview${NC}"
# Clean up and summary
echo
# Success message
echo
echo -e "${GREEN}╔══════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Installation completed successfully! ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════╝${NC}"
echo
echo -e "${BLUE}Available commands:${NC}"
echo " mmerd - Generate ERD from SQL files in current directory"
echo " mmviz - Convert .mermaid file to high-res PNG"
echo " mmsvg - Convert .mermaid file to scalable SVG"
echo " mmview - Quick view any image file"
echo
echo -e "${YELLOW}Quick start:${NC}"
echo " 1. cd to a directory with .sql files"
echo " 2. Run: mmerd"
echo " 3. View generated database_erd.png"
echo
echo -e "${BLUE}Example files available in:${NC} $SCRIPT_DIR/examples/"