blob: d0d2f2e313cf7727cd8e635973e1ad34ae88ce47 (
plain)
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
|
_detect_gpu() {
if lspci | grep -i "VGA\|3D\|Display controller" | grep -qi "AMD\|Radeon"; then
echo "rocm"
elif lspci | grep -i "VGA\|3D" | grep -qi "NVIDIA"; then
echo "cuda"
else
echo "cpu"
fi
}
_comfyui_setup() {
local pip="_PREFIX_/venv/bin/pip"
export PIP_CACHE_DIR="_PREFIX_/.pip-cache"
# Check if PyTorch is already installed and functional
if "_PREFIX_/venv/bin/python" -c "import torch" 2>/dev/null; then
echo ":: PyTorch already installed, skipping download."
else
local gpu="${COMFYUI_GPU:-$(_detect_gpu)}"
local torch_args="torch torchvision torchaudio"
if [ -n "$COMFYUI_GPU" ]; then
echo ":: GPU override: COMFYUI_GPU=$COMFYUI_GPU"
fi
case "$gpu" in
rocm)
echo ":: Installing PyTorch with ROCm 7.2 support."
torch_args="$torch_args --index-url https://download.pytorch.org/whl/rocm7.2"
;;
cuda)
echo ":: Installing PyTorch with CUDA 13.0 support."
torch_args="$torch_args --extra-index-url https://download.pytorch.org/whl/cu130"
;;
*)
echo ":: No supported GPU detected, installing CPU-only PyTorch."
;;
esac
echo ":: This may take a while (several GB to download)."
if ! "$pip" install $torch_args; then
echo ""
echo ":: ERROR: PyTorch installation failed."
echo ":: Pip cache preserved at _PREFIX_/.pip-cache for retry."
echo ":: To retry, reinstall the package."
return 1
fi
fi
echo ":: Installing ComfyUI dependencies..."
if ! "$pip" install -r "_PREFIX_/requirements.txt"; then
echo ""
echo ":: ERROR: ComfyUI dependencies installation failed."
echo ":: Pip cache preserved at _PREFIX_/.pip-cache for retry."
echo ":: To retry, reinstall the package."
return 1
fi
# Cleanup pip cache on success
rm -rf "_PREFIX_/.pip-cache"
echo ":: Setting ownership to comfy:comfy..."
chown -R comfy:comfy "_PREFIX_"
return 0
}
post_install() {
echo ":: Creating system user comfy..."
systemd-sysusers comfyui.conf
echo ":: Creating data directories..."
systemd-tmpfiles --create comfyui.conf 2>/dev/null || true
if [ -d "_PREFIX_/venv" ] && "_PREFIX_/venv/bin/python" --version >/dev/null 2>&1; then
echo ":: Existing Python venv found, reusing it."
else
echo ":: Creating Python virtual environment..."
rm -rf "_PREFIX_/venv"
python -m venv "_PREFIX_/venv"
fi
if _comfyui_setup; then
echo ""
echo ":: ComfyUI installed successfully."
echo ":: Run 'comfyui' to start, or enable the systemd service:"
echo ":: systemctl enable --now comfyui"
echo "::"
echo ":: Edit /etc/comfyui/extra_model_paths.yaml to configure model paths."
echo "::"
echo ":: To override GPU detection (rocm, cuda, cpu):"
echo ":: sudo COMFYUI_GPU=cuda makepkg -sf"
fi
}
post_upgrade() {
systemd-sysusers comfyui.conf
if [ -d "_PREFIX_/venv" ] && "_PREFIX_/venv/bin/python" --version >/dev/null 2>&1; then
echo ":: Existing Python venv found, reusing it."
else
echo ":: Creating Python virtual environment..."
rm -rf "_PREFIX_/venv"
python -m venv "_PREFIX_/venv"
fi
if _comfyui_setup; then
echo ":: ComfyUI upgraded successfully."
fi
}
pre_remove() {
rm -rf "_PREFIX_/.pip-cache"
echo ":: The Python venv at _PREFIX_/venv has been preserved."
echo ":: If you reinstall comfyui, dependencies will not be re-downloaded."
echo ":: To free disk space, remove it manually:"
echo ":: sudo rm -rf _PREFIX_"
echo "::"
echo ":: Data in /var/lib/comfyui/ has also been preserved."
}
|