Compare commits

...

5 Commits

Author SHA1 Message Date
19a6ff09f1 minor-fixes (#117)
All checks were successful
Artools shellcheck / lint (push) Successful in 46s
Co-authored-by: Cory Sanin <corysanin@artixlinux.org>
Reviewed-on: #117
2024-03-22 23:03:09 +01:00
fac634cf14 Merge pull request 'artixpkg: add "admin maintainer" to bash completion' (#115) from corysanin/artools:completion-maintainer into master
All checks were successful
Artools shellcheck / lint (push) Successful in 43s
Reviewed-on: #115
Reviewed-by: artoo <artoo@artixlinux.org>
2024-03-22 21:09:03 +01:00
71ed464c33 artixpkg: add "admin maintainer" to bash completion 2024-03-22 14:54:58 -05:00
f7286a0661 artixpkg: remove --manual flag (#110)
All checks were successful
Artools shellcheck / lint (push) Successful in 47s
It is possible to autodetect whether or not a short name is being used.
Remove this flag to avoid breaking the interface.

Co-authored-by: artoo <artoo@artixlinux.org>
Reviewed-on: #110
Co-authored-by: Dudemanguy <dudemanguy@artixlinux.org>
Co-committed-by: Dudemanguy <dudemanguy@artixlinux.org>
2024-03-22 20:45:27 +01:00
aee7c07a04 Artixpkg admin: maintainer (#114)
All checks were successful
Artools shellcheck / lint (push) Successful in 47s
Reviewed-on: #114
Co-authored-by: Artoo <artoo@artixlinux.org>
Co-committed-by: Artoo <artoo@artixlinux.org>
2024-03-22 19:15:12 +01:00
8 changed files with 233 additions and 115 deletions

View File

@@ -25,9 +25,11 @@ _artixpkg_completion() {
comps=""
comps_all=""
comp_cword_exflag=0
comp_cword_all=0
for ((i = 0; i < ${#COMP_WORDS[@]} - 1; i++)); do
word="${COMP_WORDS[i]}"
comps_all+=" $word"
((comp_cword_all++))
if [[ $word != -* ]]; then
comps+=" $word"
((comp_cword_exflag++))
@@ -74,7 +76,7 @@ _artixpkg_completion() {
2)
case ${prev} in
admin)
COMPREPLY=($(compgen -W "query team topic transfer -h --help" -- ${cur}))
COMPREPLY=($(compgen -W "maintainer query team topic transfer -h --help" -- ${cur}))
;;
ci)
COMPREPLY=($(compgen -W "config -h --help" -- ${cur}))
@@ -96,14 +98,7 @@ _artixpkg_completion() {
local repoAddCommon="-p --push -r --rebuild -n --nocheck -h --help"
case "${comp_cword_exflag}" in
3)
case "${comps_all}" in
*-m*|*--manual*)
COMPREPLY=($(compgen -W "$repoAddCommon $repos" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-m --manual $repoAddCommon $autorepos" -- ${cur}))
;;
esac
COMPREPLY=($(compgen -W "$repoAddCommon $autorepos $repos" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "$repoAddCommon $(_artixpkg_pkgbase)" -- ${cur}))
@@ -113,14 +108,7 @@ _artixpkg_completion() {
"artixpkg repo remove"*)
case "${comp_cword_exflag}" in
3)
case "${comps_all}" in
*-m*|*--manual*)
COMPREPLY=($(compgen -W "-p --push -h --help $autorepos" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-m --manual -p --push -h --help $repos" -- ${cur}))
;;
esac
COMPREPLY=($(compgen -W "-p --push -h --help $autorepos $repos" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-p --push -h --help $(_artixpkg_pkgbase)" -- ${cur}))
@@ -130,14 +118,7 @@ _artixpkg_completion() {
"artixpkg repo move"*)
case "${comp_cword_exflag}" in
3|4)
case "${comps_all}" in
*-m*|*--manual*)
COMPREPLY=($(compgen -W "-p --push -h --help $autorepos" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-m --manual -p --push -h --help $repos" -- ${cur}))
;;
esac
COMPREPLY=($(compgen -W "-p --push -h --help $autorepos $repos" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-p --push -h --help $(_artixpkg_pkgbase)" -- ${cur}))
@@ -248,6 +229,16 @@ _artixpkg_completion() {
;;
esac
;;
"artixpkg admin maintainer"*)
case "${comp_cword_all}" in
3)
COMPREPLY=($(compgen -W "-a --adopt --o --orphan -h --help" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-h --help $(_artixpkg_pkgbase)" -- ${cur}))
;;
esac
;;
"artixpkg admin query"*)
case "${prev}" in
"-m"|"--maintainer"|"-t"|"--topic")

View File

@@ -17,6 +17,7 @@ artixpkg_admin_usage() {
Usage: ${COMMAND} [COMMAND] [OPTIONS]
COMMANDS
maintainer Manage repo maintainer
query Query maintainers and topics
team Manage repo team
topic Manage topics
@@ -27,8 +28,10 @@ artixpkg_admin_usage() {
EXAMPLES
$ ${COMMAND} transfer libfoo libbar
$ ${COMMAND} query --maintainer tux
$ ${COMMAND} query --topic kf5
$ ${COMMAND} query --topic mytopic
$ ${COMMAND} topic --add mytopic libfoo
$ ${COMMAND} team --add ${ARTIX_TEAMS[3]} libfoo
$ ${COMMAND} --adopt libfoo libbar
_EOF_
}
@@ -78,6 +81,14 @@ artixpkg_admin() {
artixpkg_admin_transfer "$@"
exit 0
;;
maintainer)
_ARTOOLS_COMMAND+=" $1"
shift
# shellcheck source=src/lib/pkg/admin/maintainer.sh
source "${LIBDIR}"/pkg/admin/maintainer.sh
artixpkg_admin_maintainer "$@"
exit 0
;;
-*)
die "invalid argument: %s" "$1"
;;

View File

@@ -0,0 +1,137 @@
#!/bin/bash
#
# SPDX-License-Identifier: GPL-3.0-or-later
[[ -z ${ARTOOLS_INCLUDE_ADMIN_MAINTAINER_SH:-} ]] || return 0
ARTOOLS_INCLUDE_ADMIN_MAINTAINER_SH=1
# shellcheck source=src/lib/pkg/packager.sh
source "${LIBDIR}"/pkg/packager.sh
set -e
artixpkg_admin_maintainer_usage() {
local -r COMMAND=${_ARTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
cat <<- _EOF_
Usage: ${COMMAND} [OPTIONS] [PKGBASE]...
OPTIONS
-a, --adopt Adopt repo
-o, --orphan Orphan repo
-h, --help Show this help text
EXAMPLES
$ ${COMMAND} --adopt libfoo
$ ${COMMAND} --orphan libfoo libbar
_EOF_
}
artixpkg_admin_maintainer() {
if (( $# < 1 )); then
artixpkg_admin_maintainer_usage
exit 0
fi
# options
local pkgbases=()
local pkgbase
local ADOPT=0
local ORPHAN=0
local packager_name
local maintainer
local -r orphan="orphan"
local command=${_ARTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
while (( $# )); do
case $1 in
-h|--help)
artixpkg_admin_maintainer_usage
exit 0
;;
-a|--adopt)
ADOPT=1
RUNCMD+=" $1 $maintainer"
shift
;;
-o|--orphan)
ORPHAN=1
RUNCMD+=" $1 $orphan"
shift
;;
--)
shift
break
;;
-*)
die "invalid argument: %s" "$1"
;;
*)
break
;;
esac
done
pkgbases+=("$@")
load_makepkg_config
if [[ -n ${PACKAGER} ]]; then
if ! packager_name=$(get_packager_name "${PACKAGER}") || \
! packager_email=$(get_packager_email "${PACKAGER}"); then
die "invalid PACKAGER format '${PACKAGER}' in makepkg.conf"
fi
if ! is_packager_name_valid "${packager_name}"; then
die "invalid PACKAGER '${PACKAGER}' in makepkg.conf"
fi
fi
maintainer="maintainer-${packager_name}"
if [[ -n ${GIT_TOKEN} ]]; then
# parallelization
if [[ ${jobs} != 1 ]] && (( ${#pkgbases[@]} > 1 )); then
# force colors in parallel if parent process is colorized
if [[ -n ${BOLD} ]]; then
export ARTOOLS_COLOR=always
fi
if ! parallel --bar --jobs "${jobs}" "${RUNCMD}" ::: "${pkgbases[@]}"; then
die 'Failed to pull some packages, please check the output'
exit 1
fi
exit 0
fi
for pkgbase in "${pkgbases[@]}"; do
local gitname
gitname=$(get_compliant_name "${pkgbase}")
if (( ADOPT )); then
if ! add_topic "${gitname}" "$maintainer"; then
warning "failed to add topic: $maintainer"
fi
if ! remove_topic "${gitname}" "$orphan"; then
warning "failed to remove topic: $orphan"
fi
fi
if (( ORPHAN )); then
if ! add_topic "${gitname}" "$orphan"; then
warning "failed to add topic: $orphan"
fi
if ! remove_topic "${gitname}" "$maintainer"; then
warning "failed to remove topic: $maintainer"
fi
fi
done
fi
}

View File

@@ -5,6 +5,9 @@
[[ -z ${ARTOOLS_INCLUDE_GIT_CONFIG_SH:-} ]] || return 0
ARTOOLS_INCLUDE_GIT_CONFIG_SH=1
# shellcheck source=src/lib/pkg/packager.sh
source "${LIBDIR}"/pkg/packager.sh
set -e
@@ -23,54 +26,6 @@ artixpkg_git_config_usage() {
_EOF_
}
get_packager_name() {
local packager=$1
local packager_pattern="(.+) <(.+@.+)>"
local name
if [[ ! $packager =~ $packager_pattern ]]; then
return 1
fi
name=$(echo "${packager}"|sed -E "s/${packager_pattern}/\1/")
printf "%s" "${name}"
}
get_packager_email() {
local packager=$1
local packager_pattern="(.+) <(.+@.+)>"
local email
if [[ ! $packager =~ $packager_pattern ]]; then
return 1
fi
email=$(echo "${packager}"|sed -E "s/${packager_pattern}/\2/")
printf "%s" "${email}"
}
is_packager_name_valid() {
local packager_name=$1
if [[ -z ${packager_name} ]]; then
return 1
elif [[ ${packager_name} == "John Tux" ]]; then
return 1
elif [[ ${packager_name} == "Unknown Packager" ]]; then
return 1
fi
return 0
}
is_packager_email_official() {
local packager_email=$1
if [[ -z ${packager_email} ]]; then
return 1
elif [[ $packager_email =~ .+@artixlinux.org ]]; then
return 0
fi
return 1
}
artixpkg_git_config() {
# options
local GIT_REPO_BASE_URL=${GIT_HTTPS}

51
src/lib/pkg/packager.sh Normal file
View File

@@ -0,0 +1,51 @@
#!/bin/bash
#
# SPDX-License-Identifier: GPL-3.0-or-later
get_packager_name() {
local packager=$1
local packager_pattern="(.+) <(.+@.+)>"
local name
if [[ ! $packager =~ $packager_pattern ]]; then
return 1
fi
name=$(echo "${packager}"|sed -E "s/${packager_pattern}/\1/")
printf "%s" "${name}"
}
get_packager_email() {
local packager=$1
local packager_pattern="(.+) <(.+@.+)>"
local email
if [[ ! $packager =~ $packager_pattern ]]; then
return 1
fi
email=$(echo "${packager}"|sed -E "s/${packager_pattern}/\2/")
printf "%s" "${email}"
}
is_packager_name_valid() {
local packager_name=$1
if [[ -z ${packager_name} ]]; then
return 1
elif [[ ${packager_name} == "John Tux" ]]; then
return 1
elif [[ ${packager_name} == "Unknown Packager" ]]; then
return 1
fi
return 0
}
is_packager_email_official() {
local packager_email=$1
if [[ -z ${packager_email} ]]; then
return 1
elif [[ $packager_email =~ .+@artixlinux.org ]]; then
return 0
fi
return 1
}

View File

@@ -38,8 +38,6 @@ artixpkg_repo_add_usage() {
Usage: ${COMMAND} [OPTIONS] [DEST_REPO] [PKGBASE]...
OPTIONS
-m, --manual Disable auto repo
Possible auto values: $(yaml_array ${ARTIX_DB_MAP[@]})
-p, --push Push pkgbase
-r, --rebuild Triggers a rebuild
-n, --nocheck Disable the check function
@@ -48,7 +46,7 @@ artixpkg_repo_add_usage() {
EXAMPLES
$ ${COMMAND} ${ARTIX_DB[4]} libfoo
$ ${COMMAND} --push ${ARTIX_DB[4]} libfoo
$ ${COMMAND} --auto --push ${ARTIX_DB_MAP[2]} libfoo
$ ${COMMAND} --push ${ARTIX_DB_MAP[2]} libfoo
_EOF_
}
@@ -67,7 +65,7 @@ artixpkg_repo_add() {
local REBUILD=0
local NOCHECK=0
local ADD=1
local AUTO=1
local AUTO=0
while (( $# )); do
case $1 in
@@ -75,10 +73,6 @@ artixpkg_repo_add() {
artixpkg_repo_add_usage
exit 0
;;
-m|--manual)
AUTO=0
shift
;;
-p|--push)
PUSH=1
shift
@@ -104,10 +98,8 @@ artixpkg_repo_add() {
shift
pkgbases+=("$@")
if (( AUTO )); then
if ! in_array "${DEST}" "${ARTIX_DB_MAP[@]}"; then
die "${DEST} does not exist!"
fi
if in_array "${DEST}" "${ARTIX_DB_MAP[@]}"; then
AUTO=1
else
if ! in_array "${DEST}" "${ARTIX_DB[@]}"; then
die "${DEST} does not exist!"

View File

@@ -14,15 +14,13 @@ artixpkg_repo_move_usage() {
Usage: ${COMMAND} [OPTIONS] [SOURCE_REPO] [DEST_REPO] [PKGBASE]...
OPTIONS
-m, --manual Disable auto repo
Possible auto values: $(yaml_array ${ARTIX_DB_MAP[@]})
-p, --push Push pkgbase
-h, --help Show this help text
EXAMPLES
$ ${COMMAND} ${ARTIX_DB[4]} ${ARTIX_DB[5]} libfoo
$ ${COMMAND} --push ${ARTIX_DB[4]} ${ARTIX_DB[5]} libfoo
$ ${COMMAND} --auto --push ${ARTIX_DB_MAP[1]} ${ARTIX_DB_MAP[2]} libfoo
$ ${COMMAND} --push ${ARTIX_DB_MAP[1]} ${ARTIX_DB_MAP[2]} libfoo
_EOF_
}
@@ -37,7 +35,7 @@ artixpkg_repo_move() {
local pkgbase
local PUSH=0
local AUTO=1
local AUTO=0
local DEST
local SRC
@@ -48,10 +46,6 @@ artixpkg_repo_move() {
artixpkg_repo_move_usage
exit 0
;;
-m|--manual)
AUTO=0
shift
;;
-p|--push)
PUSH=1
shift
@@ -65,17 +59,12 @@ artixpkg_repo_move() {
esac
done
SRC="$1"
SRC="$1"
DEST="$2"
shift 2
if (( AUTO )); then
if ! in_array "${SRC}" "${ARTIX_DB_MAP[@]}"; then
die "${SRC} does not exist!"
fi
if ! in_array "${DEST}" "${ARTIX_DB_MAP[@]}"; then
die "${DEST} does not exist!"
fi
if in_array "${SRC}" "${ARTIX_DB_MAP[@]}" && in_array "${DEST}" "${ARTIX_DB_MAP[@]}"; then
AUTO=1
else
if ! in_array "${SRC}" "${ARTIX_DB[@]}"; then
die "${SRC} does not exist!"

View File

@@ -14,15 +14,13 @@ artixpkg_repo_remove_usage() {
Usage: ${COMMAND} [OPTIONS] [DEST_REPO] [PKGBASE]...
OPTIONS
-m, --manual Disable auto repo
Possible auto values: $(yaml_array ${ARTIX_DB_MAP[@]})
-p, --push Push pkgbase
-h, --help Show this help text
EXAMPLES
$ ${COMMAND} ${ARTIX_DB[4]} libfoo
$ ${COMMAND} --push ${ARTIX_DB[4]} libfoo
$ ${COMMAND} --auto --push ${ARTIX_DB_MAP[2]} libfoo
$ ${COMMAND} --push ${ARTIX_DB_MAP[2]} libfoo
_EOF_
}
@@ -37,7 +35,7 @@ artixpkg_repo_remove() {
local pkgbase
local PUSH=0
local AUTO=1
local AUTO=0
local DEST=''
while (( $# )); do
@@ -46,10 +44,6 @@ artixpkg_repo_remove() {
artixpkg_repo_remove_usage
exit 0
;;
-m|--manual)
AUTO=0
shift
;;
-p|--push)
PUSH=1
shift
@@ -67,10 +61,8 @@ artixpkg_repo_remove() {
shift
pkgbases=("$@")
if (( AUTO )); then
if ! in_array "${DEST}" "${ARTIX_DB_MAP[@]}"; then
die "${DEST} does not exist!"
fi
if in_array "${DEST}" "${ARTIX_DB_MAP[@]}"; then
AUTO=1
else
if ! in_array "${DEST}" "${ARTIX_DB[@]}"; then
die "${DEST} does not exist!"