LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to get user to agree to EULA in bash script? (https://www.linuxquestions.org/questions/programming-9/how-to-get-user-to-agree-to-eula-in-bash-script-4175441390/)

aus9 12-13-2012 11:17 PM

how to get user to agree to EULA in bash script?
 
Hi

I intend to write a package, actually its a tinycore package that encloses an EULA from a third party.

its a text file.

I lack the skills on how to enforce the reader to read the text and then type "I accept" and "reject"

2) It would be handy that this script also produces a file such as
/home/yourname/EULA/accepted (or rejected)

That way, I can make a simple if-then script that searches for this new file.
-if accepted found....do some work
-if rejected found....call up aterm or some terminal and re-submit the EULA to the end user

Any clues greatly appreciated

As my skills are not so great to ask, feel free to be verbose

cheers

Gordon

grail 12-14-2012 11:42 AM

I am not sure I understand the complexities :( Surely you write an if to check for the files, if none get response and if file perform appropriate task.

So is your question that you do not know how to do an 'if' in bash?

aus9 12-14-2012 09:27 PM

deleted later post

grail 12-15-2012 04:51 AM

hmmmm ... well there are a few issues but the most glaring would be an assumption you have made:
Code:

# if here, agreement confirmed
/usr/local/bin/pepper

As the only exit in the entire code is on checking for the root user (testing $USER may need to be looked at), the above is completely wrong as nothing
else stops you from getting here.

aus9 12-20-2012 12:59 AM

Thanks lets try mark II

aus9 12-20-2012 01:02 AM

re-wrote as

Code:

#!/bin/sh                                                 
if [ "$USER" == "root" ] ; then                           
  echo "Run as non-root please, exiting."                   
  exit 1                                                   
  fi                                                         

# set the local user to $THISUSER                         
THISUSER=`cat /etc/sysconfig/tcuser`                       

echo "This plugin has an EULA that needs your consent"     
echo "if you use it, you grant consent as well"           
echo "after reading the agreement please close the browser"
/bin/sleep 6                                               
chromium-browser /usr/local/share/doc/pepper/eula_text.html
echo "Do you accept the EULA? type  yes  or no  please"   
read input                                               

if [ $input = yes ] ; then                                 
# agreement confirmed                                     
# refresh OR create agreement file status                 
rm -r -f /home/$THISUSER/.pepper                           
mkdir /home/$THISUSER/.pepper                             
touch -f /home/$THISUSER/.pepper/agreed                   
  else                                                   
  echo "agreement refused, exitting"                     
  rm -r -f /home/$THISUSER/.pepper                       
  exit 1                                                 
  fi


grail 12-20-2012 05:48 AM

Well starting at the top, I would probably use the 'id' command instead of the variable as someone may set it on the command line to something else (if we assume someone is being naughty).

I am not understanding the point of the THISUSER? What I mean is, unless you are root you will not be able to go into another user's account (generally) so if
it is in 'this user' , ie the logged in user, why not simply use $USER, id or even '~' (synonym for home directory)??

I am next a little dubious about firing off a browser, does the accepting of the agreement close the browser?

You are testing your 'input' variable against a set string, "yes", what if the user enters "y" or "Yes"?

Irrelevant of the user's reply yuou do the following:
Code:

rm -r -f /home/$THISUSER/.pepper
I have 2 issues here:

1. If it is a given this will always occur then simply do it prior to testing 'input'

2. You never check to see if the directory actually exists and in the case of the 'else', ie likely the first time this has been run and the says "no", the user will now be presented with an error
from rm saying no such directory

Hope some of this helps :)

NyteOwl 12-20-2012 02:08 PM

Frankly, trying to do EULA install enforcement in a shell script is kind of pointless since it's so easy to bypass.


All times are GMT -5. The time now is 06:44 AM.