mirror of
https://github.com/macports/mpbb.git
synced 2026-07-12 18:18:44 -07:00
The location of the jobs tools is used in a couple of places, so don't repeat ourselves. git-svn-id: https://svn.macports.org/repository/macports/contrib/mp-buildbot@152531 d073be05-634f-4543-b044-5fe20cf6d1d6
140 lines
4.7 KiB
Bash
140 lines
4.7 KiB
Bash
#!/bin/bash
|
|
# -*- coding: utf-8; mode: sh; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=sh:et:sw=4:ts=4:sts=4
|
|
|
|
# Note:
|
|
# This script is sourced by the mpbb wrapper script.
|
|
# Do not execute this directly!
|
|
|
|
checkout-usage() {
|
|
# "prog" is defined in mpbb-help.
|
|
# shellcheck disable=SC2154
|
|
cat <<EOF
|
|
usage: $prog [<global opts>] checkout [<opts>]
|
|
|
|
Obtain a working copy of the jobs tools and ports tree and configure
|
|
MacPorts to use the latter as a port source.
|
|
|
|
Options:
|
|
|
|
--jobs-url=<URL>
|
|
URL to a repository containing the jobs tools. Only used when
|
|
checking out a new working copy. Defaults to
|
|
\`https://svn.macports.org/repository/macports/trunk/base/portmgr/jobs'.
|
|
|
|
--ports-commit=<commit>
|
|
A commit or revision at which the ports tree will be checked out.
|
|
Any specifier understood by the version-control client may be used.
|
|
Defaults to \`HEAD'.
|
|
|
|
--ports-url=<URL>
|
|
URL to a repository containing the ports tree. Only used when
|
|
checking out a new working copy. Defaults to
|
|
\`https://svn.macports.org/repository/macports/trunk/dports'.
|
|
|
|
--svn[=<path>]
|
|
Use Subversion to obtain the jobs tools and ports tree; this is the
|
|
default behavior. The path to a Subversion client may be provided
|
|
explicitly, otherwise \`svn' is used.
|
|
|
|
Run \`$prog help' for global options and a list of other subcommands.
|
|
EOF
|
|
}
|
|
|
|
is-empty() {
|
|
if [[ $# -ne 1 || -z $1 ]]; then
|
|
err 'is-empty requires a single non-null argument'
|
|
return 2
|
|
fi
|
|
(shopt -s dotglob nullglob; f=("$1"/*); (( ! ${#f[@]} )))
|
|
}
|
|
|
|
svn-checkout() {
|
|
if (( $# < 2 )); then
|
|
err 'svn-checkout requires at least two arguments'
|
|
return 2
|
|
fi
|
|
|
|
local -r dst=$1 src=$2 rev=${3-HEAD}
|
|
local -r svn=("$svn" --non-interactive)
|
|
local -r root=$("${svn[@]}" info --show-item wc-root "$dst" 2>/dev/null)
|
|
|
|
if [[ -z $root ]] && is-empty "$dst"; then
|
|
printf "\n---> Checking out Subversion repository from \`%s'\n" "$src"
|
|
# "svn checkout" creates the intermediate directories.
|
|
"${svn[@]}" checkout --revision "$rev" "$src" "$dst"
|
|
elif [[ $root -ef $dst ]]; then
|
|
# TODO Allow switching the Subversion server.
|
|
printf "\n---> Updating Subversion repository from \`%s'\n" \
|
|
"$("${svn[@]}" info --show-item url "$dst")"
|
|
"${svn[@]}" cleanup "$dst" \
|
|
&& "${svn[@]}" update --revision "$rev" "$dst"
|
|
else
|
|
err "\`$dst' is not an empty directory or" \
|
|
'the root of a Subversion working copy'
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
checkout() {
|
|
local args
|
|
parseopt jobs-url:,ports-commit:,ports-url:,prefix:,svn::,svn-url: "$@" \
|
|
|| return
|
|
# shellcheck disable=SC2086
|
|
set -- ${args+"${args[@]}"}
|
|
|
|
# shellcheck disable=SC2154
|
|
# To maintain backwards compatibility, --svn-url implies --svn.
|
|
if [[ -n ${option_svn_url+_} ]]; then
|
|
: "${option_svn=}"
|
|
fi
|
|
|
|
# shellcheck disable=SC2154
|
|
local -r ports_dir=${option_work_dir}/dports
|
|
|
|
local checkout jobs_dir svn
|
|
# shellcheck disable=SC2100 disable=SC2154
|
|
if svn=${option_svn:-$(command -v svn)}; then
|
|
checkout=svn-checkout
|
|
jobs_dir=${option_jobs_dir}
|
|
if [[ -n ${option_svn_url+_} ]]; then
|
|
: "${option_jobs_url=${option_svn_url}/base/portmgr/jobs}"
|
|
: "${option_ports_url=${option_svn_url}/dports}"
|
|
else
|
|
: "${option_jobs_url=https://svn.macports.org/repository/macports/trunk/base/portmgr/jobs}"
|
|
: "${option_ports_url=https://svn.macports.org/repository/macports/trunk/dports}"
|
|
fi
|
|
else
|
|
err 'cannot find a Subversion client'
|
|
return 1
|
|
fi
|
|
readonly checkout jobs_dir svn
|
|
|
|
$checkout "${jobs_dir}" "${option_jobs_url}" || return
|
|
# shellcheck disable=SC2086 disable=SC2154
|
|
$checkout "${ports_dir}" "${option_ports_url}" \
|
|
${option_ports_commit+"${option_ports_commit}"} || return
|
|
|
|
# $option_prefix is set in mpbb
|
|
# shellcheck disable=SC2154
|
|
(cd "${ports_dir}" && "${option_prefix}/bin/portindex") || return
|
|
|
|
local -ar mirrors=(aarnet.au cjj.kr fco.it her.gr jnb.za jog.id
|
|
lil.fr mse.uk nou.nc nue.de osl.no sea.us ykf.ca)
|
|
# Unset IFS to ensure "${mirrors[*]}" uses spaces as separators.
|
|
(unset IFS && cat > "${option_work_dir}/macports.conf" <<EOF
|
|
# Automatically overwritten by mpbb-checkout
|
|
# Do not edit !!!
|
|
sources_conf ${option_work_dir}/sources.conf
|
|
host_blacklist ${mirrors[*]/%/.distfiles.macports.org} \
|
|
${mirrors[*]/%/.packages.macports.org}
|
|
EOF
|
|
) || return
|
|
|
|
cat > "${option_work_dir}/sources.conf" <<EOF || return
|
|
# Automatically overwritten by mpbb-checkout
|
|
# Do not edit !!!
|
|
file://${ports_dir} [default]
|
|
EOF
|
|
|
|
}
|