#!/usr/bin/env bash

USER="c0n"
PROJECT="relightable_fc8c4a"
LICENSE="mit"
SECTION="admin"
HOMEPAGE="https://relightable.c0n.de"
BUILD_HOME="/var/tmp/relightable_build"
#VERSION="2.1.0" 
PACKAGE="relightable"
#VERSION=$(curl "https://api.github.com/repos/${USER}/${PROJECT}/tags?per_page=5" | jq -r '.[0] | .name')
#VERSION=${VERSION:1} # strip the preceding 'v'
VERSION="1.0.0"
DEBEMAIL="person@company.tld"
DEBFULLNAME="Testy McTester"
DESCRIPTION="Recolourable enlightenment desktop default theme."
LONG_DESCRIPTION=" The standard theme comes in blue, this theme allows any colour to be substituted."

REQUIRES="imagemagick"
BUILD_DIR="/var/tmp/relightable_build"
WORKDIR="/var/tmp/relightable_build"

## Checkinstall variables - see defaults in /etc/checkinstallrc
DOC_DIR=/usr/share/doc

# make a new temporary directory for this use to avoid permission issues.
BASE_TMP_DIR=~/tmptmp/checkinstall_tmp
#-------------------------------------------------------------------------------
mkdir -p ${BUILD_DIR}

## Create and populate the install scripts and documentation for checkinstall
cat > ${BUILD_DIR}/description-pak << EOF
Recolorable-wizard 

The standard theme comes in blue, this theme allows any colour to be substituted.
EOF

# | preinstall-pak  | Run BEFORE the package is INSTALLED  |
cat > ${BUILD_DIR}/preinstall-pak << EOF
#!/usr/bin/env bash
EOF

# | postinstall-pak | Run AFTER the package is INSTALLED   |
cat > ${BUILD_DIR}/postinstall-pak << EOF
#!/usr/bin/env bash
EOF

# | preremove-pak   | Run BEFORE the package is REMOVED    |
cat > ${BUILD_DIR}/preremove-pak << EOF
#!/usr/bin/env bash
EOF

# | postremove-pak  | Run AFTER the package is REMOVED
cat > ${BUILD_DIR}/postremove-pak << EOF
#!/usr/bin/env bash
EOF

## Make the doc-pak directory for README, INSTALL, COPYING, Changelog, TODO, CREDITS
mkdir -p ${BUILD_DIR}/doc-pak
#cp README INSTALL COPYING Changelog TODO CREDITS doc-pak


cat > ${BUILD_DIR}/doc-pak/README << 'EOF'
*** rElightable ***
     - recolorable E17 default theme 

based on the E17 default theme: http://svn.enlightenment.org/svn/e/trunk/e/data/themes
patched by Stefan Baur <rElightable@c0n.de>

How to build:
a simple
  make
should do the trick.
Note: you need to have all the necessary EFL libraries and edje_cc installed.

How to change colors:
Open Enlightenment Settings -> Colors, select "Focus" Color, change to your liking and accept.
Note: make sure you set correct (non transparent) alpha.

EOF

cat > ${BUILD_DIR}/checkinstall_it.sh << FOE

## Checkinstall variables - see defaults in /etc/checkinstallrc
DOC_DIR=/usr/share/doc

# make a new temporary directory for this use to avoid permission issues.
BASE_TMP_DIR=~/tmptmp/checkinstall_tmp
mkdir -p '${BASE_TMP_DIR}'

# do your work
checkinstall -y --fstrans \
	--pkgname=${PROJECT} \
	--pkgversion=${VERSION}\
	--pkgrelease=${RELEASE} \
	--pkgarch=amd64 \
	--pkggroup=admin \
	--pkglicense=LICENSE \
 	--pkgsource=${LATEST_URL} \
 	--maintainer=cyteen@ring-zero.co.uk \
 	--requires=${REQUIRES} \
	--recommends=${RECOMENDS} \
	--suggests=${SUGGESTS} \
 	-D \
 	bash ${BUILD_DIR}/install.sh
FOE

echo "Writing install.sh to: ${BUILD_DIR}/install.sh" 
cat > ${BUILD_DIR}/install.sh << FOE
#!/usr/bin/env bash
set -e
#set -x


## Download and copy the latest version to the shared theme directory
#wget -c -P /usr/share/elementary/themes https://relightable.c0n.de/themes/rElightable.edj


wget -c -O /usr/share/elementary/themes/relightable_fc8c4a.edj https://relighted.c0n.de/?get=198#198
FOE

bash ${BUILD_DIR}/checkinstall_it.sh
