#!/bin/bash

# Copyright (C) 2015-2018, Ward Mundy & Associates LLC. Licensed for use under GPL2.

# Use this little script to convert FreePBX-produced GPL modules from GitHub for examination

# You can perform an install or update in one easy step using gpl-install-fpbx script instead.

if [ -z "$1" ]; then
 clear
 echo "Usage instructions:"
 echo "ERROR: Name of FreePBX-producted GPL module is required."
 echo "SYNTAX: ./gpl-download-fpbx packagename"
 echo " "
 echo " "
 exit 1
fi

if [ "$1" == "core" ]; then
 echo "Sorry. $1 cannot be upgraded."
 exit 2
fi
if [ "$1" == "webrtc" ]; then
 echo "Sorry. $1 cannot be installed."
 exit 2
fi
if [ "$1" == "dashboard" ]; then
 echo "Sorry. $1 cannot be upgraded."
 exit 2
fi
if [ "$1" == "firewall" ]; then
 echo "Sorry. $1 cannot be installed."
 echo "It conflicts with Travelin Man 3."
 exit 2
fi


cd /root
rm -rf $1.tar.gz
rm -rf $1
mkdir $1
cd $1
curl -L -O https://github.com/FreePBX/$1/archive/release/13.0.zip
unzip 13.0.zip
clear
rm -f *.zip && mv $1-release-13.0 $1
# fake the module signature
cd $1
touch module.sig
chmod 775 module.sig
cd ..
#
tar -cf $1.tar $1 && gzip $1.tar && rm -rf $1
mv $1.tar.gz ../. && cd .. && rm -rf $1
ls $1.tar.gz

# Now we're ready to switch to the Module Admin utility in the GUI to install the GitHub update
