#!/usr/bin/env bash
cd /var/tmp


PROJECT=atjontv/Scripts
PRERELEASE=false
RELEASE="2.5.0"
VERSION=$( date +%Y-%m-%d_ )git
DOWNLOAD_DIR=/tmp

# make a containing directory
mkdir -p /var/tmp/gitsync-"${RELEASE}"
cd /var/tmp/gitsync-"${RELEASE}" || exit

cat > ./description-pak << EOF
This script has been made to make the creation of mirrors from gitlab.atvg-studios.at to github.com easier
EOF

cat > ./checkinstall_it.sh << 'EOF'

echo "ENTERING CHECKINSTALL"

BASE_URL='https://gitlab.atvg-studios.com/atjontv/Scripts'
BASE_USER='atjontv'
BASE_REPO='Scripts'
LICENSE_URL="${BASE_URL}/${BASE_USER}/${BASE_REPO}"/-/raw/gitsync/LICENSE?inline=false
# wget -c ${LICENSE_URL}

VERSION=$( date +%Y-%m-%d_ )git
VERSION=2.5.0 
RELEASE=git
LICENSE=MIT

# make a new temporary directory for this use
BASE_TMP_DIR=~/tmptmp/checkinstall_tmp
mkdir -p ${BASE_TMP_DIR}

# do your work
checkinstall -y --fstrans \
	--pkgname=gitsync \
	--pkgversion=${VERSION}\
	--pkgrelease=${RELEASE} \
	--pkgarch=amd64 \
	--pkggroup=admin \
	--pkglicense=LICENSE \
 	--pkgsource=${LATEST_URL} \
 	--maintainer=cyteen@ring-zero.co.uk \
 	--requires=bash,wget,git \
 	-D \
 	bash ./install.sh
EOF

cat > ./install.sh << 'EOF'
BASE_URL='https://gitlab.atvg-studios.com/'
BASE_USER='atjontv'
BASE_REPO='Scripts'
LATEST_URL=https://gitlab.atvg-studios.com/atjontv/Scripts.git
# Download and copy the latest version to /usr/local/bin and make executable
#git clone ${LATEST_URL} /var/tmp/gitsync
#bash /var/tmp/gitsync/gitsync.sh install
mkdir -p /usr/local/bin
curl https://gitlab.atvg-studios.com/atjontv/Scripts/-/raw/gitsync/gitsync.sh --output /usr/local/bin/gitsync 
chmod +x /usr/local/bin/gitsync

EOF

bash ./checkinstall_it.sh
