Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

msharp

macrumors regular
Original poster
Jul 10, 2004
212
9
hi everyone I'm actually a newbie in programming for a mac. I've currently done something and just wanna make an installer(yes, I know about the "Drag&Drop" installation, but this isn't applicable for my apps since during the installation there're some script jobs needs to be done).
I knew that the installer can run scripts(referred as "postflight" etc in the documentation), but I simply can't make it run successfully after several failures.

several questions here:
1.How to make a text file a script file?
I've written a bash script, and saved it as test.sh, and chmod +x test.sh, and I can run it under Terminal, but under the finder it was described as a text file, instead of "Unix Executable".

2.How to make the script run after the installer copying files to the destination?
There's nothing about this in the documentation provided by apple. I've tried to name the script file as "postflight" and "preflight"(just as the samples in the documentation), but no luck at all. When I named it as "postflight", the installer turned out to be failed after its file copy. I can see nothing but "Can't run the script" in the install log.

3.My script include something that request administrator privilege, how to do that?
I've checked the "Require administrator privilege" checkbox in the installer wizard, but it didn't prompted me to enter my password during my tests. Is that because my script didn't run?
How to make my script run with administrator privilege? Do I have to write something like "sudo ****" instead of the original commands?





Thanks everyone!
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
I was just working on this and I got it working. I'm pretty much a noob at this stuff too. So here are a few things (out of order):

Question 2: Check a few things:
a. Your script should start with something like this:
#!/bin/bash​
It doesn't have to be bash, but it should have something like that.

b. You are right to name it "postflight" -- all lower case, no extension

c. Make sure it is getting in to your package correctly. Build your package and then control click on it and choose "Show Package Contents." go into Contents/Resources. Is postflight there? Check its permissions with the terminal. Does it have execute permissions? The Apple docs say PackageMaker will automatically give scripts that it includes in your package execute permissions, but it didn't for me--I set them on the source script and package maker did maintain them with it copied the script during the build. (Hmmm, maybe I need to set the file type correctly.)

d. Are your script line-endings correct? I use BBEdit with I have set to use DOS line endings for new files. I have to remember to save my new script files with Unix line endings. I can change that in the "save as" dialog under the options button. I assume TextWrangler is the same. Other text editors may vary. If your script is running under the terminal correctly then this isn't the problem.

e. Try a simple script first:
#!/bin/bash
echo "here i am"
exit 0​
If this works, but your script causes the install to fail, then you know the script is getting called, but you script is failing. Use lots of echos, which you can view in the install log.

Question 3: You do want to have your installer require administrator privileges. The installer didn't prompt you for your admin password because you were already logged in to an account with admin privileges. Create a more restricted account to test your installer with. ALSO: There are additional implications to having your installer require admin privliges: All the files you install have to have a standard user and group. Typically you want call "chown -R root:admin <install root>" before building your installer. Read Apple's "Software Deployment" docs for more info.

Question 1: You don't need to change the type of the file to get it to work with the installer. If you do want to change it, you can use the command line utility "/Developer/Tools/SetFile" or some other utility. You need to know what type to change it to (I don't konw--I guess find a file with the type you want and use "/Developer/Toos/GetFileInfo") These utilities are installed with the developer tools, but if you are using PackageMaker, you obviously probably already have that installed.

I hope this helps...
 

msharp

macrumors regular
Original poster
Jul 10, 2004
212
9
iSee said:
I was just working on this and I got it working. I'm pretty much a noob at this stuff too. So here are a few things (out of order):

Question 2: Check a few things:
a. Your script should start with something like this:
#!/bin/bash​
It doesn't have to be bash, but it should have something like that.

b. You are right to name it "postflight" -- all lower case, no extension

c. Make sure it is getting in to your package correctly. Build your package and then control click on it and choose "Show Package Contents." go into Contents/Resources. Is postflight there? Check its permissions with the terminal. Does it have execute permissions? The Apple docs say PackageMaker will automatically give scripts that it includes in your package execute permissions, but it didn't for me--I set them on the source script and package maker did maintain them with it copied the script during the build. (Hmmm, maybe I need to set the file type correctly.)

d. Are your script line-endings correct? I use BBEdit with I have set to use DOS line endings for new files. I have to remember to save my new script files with Unix line endings. I can change that in the "save as" dialog under the options button. I assume TextWrangler is the same. Other text editors may vary. If your script is running under the terminal correctly then this isn't the problem.

e. Try a simple script first:
#!/bin/bash
echo "here i am"
exit 0​
If this works, but your script causes the install to fail, then you know the script is getting called, but you script is failing. Use lots of echos, which you can view in the install log.

Question 3: You do want to have your installer require administrator privileges. The installer didn't prompt you for your admin password because you were already logged in to an account with admin privileges. Create a more restricted account to test your installer with. ALSO: There are additional implications to having your installer require admin privliges: All the files you install have to have a standard user and group. Typically you want call "chown -R root:admin <install root>" before building your installer. Read Apple's "Software Deployment" docs for more info.

Question 1: You don't need to change the type of the file to get it to work with the installer. If you do want to change it, you can use the command line utility "/Developer/Tools/SetFile" or some other utility. You need to know what type to change it to (I don't konw--I guess find a file with the type you want and use "/Developer/Toos/GetFileInfo") These utilities are installed with the developer tools, but if you are using PackageMaker, you obviously probably already have that installed.

I hope this helps...


thanks so much for your help, and I'll give it a try as soon as possible! thank you very much!!!
 

msharp

macrumors regular
Original poster
Jul 10, 2004
212
9
thanks man! it worked for me, too!

thank you all the way!!!!!!!!!
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
msharp said:
thanks man! it worked for me, too!

thank you all the way!!!!!!!!!

You're welcome... I was just dealing with the same problems, so I felt your pain... Anywaym what was the thing that fixed it for you?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.