Skip to main content

I'm trying to run a script to check first if a file is already on the mac I want it to quit, and if the file is not on the mac to go ahead and install it.

At the moment I have a policy that copy the file to /tmp/CB/file.pkg than it gets installed.
( file.pkg gets installed into "/Applications/file.pkg")
But I want it to skip install if the file.pkg is already installed on the "/Applications/file.pkg"

I told you it was basic =)

this is what I have so far:

#!/bin/sh
installer -pkg /tmp/CB/file.pkg -target /

Many examples available online for "bash if" (and other conditional statements)

#!/bin/bash

pkgDir="/tmp/CB/file.pkg"

if [ -d $pkgDir ]; then 
    do this 
else
    do that 
fi

that was fast! thank you.
one last question I want it to exit if the file is on the /tmp/CD/file.pkg and install if its not there....does the "exit" looks correct? (do I need a "exit 0" or "exit 1")?

thank you very much!

#!/bin/bash

pkgDir="/tmp/CB/file.pkg"

if [ -d $pkgDir ]; then 
    exit
else
   installer -pkg /tmp/CB/file.pkg -target /
fi

You're on the right track, and yes, ideally you'll want to use the appropriate exit code


got it thank you again!


Would probably use -e unless that's a non-flat PKG.


A few comments:

  • Good idea to save resources and not do the transfer and install if not needed.

  • Instead of running the script again and again, just to find out the package is already there you could make a smart group that contains the devices that don't have the package installed, and run it only on these.

  • Non-zero exit codes usually indicate that an error occurred. It is useful to stick to that convention and don't use non-zero exit codes to signal something else.

  • A package in /Applications? Sounds weird to me.

Cheers,

Matthias


@mschroder thank you for your comments =)

yes you are right a package in Applications doesn't make sense =) I didn't explain it correctly, so the package gets download it to /tmp/CD/file.pkg than the scripts run the installer and what it actually happens the file.pkg installs the application into /Applications =)

I will also try your suggestion on using a smart group.

Thank you very much!