autodownload gamepacks from make
authorRudolf Polzer <divverent@alientrap.org>
Mon, 12 Apr 2010 06:15:27 +0000 (08:15 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 12 Apr 2010 06:15:27 +0000 (08:15 +0200)
Makefile
download-gamepacks.sh
install-gamepacks.sh [new file with mode: 0755]

index 2582789..111e2eb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -44,9 +44,11 @@ TR                 ?= tr
 FIND               ?= find
 DIFF               ?= diff
 SED                ?= sed
-
-# optional:
 GIT                ?= git
+SVN                ?= svn
+WGET               ?= wget
+MV                 ?= mv
+UNZIP              ?= unzip
 
 STDOUT_TO_DEVNULL  ?= >/dev/null
 STDERR_TO_DEVNULL  ?= 2>/dev/null
@@ -75,6 +77,7 @@ LIBS_DL            ?= -ldl # nothing on Win32
 CPPFLAGS_ZLIB      ?=
 LIBS_ZLIB          ?= -lz
 DEPEND_ON_MAKEFILE ?= yes
+DOWNLOAD_GAMEPACKS ?= yes # set to no to disable gamepack, set to all to even download undistributable gamepacks
 DEPENDENCIES_CHECK ?= quiet
 # or: off, verbose
 
@@ -268,6 +271,7 @@ dependencies-check:
        checkbinary coreutils "$(CP_R)"; \
        checkbinary coreutils "$(RM)"; \
        checkbinary coreutils "$(RM_R)"; \
+       checkbinary coreutils "$(MV)"; \
        checkbinary coreutils "$(ECHO) test $(TEE_STDERR)"; \
        checkbinary sed "$(SED)"; \
        checkbinary findutils "$(FIND)"; \
@@ -277,6 +281,10 @@ dependencies-check:
        checkbinary binutils "$(RANLIB)"; \
        checkbinary binutils "$(AR)"; \
        checkbinary pkg-config "$(PKGCONFIG)"; \
+       checkbinary unzip "$(UNZIP)"; \
+       checkbinary git-core "$(GIT)"; \
+       checkbinary subversion "$(SVN)"; \
+       checkbinary wget "$(WGET)"; \
        [ "$(OS)" = "Win32" ] && checkbinary mingw32 "$(WINDRES)"; \
        [ -n "$(LDD)" ] && checkbinary libc6 "$(LDD)"; \
        [ -n "$(OTOOL)" ] && checkbinary xcode "$(OTOOL)"; \
@@ -958,16 +966,7 @@ install-data: binaries
        $(MKDIR) $(INSTALLDIR)/games
        $(FIND) $(INSTALLDIR_BASE)/ -name .svn -exec $(RM_R) {} \; -prune
        [ "$(OS)" != "Darwin" ] || $(CP_R) setup/data/osx/NetRadiant.app/* $(INSTALLDIR_BASE)/NetRadiant.app/
-       set -ex; \
-       for GAME in games/*; do \
-               if [ "$$GAME" = "games/*" ]; then \
-                       $(ECHO) "Game packs not found, please run"; \
-                       $(ECHO) "  ./download-gamepacks.sh"; \
-                       $(ECHO) "and then try again!"; \
-               else \
-                       CP="$(CP)" CP_R="$(CP_R)" $(SH) install-gamepack.sh "$$GAME" "$(INSTALLDIR)"; \
-               fi; \
-       done
+       DOWNLOAD_GAMEPACKS="$(DOWNLOAD_GAMEPACKS)" GIT="$(GIT)" SVN="$(SVN)" WGET="$(WGET)" RM_R="$(RM_R)" MV="$(MV)" UNZIP="$(UNZIP)" ECHO="$(ECHO)" SH="$(SH)" CP="$(CP)" CP_R="$(CP_R)" $(SH) install-gamepacks.sh "$(INSTALLDIR)"
        $(ECHO) $(RADIANT_MINOR_VERSION) > $(INSTALLDIR)/RADIANT_MINOR
        $(ECHO) $(RADIANT_MAJOR_VERSION) > $(INSTALLDIR)/RADIANT_MAJOR
        $(CP_R) setup/data/tools/* $(INSTALLDIR)/
index 6869ea2..e15ded9 100755 (executable)
@@ -4,13 +4,22 @@
 #   sh download-gamepack.sh
 #   LICENSEFILTER=GPL BATCH=1 sh download-gamepack.sh
 
+: ${GIT:=git}
+: ${SVN:=svn}
+: ${WGET:=wget}
+: ${ECHO:=echo}
+: ${MKDIR:=mkdir}
+: ${RM_R:=rm -r}
+: ${MV:=mv}
+: ${UNZIP:=unzip}
+
 set -e
 
 extra_urls()
 {
        if [ -f "$1/extra-urls.txt" ]; then
                while IFS="     " read -r FILE URL; do
-                       wget -O "$1/$FILE" "$URL"
+                       $WGET -O "$1/$FILE" "$URL"
                done < "$1/extra-urls.txt"
        fi
 }
@@ -23,32 +32,32 @@ pack()
        source=$1; shift
 
        if [ -d "games/$pack" ]; then
-               echo "Updating $pack..."
+               $ECHO "Updating $pack..."
                case "$sourcetype" in
                        svn)
-                               svn update "games/$pack" "$@"
+                               $SVN update "games/$pack" "$@"
                                ;;
                        zip1)
-                               rm -rf zipdownload
-                               mkdir zipdownload
+                               $RM_R zipdownload
+                               $MKDIR zipdownload
                                cd zipdownload
-                               wget "$source" "$@"
-                               unzip *
+                               $WGET "$source" "$@"
+                               $UNZIP *
                                cd ..
-                               rm -rf "games/$pack"
-                               mkdir "games/$pack"
-                               mv zipdownload/*/* "games/$pack/"
-                               rm -rf zipdownload
+                               $RM_R "games/$pack"
+                               $MKDIR "games/$pack"
+                               $MV zipdownload/*/* "games/$pack/"
+                               $RM_R zipdownload
                                ;;
                        gitdir)
-                               rm -rf "games/$pack"
+                               $RM_R "games/$pack"
                                cd games
-                               git archive --remote="$source" --prefix="$pack/" "$2":"$1" | tar xvf -
+                               $GIT archive --remote="$source" --prefix="$pack/" "$2":"$1" | tar xvf -
                                cd ..
                                ;;
                        git)
                                cd "games/$pack"
-                               git pull
+                               $GIT pull
                                cd ../..
                                ;;
                esac
@@ -56,18 +65,18 @@ pack()
                return
        fi
 
-       echo
-       echo "Available pack: $pack"
-       echo "  License: $license"
-       echo "  Download via $sourcetype from $source"
-       echo
+       $ECHO
+       $ECHO "Available pack: $pack"
+       $ECHO "  License: $license"
+       $ECHO "  Download via $sourcetype from $source"
+       $ECHO
        case " $PACKFILTER " in
                "  ")
                        ;;
                *" $pack "*)
                        ;;
                *)
-                       echo "Pack $pack rejected because it is not in PACKFILTER."
+                       $ECHO "Pack $pack rejected because it is not in PACKFILTER."
                        return
                        ;;
        esac
@@ -77,14 +86,14 @@ pack()
                *" $license "*)
                        ;;
                *)
-                       echo "Pack $pack rejected because its license is not in LICENSEFILTER."
+                       $ECHO "Pack $pack rejected because its license is not in LICENSEFILTER."
                        return
                        ;;
        esac
        case "$BATCH" in
                '')
                        while :; do
-                               echo "Download this pack? (y/n)"
+                               $ECHO "Download this pack? (y/n)"
                                read -r P
                                case "$P" in
                                        y*)
@@ -100,30 +109,30 @@ pack()
                        ;;
        esac
        
-       echo "Downloading $pack..."
+       $ECHO "Downloading $pack..."
        case "$sourcetype" in
                svn)
-                       svn checkout "$source" "games/$pack" "$@"
+                       $SVN checkout "$source" "games/$pack" "$@"
                        ;;
                zip1)
-                       rm -rf zipdownload
-                       mkdir zipdownload
+                       $RM_R zipdownload
+                       $MKDIR zipdownload
                        cd zipdownload
-                       wget "$source" "$@"
-                       unzip *
+                       $WGET "$source" "$@"
+                       $UNZIP *
                        cd ..
-                       mkdir "games/$pack"
-                       mv zipdownload/*/* "games/$pack/"
-                       rm -rf zipdownload
+                       $MKDIR "games/$pack"
+                       $MV zipdownload/*/* "games/$pack/"
+                       $RM_R zipdownload
                        ;;
                gitdir)
                        cd games
-                       git archive --remote="$source" --prefix="$pack/" "$2":"$1" | tar xvf -
+                       $GIT archive --remote="$source" --prefix="$pack/" "$2":"$1" | tar xvf -
                        cd ..
                        ;;
                git)
                        cd games
-                       git clone "$source" "$pack"
+                       $GIT clone "$source" "$pack"
                        cd ..
                        ;;
        esac
diff --git a/install-gamepacks.sh b/install-gamepacks.sh
new file mode 100755 (executable)
index 0000000..f4ae842
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+: ${ECHO:=echo}
+: ${SH:=sh}
+: ${CP:=cp}
+: ${CP_R:=cp -r}
+
+dest=$1
+
+case "$DOWNLOAD_GAMEPACKS" in
+       yes)
+               LICENSEFILTER=GPL BATCH=1 $SH download-gamepacks.sh
+               ;;
+       all)
+               BATCH=1 $SH download-gamepacks.sh
+               ;;
+       *)
+               ;;
+esac
+
+set -e
+for GAME in games/*; do
+       if [ "$GAME" = "games/*" ]; then
+               $ECHO "Game packs not found, please run"
+               $ECHO "  ./download-gamepacks.sh"
+               $ECHO "and then try again!"
+       else
+               $SH install-gamepack.sh "$GAME" "$dest"
+       fi
+done