#!/bin/bash

fedoras="29 30 31"

tar xf rpm.tar.bz2
chown root:root *.rpm
chmod 644 *.rpm

for version in $fedoras
do

    for i in *.fc$version.i686.rpm;
    do
        filename="${i##*/}"
        firstletter="${filename:0:1}"

        echo "Copying ${i} to releases/${version}/i686/os/${firstletter,,}"
        mkdir -p releases/$version/i686/os/${firstletter,,}
        cp -f $i releases/$version/i686/os/${firstletter,,}
        
        echo "Copying ${i} to releases/${version}/x86_64/os/${firstletter,,}"
        mkdir -p releases/$version/x86_64/os/${firstletter,,}
        cp -f $i releases/$version/x86_64/os/${firstletter,,}
    done

    for i in *.fc$version.x86_64.rpm;
    do
        filename="${i##*/}"
        firstletter="${filename:0:1}"
        
        echo "Copying ${i} to releases/${version}/x86_64/os/${firstletter,,}"
        mkdir -p releases/$version/x86_64/os/${firstletter,,}
        cp -f $i releases/$version/x86_64/os/${firstletter,,}
    done
    
    for i in *.fc$version.aarch64.rpm;
    do
        filename="${i##*/}"
        firstletter="${filename:0:1}"
        
        echo "Copying ${i} to releases/${version}/aarch64/os/${firstletter,,}"
        mkdir -p releases/$version/aarch64/os/${firstletter,,}
        cp -f $i releases/$version/aarch64/os/${firstletter,,}
    done
    
    for i in *.fc$version.armv7hl.rpm;
    do
        filename="${i##*/}"
        firstletter="${filename:0:1}"
        
        echo "Copying ${i} to releases/${version}/armhfp/os/${firstletter,,}"
        mkdir -p releases/$version/armhfp/os/${firstletter,,}
        cp -f $i releases/$version/armhfp/os/${firstletter,,}
    done
    
    for i in *.fc$version.noarch.rpm;
    do
        filename="${i##*/}"
        firstletter="${filename:0:1}"
        
        echo "Copying ${i} to releases/${version}/i686/os/${firstletter,,}"
        mkdir -p releases/$version/i686/os/${firstletter,,}
        cp -f $i releases/$version/i686/os/${firstletter,,}
        
        echo "Copying ${i} to releases/${version}/x86_64/os/${firstletter,,}"
        mkdir -p releases/$version/x86_64/os/${firstletter,,}
        cp -f $i releases/$version/x86_64/os/${firstletter,,}

        echo "Copying ${i} to releases/${version}/aarch64/os/${firstletter,,}"
        mkdir -p releases/$version/aarch64/os/${firstletter,,}
        cp -f $i releases/$version/aarch64/os/${firstletter,,}

        echo "Copying ${i} to releases/${version}/armhfp/os/${firstletter,,}"
        mkdir -p releases/$version/armhfp/os/${firstletter,,}
        cp -f $i releases/$version/armhfp/os/${firstletter,,}
    done
    
    for i in *.fc$version.src.rpm;
    do
        filename="${i##*/}"
        firstletter="${filename:0:1}"
        
        echo "Copying ${i} to releases/${version}/source/SRPMS/${firstletter,,}"
        mkdir -p releases/$version/source/SRPMS/${firstletter,,}
        cp -f $i releases/$version/source/SRPMS/${firstletter,,}
    done
done

rm *.rpm
rm rpm.tar.bz2
