#!/bin/bash

# Welcome to the powerfull saving technology
# Thanks a lot to Hector Garcia and Raul Rodrigo for 
# his help. 

# This script is licensed under GPL V3 or higher
# The purpose of this script is simple:
#
# First we must download the latest version of 
# lliurex-ultimate-actions
# 
# Then install it 
# and run it...
# 

# This is the URL of the package list
# http://lliurex.net/xenial/dists/xenial/main/binary-i386/Packages

ROOTURL="http://lliurex.net/xenial/"
PACKAGES_LIST=${ROOTURL}"dists/xenial/main/binary-i386/Packages"

# Some useful files
TEMPDIR=$(mktemp -d "/tmp/lliurex-ultimate-actions.XXXX")


rc=0 
# Get the packages list
wget ${PACKAGES_LIST} -O ${TEMPDIR}"/Packages"

# Get the URL of the package (last version of it)
URL=${ROOTURL}$(grep "Filename: .*lliurex-ultimate-actions.*\.deb" "${TEMPDIR}"/Packages|sed 's/Filename: //'|head -n 1) 

# Download the deb
wget ${URL} -O ${TEMPDIR}/lliurex-ultimate-actions.deb  || rc=1

# Install the package downloaded
dpkg -i --force-all ${TEMPDIR}/lliurex-ultimate-actions.deb

# Run it !
lliurex-ultimate-actions || true

# Cleanup actions
echo "rm -rf "$TEMPDIR""

exit 0