Visual Studio Code Install

markacorum
New Contributor II

Just putting this out to share since deploying software via Jamf apps have been very flakey for me lately. I am by no means a scripting expert so feel free to make changes or offer any refinement, so far it does what I want it to do, downloads the universal zip file for VS Code, Unzips it, moves it to Applications, trusts the app, and then deletes the install folder for the secure temp folder.

 

#!/bin/sh
pkgfile="VSCode-darwin-universal.zip"
tmpDir=$(/usr/bin/mktemp -d "/tmp/VSCode-install.XXXXXX") 
logfile="/Library/Logs/VSCodeInstallScript.log"
url='
https://code.visualstudio.com/sha/download?build=stable&os=darwin-universal'
/bin/echo "--" >> ${logfile}
/bin/echo "`date`: Downloading latest version." >> ${logfile}
/usr/bin/curl -L -o ${tmpDir}/${pkgfile} ${url} 
/bin/echo "`date`: Installing..." >> ${logfile}
cd ${tmpDir}
tar xvfz VSCode-darwin-universal.zip
/bin/sleep 5
mv "${tmpDir}/Visual Studio Code.app" "/Applications/Visual Studio Code.app"
/bin/echo "`date`: Deleting package installer." >> ${logfile}
rm -rf "${tmpDir}"
#Bless VS Code
xattr -rc "/Applications/Visual Studio Code.app"
exit 0
5 REPLIES 5

pete_c
Contributor III

You might consider adding a `codesign` check to verify that your download is authentic:

/usr/bin/codesign -dvv /path/to/Visual\ Studio\ Code.app

# expected values:
#
# Developer ID Application: Microsoft Corporation (UBF8T346G9)
# TeamIdentifier=UBF8T346G9

markacorum
New Contributor II

thanks Ill check it out!

dvasquez
Valued Contributor

I have seen that after the Visual Studio Code was updated it fails to open, as of recent.

I will test your script and get back to you on the effectiveness. 

Thank you!

image.png

dvasquez
Valued Contributor

Initially, I received these when testing your script, see screenshots. I then simply added a line to the script to remove before installation and all went well. After that, I removed the line and tried again and all was ok.  I think I am still going with MacApps as the issue with Visual Studio Code seems to be resolved for us. 

Screenshot 2023-10-11 at 3.52.28 PM.pngScreenshot 2023-10-11 at 3.52.37 PM.png

markacorum
New Contributor II

I had one similar to this last week with Xcode, for some reason it was showing as installed in my ~/Applications folder which was weird and had to manually uninstall it. I still cant find an approved process from my security team to deploy Xcode because my users refuse to be on the current version at any time, and also not allow local admin rights.