#!/bin/bash

fedora_releases="35 36 37 38"
fedora_developments="39 40"

chown root:root $1*.rpm
chmod 644 $1*.rpm

for version in $fedora_releases
do

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}releases/${version}/i686/debug/${firstletter}"
            mkdir -p $2releases/$version/i686/debug/${firstletter}
            cp -f $i $2releases/$version/i686/debug/${firstletter}

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

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

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}releases/${version}/x86_64/debug/${firstletter}"
            mkdir -p $2releases/$version/x86_64/debug/${firstletter}
            cp -f $i $2releases/$version/x86_64/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}releases/${version}/x86_64/os/${firstletter}"
            mkdir -p $2releases/$version/x86_64/os/${firstletter}
            cp -f $i $2releases/$version/x86_64/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}releases/${version}/aarch64/debug/${firstletter}"
            mkdir -p $2releases/$version/aarch64/debug/${firstletter}
            cp -f $i $2releases/$version/aarch64/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}releases/${version}/aarch64/os/${firstletter}"
            mkdir -p $2releases/$version/aarch64/os/${firstletter}
            cp -f $i $2releases/$version/aarch64/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}releases/${version}/armhfp/debug/${firstletter}"
            mkdir -p $2releases/$version/armhfp/debug/${firstletter}
            cp -f $i $2releases/$version/armhfp/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}releases/${version}/armhfp/os/${firstletter}"
            mkdir -p $2releases/$version/armhfp/os/${firstletter}
            cp -f $i $2releases/$version/armhfp/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}releases/${version}/i686/debug/${firstletter}"
            mkdir -p $2releases/$version/i686/debug/${firstletter}
            cp -f $i $2releases/$version/i686/debug/${firstletter}

            echo "Copying ${i} to ${2}releases/${version}/x86_64/debug/${firstletter}"
            mkdir -p $2releases/$version/x86_64/debug/${firstletter}
            cp -f $i $2releases/$version/x86_64/debug/${firstletter}

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

            echo "Copying ${i} to ${2}releases/${version}/armhfp/debug/${firstletter}"
            mkdir -p $2releases/$version/armhfp/debug/${firstletter}
            cp -f $i $2releases/$version/armhfp/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}releases/${version}/i686/os/${firstletter}"
            mkdir -p $2releases/$version/i686/os/${firstletter}
            cp -f $i $2releases/$version/i686/os/${firstletter}

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

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

            echo "Copying ${i} to ${2}releases/${version}/armhfp/os/${firstletter}"
            mkdir -p $2releases/$version/armhfp/os/${firstletter}
            cp -f $i $2releases/$version/armhfp/os/${firstletter}
        fi
    done

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

        echo "Copying ${i} to ${2}releases/${version}/source/SRPMS/${firstletter}"
        mkdir -p $2releases/$version/source/SRPMS/${firstletter}
        cp -f $i $2releases/$version/source/SRPMS/${firstletter}
    done
done

for version in $fedora_developments
do

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}development/${version}/i686/debug/${firstletter}"
            mkdir -p $2development/$version/i686/debug/${firstletter}
            cp -f $i $2development/$version/i686/debug/${firstletter}

            echo "Copying ${i} to ${2}development/${version}/x86_64/debug/${firstletter}"
            mkdir -p $2development/$version/x86_64/debug/${firstletter}
            cp -f $i $2development/$version/x86_64/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}development/${version}/i686/os/${firstletter}"
            mkdir -p $2development/$version/i686/os/${firstletter}
            cp -f $i $2development/$version/i686/os/${firstletter}

            echo "Copying ${i} to ${2}development/${version}/x86_64/os/${firstletter}"
            mkdir -p $2development/$version/x86_64/os/${firstletter}
            cp -f $i $2development/$version/x86_64/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}development/${version}/x86_64/debug/${firstletter}"
            mkdir -p $2development/$version/x86_64/debug/${firstletter}
            cp -f $i $2development/$version/x86_64/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}development/${version}/x86_64/os/${firstletter}"
            mkdir -p $2development/$version/x86_64/os/${firstletter}
            cp -f $i $2development/$version/x86_64/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}development/${version}/aarch64/debug/${firstletter}"
            mkdir -p $2development/$version/aarch64/debug/${firstletter}
            cp -f $i $2development/$version/aarch64/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}development/${version}/aarch64/os/${firstletter}"
            mkdir -p $2development/$version/aarch64/os/${firstletter}
            cp -f $i $2development/$version/aarch64/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}development/${version}/armhfp/debug/${firstletter}"
            mkdir -p $2development/$version/armhfp/debug/${firstletter}
            cp -f $i $2development/$version/armhfp/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}development/${version}/armhfp/os/${firstletter}"
            mkdir -p $2development/$version/armhfp/os/${firstletter}
            cp -f $i $2development/$version/armhfp/os/${firstletter}
        fi
    done

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

        if [[ "$filename" == *"-debuginfo-"* ]] || [[ "$filename" == *"-debugsource-"* ]];
        then
            echo "Copying ${i} to ${2}development/${version}/i686/debug/${firstletter}"
            mkdir -p $2development/$version/i686/debug/${firstletter}
            cp -f $i $2development/$version/i686/debug/${firstletter}

            echo "Copying ${i} to ${2}development/${version}/x86_64/debug/${firstletter}"
            mkdir -p $2development/$version/x86_64/debug/${firstletter}
            cp -f $i $2development/$version/x86_64/debug/${firstletter}

            echo "Copying ${i} to ${2}development/${version}/aarch64/debug/${firstletter}"
            mkdir -p $2development/$version/aarch64/debug/${firstletter}
            cp -f $i $2development/$version/aarch64/debug/${firstletter}

            echo "Copying ${i} to ${2}development/${version}/armhfp/debug/${firstletter}"
            mkdir -p $2development/$version/armhfp/debug/${firstletter}
            cp -f $i $2development/$version/armhfp/debug/${firstletter}
        else
            echo "Copying ${i} to ${2}development/${version}/i686/os/${firstletter}"
            mkdir -p $2development/$version/i686/os/${firstletter}
            cp -f $i $2development/$version/i686/os/${firstletter}

            echo "Copying ${i} to ${2}development/${version}/x86_64/os/${firstletter}"
            mkdir -p $2development/$version/x86_64/os/${firstletter}
            cp -f $i $2development/$version/x86_64/os/${firstletter}

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

            echo "Copying ${i} to ${2}development/${version}/armhfp/os/${firstletter}"
            mkdir -p $2development/$version/armhfp/os/${firstletter}
            cp -f $i $2development/$version/armhfp/os/${firstletter}
        fi
    done

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

        echo "Copying ${i} to ${2}development/${version}/source/SRPMS/${firstletter}"
        mkdir -p $2development/$version/source/SRPMS/${firstletter}
        cp -f $i $2development/$version/source/SRPMS/${firstletter}
    done
done
