mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 11:33:13 +00:00
104 lines
2.8 KiB
Bash
Executable file
104 lines
2.8 KiB
Bash
Executable file
#!/bin/bash -e
|
|
#
|
|
# script/bottle
|
|
# mas
|
|
#
|
|
# Builds bottles of mas Homebrew formula for custom tap:
|
|
# https://github.com/mas-cli/homebrew-tap
|
|
#
|
|
|
|
################################################################################
|
|
#
|
|
# Variables
|
|
#
|
|
|
|
BUILD_DIR="$PWD/build"
|
|
BOTTLE_DIR="$BUILD_DIR/bottles"
|
|
VERSION=$(script/version)
|
|
ROOT_URL="https://dl.bintray.com/phatblat/mas-bottles"
|
|
|
|
# Supports macOS versions 11.0 (arm64 & x86_64), 10.15, 10.14, 10.13, 10.12, 10.11
|
|
# NOTE: The built bottle will have the *current* macOS name, which is why the
|
|
# latest is first in the list (aka ${OS_VERSIONS[0]})
|
|
# TODO: Add support for arm64_big_sur
|
|
OS_VERSIONS=(big_sur catalina mojave high_sierra sierra el_capitan)
|
|
|
|
# Output filename from build-bottle command
|
|
OLD_FILENAME="mas--${VERSION}.${OS_VERSIONS[0]}.bottle.tar.gz"
|
|
|
|
################################################################################
|
|
#
|
|
# Preflight checks
|
|
#
|
|
|
|
# Ensure core formula isn't shadowed by custom tap
|
|
brew tap --list-pinned | grep mas-cli/tap && brew tap-unpin mas-cli/tap
|
|
|
|
# Uninstall if necessary
|
|
if brew ls --versions mas >/dev/null; then
|
|
brew uninstall mas
|
|
fi
|
|
|
|
# Uninstall if still found on path
|
|
if command -v mas >/dev/null; then
|
|
script/uninstall || true # ignore failure
|
|
fi
|
|
|
|
# Purge the Carthage cache to avoid this error from Homebrew sandboxing:
|
|
# A shell task (/usr/bin/env git checkout --quiet --force 0.15.0 (launched in /Users/ben/Library/Caches/org.carthage.CarthageKit/dependencies/Commandant)) failed with exit code 128:
|
|
# fatal: Unable to create '/Users/ben/Library/Caches/org.carthage.CarthageKit/dependencies/Commandant/./index.lock': Operation not permitted
|
|
rm -rf ~/Library/Caches/org.carthage.CarthageKit
|
|
|
|
################################################################################
|
|
#
|
|
# Build the formula for the current macOS version and architecture.
|
|
#
|
|
|
|
echo "==> 🍼 Bottling mas ${VERSION} for: ${OS_VERSIONS[*]}"
|
|
brew install --build-bottle mas
|
|
|
|
# Generate bottle do block, dropping last 2 lines
|
|
brew bottle --verbose --no-rebuild --root-url=$ROOT_URL mas
|
|
SHA256=$(shasum --algorithm 256 "${OLD_FILENAME}" | cut -f 1 -d ' ' -)
|
|
|
|
mkdir -p "$BOTTLE_DIR"
|
|
|
|
# Start of bottle block
|
|
BOTTLE_BLOCK=$(
|
|
cat <<-EOF
|
|
bottle do
|
|
root_url "$ROOT_URL"
|
|
EOF
|
|
)
|
|
|
|
################################################################################
|
|
#
|
|
# Copy the bottle for all macOS version + architecture combinations.
|
|
#
|
|
|
|
# Fix filename
|
|
for os in ${OS_VERSIONS[*]}; do
|
|
new_filename="mas-${VERSION}.${os}.bottle.tar.gz"
|
|
cp -v "${OLD_FILENAME}" "${BOTTLE_DIR}/${new_filename}"
|
|
|
|
# Append each os
|
|
# BOTTLE_BLOCK="$(printf "${BOTTLE_BLOCK}\n sha256 cellar: :any, %-15s %s" "${os}:" "${SHA256}")"
|
|
BOTTLE_BLOCK="$BOTTLE_BLOCK"$(
|
|
cat <<-EOF
|
|
|
|
sha256 cellar: :any, $os: "$SHA256"
|
|
EOF
|
|
)
|
|
done
|
|
|
|
# End of bottle block
|
|
BOTTLE_BLOCK=$(
|
|
cat <<-EOF
|
|
|
|
end
|
|
EOF
|
|
)
|
|
|
|
rm "${OLD_FILENAME}"
|
|
ls -l "${BOTTLE_DIR}"
|
|
echo "${BOTTLE_BLOCK}"
|