No printlog function so echo it is

This commit is contained in:
Theile
2022-09-21 08:43:31 +02:00
parent e6088a2eda
commit 5b39697bf8

View File

@@ -47,92 +47,92 @@ fi
# swiftDialog installation # swiftDialog installation
name="Dialog" name="Dialog"
printlog "$name check for installation" echo "$name check for installation"
# download URL, version and Expected Team ID # download URL, version and Expected Team ID
# Method for GitHub pkg w. app version check # Method for GitHub pkg w. app version check
gitusername="bartreardon" gitusername="bartreardon"
gitreponame="swiftDialog" gitreponame="swiftDialog"
#printlog "$gitusername $gitreponame" #echo "$gitusername $gitreponame"
filetype="pkg" filetype="pkg"
downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)"
if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then
printlog "Trying GitHub API for download URL." echo "Trying GitHub API for download URL."
downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }")
fi fi
#printlog "$downloadURL" #echo "$downloadURL"
appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g')
#printlog "$appNewVersion" #echo "$appNewVersion"
expectedTeamID="PWA5E9TQ59" expectedTeamID="PWA5E9TQ59"
destFile="/Library/Application Support/Dialog/Dialog.app" destFile="/Library/Application Support/Dialog/Dialog.app"
versionKey="CFBundleShortVersionString" #CFBundleVersion versionKey="CFBundleShortVersionString" #CFBundleVersion
currentInstalledVersion="$(defaults read "${destFile}/Contents/Info.plist" $versionKey || true)" currentInstalledVersion="$(defaults read "${destFile}/Contents/Info.plist" $versionKey || true)"
printlog "${name} version: $currentInstalledVersion" echo "${name} version: $currentInstalledVersion"
if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then
printlog "$name not found or version not latest." echo "$name not found or version not latest."
printlog "${destFile}" echo "${destFile}"
printlog "Installing version ${appNewVersion}" echo "Installing version ${appNewVersion}"
# Create temporary working directory # Create temporary working directory
tmpDir="$(mktemp -d || true)" tmpDir="$(mktemp -d || true)"
printlog "Created working directory '$tmpDir'" echo "Created working directory '$tmpDir'"
# Download the installer package # Download the installer package
printlog "Downloading $name package version $appNewVersion from: $downloadURL" echo "Downloading $name package version $appNewVersion from: $downloadURL"
installationCount=0 installationCount=0
exitCode=9 exitCode=9
while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do
curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true)
curlDownloadStatus=$(echo $?) curlDownloadStatus=$(echo $?)
if [[ $curlDownloadStatus -ne 0 ]]; then if [[ $curlDownloadStatus -ne 0 ]]; then
printlog "error downloading $downloadURL, with status $curlDownloadStatus" echo "error downloading $downloadURL, with status $curlDownloadStatus"
printlog "${curlDownload}" echo "${curlDownload}"
exitCode=1 exitCode=1
else else
printlog "Download $name succes." echo "Download $name succes."
# Verify the download # Verify the download
teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true)
printlog "Team ID for downloaded package: $teamID" echo "Team ID for downloaded package: $teamID"
# Install the package if Team ID validates # Install the package if Team ID validates
if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then
printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." echo "$name package verified. Installing package '$tmpDir/$name.pkg'."
pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1)
pkgInstallStatus=$(echo $?) pkgInstallStatus=$(echo $?)
if [[ $pkgInstallStatus -ne 0 ]]; then if [[ $pkgInstallStatus -ne 0 ]]; then
printlog "ERROR. $name package installation failed." echo "ERROR. $name package installation failed."
printlog "${pkgInstall}" echo "${pkgInstall}"
exitCode=2 exitCode=2
else else
printlog "Installing $name package succes." echo "Installing $name package succes."
exitCode=0 exitCode=0
fi fi
else else
printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." echo "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid."
exitCode=3 exitCode=3
fi fi
fi fi
((installationCount++)) ((installationCount++))
printlog "$installationCount time(s), exitCode $exitCode" echo "$installationCount time(s), exitCode $exitCode"
if [[ $installationCount -lt 3 ]]; then if [[ $installationCount -lt 3 ]]; then
if [[ $exitCode -gt 0 ]]; then if [[ $exitCode -gt 0 ]]; then
printlog "Sleep a bit before trying download and install again. $installationCount time(s)." echo "Sleep a bit before trying download and install again. $installationCount time(s)."
printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" echo "Remove $(rm -fv "$tmpDir/$name.pkg" || true)"
sleep 2 sleep 2
fi fi
else else
printlog "Download and install of $name succes." echo "Download and install of $name succes."
fi fi
done done
# Remove the temporary working directory # Remove the temporary working directory
printlog "Deleting working directory '$tmpDir' and its contents." echo "Deleting working directory '$tmpDir' and its contents."
printlog "Remove $(rm -Rfv "${tmpDir}" || true)" echo "Remove $(rm -Rfv "${tmpDir}" || true)"
# Handle installation errors # Handle installation errors
if [[ $exitCode != 0 ]]; then if [[ $exitCode != 0 ]]; then
printlog "ERROR. Installation of $name failed. Aborting." echo "ERROR. Installation of $name failed. Aborting."
caffexit $exitCode caffexit $exitCode
else else
printlog "$name version $appNewVersion installed!" echo "$name version $appNewVersion installed!"
fi fi
else else
printlog "$name version $appNewVersion already found. Perfect!" echo "$name version $appNewVersion already found. Perfect!"
fi fi
# check for Swift Dialog # check for Swift Dialog