I would like to do create a bash script that downloads a specific installer from the internet, installs it, create a desktop file that launches it, make it auto start, then remove the installer, but there are a few things I would like the script to check. These things are:

  • the existence of the installer (if not existing, then download it, else set it executable)

  • the existence of a previous installation (if exists, then set it's uninstaller executable, run it and remove everything it left behind, else go to next step)

  • the state of the gksu package via apt list | grep gksu (if it's installed, then go to next step, else install it) and

  • the output of gksu example.run (if there's a "GNOME_SUDO_PASS" line, then repeat gksu example.run, else go to next step)

closed as unclear what you're asking by jimmij, Michael Durrant, Archemar, terdon Jun 11 '16 at 21:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please read this, then edit your question. – garethTheRed Jun 11 '16 at 19:35

Condition: installer - ls . | grep example.runchmod +x pelda.run else wget download/link/of/example.run

As I understand the above, it translates to:

if [ -f example.run ]
    chmod +x pelda.run
    wget download/link/of/example.run

[ -f example.run ] is an example of using the test command. If a file named example.run exists, then the test command set a return code of 0 (meaning true). If it doesn't, it sets a return code of 1 (meaning false).

Condition: gksu - apt list --installed | grep gksu, if !exists, then sudo apt install gksu else gksu pelda.run

As I interpret the above, it translates to:

if apt list --installed | grep gksu
    gksu pelda.run
    sudo apt install gksu

Here, we are using the fact that grep sets a return code depending on whether it finds a match or not. apt list --installed returns a list of installed packages. If its output anywhere contains the string gksu, then grep sets a return code of 0 (meaning true) and the then clause is executed. If it doesn't, the else clause is executed.

  • Sorry if was not clear enough. "if [ -f example.run ]" was what i tried first. But it will download the file even if it's existing, but yes that's what i would like to do. You misunderstood the gksu condition. What i would like to fid out with it is that the gksu package is installed or not on the computer. If installed, go to the next step, if not, then install it. – Weylyn Savan Jun 12 '16 at 10:42
  • (1) ""if [ -f example.run ]" was what i tried first. But it will download the file even if it's existing" No, it won't. If the example.run exists in the current directory, then the script will run chmod +x pelda.run. (2) I have updated the gksu example as per your info. – John1024 Jun 12 '16 at 17:39
  • @WeylynSavan Very good. – John1024 Jun 12 '16 at 18:42
  • Now the gksu part: apt list --installed | grep "gksu/" > tmp while read gksu do if [ "[installed]" ] then gksu example.run else sudo apt install gksu fi done < tmp At this point the content of tmp is: gksu/unknown,now 2.0.2-60 amd64 [installed] But it won't install gksu if it's not installed (tried in vm without gksu installed). – Weylyn Savan Jun 12 '16 at 19:01
  • That code is very different. Among other possible issues, this part won't work as you would like it to: ... if [ "[installed]" ] then ... – John1024 Jun 12 '16 at 20:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.