relaunch method

Future<void> relaunch()

Relaunching the Liquid Galaxy System: We used to type: --lg-relaunch in terminal

Implementation

Future<void> relaunch() async {
  final pw = _sshData.passwordOrKey;
  final user = _sshData.username;

  final result = await getScreenAmount();
  if (result != null) {
    screenAmount = int.parse(result);
  }

  for (var i = screenAmount; i >= 1; i--) {
    try {
      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 _sshData.client!
          .execute("'/home/$user/bin/lg-relaunch' > /home/$user/log.txt");

      await _sshData.client!.execute(relaunchCommand);
    } catch (e) {
      // ignore: avoid_print
      print(e);
    }
  }
}