X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=tools%2Fnd-autoinstall;h=1f2896d4f13312ea24790c31a24f223c9f10c4bc;hb=HEAD;hp=2b5e2b4f0b3a918a8707eed082959ac406a2b856;hpb=18ae101a9085311664d4b87fb7c57795c6302b59;p=neurodebian.git diff --git a/tools/nd-autoinstall b/tools/nd-autoinstall index 2b5e2b4..1f2896d 100755 --- a/tools/nd-autoinstall +++ b/tools/nd-autoinstall @@ -2,7 +2,7 @@ #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*- #ex: set sts=4 ts=4 sw=4 et: -# play save +# play safe set -e set -u @@ -12,14 +12,13 @@ set -u nd_autoinstall_version=0.1 -# Not used atm -#ai_install_cmd="/usr/bin/gksudo '/usr/bin/aptitude install -y @PACKAGE@'" -#ai_install_cmd_terminal=no - # To be set by cmdline args ai_envfile= ai_package= ai_verbose= +ai_dialog_title= +ai_force=0 +ai_file= print_verbose() { @@ -64,9 +63,19 @@ Options: File to be sourced before invocation of the COMMAND. If not found, PACKAGE gets installed first. + -f, --force + Skip all checks and install package(s) provided via --package. + + -F, --file=FILE + If specified file is not present, install the PACKAGE and run + the COMMAND. + -v, --verbose Enable additional progress messages. + -t, --title + Optinal title of the installation dialog. + -h, --help Print short description, usage summary and option list. @@ -90,7 +99,7 @@ EOT # Note that we use `"$@"' to let each command-line parameter expand to a # separate word. The quotes around `$@' are essential! # We need CLOPTS as the `eval set --' would nuke the return value of getopt. -CLOPTS=`getopt -o h,e:,p:,v --long help,version,environment-file:,package:,verbose, -n 'nd-autoinstall' -- "$@"` +CLOPTS=`getopt -o h,e:,p:,t:,f,F:,v --long help,version,environment-file:,package:,title:,verbose,force,file: -n 'nd-autoinstall' -- "$@"` if [ $? != 0 ] ; then echo "Terminating..." >&2 @@ -102,8 +111,11 @@ eval set -- "$CLOPTS" while true ; do case "$1" in - -e|--environment-file) shift; ai_envfile=$1; shift;; - -p|--package) shift; ai_package=$1; shift;; + -e|--environment-file) shift; ai_envfile="$1"; shift;; + -f|--force) ai_force=1; shift;; + -F|--file) shift; ai_file="$1"; shift;; + -p|--package) shift; ai_package="$1"; shift;; + -t|--title) shift; ai_dialog_title="$1"; shift;; -v|--verbose) ai_verbose=1; shift;; -h|--help) print_help; exit 0;; --version) print_version; exit 0;; @@ -118,49 +130,63 @@ if [ $# -lt 1 ] ; then exit 2 fi -ai_command=$1; shift -[ -z "$ai_package" ] && ai_package=$ai_command +ai_command="$1"; shift +[ -z "$ai_package" ] && ai_package=$(basename "$ai_command") + +[ -z "$ai_dialog_title" ] && ai_dialog_title="Package installation" ai_envfile_failed= if [ ! -z "$ai_envfile" ]; then source "$ai_envfile" || ai_envfile_failed=1 fi -if [ ! -z "$ai_envfile_failed" ] || ! which $ai_command >/dev/null; then - if ! zenity --question \ - --text="To run '$ai_command', $ai_package package needs to be installed. Do you want to proceed?"; then - exit 2 - fi +# +# Decide either installation is necessary +# +do_install=0 +if [ ! -z "$ai_envfile_failed" ]; then + print_verbose "Environment file $ai_envfile failed to source. Install $ai_package" + do_install=1 +fi +if [ ! -z "$ai_file" ] && [ ! -e "$ai_file" ]; then + print_verbose "File $ai_file absent. Install $ai_package" + do_install=1 +fi +if ! which "$ai_command" > /dev/null && [ ! -e "$ai_command" ]; then + print_verbose "Command $ai_command is not available. Install $ai_package" + do_install=1 +fi +if [ $ai_force -eq 1 ]; then + print_verbose "Force installation of $ai_package" + do_install=1 +fi + +if [ $do_install -eq 1 ]; then + # Figure out amount of space to download/occupy + space_info="$(LC_ALL=C apt-get --trivial-only --print-uris install $ai_package 2>/dev/null \ + | grep -e '^\(Need to get \|After this\)' || : )" + if [ $ai_force -eq 0 ]; then + if ! zenity --question \ + --text="To run '$ai_command', $ai_package package needs to be installed. + +$space_info + +Do you want to proceed?"; then + exit 2 + fi + fi print_verbose "Need to install $ai_package to run $ai_command" - #cmd=$ai_install_cmd - #[ "x$ai_install_cmd_terminal" = xyes ] \ -# && cmd="/usr/bin/xterm -e /bin/bash -c '$cmd'" - cmd="${ai_install_cmd//@PACKAGE@/$ai_package}" - #/usr/bin/gksudo "/usr/bin/aptitude install -y $ai_package" > /tmp/nd-autoinstall.log 2>&1 - # debconf has a nice debconf-apt-progress but it would require - # root access to each of commands for little benefit - # - # . /usr/share/debconf/confmodule - # debconf-apt-progress --start - # debconf-apt-progress --from 0 --to 100 -- apt-get -y install $ai_package - # debconf-apt-progress --from 45 --to 90 -- apt-get -y install kde - # debconf-apt-progress --from 90 --to 100 -- apt-get -y install xfce4 - # debconf-apt-progress --stop logfile=$(mktemp -u /tmp/nd-autoinstall-XXXXXX.log) - # * aptitude for some reason does not return fail exit code - # * bloody gksudo swallows all stderr output (#599233) :-/ - # So we just initiate it first to get the password - { /usr/bin/gksudo ls > /dev/null; } - # and then revert to sudo - # and enforce a GNOME front-end since otherwise things might go wrong - # and there is no way to enforce just some GUI frontend - { /usr/bin/sudo DEBIAN_FRONTEND=gnome /usr/bin/apt-get install -y $ai_package 2>&1 \ + + { SUDO_ASKPASS="/usr/bin/ssh-askpass" /usr/bin/sudo -A \ + DEBIAN_FRONTEND=gnome /usr/bin/apt-get install -y $ai_package 2>&1 \ && rm -f $logfile; } \ | tee $logfile \ - | zenity --title="nd-autoinstall" \ - --text="Installing $ai_package" \ + | zenity --title="$ai_dialog_title" \ + --text="Installing $ai_package +$space_info" \ --progress --pulsate --auto-close --auto-kill if [ -e $logfile ] ; then zenity --title="Installation of $ai_package has failed: see $logfile" \ @@ -176,5 +202,8 @@ if [ ! -z "$ai_envfile_failed" ] || ! which $ai_command >/dev/null; then } fi -print_verbose "Running $ai_command" -$ai_command "$@" +if which $ai_command > /dev/null 2>&1; then + # only run if executable + print_verbose "Running $ai_command" + $ai_command "$@" +fi