Skip to content

Instantly share code, notes, and snippets.

@DavidePrincipi
Created February 6, 2018 13:58
Show Gist options
  • Save DavidePrincipi/441d77eb5622b12785a8872611a7ada0 to your computer and use it in GitHub Desktop.
Save DavidePrincipi/441d77eb5622b12785a8872611a7ada0 to your computer and use it in GitHub Desktop.
Merge %changelog from multiple spec files and sort entries by date

sort-changelog.sh

Merge changelogs from multiple RPM files and sort entries by date

$ bash sort-changelog.sh file1.rpm file2.rpm [...]
#!/bin/bash
#
# Copyright (C) 2018 Davide Principi <davide.principi@nethesis.it>
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#
# requires jq (https://stedolan.github.io/jq)
#
rpm -qp --changelog "$@" | while read line; do
entry="${line}"
read skip1 wd mo da yr skip2 <<<"${line}"
echo -n $(date --date="$wd $mo $da $yr" +"%s:")
while read line; do
if [[ "${line}" == "" ]]; then
echo "${entry}" | jq -R -s .
break
else
entry="${entry}"$'\n'"${line}"
fi
done
done | sort -n -r | cut -d : -f 2- | jq -r .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment