-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaktualizr-toml-update
executable file
·53 lines (43 loc) · 1.56 KB
/
aktualizr-toml-update
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
#!/bin/sh -e
SOTA_CLIENT=aktualizr-lite
# This is an OnChanged handler that can handle aktualir-lite .toml files.
# It copies the toml file to /etc/sota/conf.d/ and will restart aktualizr-lite
[ -z "$CONFIG_FILE" ] && (echo "No CONFIG_FILE specified"; exit 1)
[ -z "$SOTA_DIR" ] && (echo "No SOTA_DIR specified"; exit 1)
ORIGIFS="$IFS"
IFS=","
for s in $SOTA_DIR ; do
if [[ "$s" == */sota.toml ]] ; then
SOTA_CONF=$s
break
fi
done
IFS=$ORIGIFS
[ -n "$SOTA_CONF" ] && echo "Primary sota.toml is $SOTA_CONF"
if [ -f $CONFIG_FILE ] ; then
mkdir -p -m 0700 /etc/sota/conf.d/
cp $CONFIG_FILE /etc/sota/conf.d/
if [ -n "$SOTA_CONF" ] ; then
# If we take control of tags/apps, then we should try and remove from sota.toml.
# Note: there is no way to surrender that control other than remove config altogether.
if grep -q "^\s*tags\s*=" $CONFIG_FILE 2>/dev/null ; then
sed -e '/^\s*tags\s*=/ s/^/# MANAGED BY FIOCONFIG: /' -i "${SOTA_CONF}"
else
sed -r 's/^# MANAGED BY FIOCONFIG:\s*(tags\s*=)/\1/g' -i "${SOTA_CONF}"
fi
if grep -q "^\s*compose_apps\s*=" $CONFIG_FILE 2>/dev/null ; then
sed -e '/^\s*compose_apps\s*=/ s/^/# MANAGED BY FIOCONFIG: /' -i "${SOTA_CONF}"
else
sed -r 's/^# MANAGED BY FIOCONFIG:\s*(compose_apps\s*=)/\1/g' -i "${SOTA_CONF}"
fi
fi
else
rm -f /etc/sota/conf.d/$(basename $CONFIG_FILE)
if [ -n "$SOTA_CONF" ] ; then
# Restore an original control of tags/apps in sota.toml.
sed -e 's/^# MANAGED BY FIOCONFIG: //g' -i "${SOTA_CONF}"
fi
fi
if systemctl is-enabled --quiet ${SOTA_CLIENT} ; then
systemctl restart ${SOTA_CLIENT}
fi