#!/bin/bash
# Sync mock sign and create repo
# Copyright Stephen Collier 2014
#
# 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/>.

DIST=$1
ARCH=$2

cd /var/ftp/pub/home
find /var/ftp/pub/home  ! \( -user build -a -group mock \) -exec sudo chown build:mock {} \;
find ~/rpmbuild/SOURCES  ! \( -user build -a -group mock \) -exec sudo chown build:mock {} \;
find /var/ftp/pub/home -name "*.rpm" ! -perm 644 -exec chmod 644 {} \;
find /var/ftp/pub/home -name "*.rpm" ! \( -user build -a -group mock \) -exec sudo chown build:mock {} \;
find /var/ftp/pub/home -type d ! \( -user build -a -group mock \) -exec sudo chown build:mock {} \;
#find /var/ftp/pub/home/RPMS/$DIST/$ARCH -mtime -1000 -name "*.rpm" -exec sudo rpm -addsign {} \;
find /var/ftp/pub/home/RPMS/$DIST/$ARCH -mtime -7 -name "*.rpm" -exec sudo rpm -resign {} \;
find /var/ftp/pub/home/RPMS/debug/$DIST/$ARCH -mtime -7 -name "*.rpm" -exec sudo rpm --resign {} \;
find /var/ftp/pub/home/SRPMS -mtime -7 -name "*.rpm" -exec  sudo rpm --resign {} \;

createrepo  --update /var/ftp/pub/home/RPMS/$1/$2
createrepo  --update /var/ftp/pub/home/RPMS/debug/$1/$2
sudo createrepo   /var/ftp/pub/home/RPMS/$1/$2
repoview  -t "SCRPMS $1 $2" -u http://scrpms.net/pub/RPMS/$1/$2 /var/ftp/pub/home/RPMS/$1/$2
repoview  -t "SCRPMS debug $1 $2" -u http://scrpms.net/pub/RPMS/debug/$1/$2 /var/ftp/pub/home/RPMS/debug/$1/$2
#ssh docker.scrpms.net /usr/local/bin/homerepo $DIST $ARCH
