Skip to content

Commit

Permalink
reworked backend to use shell script when calling long functions in bash
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Dream-in-Code committed Sep 28, 2018
1 parent c1e32fd commit 9e7c6f9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 34 deletions.
36 changes: 34 additions & 2 deletions ArchUpdater
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#!/bin/bash
echo "$@"
"$@"


command=""
if [ "$1" == "konsole" ];then
IFS=',' read -r -a array <<<"${@:2}"
for i in "${array[@]}"
do
command="$command $i;"
done
echo "$command"
konsole --hold -e /bin/bash -c "$command"
fi

if [ "$1" == "yakuake" ]; then
IFS=',' read -r -a array <<<"${@:3}"
for i in "${array[@]}"
do
command="$command $i;"
done
echo "$command"
qdbus org.kde.yakuake /Sessions/$2 runCommand "$command"
fi

if [ $1 == "pkexec" ]
then
IFS=',' read -r -a array <<<"${@:2}"
command="pkexec"
for i in "${array[@]}"
do
command="$command $i;"
done
echo "$command"
/bin/sh -c "$command"
fi
79 changes: 47 additions & 32 deletions plugin/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,27 @@ QString Worker::prepareYakuake()

void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yakuakeFlag, bool orphan)
{
/*
* Since QProcess causes a stack crash when stringing multiple commands we call a seperate shell script to call
* the update process.
*
* Since the update process takes multiple commands seperated by ; we need to have the commands separated by , to
* then create an IFS=',' in bash to get each command in an array.
*
*
* The first argument is either konsole, yakuake or pkexec
*
* Ex :
* sudo pacman -Syu --noconfirm, echo update finished
*
* in bash the array becomes
* ("sudo pacman -Syu --noconfirm;", "echo update finished;")
*
* Then all the commands are concatintated back into a large string and called in the bash script
*
*/


QProcess systemUpdateProcess;

//if yakuake is not running start and sleep for 2 seconds then call upgradeSystem again now that yakuake is started
Expand Down Expand Up @@ -439,9 +460,7 @@ void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yaku
qDebug() << "AUR HELPER======" << AURHelper;
QStringList AURCommands = getAURHelperCommands(AURHelper);
QStringList arguments;
QString exec;
QString args = "";
QString message = "";


//remove --noconfirm if flag in settings not set
if (noconfirm == false)
Expand All @@ -461,7 +480,8 @@ void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yaku
if (yakuakeFlag)
{
QString terminal = prepareYakuake();
arguments << "qdbus-qt5" << "org.kde.yakuake" << "/Sessions/" + terminal << "runCommand";
// arguments << "yakuake" << "org.kde.yakuake" << "/Sessions/" + terminal << "runCommand" ;
arguments << "yakuake" << terminal;


toggleYakuake(terminal);
Expand All @@ -472,26 +492,22 @@ void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yaku
//run /bin/bash -c konsole --hold -e 'sh -c " *aur helper commnads* ; echo Update Finished "

// start with konsole --hold -e **aur helper**
arguments << "konsole" << "--hold" << "-e" << "/bin/sh" << "-c";
exec = "ArchUpdater";
arguments << "konsole";

}
arguments << "\'" + AURCommands[0];
for (int i = 1; i < AURCommands.size(); i++)
for (int i = 0; i < AURCommands.size()-1; i++)
arguments << AURCommands[i];


arguments << AURCommands[AURCommands.size()-1]+",";



if(orphan)
arguments << "; echo" << "Cleaning" << " Orphans" << "; sudo" << "pacman" << "-Rns" << "$(pacman -Qtdq)" << "--noconfirm";

arguments << ";echo;" << "echo" << "----------------;" << "echo" << "Update" << "Finished\'";
arguments= QStringList();
arguments<< "ArchUpdater" << "konsole" << "--hold" << "-e" << "/bin/sh" << "-c" << " \'echo 5\'" ;
//start system update process
qDebug() << "AUR ARGS " << exec << arguments;
systemUpdateProcess.start("source",arguments);
arguments << "echo" << "Cleaning" << " Orphans," << "sudo" << "pacman" << "-Rns" << "$(pacman -Qtdq),";

arguments << "echo," << "echo" << "----------------," << "echo" << "Update" << "Finished";
//start system update process
qDebug() << "AUR ARGS " << arguments;
systemUpdateProcess.start("/usr/bin/ArchUpdater", arguments);
}

else //no aur flag
Expand All @@ -501,12 +517,12 @@ void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yaku
{
QStringList arguments;
// /bin/bash -c konsole --hold -e 'sh -c "sudo pacman -Syu ; echo Update Finished'""
arguments << "konsole" << "--hold" << "-e" << "/bin/sh" << "-c " << "'sudo" << "pacman" << "-Syu;";

if(orphan)
arguments << "; echo" << "Cleaning" << " Orphans" << "; sudo" << "pacman" << "-Rns" << "\"$(pacman -Qtdq)\"" << "--noconfirm";
arguments << "sudo" << "pacman" << "-Syu,";
if(orphan)
arguments << "echo" << "Cleaning" << " Orphans," << "sudo" << "pacman" << "-Rns" << "$(pacman -Qtdq),";

arguments << ";echo;" << "echo"<< "----------------;" << "echo" << "Update" << "Finished'";
arguments << "echo," << "echo" << "----------------," << "echo" << "Update" << "Finished";
systemUpdateProcess.start("/usr/bin/ArchUpdater", arguments);
}

Expand All @@ -515,13 +531,12 @@ void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yaku
{
QStringList arguments;
QString terminal = prepareYakuake();
arguments << "qdbus-qt5" << "org.kde.yakuake" << "/Sessions/" + terminal << "runCommand" << "sudo" << "pacman" << "-Syu;";
arguments << "qdbus-qt5" << "org.kde.yakuake" << "/Sessions/" + terminal << "runCommand" << "/bin/bash"<< "sudo" << "pacman" << "-Syu,";

if(orphan)
arguments << "; echo" << "Cleaning" << " Orphans" << "; sudo" << "pacman" << "-Rns" << "\"$(pacman -Qtdq)\"" << "--noconfirm";

arguments << ";echo;" << "echo" << "----------------;" << "echo" << "Update" << " Finished\"";
if(orphan)
arguments << "echo" << "Cleaning" << " Orphans," << "sudo" << "pacman" << "-Rns" << "$(pacman -Qtdq),";

arguments << "echo," << "echo" << "----------------," << "echo" << "Update" << "Finished";
systemUpdateProcess.start("/usr/bin/ArchUpdater", arguments);
qDebug() << "ARGS " << arguments;
toggleYakuake(terminal);
Expand All @@ -532,10 +547,10 @@ void Worker::upgradeSystem(bool konsoleFlag, bool aur, bool noconfirm, bool yaku
{
//pexec pacman -Syu --noconfirm
QStringList arguments;
arguments << "pkexec" << "/usr/bin/pacman" << "-Syu" << "--noconfirm;";
if(orphan)
arguments << "pacman" << "-Rns" << "\"$(pacman -Qtdq)\"" << "--noconfirm";
arguments << "pkexec" << "/usr/bin/pacman" << "-Syu" << "--noconfirm,";

if(orphan)
arguments << "pacman" << "-Rns" << "$(pacman -Qtdq)" << "--noconfirm";


systemUpdateProcess.start("usr/bin/ArchUpdater", arguments);
Expand Down

0 comments on commit 9e7c6f9

Please sign in to comment.