Skip to content

Commit b0d2a6b

Browse files
committed
Improve syncthing user service enable
1 parent 5aea85f commit b0d2a6b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

plugins/syncthing

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ then
5151
mkdir -p $assetdir
5252
if [ $notfirst -eq 1 ]
5353
then
54-
#logtobothex "? Plugin $pfx: Currently unable to configure multiple syncthing users"
5554
[ "$gui__address" == "" ] && logtobothex "? Plugin $pfx: User '$runasuser' is not the first user; argument 'gui-address' is required"
5655
[ "$connect__address" == "" ] && logtobothex "? Plugin $pfx: User '$runasuser' is not the first user; argument 'connect-address' is required"
5756
fi
@@ -98,9 +97,9 @@ then
9897
logtoboth " Home Directory: $homedir"
9998
logtoboth " Send Statistics: $sendstats"
10099
[ "$enablesvc" == "y" ] && s1="yes" || s1="no"
101-
logtoboth " Service Enabled: $s1"
100+
logtoboth " Enable syncthing user service: $s1"
102101
[ "$nolinger" == "y" ] && s1="no" || s1="yes"
103-
logtoboth " Start service for user at boot: $s1"
102+
[ "$enablesvc" == "y" ] && logtoboth " Start syncthing user service at boot: $s1"
104103
#logfreespace "at start of Plugin $pfx Phase post-install"
105104
if [ ! -f /etc/sysctl.d/062-syncthing-receive-buffer-size.conf ]
106105
then
@@ -109,7 +108,7 @@ then
109108
echo "net.core.wmem_max=7500000" >> /etc/sysctl.d/062-syncthing-receive-buffer-size.conf
110109
fi
111110

112-
logtoboth "> Plugin $pfx: Prepare sdm FirstBoot script for user '$runasuser' to complete syncthing configuration"
111+
logtoboth "> Plugin $pfx: Create sdm FirstBoot script for user '$runasuser' to complete syncthing configuration"
113112
[ "$gui__address" == "" ] && gui__address="127.0.0.1:8384"
114113
[ "$connect__address" != "" ] && [[ "${connect__address##*://}" == "$connect__address" ]] && connect__address="tcp://$connect__address"
115114
cat > $assetdir/cfgsyncthing <<EOF
@@ -136,7 +135,6 @@ syncthing --generate $homedir/.local/state/syncthing
136135
sed -i "s/<urAccepted>0/<urAccepted>$sendstats/" $homedir/.local/state/syncthing/config.xml
137136
[ "$gui__user" != "" ] && syncthing generate --gui-user "$gui__user" --gui-password "$gui__password"
138137
EOF
139-
[ "$enablesvc" == "y" ] && echo "systemctl enable --user syncthing" >> $assetdir/cfgsyncthing
140138
chmod 755 $assetdir/cfgsyncthing
141139
# Run syncthing configuration script at end of sdm FirstBoot
142140
cat > /etc/sdm/0piboot/098-enable-syncthing-$runasuser.sh <<EOF
@@ -147,17 +145,25 @@ cp $assetdir/cfgsyncthing /tmp/cfgsyncthing-$runasuser
147145
chmod 755 /tmp/cfgsyncthing-$runasuser
148146
logger "sdm FirstBoot: Configure syncthing as user '$runasuser' using '$assetdir/cfgsyncthing'"
149147
logger " Log: $assetdir/cfgsyncthing-$runasuser.log"
150-
su $runasuser /tmp/cfgsyncthing-$runasuser </dev/null >/tmp/cfgsyncthing-$runasuser.log 2>&1
148+
su --login $runasuser /tmp/cfgsyncthing-$runasuser </dev/null >/tmp/cfgsyncthing-$runasuser.log 2>&1
151149
mv /tmp/cfgsyncthing-$runasuser.log $assetdir
152150
rm -f /tmp/cfgsyncthing-$runasuser # be neat
151+
#mkdir -p $homedir/.config/systemd/user/multi-user.target.wants
152+
#IFS=":" read xuser xpw xuid gx rest <<< \$(getent passwd $runasuser)
153+
#chown -R $runasuser:\$gx $homedir/.config
153154
if [ "$nolinger" != "y" ]
154155
then
155156
logger "sdm FirstBoot: Enable linger for user '$runasuser'"
156157
loginctl enable-linger $runasuser
157158
fi
159+
if [ "$enablesvc" == "y" ]
160+
then
161+
logger "sdm FirstBoot: Enable syncthing user service for '$runasuser'"
162+
systemctl --machine "$runasuser@" --user enable syncthing
163+
#ln -s /usr/lib/systemd/user/syncthing.service $homedir/.config/systemd/user/multi-user.target.wants
164+
fi
158165
exit 0
159166
EOF
160-
161167
#
162168
#logfreespace "at end of $pfx Custom Phase post-install"
163169
logtoboth "* Plugin $pfx: Complete Phase post-install"

0 commit comments

Comments
 (0)