source: branches/cache/bin/gpl_license.sh @ 3324

Last change on this file since 3324 was 3324, checked in by bradbell, 6 years ago

merge trunk changes into cache

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1#! /bin/bash -e
2# $Id: gpl_license.sh 3324 2014-09-12 12:14:53Z bradbell $
3# -----------------------------------------------------------------------------
4# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
5#
6# CppAD is distributed under multiple licenses. This distribution is under
7# the terms of the
8#                     Eclipse Public License Version 1.0.
9#
10# A copy of this license is included in the COPYING file of this distribution.
11# Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
12# -----------------------------------------------------------------------------
13# Bradley M. Bell has given COIN-OR permission to use this script to generate
14# a distribution of CppAD that has "GNU General Public License Version 3"
15# in place of "Eclipse Public License Version 1.0." in all occurrences
16# of the message above.
17# -----------------------------------------------------------------------------
18if [ ! -e "bin/gpl_license.sh" ]
19then
20        echo "bin/gpl_license.sh: must be executed from its parent directory"
21        exit 1
22fi
23echo_eval() {
24     echo $* 
25     eval $*
26}
27# ----------------------------------------------------------------------------
28if [ "$3" == '' ]
29then
30        echo 'usage: bin/gpl_license.sh archive_name archive_dir work_dir'
31        exit 1
32fi
33archive_name="$1"
34archive_dir="$2"
35work_dir="$3"
36# ----------------------------------------------------------------------------
37start_dir=`pwd`
38if [[ "$archive_name" =~ .*/.* ]]
39then
40        echo "bin/gpl_version.sh: archive_name = $archive_name"
41        echo "                    archive_name cannot contain a / character"
42        exit 1
43fi
44# change archive_dir to an absolute path so can use after changing directories
45first_character=`echo "$archive_dir" | sed -e 's/\(.\).*/\1/'`
46if [ "$first_character" != '/' ]
47then
48        archive_dir="$start_dir/$archive_dir"
49fi
50#
51# delete old gpl version of tarball (if it exists)
52if [ -e $archive_dir/$archive_name.gpl.tgz ]
53then
54        echo_eval rm $archive_dir/$archive_name.gpl.tgz
55fi
56#
57# change into work directory
58echo_eval cd $work_dir
59#
60# delete old version of directory (if it exists)
61if [ -e $archive_name ]
62then
63        echo_eval rm -r $archive_name
64fi
65if [ -e $archive_name ]
66then
67        echo "bin/gpl_license.sh: cannot remove old $archive_name directory"
68        exit 1
69fi
70#
71# extract from the EPL version
72echo_eval tar -xzf $archive_dir/$archive_name.epl.tgz
73#
74# remove documentation directory (if it exists)
75if [ -e $archive_name/doc ]
76then
77        echo_eval rm -r $archive_name/doc
78fi
79#
80# change into the directory
81echo_eval cd $archive_name
82#
83# files that need removing
84echo_eval rm epl-v10.html epl-v10.txt
85#
86# files that need changing
87list=`find . \
88        \( -name '*.ac'  \) -or \
89        \( -name '*.am'  \) -or \
90        \( -name '*.c'   \) -or \
91        \( -name '*.cpp' \) -or \
92        \( -name '*.hpp' \) -or \
93        \( -name '*.in'  \) -or \
94        \( -name '*.omh' \) -or \
95        \( -name '*.pc' \)  -or \
96        \( -name '*.py' \)  -or \
97        \( -name '*.sh' \)  -or \
98        \( -name '*.txt'  \)`
99#
100# change back up to work directory (to be safe)
101echo_eval cd ..
102#
103echo "Changing license from EPL to GPL"
104for file in $list
105do
106        file=`echo $file | sed -e 's|^\./||'`
107        name=`echo $file | sed -e 's|.*\/||'`
108        ext=`echo $name  | sed -e 's|.*\.|\.|'`
109        #
110        if [ "$name" == 'gpl-3.0.txt' ]
111        then
112                echo "gpl-3.0.txt is in $archive_dir/$archive_name.epl.tgz"
113        fi
114        if [ "$name" == 'gpl_license.sh' ]
115        then
116                echo "gpl_license.sh is in $archive_dir/$archive_name.epl.tgz"
117        fi
118        if grep "GNU General Public License" $archive_name/$file > /dev/null
119        then
120                if [ "$name" != "doc.omh" ]
121                then
122                        echo "GPL license in initial $archive_name/$file"
123                        exit 1
124                fi
125        fi
126        #
127        sed -i $archive_name/$file \
128-e 's/Eclipse Public License Version 1.0/GNU General Public License Version 3/' 
129        #
130        if ! grep "GNU General Public License Version 3" $archive_name/$file \
131                > /dev/null
132        then
133                if \
134                [ "$name" != 'config.h.in' ] && \
135                [ "$name" != 'colpack.sh' ]  && \
136                [ "$name" != 'svn_commit.sh' ]
137                then
138                        echo "Cannot change EPL to GPL for $archive_name/$file"
139                        exit 1
140                fi
141        fi
142        if [ "$ext" = ".sh" ]
143        then
144                chmod +x $archive_name/$file
145        fi
146done
147#
148echo "change the COPYING file"
149sed -n -i $archive_name/COPYING -e '/-\{70\}/,/-\{70\}/p'
150cat $start_dir/gpl-3.0.txt >> $archive_name/COPYING
151#
152echo "change the file epl-v10.txt to the file gpl-3.0.txt"
153cp $start_dir/gpl-3.0.txt $archive_name/gpl-3.0.txt
154#
155list="
156        makefile.am
157        makefile.in
158        omh/license.omh
159"
160for file in $list
161do
162        if grep "gpl-3.0.txt" $archive_name/$file > /dev/null
163        then
164                echo bin/"gpl_license.sh: gpl-3.0.txt in initial $archive_name/$file"
165                exit 1
166        fi
167        sed -i $archive_name/$file -e 's/epl-v10.txt/gpl-3.0.txt/'
168        if ! grep "gpl-3.0.txt" $archive_name/$file > /dev/null
169        then
170                msg=bin/"gpl_license.sh: cannot change epl-v10.txt to gpl-3.0.txt"
171                echo "$msg for $archive_name/$file"
172                exit 1
173        fi
174done
175#
176# change into the version directory
177echo_eval cd $archive_name
178#
179# Only include the *.xml verison of the documentation in distribution
180# So remove the table at the top (but save the original doc.omh file).
181if ! grep < doc.omh > /dev/null \
182        'This comment is used to remove the table below' 
183then
184        echo "Missing comment expected in doc.omh"
185        exit 1
186fi
187echo "sed -i.save doc.omh ..."
188sed -i.save doc.omh \
189        -e '/This comment is used to remove the table below/,/$tend/d'
190#
191# This command creates omhelp.xml.log in current directory (and says so)
192echo "bin/run_omhelp.sh xml"
193if ! bin/run_omhelp.sh xml
194then
195        mv omhelp.xml.log ../..
196        echo_eval mv doc.omh.save doc.omh
197        exit 1
198fi
199# Move the log to the directory where the start directory
200echo_eval mv omhelp.xml.log $start_dir
201#
202echo_eval mv doc.omh.save doc.omh
203echo_eval cd ..
204# ----------------------------------------------------------------------------
205#
206# create GPL tarball file as copy or the version directory
207echo_eval tar -czf $archive_dir/$archive_name.gpl.tgz $archive_name
208
209# if we reach here, no error occurred
210echo "bin/gpl_license.sh: OK"
Note: See TracBrowser for help on using the repository browser.