I’m having some problems running a script file. I have two scripts – one works, one doesn’t. The one that doesn’t work was created by pulling lines out of the first script and modifying them to install a different program.
The script install_latest_flash_player.sh reaches out to Adobe’s website to find the URL to the latest version of Flash Player, then downloads it and installs it. This script works fine.
The script install_latest_shockwave_recopy.sh downloads the latest Shockwave DMG and installs it. The path to the latest installer does not change for Shockwave, so I stripped out the version checking. I also removed the lines relating to checking the OS version, as I’m not concerned that any of my Macs will have an old OS on them.
When I run the script to install Shockwave, the computer returns “command not found” errors for any line that isn’t an actual command (such as setting variables). If I run all of the commands manually in terminal the process works.
Some google searching found this - http://superuser.com/questions/291361/command-not-found-when-running-a-shell-script-what-did-i-break but I don't know how to use that information to fix my script, or why the original script works when it doesn't seem to call out anything different than the script I made.
Can anyone shed some light on this?
Here are the two scripts.
install_latest_flash_player.sh:
#!/bin/sh
# This script downloads and installs the latest Flash player for compatible Macs
# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
# Determine current major version of Adobe Flash for use
# with the fileURL variable
flash_major_version=`/usr/bin/curl --silent http://fpdownload2.macromedia.com/get/flashplayer/update/current/xml/version_en_mac_pl.xml | cut -d , -f 1 | awk -F" '/update version/{print $NF}'`
# Specify the complete address of the Adobe Flash Player
# disk image
fileURL="http://fpdownload.macromedia.com/get/flashplayer/current/licensing/mac/install_flash_player_"$flash_major_version"_osx_pkg.dmg"
# Specify name of downloaded disk image
flash_dmg="/tmp/flash.dmg"
if [[ ${osvers} -lt 6 ]]; then
echo "Adobe Flash Player is not available for Mac OS X 10.5.8 or below."
fi
if [[ ${osvers} -ge 6 ]]; then
# Download the latest Adobe Flash Player software disk image
/usr/bin/curl --output "$flash_dmg" "$fileURL"
# Specify a /tmp/flashplayer.XXXX mountpoint for the disk image
TMPMOUNT=`/usr/bin/mktemp -d /tmp/flashplayer.XXXX`
# Mount the latest Flash Player disk image to /tmp/flashplayer.XXXX mountpoint
hdiutil attach "$flash_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
# Install Adobe Flash Player from the installer package stored inside the disk image
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.pkg -o -iname *.mpkg ))" -target "/"
# Clean-up
# Unmount the Flash Player disk image from /tmp/flashplayer.XXXX
/usr/bin/hdiutil detach "$TMPMOUNT"
# Remove the /tmp/flashplayer.XXXX mountpoint
/bin/rm -rf "$TMPMOUNT"
# Remove the downloaded disk image
/bin/rm -rf "$flash_dmg"
fi
exit 0
install_latest_shockwave_recopy.sh:
#!/bin/sh
# This script downloads and installs the latest Flash player for compatible Macs
# Specify the complete address of the Adobe Flash Player
# disk image
fileURL="http://fpdownload.macromedia.com/get/shockwave/default/english/macosx/latest/Shockwave_Installer_Full_64bit.dmg"
# Specify name of downloaded disk image
flash_dmg="/tmp/shockwave.dmg"
# Download the latest Adobe Flash Player software disk image
/usr/bin/curl --output "$flash_dmg" "$fileURL"
# Specify a /tmp/shockwave.XXXX mountpoint for the disk image
TMPMOUNT=`/usr/bin/mktemp -d /tmp/shockwave.XXXX`
# Mount the latest Shockwave disk image to /tmp/shockwave.XXXX mountpoint
hdiutil attach "$flash_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
# Install Adobe Shockwave from the installer package stored inside the disk image
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.pkg -o -iname *.mpkg ))" -target "/"
# Clean-up
# Unmount the Flash Player disk image from /tmp/shockwave.XXXX
/usr/bin/hdiutil detach "$TMPMOUNT"
# Remove the /tmp/shockwave.XXXX mountpoint
/bin/rm -rf "$TMPMOUNT"
# Remove the downloaded disk image
/bin/rm -rf "$flash_dmg"
fi
exit 0