-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·280 lines (251 loc) · 8.92 KB
/
install.sh
File metadata and controls
executable file
·280 lines (251 loc) · 8.92 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
# PostForge Installation Script
# Checks prerequisites and sets up the Python environment
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "=================================="
echo " PostForge Installation Script"
echo "=================================="
echo ""
# Detect OS
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
echo "windows"
elif [[ -f /etc/os-release ]]; then
. /etc/os-release
if [[ "$ID" == "ubuntu" || "$ID" == "debian" || "$ID_LIKE" == *"debian"* ]]; then
echo "debian"
elif [[ "$ID" == "fedora" ]]; then
echo "fedora"
elif [[ "$ID" == "centos" || "$ID" == "rhel" || "$ID_LIKE" == *"rhel"* ]]; then
echo "rhel"
elif [[ "$ID" == "arch" || "$ID_LIKE" == *"arch"* ]]; then
echo "arch"
elif [[ "$ID" == "opensuse"* || "$ID_LIKE" == *"suse"* ]]; then
echo "suse"
else
echo "linux"
fi
else
echo "unknown"
fi
}
OS=$(detect_os)
echo "Detected OS: $OS"
echo ""
# Check Python version
echo "Checking Python version..."
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
PYTHON_CMD="python"
else
echo -e "${RED}Error: Python not found.${NC}"
echo "Please install Python 3.13+ and try again."
exit 1
fi
PYTHON_VERSION=$($PYTHON_CMD -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PYTHON_MAJOR=$($PYTHON_CMD -c 'import sys; print(sys.version_info.major)')
PYTHON_MINOR=$($PYTHON_CMD -c 'import sys; print(sys.version_info.minor)')
echo "Found Python $PYTHON_VERSION"
if [[ "$PYTHON_MAJOR" -lt 3 ]] || [[ "$PYTHON_MAJOR" -eq 3 && "$PYTHON_MINOR" -lt 12 ]]; then
echo -e "${RED}Error: Python 3.12+ required (3.13+ recommended).${NC}"
echo "Found Python $PYTHON_VERSION"
exit 1
elif [[ "$PYTHON_MAJOR" -eq 3 && "$PYTHON_MINOR" -lt 13 ]]; then
echo -e "${YELLOW}Warning: Python 3.13+ recommended for best experience.${NC}"
fi
echo -e "${GREEN}Python version OK${NC}"
echo ""
# Check for Cairo library (not needed on Windows - pip handles it)
if [[ "$OS" != "windows" ]]; then
echo "Checking for Cairo graphics library..."
CAIRO_FOUND=false
if command -v pkg-config &> /dev/null; then
if pkg-config --exists cairo 2>/dev/null; then
CAIRO_FOUND=true
fi
fi
# Fallback checks
if [[ "$CAIRO_FOUND" == false ]]; then
if [[ "$OS" == "macos" ]]; then
if [[ -d "/opt/homebrew/lib/pkgconfig" ]] && PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig" pkg-config --exists cairo 2>/dev/null; then
CAIRO_FOUND=true
elif [[ -d "/usr/local/lib/pkgconfig" ]] && PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" pkg-config --exists cairo 2>/dev/null; then
CAIRO_FOUND=true
fi
elif ldconfig -p 2>/dev/null | grep -q libcairo; then
CAIRO_FOUND=true
fi
fi
if [[ "$CAIRO_FOUND" == false ]]; then
echo -e "${RED}Cairo graphics library not found.${NC}"
echo ""
echo "Please install Cairo and run ./install.sh again:"
echo ""
case "$OS" in
debian)
echo -e " ${YELLOW}sudo apt-get update && sudo apt-get install libcairo2-dev pkg-config python3-dev${NC}"
;;
fedora)
echo -e " ${YELLOW}sudo dnf install cairo-devel pkgconfig python3-devel${NC}"
;;
rhel)
echo -e " ${YELLOW}sudo yum install cairo-devel pkgconfig python3-devel${NC}"
;;
arch)
echo -e " ${YELLOW}sudo pacman -S cairo pkgconf${NC}"
;;
suse)
echo -e " ${YELLOW}sudo zypper install cairo-devel pkg-config python3-devel${NC}"
;;
macos)
echo -e " ${YELLOW}brew install cairo pkg-config${NC}"
;;
*)
echo " Install cairo development libraries for your distribution."
;;
esac
echo ""
exit 1
fi
echo -e "${GREEN}Cairo found${NC}"
echo ""
fi
# Create virtual environment
echo "Setting up Python virtual environment..."
if [[ -d "venv" && -x "venv/bin/python" ]]; then
echo "Virtual environment already exists."
else
# Remove partial venv from a previous failed attempt
rm -rf venv 2>/dev/null
if ! $PYTHON_CMD -m venv venv 2>&1; then
rm -rf venv 2>/dev/null
echo ""
echo -e "${RED}Failed to create virtual environment.${NC}"
echo ""
case "$OS" in
debian)
echo "On Debian/Ubuntu, install the venv package:"
echo ""
echo -e " ${YELLOW}sudo apt install python${PYTHON_VERSION}-venv${NC}"
;;
fedora)
echo "On Fedora, install the venv package:"
echo ""
echo -e " ${YELLOW}sudo dnf install python${PYTHON_VERSION//.}-venv${NC}"
;;
arch)
echo "On Arch Linux, venv is included with python. Ensure python is installed:"
echo ""
echo -e " ${YELLOW}sudo pacman -S python${NC}"
;;
suse)
echo "On openSUSE, install the venv package:"
echo ""
echo -e " ${YELLOW}sudo zypper install python${PYTHON_VERSION//.}-venv${NC}"
;;
macos)
echo "On macOS, reinstall Python via Homebrew:"
echo ""
echo -e " ${YELLOW}brew install python@${PYTHON_VERSION}${NC}"
;;
*)
echo "Install the Python venv module for your distribution."
;;
esac
echo ""
echo "Then run ./install.sh again."
exit 1
fi
echo "Created virtual environment."
fi
# Install package with dependencies
echo "Installing Python dependencies..."
echo ""
./venv/bin/pip install --upgrade pip -q
./venv/bin/pip install -e ".[qt,dev,visual-test]"
# Build Cython accelerators (optional — PostForge runs without them)
echo ""
echo "Building Cython accelerators..."
if ./venv/bin/python setup_cython.py build_ext --inplace 2>&1; then
echo -e "${GREEN}Cython build OK — execution loop accelerated (15-40% speedup)${NC}"
else
echo -e "${YELLOW}Cython build failed — PostForge will use the pure Python fallback.${NC}"
echo "To enable Cython acceleration, install a C compiler:"
echo ""
case "$OS" in
debian)
echo -e " ${YELLOW}sudo apt install build-essential${NC}"
;;
fedora)
echo -e " ${YELLOW}sudo dnf install gcc${NC}"
;;
rhel)
echo -e " ${YELLOW}sudo yum install gcc${NC}"
;;
arch)
echo -e " ${YELLOW}sudo pacman -S base-devel${NC}"
;;
suse)
echo -e " ${YELLOW}sudo zypper install gcc${NC}"
;;
macos)
echo -e " ${YELLOW}xcode-select --install${NC}"
;;
*)
echo " Install a C compiler (gcc or clang) for your distribution."
;;
esac
echo ""
echo "Then run ./install.sh again."
fi
# Install system-wide launcher commands
echo ""
echo "Installing system commands (pf, postforge)..."
INSTALL_DIR="/usr/local/bin"
# Create the pf launcher
TEMP_PF=$(mktemp)
cat > "$TEMP_PF" <<EOF
#!/bin/bash
# PostForge PostScript Interpreter
# Auto-generated by install.sh — do not edit
exec "$SCRIPT_DIR/venv/bin/python" -m postforge "\$@"
EOF
chmod +x "$TEMP_PF"
# Create the postforge launcher
TEMP_POSTFORGE=$(mktemp)
cat > "$TEMP_POSTFORGE" <<EOF
#!/bin/bash
# PostForge PostScript Interpreter
# Auto-generated by install.sh — do not edit
exec "$SCRIPT_DIR/venv/bin/python" -m postforge "\$@"
EOF
chmod +x "$TEMP_POSTFORGE"
# Install to /usr/local/bin (needs sudo)
if sudo mv "$TEMP_PF" "$INSTALL_DIR/pf" && sudo mv "$TEMP_POSTFORGE" "$INSTALL_DIR/postforge"; then
echo -e "${GREEN}Installed: ${INSTALL_DIR}/pf${NC}"
echo -e "${GREEN}Installed: ${INSTALL_DIR}/postforge${NC}"
else
echo -e "${YELLOW}Could not install to ${INSTALL_DIR} (sudo required).${NC}"
echo "You can still run PostForge with: ./postforge.sh"
rm -f "$TEMP_PF" "$TEMP_POSTFORGE" 2>/dev/null
fi
echo ""
echo -e "${GREEN}=================================="
echo -e " Installation Complete!"
echo -e "==================================${NC}"
echo ""
echo "Run PostForge with:"
echo ""
echo " pf # Interactive prompt"
echo " pf samples/tiger.ps # Render the classic tiger"
echo " pf -d png input.ps # Save to ./output directory"
echo ""