mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-08 05:31:53 +00:00
first experimental version of buildCaseStatement
This commit is contained in:
72
buildCaseStatement.sh
Executable file
72
buildCaseStatement.sh
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/sh
|
||||
|
||||
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
||||
|
||||
downloadURL=${1?:"need to provide a download URL"}
|
||||
|
||||
# Note: this tool _very_ experimental and does not work in many cases
|
||||
|
||||
|
||||
# create temporary working directory
|
||||
tmpDir=$(mktemp -d )
|
||||
|
||||
# change directory to temporary working directory
|
||||
echo "Changing directory to $tmpDir"
|
||||
if ! cd "$tmpDir"; then
|
||||
echo "error changing directory $tmpDir"
|
||||
#rm -Rf "$tmpDir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# download the dmg
|
||||
echo "Downloading $downloadURL"
|
||||
if ! curl --location --fail --silent "$downloadURL" --remote-header-name --remote-name; then
|
||||
echo "error downloading $downloadURL"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
archivePath=$(find $tmpDir -print )
|
||||
archiveName=${archivePath##*/}
|
||||
name=${archiveName%.*}
|
||||
archiveExt=${archiveName##*.}
|
||||
identifier=$(echo $name | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
if [ "$archiveExt" = "pkg" ]; then
|
||||
teamID=$(spctl -a -vv -t install "$archiveName" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' )
|
||||
elif [ "$archiveExt" = "dmg" ]; then
|
||||
# mount the dmg
|
||||
echo "Mounting $archiveName"
|
||||
if ! dmgmount=$(hdiutil attach "$archiveName" -nobrowse -readonly | tail -n 1 | cut -c 54- ); then
|
||||
echo "Error mounting $archiveName"
|
||||
exit 3
|
||||
fi
|
||||
echo "Mounted: $dmgmount"
|
||||
# check if app exists
|
||||
|
||||
appPath=$(find "$dmgmount" -name "*.app" -maxdepth 1 -print )
|
||||
|
||||
# verify with spctl
|
||||
echo "Verifying: $appPath"
|
||||
if ! teamID=$(spctl -a -vv "$appPath" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' ); then
|
||||
echo "Error verifying $appPath"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
hdiutil detach "$dmgmount"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo " $identifier)"
|
||||
echo " name=\"$name\""
|
||||
echo " type=\"$archiveExt\""
|
||||
echo " downloadURL=\"$downloadURL\""
|
||||
echo " teamID=\"$teamID\""
|
||||
echo " ;;"
|
||||
echo
|
||||
|
||||
if [ -e "${tmpDir}" ]; then
|
||||
#echo "deleting tmp dir"
|
||||
rm -rf "${tmpDir}"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user