summaryrefslogtreecommitdiffstats
path: root/configuration/debian/tedge_agent/postinst
blob: 399da983406c136c551329a907df1d37cf8e4fc8 (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
#!/bin/sh

set -e

# Create a group "tedge-agent" if not created before
if ! getent group tedge-agent > /dev/null; then
    addgroup --quiet --system tedge-agent
fi

# Create a user "tedge-agent" if not created before
if ! getent passwd tedge-agent > /dev/null; then
    adduser --quiet --system --no-create-home --ingroup tedge-agent --shell /usr/sbin/nologin tedge-agent
fi

### Create file in /etc/sudoers.d directory
echo "%tedge-agent   ALL = (ALL) NOPASSWD: /etc/tedge/sm-plugins/[a-zA-Z0-9]*" > /etc/sudoers.d/tedge-agent

if [ -f "/etc/sudoers.d/010_pi-nopasswd" ]; then
    echo "%tedge-agent   ALL = (ALL) NOPASSWD: /etc/tedge/sm-plugins/[a-zA-Z0-9]*" > /etc/sudoers.d/tedge-agent-nopasswd
fi

# create /etc/tedge/.agent directory
install -g tedge-agent -o tedge-agent -m 754 -d /etc/tedge/.agent

# create /var/log/tedge/agent directory
install -g tedge-agent -o tedge-agent -m 754 -d /var/log/tedge/agent

## Enable the sm services if the device is connected to c8y cloud
if [ -f "/etc/tedge/mosquitto-conf/c8y-bridge.conf" ]; then 
    # start and enable tedge-agent
    systemctl start tedge-agent.service
    systemctl enable tedge-agent.service

    # start and enable tedge-mapper-sm-c8y
    systemctl start tedge-mapper-sm-c8y.service
    systemctl enable tedge-mapper-sm-c8y.service
fi
#DEBHELPER#