aboutsummaryrefslogtreecommitdiff
path: root/subprojects/freeamo/src/get-licenses
blob: c7e5559d2d8c988646e91d0ea230960d985e930d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
#    This file is part of FreeAMO
#    Copyright (C) 2018 David Hedlund
#
#    FreeAMO is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FreeAMO is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# API: Please adopt SPDX - https://github.com/mozilla/addons-server/issues/8706
# Allow GNU [L]GPL x.x or later - https://github.com/mozilla/addons-server/issues/8707

cd "build/json/search-pages"

function get-licenses--download {

    echo -e "\\nDownloading license pages:"

    
    output_file="$output_file_1";
    pv__size="$(wc -l < "$output_file")"
    source "$run_path/src/main_functions"
    
    while IFS= read -r table; do

        ((++line))
        
        if [ "$debug" = true ] && [ "$line" -le "3" ] || [ "$debug" = false ] ; then
            
            file=$(echo $table | awk '{print $1}');
            entry=$(echo $table | awk '{print $2}');

            source "$run_path/src/main_functions"
            amo_variables

            total=$(wc -l < "$output_file_1")
            #            echo -e "#==================
            #Entry $line (of $total): $name\n"

            # Do now download the same license files over and over
            wget -nc -q "https://addons.mozilla.org/api/v3/addons/addon/$slug/versions/$current_version__id/" -O "$run_path/build/json/current_versions/$current_version__id.json"

        fi


        echo "foo" # Must be here to work with pv
    done < "$output_file_1" | progress

}

function get-licenses--filter {

    echo -e "\\nFilter license pages:"

    output_file="$output_file_1";
    pv__size="$(wc -l < "$output_file")"
    source "$run_path/src/main_functions"
    rm -f "$run_path/build/index-search-pages--free-licenses.txt"

    
    while IFS= read -r table; do

        ((++line))
        
        if [ "$debug" = true ] && [ "$line" -le "3" ] || [ "$debug" = false ] ; then
            
            file=$(echo $table | awk '{print $1}');
            entry=$(echo $table | awk '{print $2}');

            source "$run_path/src/main_functions"
            amo_variables
            amo_variables__licenses

            #            license="$(jq ".license.name" "$run_path/build/json/current_versions/$current_version__id.json" | sed "s|en-US|enUS|;" | jq .enUS | sed "s|^\"||; s|\"$||;")"
            
            #            echo "$run_path/build/json/current_versions/$(jq ".results[$entry].current_version.id" "$file")"
            
            # This is the complete list of pre-defined licenses listed on AMO. Apache License 2.0 is not on the list so its not easy to detect because it has to be released under a "Custom License".
            # Make a drop-down menu with all SPDX licenses - https://github.com/mozilla/addons-server/issues/8866
            # See https://addons.mozilla.org/en-US/developers/addon/<your add-on>/ownership for the current add-on list. Note that not all licenses are added to the list.
            # DuckDuckGo Privacy Essentials is distributed under Apache License 2.0.
            # Apache License, version 2.0 is not on the add-on license list - https://github.com/mozilla/addons-server/issues/8545
            if
                [ "$license__amo_full_name" == "BSD License" ] ||
                    [ "$license__amo_full_name" == "GNU General Public License, version 3.0" ] ||
                    [ "$license__amo_full_name" == "GNU General Public License, version 2.0" ] ||
                    [ "$license__amo_full_name" == "GNU Lesser General Public License, version 3.0" ] ||
                    [ "$license__amo_full_name" == "GNU Lesser General Public License, version 2.1" ] ||
                    [ "$license__amo_full_name" == "MIT/X11 License" ] ||
                    [ "$license__amo_full_name" == "Mozilla Public License, version 2.0" ] ||
                    [ "$license__amo_full_name" == "Mozilla Public License Version 1.1" ]
            then

                # The nonfree add-ons should not be removed since the line number must correspond with the entry number in the search result JSON files.
                #                echo "$name: $license__amo_full_name"
                echo "$file $entry" >> "$output_file_2"
                
                freedom_status="free";

            elif [ "$license__amo_full_name" == "All Rights Reserved" ]; then

                freedom_status="nonfree";

            else

                freedom_status="unknown";
            fi    


            
        fi

        echo "foo" # Must be here to work with pv
        
    done < "$output_file_1" | progress

}