LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   args or questions in a shell script which is easyer (http://www.linuxquestions.org/questions/linux-newbie-8/args-or-questions-in-a-shell-script-which-is-easyer-496347/)

hoodedmanwithsythe 10-28-2006 08:51 AM

args or questions in a shell script which is easyer
 
Hi,
I am creating a shell script that will save some blender users a lot of time at the moment I have 2 separate scripts the 64 bit version and the 32 bit version the script basically loads the PYTHONPATH and then runs blender but what i wan't to do is have only one script that asks you wether or not your system is 64Bit and if the default command for blender is what you wish to use.
The script currently looks like this
Code:

#!/bin/sh
    PATH=/usr/ucb:/usr/bin:/bin; export PATH
# setting Python Directory
echo "Setting PYTHONPATH for 64Bit OS"
export PYTHONHOME=/lib64/python2.4
export PYTHONPATH=/lib64/python2.4
set $PYTHONHOME /lib64/python2.4
set $PYTHONPATH /lib64/python2.4
# loading blender
echo "Running Blender"
/usr/bin/blender

What I was wondering is wether I should use questions or arguments for this and how would i do this?
I realise that scripting at this level may not be classed as a :newbie: thing so i am sorry if i have placed this in the wrong area of this forum

uselpa 10-28-2006 08:59 AM

I think that you can find out if the system is 64 bits without asking at all. Like checking if there is a /lib64/ directory.

Generally speaking, I'd suggest args or command-line switches because this allows you to use your script from another script.

So
- the best option is to find out yourself (if possible)
- the second best option is to use args
- the last resort would be an interactive question.

frob23 10-28-2006 09:55 AM

I have to agree with uselpa. If it asks questions, and I'm unable to edit it to accept args instead, then I'm going to need to write an expect script or something if I want to have a default. There seems to be many ways to know the 64 bit answer instead of needing args so you can use those instead.

If there was no way to tell, then you could always define a default value and have a shell variable choose the different path. Much like $EDITOR does. It defaults to vi in most applications if not defined but if defined then the programs will use the editor you want and don't need to prompt you or anything for it.

makyo 10-28-2006 10:07 AM

Hi.

If you cannot determine about the 64-bit, you may be able to automate using either arguments or an interactive question. If you are called with STDIN being re-directed, you could assume non-interactive, in which case you might look for arguments, otherwise ask a question.

For example:
Code:

#!/bin/sh

# @(#) s2      Demonstrate test for interactive use.

if tty -s
then
        echo " YES! Interactive use."
        exit 0
else
        echo " Not interactive."
        exit 0
fi

And a driver:
Code:

#!/bin/sh

# @(#) s1      Drive test for interactive use.

./s2

touch t2
./s2 <t2

Running the driver produces:
Code:

% ./s1
 YES! Interactive use.
 Not interactive.

Best wishes ... cheers, makyo

hoodedmanwithsythe 10-28-2006 12:28 PM

64bit detection
 
Ok,
I like the idea of auto detection as i have seen this done before if i recall it has something to do with the system locale so I will start my search for info on this grounds there using the locale command.
any help would be greatly appreciated.
secondly I have no idea on how to put args in to my script,I could do with some help for this part please.

thanks for the suggestions guys

hoodedmanwithsythe 10-28-2006 12:30 PM

Quote:

Originally Posted by hoodedmanwithsythe
Ok,
I like the idea of auto detection as i have seen this done before if i recall it has something to do with the system locale so I will start my search for info on this grounds there using the locale command.
any help would be greatly appreciated.
secondly I have no idea on how to put args in to my script,I could do with some help for this part please.

thanks for the suggestions guys

red=wrong I think I will keep searching I have read about this some where

uselpa 10-28-2006 12:34 PM

I don't have a 64bit processor, but try uname. On my P4:
Code:

pu@slackw:~$ uname -p
pentium4
pu@slackw:~$ uname -i
i386


hoodedmanwithsythe 10-28-2006 12:46 PM

Quote:

Originally Posted by uselpa
I don't have a 64bit processor, but try uname. On my P4:
Code:

pu@slackw:~$ uname -p
pentium4
pu@slackw:~$ uname -i
i386


close but no cigar mmy 64bit mandrake says:
Code:

timothy@Linux-Box ~$ uname -p
AMD Athlon(tm) 64 Processor 3200+
timothy@Linux-Box ~$ uname -i
unknown

I need something that works on all linux machines without fail

uselpa 10-28-2006 12:49 PM

Code:

pu@slackw:~$ cat /proc/cpuinfo
processor      : 0
vendor_id      : GenuineIntel
cpu family      : 15
model          : 2
model name      : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping        : 9
cpu MHz        : 2810.351
cache size      : 512 KB
fdiv_bug        : no
hlt_bug        : no
f00f_bug        : no
coma_bug        : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 2
wp              : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe up cid xtpr
bogomips        : 5624.91


hoodedmanwithsythe 10-28-2006 12:58 PM

Quote:

Originally Posted by uselpa
Code:

pu@slackw:~$ cat /proc/cpuinfo
processor      : 0
vendor_id      : GenuineIntel
cpu family      : 15
model          : 2
model name      : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping        : 9
cpu MHz        : 2810.351
cache size      : 512 KB
fdiv_bug        : no
hlt_bug        : no
f00f_bug        : no
coma_bug        : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 2
wp              : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe up cid xtpr
bogomips        : 5624.91


Code:

cat /proc/cpuinfo
processor      : 0
vendor_id      : AuthenticAMD
cpu family      : 15
model          : 31
model name      : AMD Athlon(tm) 64 Processor 3200+
stepping        : 0
cpu MHz        : 2200.236
cache size      : 512 KB
fpu            : yes
fpu_exception  : yes
cpuid level    : 1
wp              : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow lahf_lm
bogomips        : 4358.14
TLB size        : 1024 4K pages
clflush size    : 64
cache_alignment : 64

address sizes  : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp

on this our systems are simmilar but on yours i cannot see the 64/32 bit defineing sections higlited on mine in red text

hoodedmanwithsythe 10-28-2006 01:00 PM

Maby if i were to runn a seek on these variables, but how

unSpawn 10-28-2006 01:01 PM

How about taking hints from FOSS?
Rootkit Hunter uses the distributions release file.
Get Rootkit Hunter then do a "grep 64\) os.dat".

hoodedmanwithsythe 10-28-2006 01:17 PM

Quote:

Originally Posted by unSpawn
How about taking hints from FOSS?
Rootkit Hunter uses the distributions release file.
Get Rootkit Hunter then do a "grep 64\) os.dat".

This would require a compiled program that was written in source not in shell and so is not possible sorry but I had already looked at this option.
thinking back to the idea of checking for the /lib64 directory this could solve all problems and no args or other detection would be needed provided that we can find a way of detecting the existance of both that and the blender binarythen the rest would simply be else and elif strings

hoodedmanwithsythe 10-28-2006 04:54 PM

a new idea
 
ok so while trying various things I thought there has to be an easy way of checking the platform type.
I had tried all the obvious and all of the ideas above and came to no end. so when i finally got board of trying various techniques including;
Code:

find /lib64/python2.4 >$HOME/python.lock
if [ "$HOME/Python.lock" = "/lib64/python2.4/*" ]
then etc...

I decided to google for "shell script" and guess what the fist item was "Advanced Bash-Scripting Guide" "An in-depth exploration of the art of shell scripting"
When flicking through it's pages i came across "9.1. Internal Variables" intreagued i scrolled down to find "$HOSTTYPE"
host type

Like $MACHTYPE, identifies the system hardware.

Code:

bash$ echo $HOSTTYPE
i686

and so I ran this on my machine and it came up
Code:

[timothy@Linux-Box ~]$ echo $HOSTTYPE
x86_64

So I thought and then i tested it on my 32bit machine
Code:

[timothy@Slow-Linux-Box ~]$ echo $HOSTTYPE
i386

So it turns out that bash has a builtin platform checker, so i guess it is time for me to get working on the final coding of my blender starter program.

hoodedmanwithsythe 10-28-2006 06:39 PM

Finished
 
Ok what I have Finaly Decided to do is use the forgotten about built in
Code:

$HOSTTYPE
system variable in a bog standard
Code:

if [ "<Attribute1>" = "<Attribute2>" ]
then <run this>

layout for my PYTHONPATH preloader for blender. At the moment I am going to stick to a simple version of my preloader that doesn't check the python version nor does it check the location of the Blender Wrapper Script.
The reason for this is that I have not worked out how to check the version of python other than with the python -V command(which I cannot channle the output of) and the reason for not checking where the blender Shell Script is because i have made a icon for my preloader and have also made a .desktop for it so as the preloader will now need to reside in /usr/bin or wherever your Blender Wrapper Script (/usr/bin/ is standard location for static versions of blender)resides.

here is my final release of the code
Code:

#!/bin/bash
    PATH=/usr/ucb:/usr/bin:/bin; export PATH
# checking the platform
echo "checking Platform"
echo "Platform is "$HOSTTYPE
if [ "$HOSTTYPE" = "x86_64" ]
then        #Checking Python Directory
        echo "Setting PYTHONPATH for 64Bit OS"
        export PYTHONHOME=/usr/lib64/python2.4
        export PYTHONPATH=/usr/lib64/python2.4
        # loading blender
        echo "Running Blender"       
        ./blender

else        # setting Python Directory
        echo "Setting PYTHONPATH for a 32Bit OS"
        export PYTHONHOME=/usr/lib/python2.4
        export PYTHONPATH=/usr/lib/python2.4
        # loading blender
        echo "Running Blender"
        ./blender

fi
exit

here is where you can download it from


All times are GMT -5. The time now is 04:55 AM.