#!/bin/bash

# Slackware build script for gnome-shell-extension-tray-icons-reloaded 

# Copyright 2022-2023 Frank Honolka <slackernetuk@gmail.com>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=gnome-shell-extension-tray-icons-reloaded
SRCNAM=Tray-Icons-Reloaded
VERSION=${VERSION:-32}
TAG=_gfs
BUILD=${BUILD:-1}
PKGTYPE=${PKGTYPE:-txz}
_commit=54438e11e066b9ef66426d00e3a0951565a5e99f

ARCH=noarch

TMP=${TMP:-/tmp/gfs}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-$CWD}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG
cd $TMP
rm -rf $SRCNAM
git clone https://github.com/MartinPL/Tray-Icons-Reloaded.git
cd $SRCNAM
git checkout $_commit
#sed -i 's/"shell-version": \["47"\]/"shell-version": ["46", "47"]/g' metadata.json

mkdir -p $PKG/usr/share/gnome-shell/extensions/trayIconsReloaded@selfmade.pl
cp -r * $PKG/usr/share/gnome-shell/extensions/trayIconsReloaded@selfmade.pl/
rm -rf $PKG/usr/share/gnome-shell/extensions/trayIconsReloaded@selfmade.pl/makefile

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a LICENSE README.md $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
if [ -f $CWD/slack-required ]; then cat $CWD/slack-required > $PKG/install/slack-required; fi
cat $CWD/slack-desc > $PKG/install/slack-desc
if [ -f $CWD/slack-suggests ]; then cat $CWD/slack-suggests > $PKG/install/slack-suggests; fi
if [ -f $CWD/slack-conflicts ]; then cat $CWD/slack-conflicts > $PKG/install/slack-conflicts; fi

cd $PKG
if [ -f $CWD/slack-required ]; then cat $CWD/slack-required > $PKG/usr/doc/$PRGNAM-$VERSION/slack-required; fi
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
