homebrew/script/app-to-cask.sh
2025-03-17 22:27:18 +13:00

45 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Assign arguments to variables
APP_FILE=$1
S3_BUCKET="https://dl.breadone.xyz/cask" # prod
# S3_BUCKET="https://dl.breadone.xyz/homebrew/casks" # staging
# get reported version of app, remove quotes, print just the version
version=$(mdls -name kMDItemVersion "$APP_FILE" | tr -d '"' | awk '{print $3}')
# just the app file name, eg Things3.app
FILENAME=$(basename "$APP_FILE")
# remove extension, eg Things3
APPNAME="${FILENAME%.app}"
APPNAME_TRIM=$(echo $APPNAME | sed 's/^[^=]*= //; s/"//g' | tr ' ' '-') # replace spaces with dashes
# interpolate to final zip name, eg Things3-3.12.5.zip
ZIP_PATH="$APPNAME_TRIM-$version.zip"
# Compress the file
ditto -c -k --sequesterRsrc --keepParent "$APP_FILE" $ZIP_PATH
# Get hash of file
hash=$(sha256 $ZIP_PATH | awk '{ print $4 }')
# Upload the .app file to the specified S3 bucket
curl -X PUT "$S3_BUCKET/$ZIP_PATH" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$ZIP_PATH"
# output (mostly complete) cask file
echo 'cask "'$(echo "$APPNAME_TRIM" | tr '[:upper:]' '[:lower:]')'" do' # lowercase appname
echo ' version "'$version'"'
echo ' sha256 "'$hash'"'
echo ''
echo ' url "'$S3_BUCKET/$ZIP_PATH'"'
echo ' name "'$APPNAME'"'
echo ' desc "ENTER_DESCRIPTION"'
echo ' homepage "ENTER_HOMEPAGE"'
echo ''
echo ' app "'$FILENAME'"'
echo 'end'
rm $ZIP_PATH