blob: 2827fc7ab43b23ac508cecc6f776303c23598fd6 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/bin/sh
set -ex
# Create all necessary directories we need at runtime
mkdir -p $SNAP_DATA/conf/system-connections
mkdir -p $SNAP_DATA/run
# Create DHCP lease directory
mkdir -p /run/NetworkManager/dhcp
# Select which config we're going to use. We offer our users
# to provide their own configuration file in $SNAP_DATA but
# will fallback if no one exists to the default one we ship
# in $SNAP
NM_CONF="$SNAP/etc/NetworkManager/NetworkManager.conf"
if [ -e $SNAP_DATA/NetworkManager.conf ]; then
NM_CONF="$SNAP_DATA/NetworkManager.conf"
fi
# A directory where users can place any additional configuration
# files for NetworkManager
mkdir -p $SNAP_DATA/conf.d
# State dir where network-manager stores several things like the
# secret key used for IPv6
mkdir -p $SNAP_DATA/state
mkdir -p $SNAP_DATA/state/dhcp
# If netplan is not configured to render by default to NetworkManager
# configuration files we disable management of any ethernet device
# as this will clash with any configuration netplan puts in place
# for networkd.
if [ ! -e "/etc/netplan/00-default-nm-renderer.yaml" ] ; then
if [ ! -e "$SNAP_DATA/conf.d/disable-ethernet.conf" ] ; then
echo "[keyfile]" > $SNAP_DATA/conf.d/disable-ethernet.conf
echo "unmanaged-devices+=interface-name:eth*,interface-name:enx*" >> $SNAP_DATA/conf.d/disable-ethernet.conf
fi
else
# Enable ethernet management again if the user switched the netplan
# backend and wants us to manage ethernet
if [ -e $SNAP_DATA/conf.d/disable-ethernet.conf ] ; then
rm -f $SNAP_DATA/conf.d/disable-ethernet.conf
fi
# If the snapd configuration for netplan is not present or empty
# we will start managing all ethernet ports automatically. Because
# of that we need to remove any previously created configuration files
# which prevented us from doing that.
if [ ! -e /etc/netplan/00-snapd-config.yaml ] || [ -s /etc/netplan/00-snapd-config.yaml ] ; then
rm -f $SNAP_DATA/conf.d/no-auto-default-ethernet.conf
else
if [ ! -e "$SNAP_DATA/conf.d/no-auto-default-ethernet.conf" ] ; then
# If we're running as the only network management service
# and are configured via netplan on first boot then we should
# not try to auto configure ethernet ports as this is up to
# netplan and will be the same for networkd.
echo "[main]" > $SNAP_DATA/conf.d/no-auto-default-ethernet.conf
echo "no-auto-default=interface-name:eth*,interface-name:enx*" >> $SNAP_DATA/conf.d/no-auto-default-ethernet.conf
fi
fi
fi
# HACK: Until we've fixed probert to look in $SNAP_DATA/state/dhcp or
# somewhere else for our lease files we use inotifywatch to monitor
# our lease files and copy all over when something has changed. This
# background process gets stopped when our systemd service unit gets
# stopped.
$SNAP/bin/dhcp-lease-mover &
# Identify if we are in debug mode or not
LOG_LEVEL="INFO"
if [ -f $SNAP_DATA/.debug_enabled ]; then
LOG_LEVEL="DEBUG"
fi
# Run available startup hooks to have a point to store custom
# logic outside of this script. More of the things from above
# should be moved into these.
for hook in $SNAP/startup-hooks/* ; do
[ -x "$hook" ] && /bin/sh -x "$hook"
done
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/NetworkManager"
exec $SNAP/usr/sbin/NetworkManager \
--config-dir=$SNAP_DATA/conf.d/ \
--config=$NM_CONF \
--log-level=$LOG_LEVEL \
--no-daemon
|