#!/bin/bash

VERSION_COUNT=$1
WEB_PATH="https://mirror.truenetwork.ru/gnu"
VERSIONS=("gcc-4.0.4"
              "gcc-4.3.2"
              "gcc-4.3.3"
              "gcc-4.3.4"
              "gcc-4.3.5"
              "gcc-4.3.6"
              "gcc-4.4.0"
              "gcc-4.4.1"
              "gcc-4.4.2"
              "gcc-4.4.3"
              "gcc-4.4.4"
              "gcc-4.4.5"
              "gcc-4.4.6"
              "gcc-4.4.7"
              "gcc-4.5.0"
              "gcc-4.5.1"
              "gcc-4.5.2"
              "gcc-4.5.3"
              "gcc-4.5.4"
              "gcc-4.6.0"
              "gcc-4.6.1"
              "gcc-4.6.2"
              "gcc-4.6.3"
              "gcc-4.6.4"
              "gcc-4.7.0"
              "gcc-4.7.1"
              "gcc-4.7.2"
              "gcc-4.7.3"
              "gcc-4.7.4"
              "gcc-4.8.0"
              "gcc-4.8.1"
              "gcc-4.8.2"
              "gcc-4.8.3"
              "gcc-4.8.4"
              "gcc-4.8.5"
              "gcc-4.9.0"
              "gcc-4.9.1"
              "gcc-4.9.2"
              "gcc-4.9.3"
              "gcc-4.9.4"
              "gcc-5.1.0"
              "gcc-5.2.0"
              "gcc-5.3.0"
              "gcc-5.4.0"
              "gcc-5.5.0"
              "gcc-6.1.0"
              "gcc-6.2.0"
              "gcc-6.3.0"
              "gcc-6.4.0"
              "gcc-6.5.0"
              "gcc-7.1.0"
              "gcc-7.2.0"
              "gcc-7.3.0"
              "gcc-7.4.0"
              "gcc-7.5.0"
              "gcc-8.1.0"
              "gcc-8.2.0"
              "gcc-8.3.0"
              "gcc-8.4.0"
              "gcc-8.5.0"
              "gcc-9.1.0"
              "gcc-9.2.0"
              "gcc-9.3.0"
              "gcc-9.4.0"
              "gcc-9.5.0"
              "gcc-10.1.0"
              "gcc-10.2.0"
              "gcc-10.3.0"
              "gcc-10.4.0"
              "gcc-10.5.0"
              "gcc-11.1.0"
              "gcc-11.2.0"
              "gcc-11.3.0"
              "gcc-11.4.0"
              "gcc-11.5.0"
              "gcc-12.1.0"
              "gcc-12.2.0"
              "gcc-12.3.0"
              "gcc-12.4.0"
              "gcc-13.1.0"
              "gcc-13.2.0"
              "gcc-13.3.0"
              "gcc-14.1.0"
              "gcc-14.2.0" )

mkdir downloads
mkdir downloads/gcc
cd downloads/gcc || exit

tar -cf gcc.tar -T /dev/null

for version in "${VERSIONS[@]:0:$VERSION_COUNT}"
do
  wget "$WEB_PATH/gcc/$version/$version.tar.gz"

  tar -xf "$version.tar.gz"
  rm "$version.tar.gz"

  tar --append --file=gcc.tar "$version"
  rm -r "$version"
done
