The simplest approach is to have your script continue only if apt-get
exits correctly. For example:
sudo apt-get install BadPackageName &&
## Rest of the script goes here, it will only run
## if the previous command was succesful
Alternatively, exit if any steps failed:
sudo apt-get install BadPackageName || echo "Installation failed" && exit
This would give the following output:
terdon@oregano ~ $ foo.sh
[sudo] password for terdon:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package BadPackageName
Installation failed
This is taking advantage of a basic feature of bash and most (if not all) shells:
&&
: continue only if the previous command succeeded (had an exit status of 0)
||
: continue only if the previous command failed (had an exit status of not 0)
It is the equivalent of writing something like this:
#!/usr/bin/env bash
sudo apt-get install at
## The exit status of the last command run is
## saved automatically in the special variable $?.
## Therefore, testing if its value is 0, is testing
## whether the last command ran correctly.
if [[ $? > 0 ]]
then
echo "The command failed, exiting."
exit
else
echo "The command ran succesfuly, continuing with script."
fi
Note that if a package is already installed, apt-get
will run successfully, and the exit status will be 0.
You are clicking the button before self.instvar
is set. The on_textbox_changed
handler is probably never called. Startup Glade and select your text entry. In the property editor on the right select the signals
tab and connect the GtkEditable
changed
signal to the correct handler.
You should also put a print statement inside on_textbox_changed
to see if it really is called.
Alse, this line doesn't do what you think it does:
command2 = 'xterm -e sudo apt-get install ' and self.instvar
See this interactive session:
>>> instvar = "firefox"
>>> "xterm -e sudo apt-get install" and instvar # Your code, wrong output
'firefox'
>>> "xterm -e sudo apt-get install %s" % instvar # Choose one of these
'xterm -e sudo apt-get install firefox'
>>> "xterm -e sudo apt-get install " + instvar
'xterm -e sudo apt-get install firefox'
>>> "xterm -e sudo apt-get install {}".format(instvar)
'xterm -e sudo apt-get install firefox'
Best Answer
You can create an alias for
apt-get
in your home directory. To do so, follow these:Open a terminal and do this command:
In the new opened file, type these and save and exit.
Then, whenever you run
apt-get
,apt-fast
will run insteadFor more info, see this page