2 #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
3 #ex: set sts=4 ts=4 sw=4 et:
14 #ai_install_cmd="/usr/bin/gksudo '/usr/bin/aptitude install -y @PACKAGE@'"
15 #ai_install_cmd_terminal=no
22 Usage: nd-autoinstall <package> <command> [<command_options>]
24 Runs the <command> if it is available, otherwise installs <package>
25 first, and then runs the command.
28 if <command> is available (or got sucesfully installed)
29 - exit status of the <command>
30 2 - incorrect invocation of nd-autoinstall
31 3 - <package> installation failure
35 # Possible options: --environment-file to source prior even 'which'
37 if [ $# -lt 2 ] ; then
38 echo "ERROR: Incorrect invocation" >&2
46 if ! which $command >/dev/null; then
47 if ! zenity --question \
48 --text="To run '$command', $package package needs to be installed. Do you want to proceed?"; then
52 echo "I: Need to install $package to run $command"
54 #[ "x$ai_install_cmd_terminal" = xyes ] \
55 # && cmd="/usr/bin/xterm -e /bin/bash -c '$cmd'"
56 cmd="${ai_install_cmd//@PACKAGE@/$package}"
57 #/usr/bin/gksudo "/usr/bin/aptitude install -y $package" > /tmp/nd-autoinstall.log 2>&1
58 # debconf has a nice debconf-apt-progress but it would require
59 # root access to each of commands for little benefit
61 # . /usr/share/debconf/confmodule
62 # debconf-apt-progress --start
63 # debconf-apt-progress --from 0 --to 100 -- apt-get -y install $package
64 # debconf-apt-progress --from 45 --to 90 -- apt-get -y install kde
65 # debconf-apt-progress --from 90 --to 100 -- apt-get -y install xfce4
66 # debconf-apt-progress --stop
68 logfile=$(mktemp -u /tmp/nd-autoinstall-XXXXXX.log)
69 # * aptitude for some reason does not return fail exit code
70 # * bloody gksudo swallows all stderr output (#599233) :-/
71 # So we just initiate it first to get the password
72 { /usr/bin/gksudo ls > /dev/null; }
73 # and then revert to sudo
74 # and enforce a GNOME front-end since otherwise things might go wrong
75 # and there is no way to enforce just some GUI frontend
76 { /usr/bin/sudo DEBIAN_FRONTEND=gnome /usr/bin/apt-get install -y $package 2>&1 \
77 && rm -f $logfile; } \
79 | zenity --title="Installing $package" --progress --pulsate --auto-close --auto-kill
80 if [ -e $logfile ] ; then
81 zenity --title="Installation of $package has failed: see $logfile" \
82 --window-icon=error --timeout=60 \
83 --width=800 --height=600 \
84 --text-info --filename=$logfile
89 echo "I: Running $command"