aboutsummaryrefslogtreecommitdiff
path: root/subprojects/freeamo/src/get-add-ons
blob: 6038bd6a9e0eeb9e9752504f26b5370dfa057ad9 (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
#!/usr/bin/env bash
#    This file is part of FreeAMO
#    Copyright (C) 2017 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/>.

cd "build/json/search-pages" || exit

function get-add-ons--download {


    output_file="$output_file_2";

    if [ "$debug" = true ]; then

        pv__size=$(cat "$output_file" | head -n 3 | wc -l)
        
    else
        
        pv__size="$(wc -l < "$output_file")"

    fi

    echo "Download $pv__size add-ons"
    
    while IFS= read -r table; do

        ((line++))

        file=$(echo "$table" | awk '{print $1}');
        entry=$(echo "$table" | awk '{print $2}');

        source "$run_path/src/main_functions"
        cd "$run_path/build/json/search-pages" || exit
        amo_variables

        cd "$run_path/build/add-ons" || exit
        # Add-ons not avalible for GNU/Linux will be ignored (used to be very few though).
        wget -nc -q "https://addons.mozilla.org/firefox/downloads/latest/$slug/addon-$id-latest.xpi" || wget -nc -q "https://addons.mozilla.org/firefox/downloads/latest/$slug/platform:2/addon-$id-latest.xpi"

        echo "foo" # Must be here to work with pv
        
    done < "$output_file" | pv__progress

}


function get-add-ons--filter {

    rm -f "$run_path/build/index-search-pages--free-licenses--license-file-status.txt"
    
    output_file="$output_file_2";

    if [ "$debug" = true ]; then

        pv__size=$(cat "$output_file" | head -n 3 | wc -l)
        
    else
        
        pv__size="$(wc -l < "$output_file")"

    fi

    echo "Filter $pv__size add-ons "
    
    while IFS= read -r table; do

        ((line++))

        file=$(echo "$table" | awk '{print $1}');
        entry=$(echo "$table" | awk '{print $2}');

        source "$run_path/src/main_functions"
        cd "$run_path/build/json/search-pages" || exit
        amo_variables

        cd "$run_path/build/add-ons" || exit
        license_file_text=$(unzip -l "addon-$id-latest.xpi" | awk '{ print $4 }' | grep -E "^COPYING$|^COPYING.txt$|^COPYING.md$|^LICENSE$|^LICENSE.txt$|^LICENSE.md$" | sed ':a;N;$!ba;s/\n/\t/g' || echo "NOLICENSEFILEFOUND");
        echo -e "$file\\t$entry\\t$slug\\taddon-$id-latest.xpi\\t$license_file_text" >> "$run_path/build/index-search-pages--free-licenses--license-file-status.txt"
        
        echo "foo" # Must be here to work with pv

    done < "$output_file" | pv__progress

}