#!/bin/bash

##Script begins by working in the 32bit repo


echo "which repo are you to work on?"
echo "1) Repo/veclinux-7.1 and VL64-7.1"
echo "2) Repo/veclinux-7.2 and VL64-7.2"
read repo

case $repo in
1)
    REPO="Repo/veclinux-7.1"
    REPO2="Repo/VL64-7.1"
    Bthrower="build-thrower/veclinux-7.1"
    ;;
2)
    REPO="Repo/veclinux-7.2"
    REPO2="Repo/VL64-7.2"
    Bthrower="build-thrower/veclinux-7.2"
    ;;
*)
    echo "Yeah, that's not what I asked"
    exit
    ;;
esac

echo "Beginning work on $REPO"
##Shows the date when last ran.
echo "This script last ran on..."
stat -c%y ~/$REPO/date

rm ~/$REPO/untestedtxz.txt
cd ~/Upload/vectorcontrib/$Bthrower/x86/
echo "Press enter to start update from last run date"
read days
echo "Searching for new packages in build-thrower"

find ./ -name "*txz" -newer ~/Repo/veclinux-7.1/date >> ~/$REPO/untestedtxz.txt
cd ~/$REPO/


while read line
do
sh ~/Repo/MovinFromUntested.sh $line $REPO
done < "./untestedtxz.txt"






##This repeats the above on the 64bit repo

rm ~/$REPO2/untestedtxz.txt
cd ~/Upload/vectorcontrib/$Bthrower/x86_64/

find ./ -name "*txz" -newer ~/Repo/veclinux-7.1/date >> ~/$REPO2/untestedtxz.txt
cd ~/$REPO2/


while read line
do
sh ~/Repo/MovinFromUntested.sh $line $REPO2
done < "./untestedtxz.txt"

echo
echo



##This checks the old repo for anything older than 20 days and deletes them.
for file in $REPO $REPO2;
do
echo "Deleting packages backed up to old after 20 days"
find ~/$file/old/ -mtime +20 -exec rm {} \;
done

##Create a file whose modification time will be the new last ran date
cd ~/Repo/veclinux-7.1/

less1hour=`date -d '1 hour ago' "+%Y%m%d -%H:%M:%S" | sed s'@ @@'g | sed s'/-//'g | sed s'/://'g`
less1hour=`echo ${less1hour:0:12}`

touch -t $less1hour ./"date"

##Ok now that both the 32bit and 64 bit repos have been updated we can makenew



cd ~/$REPO/extra/
sh ./makenew

cd ~/$REPO2/extra/
sh ./makenew

cd ~/
sh ./trigger-vectorlinux




