homebrew/script/app-to-cask.sh

42 lines
1.2 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
APP_NAME="${FILENAME%.app}"
# interpolate to final zip name, eg Things3-3.12.5.zip
ZIP_PATH="$APP_NAME-$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 "$APP_NAME" | tr '[:upper:]' '[:lower:]')'" do' # lowercase appname
echo ' version "'$version'"'
echo ' sha256 "'$hash'"'
echo ''
echo ' url "'$S3_BUCKET/$ZIP_PATH'"'
echo ' name "'$APP_NAME'"'
echo ' desc "ENTER_DESCRIPTION"'
echo ' homepage "ENTER_HOMEPAGE"'
echo ''
echo ' app "'$FILENAME'"'
echo 'end'