Skip to content

Instantly share code, notes, and snippets.

@brunerd
Created October 28, 2019 17:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save brunerd/6a0104cab32c0c372653555b072a98db to your computer and use it in GitHub Desktop.
Repack expired packages and strip off certs
#!/bin/bash
#Joel "brunerd" Bruner - repack and expired pkg, stripping off all certs
#we can specify a target as an argument
target="$1"
#if target not specified we ask
while [ ! -d "${target}" -a ! -f "${target}" ]; do
read -p "Please provide a target file or folder: " target
done
#if directory get all the pkg files inside
if [ -d "${target}" ]; then
fileList=$(find "${target}" -name '*pkg')
else
fileList="${target}"
fi
#ignore spaces and only respect newlines in for loop
IFS=$'\n'
#got through each file
for file in ${fileList}; do
#expand the pkg to folder with the extension removed
pkgutil --expand "${file}" "${file%.*}"
#flatten the package with "-repack.pkg" appended to the name
pkgutil --flatten "${file%.*}" "${file%.*}"-repack.pkg
#delete the expanded temp folder
rm -rf "${file%.*}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment