Remove package identifier file during installation - macos

I'm a newbie in OSx development.
I'm creating an installer package using Packagemaker 3.0.4. Since I want to remove the local settings of my app during installation, I decided to remove the com.identifier.plist. However, I'm not that good in scripting and I'm just starting to explore what Packagemaker is capable of.
Ideally, I want my implementation to be as simple as this:
Check if the .plist file exists
Remove it.
I have tried:
#!/bin/sh
defaults delete ~/Library/Preferences/com.identifier.AppName.plist
Then I saved the delete.sh file to the Desktop. I opened the Packagemaker app and provided the path to my Desktop: /Users/MyName/Desktop/delete.sh in the Scripts Postflight. Then I executed build & run. It didn't work. I thought that it might probably be the script, so I changed it to:
#!/bin/sh
rm ~/Library/Preferences/com.identifier.AppName.plist;
Then I loaded the delete.sh file the same way as I did on the script above. But I received this error:
Mar 29 20:50:54 Mac-mini installd[5425]: PackageKit: Install Failed: PKG: post-flight scripts for "com.testIdentifier.test.AppName.pkg"\nError Domain=PKInstallErrorDomain Code=112 UserInfo=0x100404220 "An error occurred while running scripts from the package “test.pkg”." {\n NSFilePath = "./postflight";\n NSLocalizedDescription = "An error occurred while running scripts from the package \U201ctest.pkg\U201d.";\n NSURL = "./Contents/Packages/test.pkg -- file://localhost/Users/MyName/Desktop/AppName.mpkg/";\n PKInstallPackageIdentifier = "com.testIdentifier.test.AppName.pkg";\n}
If anyone who has a Step-by-Step implementation of creating & adding script to the Packagemaker, and perhaps, my scripts aren't correct, it would be awesome if you could help me out.
Thank you so much in advance! :)

Did you try to launch your delete.sh from terminal? Looks like you have an error in syntax - ';' at the end of the rm command, and you should use -f flag for the rm command (see man rm) in other case script will prompt for confirmation and postflight script can't be interactive.
Edit: as 一二三 mentioned semicolon - is not the point, you should probably look to his answer. And before you'll create your package just try your script in terminal (you can do sudo su before to login as root)

I've got it...
Here's my script:
#!/usr/bin/env bash
file=~/Library/Preferences//com.identifier.AppName.plist
if [ -e "$file" ]
then
# file is found
/usr/bin/defaults delete ~/Library/Preferences//com.identifier.AppName
else
# file not found."
fi
exit 0
I then added it to PackageMaker. I'm not really sure if I'm right but I might have just forgotten to add the script's file into the contents. That's why it never worked earlier. I just put the script's path on the postflight.
Anyway, thanks a lot to everyone for the tips.

Related

Make shell script change script location

I have currently put together a script to move files from one directory to another.
This has gone ok however I was wondering if there was a way via a shell script to get it to run from anywhere on the server e.g I give the script for someone to use on their server and they can put the script anywhere and it will run.
I know a workaround is to put the script in /usr/local/bin or usr/bin and you can run it from anywhere but that is not what I want.
Is there a way that my script will auto run from usr/local/bin regardless of if it is in /scripts for instance?
Please see my script below:
#!/bin/sh -x
mkdir -p /var/Alitest
echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required" > /var/Alitest/action.txt
sed -i 's/This is a test that I have created/The test has been successful/g' /var/Alitest/action.txt
chmod 744 /var/Alitest/action.txt
chown root:root Alitest/action.txt
mv /var/Alitest/action.txt /script/action.txt
Any help would be greatly appreciated :)
Also in my log output for the script the following error is shown:
sed: 1: "/var/Alitest/action.txt": invalid command code A
Any ideas?
You can make a soft link in /usr/local/bin for your script. Then it will be in everyone's path to be executed.
e.g. ln -s /script/yourscript.sh /usr/local/bin/yourscript.sh
After reviewing the matter further I have decided the the best way to action this is to add the folder destination e.g /scripts to my path.
This can be done by vimming into the .bashrc file on the server and adding the below line:
export PATH=/dir_name:$PATH
remember to refresh the profile in order for the changes to take effect.
You can check if this has been successful by running the below command:
echo $PATH
There is no way to get your script to do this however this would be better then a softlink as if you add it to $PATH then you do not have to go through the task of adding softlinks each time.
Thank you all for your help.
Kind Regards
Ali

install4j: Executing bash file

I am trying to run a bash file from install4j6. install4j does indeed try to run the bash file but it just returns an error at the end of the installation. The error is very generic and has no code reference or anything that will help me determine a solution - just a message that says "Error while executing file."
The only thing I can provide is how I have it setup in install4j6 since I am pretty sure that's my issue.
The bash file is defined in the root of my installation directory distribution tree and is named set_permissions.sh. For the sake of eliminating permissions being a cause, the file permission mode is set to 777 (both in install4j and on the file system).
I believe the issue is related to what I have set as my "working directory". I currently have it set to just ".". Is there a way to debug this further? Maybe get an actual error as to why it's not executing?
Ok, first a few things to check:
make sure that you're running the batch file after the install files step (you mention it being at the root of your install)
best to have the wait for termination checked and a variable for the return code.
redirect stderr to the log file (just in case)
As for working directory, . should work, but you can change it to ${installer:sys.installationDir} to make sure that it references the installation directory chosen by the user. You can also set the executable in the form of ${installer:sys.installationDir}\set_permissions.sh
Also, try and run just your shell script to make sure that it works :)

-bash: sencha command not found

I installed Sencha SDK and Sencha command on my mac-mini and done with some sample app.. but suddenly after some time when I tried to run sencha command on terminal, I got the response as '-bash: sencha command not found', I don't know why this was happened. Earlier I didn't find such type of response but now I got this error. Please tell me what are the possible scenarios for this thing to be happened.. Thanks for your help
Alens-Mac-mini:touch-2.2.0 SenchaTools$ sencha
-bash: sencha: command not found
You should procede that way:
Verify if this command is contained in PATH. PATH is an environment variable holded by bash and initialized when a new user is logged in (.bash_profile file for all user and the corrispective into home for single user). So check what echo $PATH told you and verify if this command is contained into those folder
Probably, from step 1, the answer will be "No, it isn't". So you have to procede this way: use whereis command to search this command (that will be an executable script) and once you find it, you have two possibilities: one is to use it directly by specifying full path (returned from whereis command).
If you want to run simply it with sencha -arguments you have to add executable path returned by whereis ($PATH=$PATH:/returned/path/by/whereis) into file .bash_profile
In that way you should be able to execute your command from any "point" in your filesystem
The Sencha installer expects you to use bash as shell. It fails, if you use any other (like the nice zsh). You need to copy the content of .bash_profile to your shell startup-file (.zprofile in my case), save it and open a new terminal window.
Add PATH and VAR manually in .bash_profile file at the root of your user folder,
export SENCHA_CMD_3_0_0="/Users/you/Path/To/Sencha/Cmd/3.0.0.XXX"
export PATH=/Users/you/Path/To/Sencha/Cmd/3.0.0.188:$PATH
Find out more about this issue at sencha forum https://www.sencha.com/forum/showthread.php?245243-Command-not-found-mac-OSX-mountain-lion

How to set up system path for Ruby?

I am doing prep work for app academy. The final stage before I am done with my prep work is to complete a ruby intro course called "Test First Ruby".
The first line after you install Rspec is to enter the course directory. In the terminal it is "cd learn_ruby", simple enough, except it returns back a message that says "the system cannot find the path specified". I have been noticing this message on certain commands for all of my ruby learning thus far and I am just wondering what does this mean? And how can I fix this?
Any help would be great.
cd means 'change directory'. The error you are getting is that the directory is not existant in the location your command line is in.
This looks like a reasonable intro to UNIX filesystem: http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture2.html
UNIX reference: http://sunsite.utk.edu/UNIX-help/quickref.html
Create the directory before you cd into it:
mkdir learn_ruby
cd learn_ruby
Do check out AJcodez's links to familiarize yourself with Unix filesystem commands.

Why can't Cygwin CVS read the CVS password file in a Ruby/Perl script?

On the Windows command line and cygwin bash I can execute the following without problems:
cvs login
cvs -Q log -N -rVersion_01_00
A ruby script in the same directory contains the following:
`cvs login`;
`cvs -Q log -N -rVersion_01_00`;
When I execute the ruby script on the Windows command line I get the following error:
cvs log: warning: failed to open /cygdrive/c/Documents and Settings/za100744/.cvspass for reading: No such file or directory
If I run the script in a cygwin bash shell I get the same output I would as when I type in the commands manually.
I have no idea as to what is going wrong. The path generated by the Ruby script is wrong since it is a cygwin path but it works correctly directly on the command line. I use cvs that came as part of cygwin:
which cvs
cvs is an external : C:\cygwin\bin\cvs.exe
Ruby is the one-click installer version:
which ruby
/cygdrive/c/Ruby/bin/ruby
It seems like cvs under Ruby can not resolve /cygdrive/c to c: but works OK from the cmdline.
Perl gives me exactly the same problem.
my $str = "cvs -Q log -N -r$cvs_tag|";
open(CVS_STATUS, $str) or die "\n##ERROR##";
It looks like either CVS can't create the file, or your path is wrong. Does the file .cvspass exist? If not, this page suggests you try creating an empty .cvspass file and then run your command. e.g. do
touch ~/.cvspass
If this doesn't help, then the problem is probably path related. There are a few possibilities; $HOME not set correctly, your home dir not matching what's in \etc\passwd, etc. See this tutorial for some troubleshooting steps that should help pin down the problem.
Using a windows native compiled CVS solves the problem. It is not ideal since I have to send a cvs executable with the script for users that has cygwin CVS but its better than nothing.
We had several problems with unix-, mixed- and windows-style paths in cygwin based perl scripts and built-in tools such as rsync. E.g. rsync can't handle wind-style paths. Use the tool "cygpath.exe" to adjust them correctly. Maybe it's the cause.

Resources