summaryrefslogtreecommitdiffstats
path: root/configuration/debian/tedge/postinst
blob: 2179457045060e07eeb3161053beb1f70ad6e166 (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
#!/bin/sh
set -e

### Create groups
if ! getent group tedge >/dev/null; then
    addgroup --quiet --system tedge
fi

### Create users
# Create user tedge with no additional info(--gecos "") no home(--no-create-home), no login(--shell) and in group tedge(--ingroup)
if ! getent passwd tedge >/dev/null; then
    adduser --quiet --system --gecos "" --no-create-home --disabled-login --shell /sbin/nologin --ingroup tedge tedge
fi

### Add include to mosquitto.conf so tedge specific conf will be loaded
if ! grep -q "/etc/tedge/mosquitto-conf" "/etc/mosquitto/mosquitto.conf"; then
    echo "include_dir /etc/tedge/mosquitto-conf" >>/etc/mosquitto/mosquitto.conf
fi

### Create file in /etc/sudoers.d directory. With this configuration, the tedge user have the right to call the tedge command with sudo rights, which is required for system-wide configuration in "/etc/tedge"
echo "tedge  ALL = (ALL) NOPASSWD: /usr/bin/tedge, /etc/tedge/sm-plugins/[a-zA-Z0-9]*, /bin/sync, /sbin/init" >/etc/sudoers.d/tedge

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

# Initialize the tedge
tedge --init

### Below are automatically created script parts by cargo deb (Search for cargo deb DEBHELPER)
#DEBHELPER#