#!/bin/sh

# Copyright 2012, 2015, 2016, 2018  Patrick J. Volkerding, Sebeka, Minnesota, USA
# 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.

# Set to 1 if you'd like to install/upgrade package as they are built.
# This is recommended.

# Robby builds Thunar after xfce4-panel
# Let's try the opposite, following https://docs.xfce.org/xfce/building
# Edit: Robby is right, if I follow the doc Thunar fails to build.

#NOTA: edit it it, I have removed slint-wip

INST=1

CWD=$(pwd)


# xfce4-dev-tools \
# libxfce4util \
# xfconf \
# libxfce4ui \
# exo \
# garcon \
# libwnck3 \
# xfce4-panel \
#  Thunar \
#  thunar-volman \
#  tumbler \
#  xfce4-appfinder \
#  xfce4-power-manager \
#  xfce4-settings \
#  xfdesktop \
#  xfwm4 \
#  xfce4-session \
#  xfce4-terminal \
#  xfce4-notifyd \
#  orage \
#  xfce4-pulseaudio-plugin \
#  xfce4-clipman-plugin \
#  xfce4-screenshooter \
#  xfce4-systemload-plugin \
#  xfce4-taskmanager \
#  xfce4-weather-plugin \
#  xfce4-screensaver \
# xfce4-panel-profiles \
# elementary-xfce \

for BASENAME in \
Greybird \
xfce4-whiskermenu-plugin \
  ; do
	cd $BASENAME || exit 1
	sed -i '
	/Included in Slint/d
	/PKGNAM=/s,.*,# Included in Slint by Didier Spaier <didier~at~slint~dot~fr>\n\n&,
	s,^TMP=.*,TMP=$CWD,
	s/^BUILD=.*/BUILD=1slint/' ${BASENAME}.SlackBuild
	fakeroot sh ${BASENAME}.SlackBuild 2>&1 |tee LOG
	geany -i LOG ${BASENAME}.SlackBuild
	PKGNAME=$(echo *.txz)
	printf "(re)install $PKGNAME? [Y/n] "
	read dummy
	if [ ! "$dummy" = "n" ] & [ ! "$dummy" = "N" ]; then
		DEPNAME=${PKGNAME%.txz}.dep
		su -c "upgradepkg --install-new --reinstall $PKGNAME"
		depfinder -p -3 $PKGNAME > $DEPNAME
	else
		for i in $(find -type d -name "$BASENAME-*" -mindepth 1 -maxdepth 1) \
			$(find -type d -name  "package-*" -mindepth 1 -maxdepth 1) LOG; do
			printf "remove $i? [Y/n] "
			read dummy
			if [ ! "$dummy" = "N" ] && [ ! "$dummy" = "n" ]; then
				rm -rf $i
			fi
		done
		exit
	fi
	for i in $(find -type d -name "$BASENAME-*" ) \
		$(find -type d -name  "package-*") LOG; do
				printf "remove $i? [Y/n] "
		read dummy
		if [ ! "$dummy" = "N" ] && [ ! "$dummy" = "n" ]; then
			rm -rf $i
		fi
	done
	printf "move $PKGNAME to slint-wip? [Y/n] "
	read dummy
	if [ ! "$dummy" = "N" ] && [ ! "$dummy" = "n" ]; then
		COMMENT=$(sed -n 6p /var/log/packages/${PKGNAME%.txz}|sed "s/.*:/ /")
		mv $PKGNAME $DEPNAME /storage/repo/x86_64/slint-wip/slint
		echo "${PKGNAME}: Upgraded" >> ../ChangeLog-xfce
		echo "$COMMENT" >> ../ChangeLog-xfce
	fi
	cd -
	read -p "press Enter to continue" dummy
done
