aboutsummaryrefslogtreecommitdiffstats
path: root/linux_service_scripts/installer.sh
blob: 404fb90dbc736b272f018204399d8f359f6c9f6f (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
#!/usr/bin/env bash
# Copyright (C) 2022 The Qt Company Ltd.
#
# SPDX-License-Identifier: GPL-3.0-only WITH Qt-GPL-exception-1.0

name=licd
installdir=/opt/${name}

function exit_fail {
    echo "ERROR! $1: Aborting installation"
    exit 1
}

function create_install_dir {
    umask u=rwx,go=rx;mkdir -p -m 755 ${installdir}
    if [ $? != 0 ]; then
        exit_fail "Could not create directory ${installdir}"
    fi

}

function copy_files {
    # Copy executables and .ini
    cp ${name} ${name}.ini qtlicensetool mocwrapper licheck ${installdir}/
    if [ $? != 0 ]; then
        exit_fail "Failed to copy files to $installdir"
    fi

    # Copy .service
    cp ${name}.service /etc/systemd/system/
    if [ $? != 0 ]; then
        exit_fail "Failed to copy $name.service to /etc/systemd/system/"
    fi

    # Create a symlink for qtlongterm binary
    ln -s ${installdir}/qtlicensetool /usr/bin/qtlicensetool

    sync
}

function stop_daemon {
    running=true

    retries=0
    while [ $running != "false" ]
    do
        running=false
        systemctl is-active --quiet $name && running=true;
        if [ $running != "false" ]
        then
        systemctl stop $name
            sleep 2
            retries=$((retries+1))
            if [ $retries -gt 2 ]
            then
                exit_fail "Tried to stop qtlicenser service for $retries times already"
            fi
        fi
    done
    echo "Stopped $name.service"
}

function enable_and_start_daemon {
    # Enable the daemon
    systemctl daemon-reload
    systemctl enable ${name}.service

    # Start the daemon
    systemctl start ${name}.service
    if [ $? != 0 ]; then
        exit_fail "Could not start the daemon"
    fi
}

stop_daemon

create_install_dir

copy_files

enable_and_start_daemon

echo "Installation ok"