#!/bin/sh
#
# sbopkg_gui.SlackBuild
# 2021-05-12

PRGNAM=sbopkg_gui
VERSION=20210512
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-scr}

HOMEPAGE="http://www.gernot-walzl.at/"
SOURCE="sbopkg_gui"
DOWNLOAD="${HOMEPAGE}Slackware/sbopkg_gui/${SOURCE}"
MD5SUM="253a969433db966849a4f7eb7474e9cc"

REQUIRES="sbopkg python PyQt"

MAINTAINER="Gernot Walzl"
EMAIL="gernot.walzl@gmx.at"

DESC="sbopkg gui

Graphical User Interface for sbopkg

${HOMEPAGE}"

DOCS=""

# EOF info


# set initial variables
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# exit on error
set -e

# download the source if needed
if [ ! -f $CWD/$SOURCE ]; then
  wget -O $CWD/$SOURCE $DOWNLOAD || exit 1
fi

# check for correct source file
if [ "$(md5sum $CWD/$SOURCE | cut -f 1 -d ' ')" != "$MD5SUM" ]; then
  exit 1
fi

# install everything into the package directory
rm -rf $PKG
mkdir -p $PKG/install
mkdir -p $PKG/usr/bin
install -m 755 $CWD/$SOURCE $PKG/usr/bin/$PRGNAM

mkdir -p $PKG/usr/share/applications
cat > $PKG/usr/share/applications/$PRGNAM.desktop << EOF
[Desktop Entry]
Type=Application
Name=$PRGNAM
GenericName=Package Manager
Comment=Install and remove software
Exec=$PRGNAM
Categories=System;
Icon=system-software-update
EOF

# add documentation
if [ "$DOCS" != "" ]; then
  mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION
  find $PKG/usr/doc/$PRGNAM-$VERSION -type f -exec chmod 644 {} \;
fi

# add some description to the package
if [ "$DESC" != "" ]; then
  echo "$DESC" | sed 's/^/'$PRGNAM': /g' > $PKG/install/slack-desc
fi

# append dependency information to the package
if [ "$REQUIRES" != "" ]; then
  for REQ in $REQUIRES; do
    echo "$REQ" >> $PKG/install/slack-required
  done
fi

# build the package
cd $PKG
makepkg -l y -c n \
  $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} \
  || exit 1

# make everything clean
cd $CWD
rm -rf $PKG
