feature: generate macOS pkg files

This commit is contained in:
Sean Molenaar 2022-12-19 17:43:51 +01:00
parent 7d04dd9d68
commit 72b3348fb1
No known key found for this signature in database
GPG Key ID: AAC1C7E1A4696A9A
4 changed files with 102 additions and 0 deletions

43
.github/workflows/build-pkg.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Build Homebrew package
on:
push:
paths:
- .github/workflows/build-pkg.yml
- package/scripts
pull_request:
branches:
- master
release:
types:
- published
jobs:
build:
runs-on: macos-12
env:
IDENTIFIER: sh.brew.Homebrew
TMP_PATH: /tmp/brew
MIN_OS: '11.0'
steps:
- uses: actions/checkout@v3
with:
path: brew
fetch-depth: 0
- name: Version name
id: print-version
run: |
echo "version=$(git -C brew describe --tags --always)" > $GITHUB_OUTPUT
- name: Build package
run: |
pkgbuild --root brew \
--scripts brew/package/scripts \
--install-location "$TMP_PATH" \
--identifier "$IDENTIFIER" \
--min-os-version "$MIN_OS" \
--filter .DS_Store \
--version ${{ steps.print-version.outputs.version }} \
Homebrew-${{ steps.print-version.outputs.version }}.pkg
- uses: actions/upload-artifact@v3
with:
name: Homebrew ${{ steps.print-version.outputs.version }}
path: Homebrew-${{ steps.print-version.outputs.version }}.pkg

3
.gitignore vendored
View File

@ -179,6 +179,9 @@
!/docs
!/manpages
# Unignore our packaging files
!/package
# Ignore generated documentation site
/docs/_site
/docs/bin

43
package/scripts/postinstall Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
# verify the files exist
tmp_brew="$2"
if [[ ! -d "${tmp_brew:?}" ]]; then
echo "no directory at $tmp_brew, exiting"
exit 1
fi
# pick the correct target
if [[ "$3" != "/" ]]; then
target=$3
elif [[ $(uname -m) == "x86_64" ]];then
target="/usr/local"
else
target="/opt/Homebrew"
fi
loggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }')
if [[ -f "$target/bin/brew" ]]; then
if [[ $(sudo -u"$loggedInUser" "$target/bin/brew" developer) =~ "enabled" ]]; then
echo "developer install, exiting"
exit 0
fi
if [[ $("$tmp_brew/bin/brew" --version | head -n1) != $("$target/bin/brew" --version | head -n1) ]]; then
echo "already an outdated install at $target, updating"
sudo -u"$loggedInUser" "$target/bin/brew" update --auto-update
else
echo "already an up-to-date install at $target, exiting"
fi
exit 0
fi
group=$(id -gn "$loggedInUser")
install -d -o "$loggedInUser" -g "$group" "$target"
cp -RX "$tmp_brew/" "$target"
# set permissions
chown -R "$loggedInUser:$group" "$target/*"
# cleanup
rm -rf "${tmp_brew:?}/*"

13
package/scripts/preinstall Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Checked for installed CLT
if [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]; then
exit 0
fi
if /usr/bin/xcode-select --install; then
exit 0
fi
printf "Failed to install CommandLine Tools"
exit 1