1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#!/bin/bash
set -eu
function print_usage(){
cat <<END
NAME
cmake-fedora-pkgdb - Obtain package and branch information
SYNOPSIS
cmake-fedora-pkgdb [package]
cmake-fedora-pkgdb git-branch [package]
cmake-fedora-pkgdb newest-nvr <package>
cmake-fedora-pkgdb newest-changelog <package>
DESCRIPTION
This program get the package information from following sources:
- Fedora Product Definition Center
- Fedora Project Packages GIT repositories
Following sub-command are recognized:
git-branch [package]
Return corresponding active fedpkg git branches.
If package is given, then it will return active branches.
newest-nvr <package>
Returns NVR (e.g. cmake-fedora-2.8.0-1.fc26) of the package in master
branch.
newest-changelog <package>
Returns ChangeLog of the package in master branch.
OPTIONS
-h: Show the help
BUGS
This program will NOT filter out Orphaned and Retired branches.
END
}
ScriptFile=$(readlink -e "${BASH_SOURCE[0]}" 2>/dev/null || realpath "${BASH_SOURCE[0]}")
export ScriptDir=$(dirname $ScriptFile)
source $ScriptDir/cmake-fedora-functions
##=== Function start ===
function cmfd_rest_api_get(){
local p=$1
local query=${2-}
local cacheName=${3-}
cmfd_manage_cache "pkgdb_$cacheName" "curl -s -f -X GET 'https://pdc.fedoraproject.org/rest_api/v1/$p/$query'"
}
function cmfd_get_release_git_branches(){
local name=$1
cmfd_rest_api_get 'releases' "?active=true&name=$name" "releases_$name" |\
python -m json.tool | sed -n -e '/branch/ s/^.*\"branch\": "\([^\"]*\)".*$/\1/gp'
}
function cmfd_get_package_spec_filename(){
local name=$1
cmfd_manage_cache "$name.spec" "curl -s -f -X GET 'https://src.fedoraproject.org/cgit/rpms/${name}.git/plain/${name}.spec'" > /dev/null
echo "$LOCAL_CACHE_DIR/$name.spec"
}
##=== Dependency Checking ===
cmfd_set_dependencies_programs curl
##=== Parameter Parsing ===
while getopts "h" opt;do
case $opt in
h)
print_usage
exit 0
;;
esac
done
shift $((OPTIND-1))
SubCommand=${1-}
#TODO
case $SubCommand in
git-branch )
Package=${2-}
if [[ -z $Package ]];then
##=== Get Active branches ===
ActiveBranchArray=( $(cmfd_get_release_git_branches 'Fedora%20EPEL') )
ActiveBranchArray+=( $(cmfd_get_release_git_branches 'Fedora') )
if [[ ${#ActiveBranchArray[@]} -le 0 ]];then
echo "No Branch are found" > /dev/stderr
exit 1
fi
cmfd_inverse_list 'ActiveBranchArray'
else
##=== Get Package Active branches ===
ActiveBranchArray=( $(cmfd_rest_api_get 'component-branches'\
"?active=true&global_component=$Package&fields=name" "component_branch_$Package" |\
python -m json.tool | sed -n -e '/name/ s/^.*"name": "\([^"]*\)".*$/\1/gp' ) )
if [[ ${#ActiveBranchArray[@]} -le 0 ]];then
echo "No Branch are found" > /dev/stderr
exit 1
fi
cmfd_inverse_list 'ActiveBranchArray'
fi
;;
newest-nvr )
Package=${2-}
if [[ -z $Package ]];then
print_usage
echo "[ERROR] Requires <Package>" > /dev/stderr
exit $EXIT_FATAL_INVALID_OPTIONS
fi
specFile=$(cmfd_get_package_spec_filename $Package)
if ! grep "^Name:" "$specFile" &> /dev/null ;then
echo "[ERROR] Package $Package not found" > /dev/stderr
exit $EXIT_FATAL_INVALID_OPTIONS
fi
rpm -q --qf "%{nvr}" --specfile "$specFile"
;;
newest-changelog )
Package=${2-}
if [[ -z $Package ]];then
print_usage
echo "[ERROR] Requires <Package>" > /dev/stderr
exit $EXIT_FATAL_INVALID_OPTIONS
fi
specFile=$(cmfd_get_package_spec_filename $Package)
if ! grep "^Name:" "$specFile" &> /dev/null ;then
echo "[ERROR] Package $Package not found" > /dev/stderr
exit $EXIT_FATAL_INVALID_OPTIONS
fi
rpm -q --changelog --specfile "$specFile"
;;
* )
Package=$SubCommand
$0 git-branch $Package
;;
esac
|