zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
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
#!/usr/bin/env bash
 
set -euxo
 
export WEBODM_VERSION=1.9.7
export WEBODM_USER=odm
export WEBODM_USER_HOME="/home/${WEBODM_USER}"
export WEBODM_DIR=/opt/WebODM
export WEBODM_VENV_DIR="${WEBODM_DIR}/python3-venv"
 
function abortRemove() {
    echo "Unable to remove webodm."
}
 
function configure() {
    detectGPUs
    createGroup
    createUser
    createVenv
    setFilePermissions
    upgradePythonPip
    installPythonDockerCompose
    enableService
    startService
}
 
function createGroup() {
    if [ "${GPU_INTEL}" = true ]; then
        if ! grep -q "^render:" /etc/group; then
            groupadd render
        fi
    fi
}
 
function createUser() {
    if ! grep -q "^${WEBODM_USER}:" /etc/passwd; then
        if [ "${GPU_INTEL}" = true ]; then
            useradd -m -d "${WEBODM_USER_HOME}" -s /bin/bash -G docker,video,render "${WEBODM_USER}"
        else
            useradd -m -d "${WEBODM_USER_HOME}" -s /bin/bash -G docker "${WEBODM_USER}"
        fi
 
        chown "${WEBODM_USER}":"${WEBODM_USER}" "${WEBODM_USER_HOME}"
    fi
 
    PROFILE_PATH="/home/odm/.profile"
    if [ ! -f "${PROFILE_PATH}" ]; then
        touch "${PROFILE_PATH}"
        chmod odm:odm "${PROFILE_PATH}"
    fi
 
    if ! grep -q "PATH.*home\/odm\/\.local\/bin" "${PROFILE_PATH}"; then
        echo "export PATH=\"/home/odm/.local/bin:${PATH}\"" >> "${PROFILE_PATH}"
    fi
}
 
function createVenv() {
    if [ ! -d "${WEBODM_VENV_DIR}" ]; then
        mkdir "${WEBODM_VENV_DIR}"
        python3 -m venv "${WEBODM_VENV_DIR}"
    fi
}
 
function detectGPUs() {
    source "${WEBODM_DIR}/detect_gpus.sh"
}
 
function enableService() {
    systemctl enable "${WEBODM_DIR}/service/webodm-docker.service"
}
 
function installPythonDockerCompose() {
    su "${WEBODM_USER}" -c "python3 -m pip install --upgrade docker-compose"
}
 
function setFilePermissions() {
    chown -R "${WEBODM_USER}:${WEBODM_USER}" "${WEBODM_DIR}"
}
 
function startService() {
    systemctl daemon-reload
    systemctl restart webodm-docker.service
}
 
function upgradePythonPip() {
    su "${WEBODM_USER}" -c "python3 -m pip install --upgrade pip"
}
 
case $1 in
    abort-remove)
        abortRemove
        ;;
    configure)
        configure
        ;;
    default)
        exit 1
        ;;
esac