-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all.sh
More file actions
executable file
·144 lines (116 loc) · 2.97 KB
/
run_all.sh
File metadata and controls
executable file
·144 lines (116 loc) · 2.97 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
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
# Support both layouts:
# 1) <repo>/comfyui and <repo>/cognitive
# 2) <repo>/agents-to-agents/comfyui and <repo>/agents-to-agents/cognitive
if [[ -d "${SCRIPT_DIR}/agents-to-agents" ]]; then
PROJECT_ROOT="${SCRIPT_DIR}/agents-to-agents"
else
PROJECT_ROOT="${SCRIPT_DIR}"
fi
COMFY_DIR="${PROJECT_ROOT}/comfyui"
COGNITIVE_DIR="${PROJECT_ROOT}/cognitive"
log() {
printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
}
fail() {
printf 'Error: %s\n' "$*" >&2
exit 1
}
require_dir() {
local dir="$1"
local name="$2"
[[ -d "${dir}" ]] || fail "${name} directory not found: ${dir}"
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || fail "Required command not found: $1"
}
docker_cmd() {
if docker info >/dev/null 2>&1; then
printf 'docker'
elif command -v sudo >/dev/null 2>&1; then
printf 'sudo docker'
else
fail "Docker daemon not accessible and sudo not available"
fi
}
compose_subcommand() {
local dc="$1"
if ${dc} compose version >/dev/null 2>&1; then
printf 'compose'
elif command -v docker-compose >/dev/null 2>&1; then
printf 'docker-compose'
else
fail "Neither 'docker compose' nor 'docker-compose' is available"
fi
}
start_comfyui_linux() {
local comfy_dir="$1"
if command -v gnome-terminal >/dev/null 2>&1; then
gnome-terminal -- bash -lc "cd \"${comfy_dir}\" && ./run_host.sh"
return
fi
if command -v konsole >/dev/null 2>&1; then
konsole -e bash -lc "cd \"${comfy_dir}\" && ./run_host.sh"
return
fi
if command -v xfce4-terminal >/dev/null 2>&1; then
xfce4-terminal --hold -e "bash -lc 'cd \"${comfy_dir}\" && ./run_host.sh'"
return
fi
if command -v xterm >/dev/null 2>&1; then
xterm -hold -e "cd \"${comfy_dir}\" && ./run_host.sh" &
return
fi
fail "No supported terminal emulator found (gnome-terminal, konsole, xfce4-terminal, xterm)"
}
start_comfyui() {
local os_name
os_name="$(uname -s)"
case "${os_name}" in
Linux)
start_comfyui_linux "$1"
;;
*)
fail "Unsupported OS: ${os_name}"
;;
esac
}
main() {
require_dir "${COMFY_DIR}" "ComfyUI"
require_dir "${COGNITIVE_DIR}" "cognitive"
require_cmd chmod
require_cmd uname
log "Preparing ComfyUI scripts"
chmod +x "${COMFY_DIR}/setup_host.sh" "${COMFY_DIR}/run_host.sh"
log "Running ComfyUI host setup"
(
cd "${COMFY_DIR}"
./setup_host.sh
)
log "Starting ComfyUI in a dedicated terminal"
start_comfyui "${COMFY_DIR}"
log "Building and starting cognitive Docker services"
(
cd "${COGNITIVE_DIR}"
local dc
local compose_mode
dc="$(docker_cmd)"
compose_mode="$(compose_subcommand "${dc}")"
if [[ "${compose_mode}" == "compose" ]]; then
${dc} compose build --no-cache
${dc} compose up -d
else
if [[ "${dc}" == "sudo docker" ]]; then
sudo docker-compose build --no-cache
sudo docker-compose up -d
else
docker-compose build --no-cache
docker-compose up -d
fi
fi
)
log "All services started successfully"
}
main "$@"