#!/usr/bin/sh

#Licence GPLv3 or later
#Author: Alexey Loginov

export TEXTDOMAIN="aum++"
export TEXTDOMAINDIR="/usr/share/locale"
. gettext.sh

USER0="$1"
DISTR0="$2"

MES0="$(gettext 'You must write user as the first parameter')"
MES1="$(eval_gettext 'User $USER0 does not exist')"
MES2="$(gettext 'You must write distro as the second parameter')"
MES3="$(eval_gettext 'Distro $DISTR0 does not exist')"

if [ -z "$USER0" ]
then
  echo "$MES0"
  exit 0
fi

if [ ! -d "/home/$USER0" ]
then
  echo "$MES1"
  exit 0
fi

if [ -z "$DISTR0" ]
then
  echo "$MES2"
  exit 0
fi

if [ ! -d "/home/$USER0/repo/$DISTR0" ]
then
  echo "$MES3"
  exit 0
fi

# Clean all
rm -rf /home/$USER0/repo/$DISTR0/SRPMS/media_info/*
rm -rf /home/$USER0/repo/$DISTR0/RPMS/i586/media_info/*
rm -rf /home/$USER0/repo/$DISTR0/RPMS/noarch/media_info/*
rm -rf /home/$USER0/repo/$DISTR0/RPMS/x86_64/media_info/*

# Generate lists
genhdlist2 --xml-info /home/$USER0/repo/$DISTR0/SRPMS  --allow-empty-media
genhdlist2 --xml-info /home/$USER0/repo/$DISTR0/RPMS/i586  --allow-empty-media
genhdlist2 --xml-info /home/$USER0/repo/$DISTR0/RPMS/noarch  --allow-empty-media
genhdlist2 --xml-info /home/$USER0/repo/$DISTR0/RPMS/x86_64  --allow-empty-media

# Correct rights
chmod 644 /home/$USER0/repo/$DISTR0/SRPMS/*rpm
chmod 644 /home/$USER0/repo/$DISTR0/RPMS/i586/*.rpm
chmod 644 /home/$USER0/repo/$DISTR0/RPMS/noarch/*rpm
chmod 644 /home/$USER0/repo/$DISTR0/RPMS/x86_64/*rpm
