]> git.donarmstrong.com Git - neurodebian.git/blob - tools/nd-autoinstall
NF: basic version of nd-autoinstall -- wrapper for the menu item calls
[neurodebian.git] / tools / nd-autoinstall
1 #!/bin/bash
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:
4
5 # play save
6 set -e
7 set -u
8
9 ############
10 # Defaults #
11 ############
12
13 # Not used atm
14 #ai_install_cmd="/usr/bin/gksudo '/usr/bin/aptitude install -y @PACKAGE@'"
15 #ai_install_cmd_terminal=no
16
17
18 print_help()
19 {
20 cat << EOT
21
22 Usage:  nd-autoinstall <package> <command> [<command_options>]
23
24 Runs the <command> if it is available, otherwise installs <package>
25 first, and then runs the command.
26
27 Exit status:
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
32 EOT
33 }
34
35 # Possible options: --environment-file  to source prior even 'which'
36
37 if [ $# -lt 2 ] ; then
38     echo "ERROR: Incorrect invocation" >&2
39     print_help >&2
40     exit 2
41 fi
42
43 package=$1; shift
44 command=$1; shift
45
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
49         exit 2
50     fi
51
52     echo "I: Need to install $package to run $command"
53     #cmd=$ai_install_cmd
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
60     #
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
67
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; } \
78         | tee $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
85         exit 3
86     fi
87 fi
88
89 echo "I: Running $command"
90 $command "$@"