aboutsummaryrefslogtreecommitdiff
path: root/subprojects/freeamo/freeamo
blob: 7bcab33b861c109da319dd678b7cfb8b8646a4e1 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env bash
#    This file is part of FreeAMO
#    Copyright (C) 2017, 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/>.


scriptsrc=$(readlink -f -- "${BASH_SOURCE[0]}")
run_path=$(dirname "${scriptsrc}" || echo .)
filename=$(basename "$0");

source "$run_path/src/main_functions"
source "$run_path/freeamo.conf"


source "$run_path/src/err"

# if you don't have this locale, add this to /etc/locale.gen:
# sv_SE.UTF-8 UTF-8
# then run sudo locale-gen
# then open a new terminal.
export LC_NUMERIC=sv_SE.UTF-8


output_file_1="$run_path/build/index-search-pages.txt";
output_file_2="$run_path/build/index-search-pages--free-licenses.txt"

# Evaluate debug mode
if [ "$1" == "--debug" ] || [ "$2" == "--debug" ]; then
    
    debug=true
    debug_arg="--debug";
    
else
    
    debug=false
    unset debug_arg

fi

# Delete empty files to re-generate them -- Typical case scenario: 1) wget tried to download a file 2) The script is interupted 3) The script is run again
if [ -d "$run_path/build" ]; then
    
    find "$run_path/build" -type f -empty -delete

fi

export -p debug

if [ ! -f /usr/bin/jq ]; then echo "/usr/bin/jq not found!"; exit=true; fi
if [ ! -f /usr/bin/wget ]; then echo "/usr/bin/wget not found!"; exit=true; fi

if [[ $exit == true ]]; then exit 1; fi


case "$1" in

    ""|--debug|--normal-mode)

        freeamo_command="$0 --conf-note $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        freeamo_command="$0 --remove-build $debug_arg"
        echo "$freeamo_command"; $freeamo_command

        freeamo_command="$0 --conf-copy $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        freeamo_command="$0 --search-pages $debug_arg"
        echo "$freeamo_command"; $freeamo_command

        freeamo_command="$0 --get-licenses $debug_arg"
        echo "$freeamo_command"; $freeamo_command

        freeamo_command="$0 --get-add-ons $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        if [ ! "$1" == "--normal-mode" ]; then
            
            freeamo_command="$0 --make-directory.fsf.org-wiki $debug_arg"
            echo "$freeamo_command"; $freeamo_command
            
        fi
        
        ;;
    
    -help)
	
	[ "$1" = "" ] && echo "Usage: $filename [--option] [--debug]

OPTIONS
f.org-wiki (they are used by Free Software Directory developers)
	$0 --conf-note
            Display which icecat version the add-on will be compatible with.
	$0 --remove-build
            Remove the build directory if it exists.
	$0 --conf-copy
            Copy the conf file to the build directory.
	$0 --search-pages
            Downloads the most popular WebExtensions from https://addons.mozilla.org/en-US/firefox/search/...
	$0 --get-licenses
            The licenses are not added to the general JSON file. This option will download the neccesary license JSON files for all add-ons.
        $0 --get-add-ons
            Download the installable add-ons (the .xpi files).
        $0 --make-directory.fsf.org-wiki
            Generates .wiki files specifically for https://directory.fsf.org/wiki/

Disabled options due to limited development time
        $0 --make-repository-list
            Required file: FreeAMO-collections
            File content syntax: https://addons.mozilla.org/en-US/firefox/collections/<user>/
        $0 --make-collection-list
            Required file: FreeAMO-collections
            File content syntax: https://addons.mozilla.org/en-US/firefox/collections/<user>/<collection name>
        $0 --make-custom-list
            Required file: FreeAMO-custom
            File content syntax: https://addons.mozilla.org/en-US/firefox/addon/<add-on name>/
        $0 --download-licenses-json
        $0 --download-free-webextensions
            Downloads the latest version of the free WebExtensions.
        $0 --verify-license-copy
            Search for license files in the root directory in the downloaded WebExtensions (.xpi files)
" && exit 1

	;;

    --conf-note)
        
        echo "$notes"

        ;;

    --remove-build)

        rm -fr "$run_path/build"

        ;;
    
    --conf-copy)
        
        mkdir -p "$run_path/build/"
        echo -e "# [This file is a copy used as a receipt to declare the settings that were used to generate the files.]\\n" > "$run_path/build/freeamo.conf"
        cat "$run_path/freeamo.conf" >> "$run_path/build/freeamo.conf"
        sed -i "/^appversion=/ s/$/ # $appversion at the time/" "$run_path/build/freeamo.conf"
        
        ;;

    --search-pages)

        # This option is named after named after https://addons.mozilla.org/en-US/firefox/search/
        freeamo_command="$0 --search-pages--download $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        freeamo_command="$0 --search-pages--filter $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        ;;
    
    --search-pages--download)

        mkdir -p "$run_path/build/json/search-pages"
        source src/search-pages
        search-pages--download
        
        ;;

    --search-pages--filter)

        mkdir -p "$run_path/build/json/search-pages"
        source src/search-pages
        search-pages--filter
        
        ;;
    
    --get-licenses)

        freeamo_command="$0 --get-licenses--download $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        freeamo_command="$0 --get-licenses--filter $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        ;;

    --get-licenses--download)

        mkdir -p "$run_path/build/json/current_versions";
        source src/get-licenses
        get-licenses--download
        
        ;;

    --get-licenses--filter)

        source src/get-licenses
        get-licenses--filter
        
        ;;

    --get-add-ons)

        freeamo_command="$0 --get-add-ons--download $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        freeamo_command="$0 --get-add-ons--filter $debug_arg"
        echo "$freeamo_command"; $freeamo_command
        
        ;;

    --get-add-ons--download)

        mkdir -p "$run_path/build/add-ons"
        source src/get-add-ons
        get-add-ons--download
        
        ;;

    --get-add-ons--filter)

        source src/get-add-ons
        get-add-ons--filter
        
        ;;
    
    --make-directory.fsf.org-wiki)

        mkdir -p "$run_path/build/wiki";
        source src/make-wiki
        
        ;;
    
esac