10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 12:56:14 +01:00
quantum_package/scripts/archive_ezfio.sh

79 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# Computes the MD5 digest of an EZFIO file, and creates a tar.
# Thu Apr 3 16:55:50 CEST 2014
if [[ -z ${QPACKAGE_ROOT} ]]
then
print "The QPACKAGE_ROOT environment variable is not set."
print "Please reload the quantum_package.rc file."
fi
function archive()
{
2014-09-02 16:22:00 +02:00
FILE="$1"
MD5="$2"
ARCHIVE="${QPACKAGE_ROOT}/data/cache/$MD5"
if [[ -f "$ARCHIVE" ]]
then
2014-09-02 16:22:00 +02:00
if ! diff "$FILE" "${QPACKAGE_ROOT}/data/cache/$MD5" &> /dev/null
then
echo "Something went wrong. The file"
2014-09-02 16:22:00 +02:00
echo "${QPACKAGE_ROOT}/data/cache/$MD5"
echo "is different from $FILE"
echo "Aborting"
return 1
fi
else
2014-09-02 16:22:00 +02:00
cp "$FILE" "${QPACKAGE_ROOT}/data/cache/$MD5"
fi
}
EZFIO_FILE=$(basename ${1})
if [[ -z ${EZFIO_FILE} ]]
then
echo "Usage: $(basename $0) <EZFIO_FILE>"
exit 1
fi
2014-09-02 16:22:00 +02:00
cd "${QPACKAGE_ROOT}/EZFIO/src"
FILES=($(python << EOF | sort
from read_config import *
for group in groups:
if group == "ezfio":
continue
for d in groups[group]:
if d[2] == ():
suffix = ""
else:
suffix = ".gz"
print group+'/'+d[0]+suffix
print "ezfio/creation"
print "ezfio/library"
EOF
))
cd $OLDPWD
2014-09-02 16:22:00 +02:00
MD5_FILE=$(basename "${EZFIO_FILE}" .ezfio).md5
rm -f -- "${MD5_FILE}"
for FILE in ${FILES[@]}
do
2014-09-02 16:22:00 +02:00
FILE="${EZFIO_FILE}/${FILE}"
MD5=$(md5sum "${FILE}" 2>/dev/null | cut -d ' ' -f 1)
if [[ ! -z $MD5 ]]
then
2014-09-02 16:22:00 +02:00
if ! archive "$FILE" "$MD5"
then
2014-09-02 16:22:00 +02:00
rm -- "${MD5_FILE}"
exit 1
fi
2014-09-02 16:22:00 +02:00
echo "$MD5" "$FILE" >> "${MD5_FILE}"
fi
done