Skip to content

Commit

Permalink
Install MacPorts under an arbitrary prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
foretspaisibles committed Jun 14, 2024
1 parent 0d551db commit 4c76797
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
os: ['macos-12', 'macos-13', 'macos-14']
version: ['2.9.3']
prefix: ['/opt/local']
include:
- os: 'macos-14'
version: '2.9.3'
prefix: '/opt/package'
runs-on: '${{ matrix.os }}'
name: 'Install MacPorts'
needs: 'run-testsuite'
Expand All @@ -43,4 +47,5 @@ jobs:
- name: 'Validate transmitted MacPorts version'
run: >-
test "${{ steps.macports.outputs.version }}" = '${{ matrix.version }}'
- run: ${{ matrix.prefix }}/bin/port version
- run: port version
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ runs:
TOPLEVELDIR: ${{ github.action_path }}
run: |
${{ github.action_path }}/install_macports
env:
macports_prefix: ${{ steps.configure-macports.outputs.prefix }}
macports_version: ${{ steps.configure-macports.outputs.version }}
14 changes: 7 additions & 7 deletions configure_macports
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ experimental()

cache_key()
{
openssl ripemd160 "${macports_prefix}/etc/gha-install-macports.yaml"\
openssl ripemd160 "${macports_prefix}/etc/setup-macports.yaml"\
| awk -v "macos=${macos}" '{print(macos "-" $2)}'
}

Expand Down Expand Up @@ -101,8 +101,8 @@ main()
esac

if [ -f "${parameterfile}" -a -r "${parameterfile}" ]; then
version=$(yq ".version // \"${macports_version}\"" < "${parameterfile}")
prefix=$(yq ".prefix // \"${macports_prefix}\"" < "${parameterfile}")
macports_version=$(yq ".version // \"${macports_version}\"" < "${parameterfile}")
macports_prefix=$(yq ".prefix // \"${macports_prefix}\"" < "${parameterfile}")
fi

if [ "${action}" = 'experimental' ]; then
Expand All @@ -112,14 +112,14 @@ main()

setup_path
sudo install -d -o $(id -u -n) -g $(id -g -n) -m 755 "${macports_prefix}"
write_configuration "${parameterfile}" "${macports_prefix}/etc/gha-install-macports.yaml"
write_variants "${macports_prefix}/etc/gha-install-macports.yaml"
write_sources "${macports_prefix}/etc/gha-install-macports.yaml"
write_configuration "${parameterfile}" "${macports_prefix}/etc/setup-macports.yaml"
write_variants "${macports_prefix}/etc/setup-macports.yaml"
write_sources "${macports_prefix}/etc/setup-macports.yaml"

if [ "${GITHUB_ACTIONS}" = 'true' ]; then
{
printf 'prefix=%s\n' "${macports_prefix}"
printf 'parameters=%s\n' "${macports_prefix}/etc/gha-install-macports.yaml"
printf 'parameters=%s\n' "${macports_prefix}/etc/setup-macports.yaml"
printf 'cache-key=%sn\n' "$(cache_key)"
printf 'package=%s\n' "$(make_package)"
printf 'version=%s\n' "${macports_version}"
Expand Down
26 changes: 24 additions & 2 deletions install_macports
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ fetch_and_install_package()
sudo chown -R $(id -u -n):$(id -g -n) "${macports_prefix}"
}

install_from_source()
{
local srcdir
srcdir='/opt/local/src'
sudo install -d -o $(id -u -n) -g $(id -g -n) -m 755 "${srcdir}"
(
cd "${srcdir}"
git clone https://github.com/macports/macports-base.git
cd macports-base
git checkout "v${macports_version}"
./configure --enable-readline --prefix="${macports_prefix}"
make
sudo make install
)
rm -Rf "${srcdir}"
}

install_ports()
{
ports_document "$1" | xargs -J '%' sudo port install '%'
Expand Down Expand Up @@ -208,8 +225,13 @@ main()
'Configuration Summary'\
configuration_summary

fetch_and_install_package "$(make_package)"
install_ports "${macports_prefix}/etc/gha-install-macports.yaml"
if [ "${macports_prefix}" = '/opt/local' ]; then
fetch_and_install_package "$(make_package)"
else
install_from_source
fi

install_ports "${macports_prefix}/etc/setup-macports.yaml"
}

main "$@"
Expand Down

0 comments on commit 4c76797

Please sign in to comment.