relaunch method

Future<void> relaunch()

Relaunches the Liquid Galaxy services.

Implementation

Future<void> relaunch() async {
  final String? pw = await sshConnection.password;

  if (!await sshConnection.isConnected() || pw == null) {
    return;
  }

  final user = sshConnection.username;

  for (var i = sshConnection.screenAmount; i >= 1; i--) {
    final relaunchCommand = """RELAUNCH_CMD="\\
if [ -f /etc/init/lxdm.conf ]; then
export SERVICE=lxdm
elif [ -f /etc/init/lightdm.conf ]; then
export SERVICE=lightdm
else
exit 1
fi
if  [[ \\\$(service \\\$SERVICE status) =~ 'stop' ]]; then
echo $pw | sudo -S service \\\${SERVICE} start
else
echo $pw | sudo -S service \\\${SERVICE} restart
fi
" && sshpass -p $pw ssh -x -t lg@lg$i "\$RELAUNCH_CMD\"""";
    await sshConnection
        .sendCommand('"/home/$user/bin/lg-relaunch" > /home/$user/log.txt');
    await sshConnection.sendCommand(relaunchCommand);
  }
}