diff options
Diffstat (limited to 'src/commitpkg.in')
-rw-r--r-- | src/commitpkg.in | 136 |
1 files changed, 94 insertions, 42 deletions
diff --git a/src/commitpkg.in b/src/commitpkg.in index 235d12b..8a8087a 100644 --- a/src/commitpkg.in +++ b/src/commitpkg.in @@ -2,7 +2,39 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -m4_include(lib/common.sh) +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh + +source /usr/share/makepkg/util/util.sh + + +check_pkgbuild_validity() { + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . ./PKGBUILD + + # skip when there are no sources available + if (( ! ${#source[@]} )); then + return + fi + + # validate sources hash algo is at least > sha1 + local bad_algos=("cksums" "md5sums" "sha1sums") + local good_hash_algo=false + + # from makepkg libmakepkg/util/schema.sh + for integ in "${known_hash_algos[@]}"; do + local sumname="${integ}sums" + if [[ -n ${!sumname} ]] && ! in_array "${sumname}" "${bad_algos[@]}"; then + good_hash_algo=true + break + fi + done + + if ! $good_hash_algo; then + die "PKGBUILD lacks a secure cryptographic checksum, insecure algorithms: ${bad_algos[*]}" + fi +} # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then @@ -23,10 +55,25 @@ fi cmd=${0##*/} +# Deprecation warning +if [[ -z $_DEVTOOLS_COMMAND ]]; then + warning "${cmd} is deprecated and will be removed. Use 'pkgctl release' instead" +fi + if [[ ! -f PKGBUILD ]]; then die 'No PKGBUILD file' fi +if ! repo_spec=$(git config --local devtools.version) || [[ ${repo_spec} != "${GIT_REPO_SPEC_VERSION}" ]]; then + error "repository specs are out of date, try:" + msg2 'pkgctl repo configure' + exit 1 +fi + +if [[ "$(git symbolic-ref --short HEAD)" != main ]]; then + die 'must be run from the main branch' +fi + source=() # shellcheck source=contrib/makepkg/PKGBUILD.proto . ./PKGBUILD @@ -60,7 +107,7 @@ if (( ${#validpgpkeys[@]} != 0 )); then export-pkgbuild-keys || die 'Failed to export valid PGP keys for source files' fi - svn add --parents --force keys/pgp/* + git add --force -- keys/pgp/* fi # find files which should be under source control @@ -79,15 +126,21 @@ for key in "${validpgpkeys[@]}"; do needsversioning+=("keys/pgp/$key.asc") done -# assert that they really are controlled by SVN +# assert that they really are controlled by git if (( ${#needsversioning[*]} )); then - # svn status's output is only two columns when the status is unknown - while read -r status filename; do - [[ $status = '?' ]] && unversioned+=("$filename") - done < <(svn status -v "${needsversioning[@]}") - (( ${#unversioned[*]} )) && die "%s is not under version control" "${unversioned[@]}" + for file in "${needsversioning[@]}"; do + # skip none existing files + if [[ ! -f "${file}" ]]; then + continue + fi + if ! git ls-files --error-unmatch "$file"; then + die "%s is not under version control" "$file" + fi + done fi + +server=${PACKAGING_REPO_RELEASE_HOST} rsyncopts=(-e ssh -p '--chmod=ug=rw,o=r' -c -h -L --progress --partial -y) archreleaseopts=() while getopts ':l:a:s:f' flag; do @@ -121,31 +174,50 @@ for _arch in "${arch[@]}"; do fi done -if [[ -z $server ]]; then - server='repos.archlinux.org' +# check for PKGBUILD standards +check_pkgbuild_validity + +# auto generate .SRCINFO if present +if [[ -f .SRCINFO ]]; then + stat_busy 'Generating .SRCINFO' + makepkg --printsrcinfo > .SRCINFO + git add .SRCINFO + stat_done fi -if [[ -n $(svn status -q) ]]; then - msgtemplate="upgpkg: $pkgbase $(get_full_version)" +if [[ -n $(git status --porcelain --untracked-files=no) ]]; then + stat_busy 'Staging files' + for f in $(git ls-files --modified); do + git add "$f" + done + for f in $(git ls-files --deleted); do + git rm "$f" + done + stat_done + + msgtemplate="upgpkg: $(get_full_version)" if [[ -n $1 ]]; then - stat_busy 'Committing changes to trunk' - svn commit -q -m "${msgtemplate}: ${1}" || die + stat_busy 'Committing changes' + git commit -q -m "${msgtemplate}: ${1}" || die stat_done else - msgfile="$(mktemp)" + [[ -z ${WORKDIR:-} ]] && setup_workdir + msgfile=$(mktemp --tmpdir="${WORKDIR}" commitpkg.XXXXXXXXXX) echo "$msgtemplate" > "$msgfile" - if [[ -n $SVN_EDITOR ]]; then - $SVN_EDITOR "$msgfile" + if [[ -n $GIT_EDITOR ]]; then + $GIT_EDITOR "$msgfile" || die elif [[ -n $VISUAL ]]; then - $VISUAL "$msgfile" + $VISUAL "$msgfile" || die elif [[ -n $EDITOR ]]; then - $EDITOR "$msgfile" + $EDITOR "$msgfile" || die + elif giteditor=$(git config --get core.editor); then + $giteditor "$msgfile" || die else - vi "$msgfile" + die "No usable editor found (tried \$GIT_EDITOR, \$VISUAL, \$EDITOR, git config [core.editor])." fi [[ -s $msgfile ]] || die - stat_busy 'Committing changes to trunk' - svn commit -q -F "$msgfile" || die + stat_busy 'Committing changes' + git commit -v -q -F "$msgfile" || die unlink "$msgfile" stat_done fi @@ -219,23 +291,3 @@ if [[ ${#uploads[*]} -gt 0 ]]; then msg 'Uploading all package and signature files' rsync "${rsyncopts[@]}" "${uploads[@]}" "$server:staging/$repo/" || die fi - -if [[ "${arch[*]}" == 'any' ]]; then - if [[ -d ../repos/$repo-x86_64 ]]; then - pushd ../repos/ >/dev/null - stat_busy "Removing %s" "$repo-x86_64" - svn rm -q "$repo-x86_64" - svn commit -q -m "Removed $repo-x86_64 for $pkgname" - stat_done - popd >/dev/null - fi -else - if [[ -d ../repos/$repo-any ]]; then - pushd ../repos/ >/dev/null - stat_busy "Removing %s" "$repo-any" - svn rm -q "$repo-any" - svn commit -q -m "Removed $repo-any for $pkgname" - stat_done - popd >/dev/null - fi -fi |