#!/bin/bash

echo -n $( dirname -- "$( readlink -f -- "$0" )" ) > pwd.txt

CWD=$(cat pwd.txt)

packages=$(cat packages.txt)

for package in ${packages}
do
    if [ -d "$package" ]; then
        cd "$CWD/$package"
        git pull
        cd "$CWD"
    else
        access_location=$(curl -ILs https://gitlab.archlinux.org/archlinux/packaging/packages/${package} | grep location | awk '{print $2}')
        if [[ "$access_location" == *"gitlab.archlinux.org/users"* ]]; then
            echo ""
        else
            git clone "https://gitlab.archlinux.org/archlinux/packaging/packages/${package}.git"
        fi
    fi
done
