82 lines
3.0 KiB
Bash
Executable File
82 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Makedist automatic clean script
|
|
# Copyright (c) 2007-2023 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
|
#
|
|
. /etc/sysconfig/makedist
|
|
|
|
[ "$MAKEDIST_CRON_ENABLE" = "1" ] || exit 0
|
|
|
|
SOURCEDIR=/var/makedist
|
|
[ "$TODAYDATE" ] || TODAYDATE=`date +%Y%m%d`
|
|
LANGS="it en"
|
|
ARCHS="i586 arm x86_64 aarch64"
|
|
|
|
tmpfile=`mktemp`
|
|
|
|
[ "$tmpfile" ] || {
|
|
echo "Error: cannot create temporary files; aborting."
|
|
exit 1
|
|
}
|
|
|
|
for m in $MILESTONES; do
|
|
DESTBASEDIR=${REPODIR_LOCAL}/media/$m
|
|
for l in $LANGS; do
|
|
for d in `find $DESTBASEDIR/*/$l -maxdepth 0 -type d`; do
|
|
for a in $ARCHS; do
|
|
> $tmpfile
|
|
# the following code was used to recover when unetbootin symlink was added causing all iso to be moved
|
|
#for f in `find $d -type l`; do
|
|
# rl=`readlink -f $f`
|
|
# r=`basename $rl`
|
|
# [ -e $d/old/$r ] && mv $d/old/$r* $d/
|
|
#done
|
|
for f in `find $d -maxdepth 1 -type f -a \( -name "*.$a.iso" -o -name "*.$a.cpio.gz" -o -name "*.$a.tar.gz" -o -name "*.$a.tar.xz" -o -name "*.$a.tar.bz2" -o -name "*.$a.img.gz" \)`; do
|
|
echo `stat -c %Z $f` `basename $f` >> $tmpfile
|
|
done
|
|
# move releases to /old subdir except the current one
|
|
filecount=0
|
|
for f in `cat $tmpfile | sort -r | awk '{ print $2 }' `; do
|
|
if [ $filecount = 0 ]; then
|
|
[ "$VERBOSE" -o "$SIMULATE" ] && echo "KEEP $f"
|
|
else
|
|
[ "$VERBOSE" -o "$SIMULATE" ] && echo "MOVE $f"
|
|
[ "$SIMULATE" ] && continue
|
|
[ -e $d/old ] || mkdir -p $d/old
|
|
mv $d/$f $d/old/
|
|
[ -e $d/$f.MD5.txt ] && mv $d/$f.MD5.txt $d/old/
|
|
[ -e $d/$f.torrent ] && mv $d/$f.torrent $d/old/
|
|
fi
|
|
filecount=`expr $filecount + 1`
|
|
done
|
|
# clean old directory
|
|
if [ -d $d/old ]; then
|
|
> $tmpfile
|
|
for f in `find $d/old -maxdepth 1 -name "*.$a.iso" -o -name "*.$a.cpio.gz" -o -name "*.$a.tar.gz" -o -name "*.$a.tar.xz" -o -name "*.$a.tar.bz2" -o -name "*.$a.img.gz"`; do
|
|
echo `stat -c %Z $f` `basename $f` >> $tmpfile
|
|
done
|
|
SNAPSHOT_DATE=
|
|
for f in `cat $tmpfile | sort -r | awk '{ print $2 }' `; do
|
|
SNAPSHOT_DATE_PREVIOUS=$SNAPSHOT_DATE
|
|
SNAPSHOT_DATE=`echo $f | sed "s|.*snapshot-\([0-9]*\)\..*|\1|"`
|
|
if [ "${SNAPSHOT_DATE:0:6}" = "${SNAPSHOT_DATE_PREVIOUS:0:6}" ]; then
|
|
[ "$VERBOSE" -o "$SIMULATE" ] && echo "DELE old/$f ($SNAPSHOT_DATE)"
|
|
[ "$SIMULATE" ] && continue
|
|
rm -f $d/old/$f
|
|
[ -e $d/old/$f.MD5.txt ] && rm -f $d/old/$f.MD5.txt
|
|
[ -e $d/old/$f.torrent ] && rm -f $d/old/$f.torrent
|
|
else
|
|
[ "$VERBOSE" -o "$SIMULATE" ] && echo "KEEP old/$f ($SNAPSHOT_DATE)"
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
# echo
|
|
# ls --sort=time $d/*.iso $d/*.cpio.gz
|
|
#find $DESTBASEDIR -name *.iso
|
|
done
|
|
done
|
|
done
|
|
|
|
[ -e $tmpfile ] && rm -f $tmpfile
|