#!/bin/bash

# Place this file in /home/flask/releases/admin/ and make it executable

TIMESTAMP=${2:-$(date +"%Y%m%d_%H%M%S")}
CURL_OUTFILE="/home/flask/releases/api/$TIMESTAMP.zip"
BRANCH=${1}
HTTP_CODE=$(curl --write-out "%{http_code}" --location --output $CURL_OUTFILE --header "PRIVATE-TOKEN: <GitLab token>" "https://gitlab.com/api/v4/projects/16546505/jobs/artifacts/$BRANCH/download?job=create_artifacts")
NEW_DIR="/home/flask/releases/admin/$TIMESTAMP"
mkdir $NEW_DIR
unzip $CURL_OUTFILE -d $NEW_DIR
rm $CURL_OUTFILE
printf "Response code: $HTTP_CODE\nOut Dir: $NEW_DIR\n"