blob: 7430e3dcbc414af7c718b3ab3b9e159c619979bb (
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
# Create user tedge-agent with no home(--no-create-home), no login(--shell) and in group tedge-agent(--ingroup)
if ! getent passwd tedge-agent >/dev/null; then
adduser --quiet --system --no-create-home --ingroup tedge-agent --shell /usr/sbin/nologin tedge-agent
adduser tedge-agent tedge
fi
### Create file in /etc/sudoers.d directory
# tedge-agent needs to execute some of its operations as a system user therefore it needs an entry in /etc/sudoers.
echo "%tedge-agent ALL = (ALL) NOPASSWD: /etc/tedge/sm-plugins/[a-zA-Z0-9]*, /bin/sync, /sbin/init" >/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]*, /bin/sync, /sbin/init" >/etc/sudoers.d/tedge-agent-nopasswd
fi
# Reenable the services only if systemctl is available
if command -v systemctl >/dev/null; then
### 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
fi
fi
# Initialize the agent
runuser -u tedge-agent -- tedge_agent --init
#DEBHELPER#
|