0

I am going to create my own internal repository service via createrepo and want to provide an Java repository as well.

Downloading the JRE and JDK packages automatically and as described at Stack Overflow leaves me with files which have a timestamp from the time they were downloaded. The creation time of the files is set to the runtime of the download script.

For further processing I like to have the timestamps set to the build time of the RPM package (... so that I can query them via ls -al, ll, --full-time, etc.).

How to change creation time of files (RPM) from download time to build time automatically?

1

After some research I've found that I can query the RPM build time via rpm -qip.

BUILDTIME=$(rpm -qip --nosignature ${FILENAME} | grep -i "Build Date  : " | sed -e 's/Build Date  : //g')
echo ${BUILDTIME}

The date command can reformat the given date and time string

TIMESTAMP=$(date --date="${BUILDTIME}" "+%Y%m%d%H%M")
echo ${TIMESTAMP}

so that it could be later used with the touch command.

touch -m -a -t ${TIMESTAMP} ${FILENAME}

By iterating over all files within a specific directory it is possible to list all creation times of all packages contained and modify it automatically.

#!/bin/bash

for FILENAME in *.rpm; do

    echo ${FILENAME}

    BUILDTIME=$(rpm -qip --nosignature ${FILENAME} | grep -i "Build Date  : " | sed -e 's/Build Date  : //g')
    echo ${BUILDTIME}

    TIMESTAMP=$(date --date="${BUILDTIME}" "+%Y%m%d%H%M")
    echo ${TIMESTAMP}

    touch -m -a -t ${TIMESTAMP} ${FILENAME}

done
2
  • 1
    Or you can use rpm --qf ... to extract only the headers you care about: touch "$PACKAGE" -d"$(rpm -qp "$PACKAGE" --qf "%{BUILDTIME:date}\n")" – Ignacio Vazquez-Abrams Jul 30 '18 at 7:50
  • Just tested with rpm -qp "${FILENAME}" --qf "%{BUILDTIME:date}\n")" and found it more elegant. Thanks for the hint and +1. – U880D Jul 30 '18 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.