#! /bin/bash

if [[ $(uname -m) == "x86_64" ]]
then
    wget --backups=0 "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.14.tgz"
    tar -zxf ./mongodb-linux-x86_64-3.6.14.tgz --strip-components=1
else
    IFS=" " read -a links <<< $(apt-get -y --print-uris install mongodb | egrep -o "https?://[^']+")
    for link in ${links[@]}
    do
        wget --backups=0 ${link}
    done

    IFS=" " read -a deb_pkgs <<< $(ls ./ | egrep "\.deb")
    for pkg in ${deb_pkgs[@]}
    do
        echo "Extracting ${pkg}..."
        dpkg-deb -R ${pkg} ./
    done

    mv usr/bin bin
fi
