2019-01-13 07:15:46 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
#
|
|
|
|
# script/bottle
|
|
|
|
# mas
|
|
|
|
#
|
2019-01-19 04:37:51 +00:00
|
|
|
# Builds bottles of mas Homebrew formula for custom tap:
|
|
|
|
# https://github.com/mas-cli/homebrew-tap
|
2019-01-13 07:15:46 +00:00
|
|
|
#
|
|
|
|
|
2021-03-20 18:27:05 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Variables
|
|
|
|
#
|
|
|
|
|
2021-04-28 21:49:54 +00:00
|
|
|
BUILD_DIR="$PWD/.build"
|
2019-01-13 07:48:55 +00:00
|
|
|
BOTTLE_DIR="$BUILD_DIR/bottles"
|
|
|
|
VERSION=$(script/version)
|
2021-05-09 00:30:04 +00:00
|
|
|
ROOT_URL="https://github.com/mas-cli/mas/releases/download/v${VERSION}"
|
2021-03-20 18:27:05 +00:00
|
|
|
|
2021-10-25 23:46:56 +00:00
|
|
|
# Supports macOS 10.11 and later
|
|
|
|
OS_NAMES=(arm64_monterey monterey arm64_big_sur big_sur catalina mojave high_sierra sierra el_capitan)
|
2021-03-29 04:48:10 +00:00
|
|
|
|
|
|
|
# Semantic version number split into a list using Ugly, bash 3 compatible syntax
|
2021-03-29 05:09:52 +00:00
|
|
|
IFS=" " read -r -a CURRENT_OS_VERSION <<<"$(sw_vers -productVersion | sed 's/\./ /g'))"
|
2021-03-29 04:48:10 +00:00
|
|
|
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"
|
|
|
|
|
2021-10-25 23:46:56 +00:00
|
|
|
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
|
2021-03-29 04:48:10 +00:00
|
|
|
# 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
|
2021-03-29 03:05:00 +00:00
|
|
|
else
|
2021-03-29 04:48:10 +00:00
|
|
|
echo "Unsupported macOS version. This script requires Catalina or better."
|
|
|
|
exit 1
|
2021-03-29 03:05:00 +00:00
|
|
|
fi
|
2021-03-20 18:27:05 +00:00
|
|
|
|
2021-03-29 04:48:10 +00:00
|
|
|
echo "CURRENT_PLATFORM: ${CURRENT_PLATFORM}"
|
|
|
|
|
2021-03-20 18:27:05 +00:00
|
|
|
# Output filename from build-bottle command
|
2021-03-29 03:05:00 +00:00
|
|
|
OLD_FILENAME="mas--${VERSION}.${CURRENT_PLATFORM}.bottle.tar.gz"
|
2019-01-13 07:15:46 +00:00
|
|
|
|
2021-03-20 18:27:05 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Preflight checks
|
|
|
|
#
|
2019-01-13 07:15:46 +00:00
|
|
|
|
|
|
|
# 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
|
2021-03-21 23:50:09 +00:00
|
|
|
if brew ls --versions mas >/dev/null; then
|
2021-03-29 03:05:00 +00:00
|
|
|
brew unlink mas
|
2019-01-13 07:15:46 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-30 13:09:06 +00:00
|
|
|
# Uninstall if still found on path
|
2021-03-21 23:50:09 +00:00
|
|
|
if command -v mas >/dev/null; then
|
|
|
|
script/uninstall || true # ignore failure
|
2019-04-30 13:09:06 +00:00
|
|
|
fi
|
|
|
|
|
2021-03-20 18:27:05 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Build the formula for the current macOS version and architecture.
|
|
|
|
#
|
|
|
|
|
2021-03-29 04:48:10 +00:00
|
|
|
echo "==> 🍼 Bottling mas ${VERSION} for: ${OS_NAMES[*]}"
|
2019-01-13 07:15:46 +00:00
|
|
|
brew install --build-bottle mas
|
|
|
|
|
2019-01-13 08:24:22 +00:00
|
|
|
# Generate bottle do block, dropping last 2 lines
|
2021-06-09 01:56:27 +00:00
|
|
|
brew bottle --verbose --no-rebuild --root-url="$ROOT_URL" mas
|
2021-09-09 01:08:56 +00: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:"
|
|
|
|
echo "<BREW_HOME>/Library/Taps/homebrew/homebrew-core"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-20 19:11:38 +00:00
|
|
|
SHA256=$(shasum --algorithm 256 "${OLD_FILENAME}" | cut -f 1 -d ' ' -)
|
2019-01-13 07:48:55 +00:00
|
|
|
|
|
|
|
mkdir -p "$BOTTLE_DIR"
|
|
|
|
|
2019-01-13 08:24:22 +00:00
|
|
|
# Start of bottle block
|
2021-03-21 23:50:09 +00:00
|
|
|
BOTTLE_BLOCK=$(
|
|
|
|
cat <<-EOF
|
2021-03-20 19:11:38 +00:00
|
|
|
bottle do
|
|
|
|
root_url "$ROOT_URL"
|
2021-03-20 18:27:05 +00:00
|
|
|
EOF
|
2019-01-13 08:24:22 +00:00
|
|
|
)
|
|
|
|
|
2021-03-20 18:27:05 +00:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Copy the bottle for all macOS version + architecture combinations.
|
|
|
|
#
|
|
|
|
|
2019-01-13 07:48:55 +00:00
|
|
|
# Fix filename
|
2021-03-29 04:48:10 +00:00
|
|
|
for os in ${OS_NAMES[*]}; do
|
2021-03-21 23:50:09 +00:00
|
|
|
new_filename="mas-${VERSION}.${os}.bottle.tar.gz"
|
|
|
|
cp -v "${OLD_FILENAME}" "${BOTTLE_DIR}/${new_filename}"
|
2019-01-13 08:24:22 +00:00
|
|
|
|
2021-03-21 23:50:09 +00:00
|
|
|
# Append each os
|
2021-05-09 00:30:04 +00:00
|
|
|
# BOTTLE_BLOCK="$(printf "${BOTTLE_BLOCK}\n sha256 cellar: :any_skip_relocation, %-15s %s" "${os}:" "${SHA256}")"
|
2021-03-21 23:50:09 +00:00
|
|
|
BOTTLE_BLOCK="$BOTTLE_BLOCK"$(
|
|
|
|
cat <<-EOF
|
2019-01-13 08:24:22 +00:00
|
|
|
|
2021-05-09 00:30:04 +00:00
|
|
|
sha256 cellar: :any_skip_relocation, $os: "$SHA256"
|
2021-03-20 18:27:05 +00:00
|
|
|
EOF
|
2021-03-21 23:50:09 +00:00
|
|
|
)
|
2019-01-13 07:48:55 +00:00
|
|
|
done
|
|
|
|
|
2019-01-13 08:24:22 +00:00
|
|
|
# End of bottle block
|
2021-03-21 23:50:09 +00:00
|
|
|
BOTTLE_BLOCK=$(
|
|
|
|
cat <<-EOF
|
2019-01-13 08:24:22 +00:00
|
|
|
|
2021-03-20 19:11:38 +00:00
|
|
|
end
|
2021-03-20 18:27:05 +00:00
|
|
|
EOF
|
2019-01-13 08:24:22 +00:00
|
|
|
)
|
|
|
|
|
2021-03-20 19:11:38 +00:00
|
|
|
rm "${OLD_FILENAME}"
|
|
|
|
ls -l "${BOTTLE_DIR}"
|
|
|
|
echo "${BOTTLE_BLOCK}"
|