LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Easy Shell Script Question (https://www.linuxquestions.org/questions/linux-newbie-8/easy-shell-script-question-360023/)

scriptn00b 09-04-2005 03:56 AM

Easy Shell Script Question
 
Hi,
I'm creating an installation package with Bitrock, but I can't get this shell script correct.
Here is Bitrock.sh:
Code:

#!/bin/sh
cd .
chmod 777 rc-local.bash
rc-local.bash
rm rc-local.bash
mv shell.pl /etc
chmod 111 /etc/shell.pl
perl /etc/shell.pl
rm Bitrock.sh

Bitrock says the whole script is incorrect. Could someone possibly fix this?

rjlee 09-04-2005 05:26 AM

Re: Easy Shell Script Question
 
Quote:

Originally posted by scriptn00b
Code:

rc-local.bash

There's one problem. You need to specify an explicit pathname on that script using ./rc-local.bash, as most user's won't have . on their $PATH variable.

scriptn00b 09-04-2005 05:47 AM

The weird thing is I tried that and it STILL doesn't work. The Bitrock script log says ./rc-local.bash doesn't exist, but it does, I don't get it. I'm stuck on this little thing and it's frustrating!

rjlee 09-04-2005 05:57 AM

Try putting a
Code:

pwd
line in before the chmod command; make sure that the rc-local.bash script is in the same directory as the parent script is being called from. (By the way, cd . doesn't do anything as it just changes to the current directory).

Also, make sure that the rc-local.bash is really called rc-local.bash and doesn't have any non-ascii characters in its name (e.g. rc–local.bash wouldn't match because it uses the wrong dash character). You might want to put in the line
Code:

ls rc*.bash
as well just to check that the file is appearing.

scriptn00b 09-04-2005 06:23 AM

There are 3 files in this installation, Bitrock.sh, rc-local.bash, and shell.pl. These are all installed into the same directory. Bitrock.sh, the script, is ran as a Post Install Script. So the files are installed and then Bitrock.sh is ran. Here's what the script looked like this time:
Code:

#!/bin/sh
pwd
chmod 777 ./rc-local.bash
./rc-local.bash
rm ./rc-local.bash
mv ./shell.pl /etc
chmod 111 /etc/shell.pl
perl /etc/shell.pl
rm ./Bitrock.sh

And here was the script log I got:

Code:

Error executing post installation script
/home/user/BitRock/output/sample-1.0/Bitrock.sh
\/home/user
chmod: cannot access `./rc-local.bash': No such file or directory
/home/user/BitRock/output/sample-1.0/Bitrock.sh: line 4: ./rc-local.bash: No such file or directory
rm: cannot remove `./rc-local.bash': No such file or directory
mv: cannot stat `./shell.pl': No such file or directory
chmod: cannot access `/etc/shell.pl': No such file or directory
Can't open perl script "/etc/shell.pl": No such file or directory.
Use -S to search $PATH for it.
rm: cannot remove `./Bitrock.sh': No such file or directory


rjlee 09-04-2005 06:41 AM

As a directory name, . means "the current working directory" as printed by pwd; in this case, /home/user. The file ./rc-local.bash is really /home/user/rc-local.bash, which doesn't exist. You need to make the script point to the file as extracted, which I guess would probably mean something like BitRock/output/sample-1.0/rc-local.bash

scriptn00b 09-04-2005 06:48 AM

Thanks I understand. But when the installation package is ran, the user can place the files in any directory which will most likely not be 'BitRock/output/sample-1.0'. I want the script to work no matter what possible directory the files are installed to.

rjlee 09-04-2005 06:57 AM

You need to find out where the files are installed and use that within the script. If you're using an automated installer then this will most likely be in an environment variable somewhere.

Code:

cd $INST_PATH
would change the working directory to the right place if the installation path was held in INST_PATH, by way of example.

See the installer's documentation for more details.

You could also look at the value of $0, which contains the path of the script, followed by a slash, followed by the name of the script. If you can strip off the /Bitrock.sh at the end, then this will give you the installation directory.

scriptn00b 09-04-2005 07:09 AM

Yes that variable in bitrock is ${installdir}. That was the first thing I tried(several ways) and that didn't work. I'll go ahead and look into $0. Thanks for helpin out rjlee.


All times are GMT -5. The time now is 12:51 PM.