blob: c4cd02cf70cea3703bb138c9febac0e8084d0d77 (
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
|
#!/bin/bash
_appname="stable-diffusion-webui"
_appprefix="/opt"
_appdataprefix="/var/opt"
_apphome="${_appprefix}/${_appname}"
_appdata="${_appdataprefix}/${_appname}"
_model_url="https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors"
_model_hash="3b2aa9f1e71b1de44d7df73a35ba1f7f64f5834a"
pre_install() {
echo "Creaing user sdwebui..."
getent passwd sdwebui >/dev/null || useradd -r -s /bin/false -d "$_apphome" sdwebui
}
_install() {
# Create dirs
mkdir -p "${_apphome}"
mkdir -p "${_appdata}"
mkdir -p "$/etc/${_appname}"
# Ensure appropriate permissions
chown -R sdwebui:sdwebui "${_apphome}" || return 1
chown -R sdwebui:sdwebui "${_appdata}" || return 1
chmod -R g+w "${_appdata}" || return 1
if [ ! -d "./venv" ]; then
echo "Setting up virtual environment for $_appname..."
su sdwebui -s /bin/bash -c "python3.10 -m venv ${_apphome}/venv" || return 1
fi
echo "Preparing python environment..."
su sdwebui -s /bin/bash -c "cd ${_apphome} && ./venv/bin/python -c 'from modules.launch_utils import prepare_environment; prepare_environment()'" || return 1
# Install default config if needed
if [ ! -f "/etc/${_appname}/webui.conf" ]; then
echo "Installing default config file..."
install -Dm644 "/usr/share/${_appname}/webui.conf" "/etc/${_appname}/webui.conf"
fi
# Downhload the default model
model_file=$(basename "${_model_url}")
model_dir="/usr/share/${_appname}/models/Stable-diffusion"
current_hash=""
if [[ -f "${model_dir}/${model_file}" ]]; then
current_hash=$(sha1sum "${model_dir}/${model_file}" | cut -d ' ' -f 1)
fi
if [[ "${current_hash}" == "${_model_hash}" ]]; then
echo "stable-diffusion-v1.5 model exists and is up to date."
else
mkdir -p "${model_dir}"
echo "Downloading ${model_file}..."
wget --progress=bar:force:noscroll \
-O "${model_dir}/${model_file}" "${_model_url}" || return 1
fi
}
post_install() {
_install || { echo -e "\nERROR: Failed to install dependencies\n"; return 1; }
}
post_upgrade() {
_install || { echo -e "\nERROR: Failed to install dependencies\n"; return 1; }
}
post_remove() {
echo "Removing ${_apphome}..."
rm -rf "${_apphome}"
}
|