-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_ide_example.sh
More file actions
executable file
·267 lines (234 loc) · 6.57 KB
/
start_ide_example.sh
File metadata and controls
executable file
·267 lines (234 loc) · 6.57 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
#!/usr/bin/env bash
cd "$HOME/Documents" || exit 1
# IDE Konfigurationen - werden vom Backend geladen
declare -A IDES
# Pfade vom Backend laden
load_ide_paths() {
echo "📡 Lade IDE-Pfade vom Backend..."
# Backend API aufrufen
local response=$(curl -s http://localhost:3000/api/ide/configurations/executable-paths 2>/dev/null)
if [[ $? -eq 0 && -n "$response" ]]; then
# JSON parsen und in IDES Array laden
local cursor_path=$(echo "$response" | jq -r '.data.cursor // empty' 2>/dev/null)
local vscode_path=$(echo "$response" | jq -r '.data.vscode // empty' 2>/dev/null)
if [[ -n "$cursor_path" ]]; then
IDES["cursor"]="$cursor_path"
else
IDES["cursor"]="./Cursor-1.5.7-x86_64.AppImage" # Fallback
fi
if [[ -n "$vscode_path" ]]; then
IDES["vscode"]="$vscode_path"
else
IDES["vscode"]="code" # Fallback
fi
echo "✅ IDE-Pfade geladen"
else
echo "⚠️ Backend nicht erreichbar, verwende Fallback-Pfade"
# Fallback zu hardcoded Pfaden
IDES["cursor"]="./Cursor-1.5.7-x86_64.AppImage"
IDES["vscode"]="code"
fi
}
# Port Ranges für verschiedene IDEs
declare -A PORT_RANGES=(
["cursor"]="9222:9232"
["vscode"]="9233:9242"
)
RUNNER="appimage-run"
# Hilfsfunktion: prüft ob Port frei ist
port_in_use() {
local port=$1
# Prüfe verfügbare Tools in Reihenfolge der Präferenz
if command -v ss &> /dev/null; then
ss -tuln | grep -q ":$port "
return $?
elif command -v netstat &> /dev/null; then
netstat -tuln | grep -q ":$port "
return $?
elif command -v lsof &> /dev/null; then
lsof -i ":$port" &>/dev/null
return $?
else
echo "❌ No port check tool available!"
echo " Please install one of these tools:"
echo " - ss (iproute2): sudo apt install iproute2"
echo " - netstat (net-tools): sudo apt install net-tools"
echo " - lsof: sudo apt install lsof"
echo ""
echo " Without port checking, conflicts may occur."
echo " Do you want to continue anyway? (y/N)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
return 1 # Treat port as "free"
else
exit 1
fi
fi
}
# Hilfsfunktion: findet freien Port in Range
find_free_port() {
local range=$1
local start_port=$(echo $range | cut -d: -f1)
local end_port=$(echo $range | cut -d: -f2)
for port in $(seq $start_port $end_port); do
if ! port_in_use "$port"; then
echo $port
return 0
fi
done
return 1
}
# Hilfsfunktion: zeigt verfügbare IDEs
show_ides() {
echo "📋 Verfügbare IDEs:"
for ide in "${!IDES[@]}"; do
local range="${PORT_RANGES[$ide]}"
echo " $ide (Ports $range)"
done
}
# Hilfsfunktion: zeigt Hilfe
show_help() {
echo "🚀 IDE Starter Script"
echo ""
echo "Verwendung:"
echo " $0 [ide] [slot]"
echo " $0 [ide] auto"
echo " $0 menu"
echo ""
echo "Argumente:"
echo " ide - cursor, vscode"
echo " slot - spezifischer Slot (Zahl)"
echo " auto - automatisch freien Slot finden"
echo " menu - interaktives Menü"
echo ""
show_ides
echo ""
echo "Beispiele:"
echo " $0 cursor # Cursor mit freiem Port starten"
echo " $0 vscode 3 # VSCode auf Slot 3 starten"
echo " $0 cursor auto # Cursor mit automatischem Slot"
}
# Interaktives Menü
show_menu() {
echo "🎯 IDE Starter - Wähle deine IDE:"
echo ""
local i=1
for ide in "${!IDES[@]}"; do
local range="${PORT_RANGES[$ide]}"
echo " $i) $ide (Ports $range)"
((i++))
done
echo " $i) Hilfe"
echo " 0) Beenden"
echo ""
read -p "Wähle eine Option (0-$i): " choice
case $choice in
0) exit 0 ;;
$i) show_help; exit 0 ;;
*)
local ides_array=($(echo "${!IDES[@]}" | tr ' ' '\n'))
if [[ $choice -ge 1 && $choice -le ${#ides_array[@]} ]]; then
local selected_ide="${ides_array[$((choice-1))]}"
echo ""
read -p "Slot für $selected_ide (Zahl oder 'auto'): " slot
start_ide "$selected_ide" "$slot"
else
echo "❌ Ungültige Auswahl"
exit 1
fi
;;
esac
}
# IDE starten
start_ide() {
local ide=$1
local slot=$2
# Prüfe ob IDE existiert
if [[ ! -v IDES[$ide] ]]; then
echo "❌ Unbekannte IDE: $ide"
show_ides
exit 1
fi
local ide_path="${IDES[$ide]}"
local port_range="${PORT_RANGES[$ide]}"
# Prüfe ob IDE verfügbar ist
if [[ $ide == "cursor" ]]; then
if [[ ! -f "$ide_path" ]]; then
echo "❌ Cursor AppImage nicht gefunden: $ide_path"
exit 1
fi
else
if ! command -v "$ide_path" &> /dev/null; then
echo "❌ $ide ist nicht installiert oder nicht im PATH"
exit 1
fi
fi
local port
local dir
# Port und Verzeichnis bestimmen
if [[ -z "$slot" ]]; then
# Automatisch freien Port finden
port=$(find_free_port "$port_range")
if [[ -z "$port" ]]; then
echo "❌ Kein freier Port in Range $port_range verfügbar"
exit 1
fi
dir="$HOME/.pidea/${ide}_${port}"
elif [[ "$slot" == "auto" ]]; then
# Automatisch freien Port finden
port=$(find_free_port "$port_range")
if [[ -z "$port" ]]; then
echo "❌ Kein freier Port in Range $port_range verfügbar"
exit 1
fi
dir="$HOME/.pidea/${ide}_${port}"
elif [[ "$slot" =~ ^[0-9]+$ ]]; then
# Spezifischer Slot
local start_port=$(echo $port_range | cut -d: -f1)
port=$((start_port + slot - 1))
local end_port=$(echo $port_range | cut -d: -f2)
if [[ $port -gt $end_port ]]; then
echo "❌ Slot $slot ist außerhalb der verfügbaren Range ($port_range)"
exit 1
fi
if port_in_use "$port"; then
echo "❌ Port $port (Slot $slot) ist bereits belegt"
exit 1
fi
dir="$HOME/.pidea/${ide}_${port}"
else
echo "❌ Ungültiger Slot: $slot"
exit 1
fi
# Verzeichnis erstellen falls nicht vorhanden
mkdir -p "$dir"
# IDE starten
echo "🚀 Starte $ide auf Port $port..."
if [[ $ide == "cursor" ]]; then
$RUNNER "$ide_path" \
--user-data-dir="$dir" \
--remote-debugging-port=$port &
else
# VSCode mit Remote Debugging starten
"$ide_path" \
--user-data-dir="$dir" \
--remote-debugging-port=$port &
fi
echo "✅ $ide gestartet auf Port $port"
echo " Verzeichnis: $dir"
echo " Debug URL: http://localhost:$port"
}
# Hauptlogik
# IDE-Pfade vom Backend laden
load_ide_paths
if [[ "$1" == "menu" ]]; then
show_menu
elif [[ "$1" == "help" || "$1" == "-h" || "$1" == "--help" ]]; then
show_help
elif [[ -z "$1" ]]; then
echo "❌ Keine IDE angegeben"
echo ""
show_help
else
start_ide "$1" "$2"
fi