#!/bin/bash
# Copyright Stephen Collier 2014,2019
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#sudo umount /var/ftp/pub/home 1>/dev/null 2>&1 || exit 0
#sudo mount /var/ftp/pub/home
if [ $1 == "el8" ]
then
        timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-8-x86_64 el8 x86_64 "https://repo.almalinux.org/almalinux/8/BaseOS/x86_64/os/Packages/"

fi
if [ $1 == "el9" ]
then
        timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-9-x86_64 el9 x86_64 "https://repo.almalinux.org/almalinux/9/BaseOS/x86_64/os/Packages/"

fi
if [ $1 == "el10" ]
then
        timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-10-x86_64 el10 x86_64 "https://repo.almalinux.org/almalinux/10/BaseOS/x86_64/os/Packages/"

fi
if [ $1 == "f41" ]
then
timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-f41-x86_64 f41 x86_64 "https://dl.fedoraproject.org/pub/fedora/linux/updates/41/Everything/x86_64/Packages/k/"
fi
if [ $1 == "f42" ]
then
timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-f42-x86_64 f42 x86_64 "https://dl.fedoraproject.org/pub/fedora/linux/updates/42/Everything/x86_64/Packages/k/"
fi
if [ $1 == "f43" ]
then
timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-f43-x86_64 f43 x86_64 "https://dl.fedoraproject.org/pub/fedora/linux/updates/43/Everything/x86_64/Packages/k/"
fi
if [ $1 == "f44" ]
then
timeout 24h /usr/local/bin/update_mythtv_rpm_docker sc-atrpms-f44-x86_64 f44 x86_64 "https://dl.fedoraproject.org/pub/fedora/linux/updates/44/Everything/x86_64/Packages/k/"
fi
#rsync to upstream server and update last update file if changes
#if [ `rsync -aiz --delete --password-file=/usr/local/etc/pass.txt /var/ftp/pub/home/ jeronimo@167.160.167.42::scrpms-up | wc -l` != '0' ]; then
#    date --utc > /var/ftp/pub/home/last_update;
#    rsync -avz --delete --password-file=/usr/local/etc/pass.txt /var/ftp/pub/home/ jeronimo@167.160.167.42::scrpms-up 2>&1 >/tmp/rsync$$
#fi

if [ `rsync -rlptDiz --delete --password-file=/usr/local/etc/pass.txt /var/ftp/pub/home/* jeronimo@216.189.151.149::scrpms-up | wc -l` != '0' ]; then
    date --utc > /var/ftp/pub/home/last_update;
    rsync -rlptDvz --delete --password-file=/usr/local/etc/pass.txt /var/ftp/pub/home/* jeronimo@216.189.151.149::scrpms-up 2>&1 >/tmp/rsync$$
fi
sudo rsync -av /home/build/tmp/* /home/build/rpmbuild/SOURCES/
