Skip to content

Instantly share code, notes, and snippets.

@einsteinx2
Last active June 17, 2022 20:31
Show Gist options
  • Save einsteinx2/de098f2211e727575528eaa79dc200c4 to your computer and use it in GitHub Desktop.
Save einsteinx2/de098f2211e727575528eaa79dc200c4 to your computer and use it in GitHub Desktop.
Script to properly code sign Fluid web apps to prevent various issues due to macOS security checks (requires Apple developer account)
#!/bin/bash
# View xattrs: `xattr -lr SomeApp.app`
# Confirm signature: `spctl -a -v SomeApp.app`
# Print signature information (Fluid apps have a signature but it's invalid): `codesign -dv --verbose=4 SomeApp.app`
# NOTE: I seem to get this error, but it doesn't affect usage in any way:
# "SomeApp.app: invalid resource directory (directory or signature have been modified)"
# Information used to create this script:
# https://stackoverflow.com/questions/18441268/codesign-app-file-in-command-line
# https://developer.apple.com/library/archive/qa/qa1940/_index.html
# https://www.oreilly.com/library/view/modding-mac-os/0596007094/ch04s05.html
# https://osxdaily.com/2016/03/14/verify-code-sign-apps-mac-os-x/
# Terminal font formatting
FONT_RESET=$(tput sgr0)
FONT_BOLD=$(tput bold)
# Help text
HELP="
${FONT_BOLD}Usage:${FONT_RESET} $(basename $0) SomeApp.app
Fluid apps have broken code signing by default, which can cause some issues
with things like LittleSnitch not saving firewall rules after app restarts
and various other problems.
This script will resign the app with a valid release build developer ID.
${FONT_BOLD}App Icon Instructions:${FONT_RESET}
NOTE: This should only be necessary if Fluid fails to embed one automatically, like with Google sites
1. First create an app icon using svg2icns
a. Find an SVG version of the icon online
b. Use Pixelmator Pro to crop extra whitespace and then make the canvas square with the icon centered
c. Run \`svg2icns Icon.svg\` to generate the \`Icon.icns\` icon bundle
2. Add the icon bundle to the Fluid app
a. Copy the icns file to \`Contents/Resources\` inside the app bundle and rename if desired
b. Modify the \`Contents/Info.plist\` file inside the app bundle and add the following key/value pair:
<key>CFBundleIconFile</key>
<string>Icon.icns</string>
3. Run this script on the app bundle to sign it: \`$(basename $0) SomeApp.app\`
4. Copy the newly signed app to \`/Applications\` and enjoy!
"
# Hard coded certificate name (TODO: Add an argument to override this)
# NOTE: To find the name of your certificate, open the "Keychain Access"
# app and view the "My Certificates" category
CERT_NAME="Apple Distribution: Benjamin Baron (7596YH3S97)"
# Check for argument
if [[ $# -ne 1 ]] ; then
printf "$HELP\n"
exit 1
fi
# Remove xattrs or it won't sign correctly
xattr -cr "$1"
# Re-sign the app bundle
codesign --force -s "$CERT_NAME" -v "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment