2024-10-26 14:23:59 -06:00
|
|
|
#!/bin/bash -ex
|
2019-01-13 00:15:46 -07:00
|
|
|
#
|
|
|
|
# script/bottle
|
|
|
|
# mas
|
|
|
|
#
|
2019-01-18 21:37:51 -07:00
|
|
|
# Builds bottles of mas Homebrew formula for custom tap:
|
|
|
|
# https://github.com/mas-cli/homebrew-tap
|
2019-01-13 00:15:46 -07:00
|
|
|
#
|
2023-11-25 16:41:12 -07:00
|
|
|
# This script should be run _after_ the formula has been updated in Homebrew
|
|
|
|
#
|
2019-01-13 00:15:46 -07:00
|
|
|
|
2021-03-20 11:27:05 -07:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Variables
|
|
|
|
#
|
|
|
|
|
2024-03-10 19:53:07 -06:00
|
|
|
BUILD_DIR="${PWD}/.build"
|
|
|
|
BOTTLE_DIR="${BUILD_DIR}/bottles"
|
2024-03-10 19:32:02 -06:00
|
|
|
CORE_TAP_PATH="$(brew --repository homebrew/core)"
|
2023-11-25 16:04:18 -07:00
|
|
|
MAS_VERSION=$(script/version)
|
|
|
|
ROOT_URL="https://github.com/mas-cli/mas/releases/download/v${MAS_VERSION}"
|
2021-03-20 11:27:05 -07:00
|
|
|
|
2024-10-27 13:47:17 -04:00
|
|
|
# Supports macOS 10.13 and later
|
2024-02-18 00:09:44 -07:00
|
|
|
OS_NAMES=(
|
2024-11-03 10:59:31 -07:00
|
|
|
sequoia
|
|
|
|
arm64_sequoia
|
2024-02-18 00:09:44 -07:00
|
|
|
sonoma
|
|
|
|
arm64_sonoma
|
|
|
|
ventura
|
|
|
|
arm64_ventura
|
|
|
|
monterey
|
|
|
|
arm64_monterey
|
|
|
|
big_sur
|
|
|
|
arm64_big_sur
|
|
|
|
catalina
|
|
|
|
mojave
|
|
|
|
high_sierra
|
|
|
|
sierra
|
|
|
|
el_capitan
|
2023-11-25 16:41:12 -07:00
|
|
|
)
|
2021-03-28 21:48:10 -07:00
|
|
|
|
2024-03-10 19:53:07 -06:00
|
|
|
# Semantic version number split into a list using ugly, bash 3 compatible syntax
|
2024-03-09 08:17:50 -07:00
|
|
|
IFS=" " read -r -a CURRENT_OS_VERSION <<<"$(sw_vers -productVersion | sed 's/\./ /g')"
|
2021-03-28 21:48:10 -07:00
|
|
|
CURRENT_OS_VERSION_MAJOR=${CURRENT_OS_VERSION[0]}
|
|
|
|
CURRENT_OS_VERSION_MINOR=${CURRENT_OS_VERSION[1]}
|
|
|
|
|
2024-03-10 19:32:02 -06:00
|
|
|
echo "CURRENT_OS_VERSION_MAJOR: ${CURRENT_OS_VERSION_MAJOR}"
|
|
|
|
echo "CURRENT_OS_VERSION_MINOR: ${CURRENT_OS_VERSION_MINOR}"
|
2021-03-28 21:48:10 -07:00
|
|
|
|
2023-11-25 14:09:33 -07:00
|
|
|
case "${CURRENT_OS_VERSION_MAJOR}" in
|
2024-11-03 10:59:31 -07:00
|
|
|
15)
|
|
|
|
CURRENT_PLATFORM=sequoia
|
|
|
|
;;
|
2024-03-31 11:05:04 -06:00
|
|
|
14)
|
|
|
|
CURRENT_PLATFORM=sonoma
|
|
|
|
;;
|
|
|
|
13)
|
|
|
|
CURRENT_PLATFORM=ventura
|
|
|
|
;;
|
|
|
|
12)
|
|
|
|
CURRENT_PLATFORM=monterey
|
|
|
|
;;
|
|
|
|
11)
|
|
|
|
CURRENT_PLATFORM=big_sur
|
|
|
|
;;
|
|
|
|
10)
|
|
|
|
CURRENT_PLATFORM=catalina
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported macOS version. This script requires Catalina or better."
|
|
|
|
exit 1
|
|
|
|
;;
|
2023-11-25 14:09:33 -07:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Prefix platform with architecture
|
|
|
|
if [[ "arm64" == "$(uname -m)" ]]; then
|
|
|
|
CURRENT_PLATFORM="arm64_${CURRENT_PLATFORM}"
|
2021-03-28 20:05:00 -07:00
|
|
|
fi
|
2021-03-20 11:27:05 -07:00
|
|
|
|
2021-03-28 21:48:10 -07:00
|
|
|
echo "CURRENT_PLATFORM: ${CURRENT_PLATFORM}"
|
|
|
|
|
2021-03-20 11:27:05 -07:00
|
|
|
# Output filename from build-bottle command
|
2023-11-25 16:04:18 -07:00
|
|
|
OLD_FILENAME="mas--${MAS_VERSION}.${CURRENT_PLATFORM}.bottle.tar.gz"
|
2019-01-13 00:15:46 -07:00
|
|
|
|
2021-03-20 11:27:05 -07:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Preflight checks
|
|
|
|
#
|
2019-01-13 00:15:46 -07:00
|
|
|
|
2024-07-31 21:04:54 -06:00
|
|
|
# # Uninstall if necessary
|
|
|
|
# brew remove mas 2>/dev/null || true
|
|
|
|
# brew remove mas-cli/tap/mas 2>/dev/null || true
|
2019-01-13 00:15:46 -07:00
|
|
|
|
2024-07-31 21:04:54 -06:00
|
|
|
# # Uninstall if still found on path
|
|
|
|
# if command -v mas >/dev/null; then
|
|
|
|
# script/uninstall || true
|
|
|
|
# fi
|
2019-04-30 07:09:06 -06:00
|
|
|
|
2021-11-04 11:08:53 -07:00
|
|
|
# Use formula from custom tap
|
2024-07-31 21:04:54 -06:00
|
|
|
# brew tap mas-cli/tap
|
|
|
|
# brew update
|
2021-11-05 09:45:35 -07:00
|
|
|
|
|
|
|
# Audit formula
|
2024-10-26 14:07:04 -06:00
|
|
|
brew audit --strict --verbose --formula --tap mas-cli/tap mas
|
2024-10-26 14:23:10 -06:00
|
|
|
brew style Homebrew/mas-tap.rb
|
2021-11-04 11:08:53 -07:00
|
|
|
|
2021-03-20 11:27:05 -07:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Build the formula for the current macOS version and architecture.
|
|
|
|
#
|
|
|
|
|
2023-11-25 16:04:18 -07:00
|
|
|
echo "==> 🍼 Bottling mas ${MAS_VERSION} for: ${OS_NAMES[*]}"
|
2021-11-04 11:08:53 -07:00
|
|
|
brew install --build-bottle mas-cli/tap/mas
|
2019-01-13 00:15:46 -07:00
|
|
|
|
2019-01-13 01:24:22 -07:00
|
|
|
# Generate bottle do block, dropping last 2 lines
|
2024-03-10 19:32:02 -06:00
|
|
|
brew bottle --verbose --no-rebuild --root-url="${ROOT_URL}" mas-cli/tap/mas
|
2021-09-08 19:08:56 -06:00
|
|
|
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:"
|
2024-03-10 19:32:02 -06:00
|
|
|
echo "${CORE_TAP_PATH}"
|
2021-09-08 19:08:56 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-20 12:11:38 -07:00
|
|
|
SHA256=$(shasum --algorithm 256 "${OLD_FILENAME}" | cut -f 1 -d ' ' -)
|
2019-01-13 00:48:55 -07:00
|
|
|
|
2024-03-10 19:32:02 -06:00
|
|
|
mkdir -p "${BOTTLE_DIR}"
|
2019-01-13 00:48:55 -07:00
|
|
|
|
2019-01-13 01:24:22 -07:00
|
|
|
# Start of bottle block
|
2021-03-21 16:50:09 -07:00
|
|
|
BOTTLE_BLOCK=$(
|
|
|
|
cat <<-EOF
|
2021-03-20 12:11:38 -07:00
|
|
|
bottle do
|
2024-03-10 19:32:02 -06:00
|
|
|
root_url "${ROOT_URL}"
|
2021-03-20 11:27:05 -07:00
|
|
|
EOF
|
2019-01-13 01:24:22 -07:00
|
|
|
)
|
|
|
|
|
2021-03-20 11:27:05 -07:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Copy the bottle for all macOS version + architecture combinations.
|
|
|
|
#
|
|
|
|
|
2019-01-13 00:48:55 -07:00
|
|
|
# Fix filename
|
2021-11-07 19:13:01 -08:00
|
|
|
for os in "${OS_NAMES[@]}"; do
|
2023-11-25 16:04:18 -07:00
|
|
|
new_filename="mas-${MAS_VERSION}.${os}.bottle.tar.gz"
|
2021-03-21 16:50:09 -07:00
|
|
|
cp -v "${OLD_FILENAME}" "${BOTTLE_DIR}/${new_filename}"
|
2019-01-13 01:24:22 -07:00
|
|
|
|
2021-03-21 16:50:09 -07:00
|
|
|
# Append each os
|
2021-05-08 17:30:04 -07:00
|
|
|
# BOTTLE_BLOCK="$(printf "${BOTTLE_BLOCK}\n sha256 cellar: :any_skip_relocation, %-15s %s" "${os}:" "${SHA256}")"
|
2024-03-10 19:32:02 -06:00
|
|
|
BOTTLE_BLOCK="${BOTTLE_BLOCK}"$(
|
2021-03-21 16:50:09 -07:00
|
|
|
cat <<-EOF
|
2019-01-13 01:24:22 -07:00
|
|
|
|
2024-03-10 19:32:02 -06:00
|
|
|
sha256 cellar: :any_skip_relocation, ${os}: "${SHA256}"
|
2021-03-20 11:27:05 -07:00
|
|
|
EOF
|
2021-03-21 16:50:09 -07:00
|
|
|
)
|
2019-01-13 00:48:55 -07:00
|
|
|
done
|
|
|
|
|
2019-01-13 01:24:22 -07:00
|
|
|
# End of bottle block
|
2021-03-21 16:50:09 -07:00
|
|
|
BOTTLE_BLOCK=$(
|
|
|
|
cat <<-EOF
|
2019-01-13 01:24:22 -07:00
|
|
|
|
2021-03-20 12:11:38 -07:00
|
|
|
end
|
2021-03-20 11:27:05 -07:00
|
|
|
EOF
|
2019-01-13 01:24:22 -07:00
|
|
|
)
|
|
|
|
|
2021-03-20 12:11:38 -07:00
|
|
|
rm "${OLD_FILENAME}"
|
|
|
|
ls -l "${BOTTLE_DIR}"
|
|
|
|
echo "${BOTTLE_BLOCK}"
|