mirror of
https://github.com/mas-cli/mas
synced 2024-11-24 20:43:10 +00:00
141 lines
3.7 KiB
Bash
Executable file
141 lines
3.7 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://github.com/mas-cli/mas/releases/download/v${VERSION}"
|
|
|
|
# Supports macOS 10.11 and later
|
|
OS_NAMES=(arm64_monterey monterey arm64_big_sur big_sur catalina mojave high_sierra sierra el_capitan)
|
|
|
|
# Semantic version number split into a list using Ugly, bash 3 compatible syntax
|
|
IFS=" " read -r -a CURRENT_OS_VERSION <<<"$(sw_vers -productVersion | sed 's/\./ /g'))"
|
|
CURRENT_OS_VERSION_MAJOR=${CURRENT_OS_VERSION[0]}
|
|
CURRENT_OS_VERSION_MINOR=${CURRENT_OS_VERSION[1]}
|
|
|
|
echo "CURRENT_OS_VERSION_MAJOR: $CURRENT_OS_VERSION_MAJOR"
|
|
echo "CURRENT_OS_VERSION_MINOR: $CURRENT_OS_VERSION_MINOR"
|
|
|
|
if [[ ${CURRENT_OS_VERSION_MAJOR} == "12" ]]; then
|
|
if [[ "x86_64" == "$(uname -m)" ]]; then
|
|
CURRENT_PLATFORM=monterey
|
|
else
|
|
CURRENT_PLATFORM=arm64_monterey
|
|
fi
|
|
elif [[ ${CURRENT_OS_VERSION_MAJOR} == "11" ]]; then
|
|
# Big Sur
|
|
if [[ "x86_64" == "$(uname -m)" ]]; then
|
|
CURRENT_PLATFORM=big_sur
|
|
else
|
|
CURRENT_PLATFORM=arm64_big_sur
|
|
fi
|
|
elif [[ ${CURRENT_OS_VERSION_MAJOR} == "10" && ${CURRENT_OS_VERSION_MINOR} == "15" ]]; then
|
|
CURRENT_PLATFORM=catalina
|
|
else
|
|
echo "Unsupported macOS version. This script requires Catalina or better."
|
|
exit 1
|
|
fi
|
|
|
|
echo "CURRENT_PLATFORM: ${CURRENT_PLATFORM}"
|
|
|
|
# Output filename from build-bottle command
|
|
OLD_FILENAME="mas--${VERSION}.${CURRENT_PLATFORM}.bottle.tar.gz"
|
|
|
|
################################################################################
|
|
#
|
|
# Preflight checks
|
|
#
|
|
|
|
# Uninstall if necessary
|
|
brew remove mas 2>/dev/null || true # ignore failure
|
|
brew remove mas-cli/tap/mas 2>/dev/null || true #ignore failure
|
|
|
|
# Uninstall if still found on path
|
|
if command -v mas >/dev/null; then
|
|
script/uninstall || true # ignore failure
|
|
fi
|
|
|
|
# Use formula from custom tap
|
|
brew tap mas-cli/tap
|
|
brew update
|
|
|
|
# Audit formula
|
|
brew audit --strict mas-cli/tap/mas
|
|
brew style mas-cli/tap/mas
|
|
|
|
################################################################################
|
|
#
|
|
# Build the formula for the current macOS version and architecture.
|
|
#
|
|
|
|
echo "==> 🍼 Bottling mas ${VERSION} for: ${OS_NAMES[*]}"
|
|
brew install --build-bottle mas-cli/tap/mas
|
|
|
|
# Generate bottle do block, dropping last 2 lines
|
|
brew bottle --verbose --no-rebuild --root-url="$ROOT_URL" mas-cli/tap/mas
|
|
if ! test -e "${OLD_FILENAME}"; then
|
|
echo "Bottle not found: ${OLD_FILENAME}"
|
|
echo "If an old version is showing in the log and filename, then make sure the formula has been updated in:"
|
|
echo "<BREW_HOME>/Library/Taps/homebrew/homebrew-core"
|
|
exit 1
|
|
fi
|
|
|
|
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_NAMES[@]}"; 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_skip_relocation, %-15s %s" "${os}:" "${SHA256}")"
|
|
BOTTLE_BLOCK="$BOTTLE_BLOCK"$(
|
|
cat <<-EOF
|
|
|
|
sha256 cellar: :any_skip_relocation, $os: "$SHA256"
|
|
EOF
|
|
)
|
|
done
|
|
|
|
# End of bottle block
|
|
BOTTLE_BLOCK=$(
|
|
cat <<-EOF
|
|
|
|
end
|
|
EOF
|
|
)
|
|
|
|
rm "${OLD_FILENAME}"
|
|
ls -l "${BOTTLE_DIR}"
|
|
echo "${BOTTLE_BLOCK}"
|
|
|
|
brew remove mas-cli/tap/mas
|
|
|
|
open "${BOTTLE_DIR}"
|