summarylogtreecommitdiffstats
path: root/panopta-agent.install
blob: 1446c568645aa7dbc3f2b3ff7029076c32cdf4f9 (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
post_install() {
    # Add agent user
    if ! (id panopta-agent > /dev/null 2>&1 ); then
        useradd -r -d /usr/lib/panopta-agent -s /usr/sbin/nologin panopta-agent;
    fi

    # Create necessary data directories
    mkdir -p /var/log/panopta-agent
    mkdir -p /var/lib/panopta-agent
    mkdir -p /usr/share/panopta-agent
    mkdir -p /etc/panopta-agent

    # Perform the install handshake
    python2 /usr/bin/panopta-agent/panopta_agent.py --install

    # Change owner of needed directories to the agent user
    # The initial handshake is performed as root, so update these permissions after
    chown -R panopta-agent /var/lib/panopta-agent
    chown -R panopta-agent /var/log/panopta-agent
    chown -R panopta-agent /usr/lib/panopta-agent
    chown -R panopta-agent /usr/bin/panopta-agent
    chown -R panopta-agent /usr/share/panopta-agent
    chown -R panopta-agent /var/log/panopta-agent
    chown -R panopta-agent /etc/panopta-agent

    # Start cron
    systemctl enable --now cronie.service
}

post_upgrade() {
    post_install
}

post_remove() {
    # The agent will leave behind .pyc files, so we need to clear this out manually
    rm -rf /usr/lib/panopta-agent
    # Remove agent user
    if (id panopta-agent > /dev/null 2>&1 ); then
        userdel panopta-agent;
    fi
}