Verification on shell script

hello i have writing a shell script to download and run some packages
the only way that i use to verify download pack is , limit users ip to download from main server, if wget can download file (verified) then script run by execute it sh pack76.sh
else show and error

(stupid solution ha?)

if [ $answer = y ]; then
	cd $INSTALLDIR
	wget $MIRROR/pack76.sh
	if [ -f $INSTALLDIR/pack76.sh ]
	then
		sh pack76.sh
	else
		echo -e "$RED you dont have permition to download $RESET"
	fi
fi

any idea ?

I am not sure I understand what you mean by

What are you trying to download and from where?
Also, I see a few problems with your code, for example:

$answer = y

is an assignment statement and won't return a boolean value (True or False), which is what you seem to need here.
Second, here

	if [ -f $INSTALLDIR/pack76.sh ]
	then
		sh pack76.sh
	else
		echo -e "$RED you dont have permition to download $RESET"
	fi

You are checking for the existence of the file pack76.sh (what is this supposed to do and what are its contents, by the way?) and if it doesn't exist you are echoing a message saying that the user doesn't have permission to perform the download operation - I believe you should have checked for permissions along with existence.
But I'm afraid I can't tell for sure just by looking at the code snippet you included in your post.
Please provide more details and a concise explanation of what you're trying to accomplish, along with the source code that you're already tried and any problems you may have encountered in the process.

tnq gacanepa

i have copy part of my code that need to open this topic,
ok let me explain how i have verify :
i have add .htaccess on $mirror so if untruest machine send request to download package,only allow ip which add on .htaccess will permit to download,
i will add ips manually.

then if command will check, is file download and exist or not
if wget coud download file (allow) yes, it will open package and compile it, else, it will show warning
main part of verification is :

wget $MIRROR/pack76.sh
	if [ -f $INSTALLDIR/pack76.sh ]
	then
		sh pack76.sh
	else
		echo -e "$RED you dont have permition to download $RESET"
	fi

I insist that checking the existence of a file is not the best way to allow or deny its execution.
What I would do is wget the file, then if that command completed successfully I'd start the download operation, otherwise I'd show the error message, more like so:

wget $MIRROR/pack76.sh
	if [ $? == 0 ]
	then
		sh pack76.sh
	else
		echo -e "$RED The download cannot be performed $RESET"
	fi

Hope it helps.

1 Like

I get the point of the thread owner..., what I dont understand is since he knows who are allowed ( IP list...) why not test if you are allowed to download?

1 Like

mm i want to publish my script so i need verification method to know who use this script
i have not find any solution to encode-decode shell scripting so i use ip restriction by allow and deny

---------- Post updated at 02:18 PM ---------- Previous update was at 02:12 PM ----------

good idea
so shell scripting do not have any protection like i need?
so what shell programmer do?

[ $answer = y ]

is not an assignment, and works with all sh-type shells.
But eventually give a test syntax error when $answer is empty or multi-word. Safe is

[ "$answer" = y ]

While

[ "$answer" == y ]

is an extension of the test command - not portable.

you right, but i main question is about verification and security
i have write that code without get any output just to explain my method to verificationn by check existing file
do you have any idea to verify user, any source code protection ?

You could create a group and integrate in the groupe those allowed to use your script which yould be in a directory ony accessible to a user (specific) and by using sudo allowing to that group to su that user...