From 4cccd9ea9c975d660aad1a2cc702c6717d779a6e Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sat, 20 Dec 2014 16:31:14 +0100 Subject: [PATCH] axify: Add options to download and install COPYING file Currently the following licenses are supported: - gpl2: GNU GPL v2 - gpl3: GNU GPL v3 - lgpl21: GNU LGPL v2.1 - lgpl3: GNU LGPL v3 --- scripts/axify | 73 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/scripts/axify b/scripts/axify index 93adf39..b9ea12f 100755 --- a/scripts/axify +++ b/scripts/axify @@ -12,15 +12,58 @@ NAME=`basename "$0"` Usage() { - echo "Usage: $NAME []" + echo "Usage: $NAME [-2|-3|-l ] []" + echo + echo ' -2 Use the GNU GPLv2 for the COPYING file.' + echo ' -3 Use the GNU GPLv3 for the COPYING file.' + echo ' -l Specify license to use for the COPYING file:' + echo ' can be "gpl2", "gpl3", "lgpl21", "lgpl3".' + echo ' By default an empty COPYING file is created.' echo echo " Library directory. Default: current working directory." echo exit 2 } +Download() { + URL="$1" + FILE="$2" + + echo "Downloading $URL to $FILE ..." + + curl --version >/dev/null 2>&1 + if [ $? -eq 0 ]; then + curl -#o "$FILE" "$URL" && return 0 + echo "Failed to download $URL! [curl]" + return 1 + fi + + wget --version >/dev/null 2>&1 + if [ $? -eq 0 ]; then + wget -qO "$FILE" --show-progress "$URL" && return 0 + echo "Failed to download $URL! [wget]" + return 1 + fi + + echo "Can't download $URL, no download tool found!" + return 1 +} + +LIB_D="." +LICENSE="" + while true; do case "$1" in + "-2") + LICENSE="gpl2" + ;; + "-3") + LICENSE="gpl3" + ;; + "-l") + LICENSE="$2" + shift + ;; "-"*) Usage ;; @@ -33,7 +76,7 @@ done [ $# -gt 1 ] && Usage -[ -n "$1" ] && LIB_D="$1" || LIB_D="." +[ -n "$1" ] && LIB_D="$1" if [ -r "/usr/local/share/ax-make/Makefile.ax" ]; then MAKEFILE_AX="/usr/local/share/ax-make/Makefile.ax" @@ -95,6 +138,32 @@ if [ ! -e AUTHORS ]; then fi fi +if [ ! -e COPYING ]; then + LICENSE_URL="" + case "$LICENSE" in + "") + ;; + "gpl2") + LICENSE_URL="http://www.gnu.org/licenses/gpl-2.0.txt" + ;; + "gpl3") + LICENSE_URL="http://www.gnu.org/licenses/gpl-3.0.txt" + ;; + "lgpl21") + LICENSE_URL="https://www.gnu.org/licenses/lgpl-2.1.txt" + ;; + "lgpl3") + LICENSE_URL="https://www.gnu.org/licenses/lgpl-3.0.txt" + ;; + *) + echo "Can't setup unknown \"$LICENSE\" license!" + ;; + esac + [ -n "$LICENSE_URL" ] && Download "$LICENSE_URL" COPYING +else + [ -n "$LICENSE" ] && echo "COPYING file already exists, skipping." +fi + for f in AUTHORS COPYING README; do if [ ! -e "$f" ]; then echo "Creating empty \"$f\" file ..." -- 2.39.2