I am using the following systemd service file:
[Unit]
After=multi-user.target
Description=cifscloak
ConditionEnvironment=homeNetwork=1
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/cifscloak mount -a -r 6
ExecStop=/usr/bin/cifscloak mount -u -a
[Install]
WantedBy=multi-user.target
ConditionEnvironment should evaluate the homeNetwork variable and start the service if the value is 1.
The problem is, how can I create an instance of this variable in the way the systemd service can read it?
I would like to use something like the following:
gw=$(ip r | grep default | head -1 | awk ' {print $3;}')
if [ "$gw" == "10.1.1.10" ]; then export officeNetwork=1; else export officeNetwork=0; fi
if [ "$gw" == "192.168.1.1" ]; then export homeNetwork=1; else export homeNetwork=0; fi
The problem is: how can I run this script before the systemd service runs?