Skip to content
Snippets Groups Projects
show_solutions 2.01 KiB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
#! /bin/bash

function possible_solutions {
Pietro Incardona's avatar
Pietro Incardona committed
 sol=1
 echo "Possible solutions:"
 for com in "$@"
 do
   echo "$sol $com"
   sol=`expr $sol + 1`
 done
Pietro Incardona's avatar
Pietro Incardona committed
 sol_sk=$sol
 echo "$sol continue"
 sol=`expr $sol + 1`
Pietro Incardona's avatar
Pietro Incardona committed
 echo "$sol exit the script"
Pietro Incardona's avatar
Pietro Incardona committed
 echo -e "\033[1;34;5mChoose the solution:\033[0m"
i-bird's avatar
i-bird committed
 if [ $sq -eq 1 ]; then
i-bird's avatar
i-bird committed
   if [ -f default_choice ]; then
i-bird's avatar
i-bird committed
     choose=$(cat default_choice)
   else
     echo "No solution choosen, continue ... "
     return
   fi
i-bird's avatar
i-bird committed
 else
   read choose
 fi
Pietro Incardona's avatar
Pietro Incardona committed
 if [ x"$choose" = x"$sol" ]; then
  exit 1
 fi
Pietro Incardona's avatar
Pietro Incardona committed
 if [ x"$choose" = x"$sol_sk" ]; then
  return
 fi
Pietro Incardona's avatar
Pietro Incardona committed
 possible_solutions_ret=`expr $choose - 1`
 echo "Executing: ${command[$possible_solutions_ret]}"
 if [ -a input_install ]; then
   eval ${commands[$possible_solutions_ret]} < input_install
 else
   eval ${commands[$possible_solutions_ret]}
 possible_solutions_command=${commands[$possible_solutions_ret]}
Pietro Incardona's avatar
Pietro Incardona committed
function possible_solutions_no_continue {

Pietro Incardona's avatar
Pietro Incardona committed

 sol=1
 echo "Possible solutions:"
 for com in "$@"
 do
   echo "$sol $com"
   sol=`expr $sol + 1`
 done
 echo "$sol exit the script"
 echo -e "\033[1;34;5mChoose the solution:\033[0m"
 read choose
 if [ x"$choose" = x"$sol" ]; then
  exit 1
 fi
 possible_solutions_ret=`expr $choose - 1`
 echo "Executing: ${command[$possible_solutions_ret]}"
 if [ -a input_install ]; then
   eval ${commands[$possible_solutions_ret]} < input_install
 else
   if [ x"${commands[$possible_solutions_ret]}" != x"Accept and continue" ]; then
     eval ${commands[$possible_solutions_ret]}
   fi
Pietro Incardona's avatar
Pietro Incardona committed
 fi
 possible_solutions_command=${commands[$possible_solutions_ret]}
}

function possible_solutions_no_execute {

 if [ $sq -eq 1 ]; then
   return
 fi

 sol=1
 echo "Possible solutions:"
 for com in "$@"
 do
   echo "$sol $com"
   sol=`expr $sol + 1`
 done
 echo "$sol exit the script"
 echo -e "\033[1;34;5mChoose the solution:\033[0m"
 read choose
 if [ x"$choose" = x"$sol" ]; then
  exit 1
 fi
 possible_solutions_ret=`expr $choose - 1`
 possible_solutions_command=${commands[$possible_solutions_ret]}
}