3 ## Copyright 2011-12 Simone Sclavi 'Ito'
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 use feature
qw(say switch);
21 use Getopt
::Long
qw(:config no_ignore_case);
24 use GnuPG
qw( :algo );
30 my ($url, $file) = @_;
31 $browser = LWP
::UserAgent
->new unless $browser;
32 $browser->timeout(30);
33 $browser->show_progress(1);
34 $browser->env_proxy( );
35 my $resp = $browser->get($url, ':content_file' => $file);
36 return $resp->is_success;
43 my $conf_file = "${HOME}/.ff-downloader";
47 my $TEXT = << 'HEADER';
48 # Define here your preferred language(s) for Firefox and Thunderbird.
52 open my $fh, '>', $conf_file or do{say ":: Error in $conf_file: $!"; return };
59 open my $fh, '<', $conf_file or do{ say ":: Can't read from $conf_file: $!"; return };
60 while( defined( my $line = <$fh>))
62 chomp $line; $line =~ s/^\s+//; $line =~ s/\s+$//;
63 next if $line =~ /^#/;
64 if ($line =~ /^$p=([-a-zA-Z]+)$/)
73 my ($VER, $PACKAGE, $LANG);
74 my $pkg = 'ff'; #default value for "--package"
75 my $res = GetOptions
("version|v=s" => \
$VER,
76 "package|p=s" => \
$pkg );
78 die ":: usage: $0 -p|--package=<package name [ff|tb]> -v|--version=<version number>\n" unless $res and (scalar @ARGV == 0);
81 when ('ff') { $PACKAGE = 'firefox' }
82 when ('tb') { $PACKAGE = 'thunderbird'}
83 default { die qq{:: "$pkg" is
not a valid value
for "--package"! Please
use "ff" or "tb"\n}}
85 die qq{:: "--version" option is mandatory
!\n} unless $VER;
87 $LANG = read_config
($pkg);
92 { language
=> 'Afrikaans (South Africa)', code
=> 'af' },
93 { language
=> 'Akan', code
=> 'ak' },
94 { language
=> 'Aarabic', code
=> 'ar' },
95 { language
=> 'Assamese', code
=> 'as' },
96 { language
=> 'Asturian', code
=> 'ast' },
97 { language
=> 'Belarusian', code
=> 'be' },
98 { language
=> 'Bulgarian', code
=> 'bg' },
99 { language
=> 'Bengali (Bangladesh)', code
=> 'bn-BD' },
100 { language
=> 'Bengali (India)', code
=> 'bn-IN' },
101 { language
=> 'Breton', code
=> 'br' },
102 { language
=> 'Bosnian', code
=> 'bs' },
103 { language
=> 'Catalan', code
=> 'ca' },
104 { language
=> 'Czech', code
=> 'cs' },
105 { language
=> 'Kashubian', code
=> 'csb' },
106 { language
=> 'Welsh', code
=> 'cy' },
107 { language
=> 'Danish', code
=> 'da' },
108 { language
=> 'German', code
=> 'de' },
109 { language
=> 'Greek', code
=> 'el' },
110 { language
=> 'English (United Kingdom)', code
=> 'en-GB' },
111 { language
=> 'English (US)', code
=> 'en-US' },
112 { language
=> 'English (South African)', code
=> 'en-ZA' },
113 { language
=> 'Esperanto', code
=> 'eo' },
114 { language
=> 'Spanish (Argentina)', code
=> 'es-AR' },
115 { language
=> 'Spanish (Chile)', code
=> 'es-CL' },
116 { language
=> 'Spanish (Spain)', code
=> 'es-ES' },
117 { language
=> 'Spanish (Mexico)', code
=> 'es-MX' },
118 { language
=> 'Estonian', code
=> 'et' },
119 { language
=> 'Basque', code
=> 'eu' },
120 { language
=> 'Persian', code
=> 'fa' },
121 { language
=> 'Finnish', code
=> 'fi' },
122 { language
=> 'French', code
=> 'fr' },
123 { language
=> 'Frisian', code
=> 'fy-NL' },
124 { language
=> 'Irish', code
=> 'ga-IE' },
125 { language
=> 'Gaelic (Scotland)', code
=> 'gd' },
126 { language
=> 'Galician', code
=> 'gl' },
127 { language
=> 'Gujarati (India)', code
=> 'gu-IN' },
128 { language
=> 'Hebrew', code
=> 'he' },
129 { language
=> 'Hindi', code
=> 'hi-IN' },
130 { language
=> 'Croatian', code
=> 'hr' },
131 { language
=> 'Hungarian', code
=> 'hu' },
132 { language
=> 'Armenian', code
=> 'hy-AM' },
133 { language
=> 'Indonesian', code
=> 'id' },
134 { language
=> 'Icelandic', code
=> 'is' },
135 { language
=> 'Italian', code
=> 'it' },
136 { language
=> 'Japanese', code
=> 'ja' },
137 { language
=> 'Kazakh', code
=> 'kk' },
138 { language
=> 'Kannada', code
=> 'kn' },
139 { language
=> 'Korean', code
=> 'ko' },
140 { language
=> 'Kurdish', code
=> 'ku' },
141 { language
=> 'Ganda', code
=> 'lg' },
142 { language
=> 'Lithuanian', code
=> 'lt' },
143 { language
=> 'Latvian', code
=> 'lv' },
144 { language
=> 'Maithili', code
=> 'mai' },
145 { language
=> 'Macedonian', code
=> 'mk' },
146 { language
=> 'Malayalam', code
=> 'ml' },
147 { language
=> 'Mongolian', code
=> 'mn' },
148 { language
=> 'Marathi', code
=> 'mr' },
149 { language
=> 'Norwegian (Bokmal)', code
=> 'nb-NO' },
150 { language
=> 'Dutch', code
=> 'nl' },
151 { language
=> 'Norwegian (Nynorsk)', code
=> 'nn-NO' },
152 { language
=> 'Northern Sotho', code
=> 'nso' },
153 { language
=> 'Oriya', code
=> 'or' },
154 { language
=> 'Punjabi', code
=> 'pa-IN' },
155 { language
=> 'Polish', code
=> 'pl' },
156 { language
=> 'Portuguese (Brazil)', code
=> 'pt-BR' },
157 { language
=> 'Portuguese (Portugal)', code
=> 'pt-PT' },
158 { language
=> 'Romansh', code
=> 'rm' },
159 { language
=> 'Romanian', code
=> 'ro' },
160 { language
=> 'Russian', code
=> 'ru' },
161 { language
=> 'Sinhalese', code
=> 'si' },
162 { language
=> 'Slovak', code
=> 'sk' },
163 { language
=> 'Slovenian', code
=> 'sl' },
164 { language
=> 'Songhai', code
=> 'son' },
165 { language
=> 'Albanian', code
=> 'sq' },
166 { language
=> 'Serbian', code
=> 'sr' },
167 { language
=> 'Swedish', code
=> 'sv-SE' },
168 { language
=> 'Swahili', code
=> 'sw' },
169 { language
=> 'Tamil', code
=> 'ta' },
170 { language
=> 'Tamil (Sri Lanka)', code
=> 'ta-LK' },
171 { language
=> 'Telugu', code
=> 'te' },
172 { language
=> 'Thai', code
=> 'th' },
173 { language
=> 'Turkish', code
=> 'tr' },
174 { language
=> 'Ukrainan', code
=> 'uk' },
175 { language
=> 'Vietnamese', code
=> 'vi' },
176 { language
=> 'Chinese (Simplified)', code
=> 'zh-CN' },
177 { language
=> 'Chinese (Traditional)', code
=> 'zh-TW' },
178 { language
=> 'Zulu', code
=> 'zu' },
182 { language
=> 'Aarabic', code
=> 'ar' },
183 { language
=> 'Asturian', code
=> 'ast' },
184 { language
=> 'Belarusian', code
=> 'be' },
185 { language
=> 'Bulgarian', code
=> 'bg' },
186 { language
=> 'Bengali (Bangladesh)', code
=> 'bn-BD' },
187 { language
=> 'Breton', code
=> 'br' },
188 { language
=> 'Catalan', code
=> 'ca' },
189 { language
=> 'Czech', code
=> 'cs' },
190 { language
=> 'Danish', code
=> 'da' },
191 { language
=> 'German', code
=> 'de' },
192 { language
=> 'Greek', code
=> 'el' },
193 { language
=> 'English (United Kingdom)', code
=> 'en-GB' },
194 { language
=> 'English (US)', code
=> 'en-US' },
195 { language
=> 'Spanish (Argentina)', code
=> 'es-AR' },
196 { language
=> 'Spanish (Spain)', code
=> 'es-ES' },
197 { language
=> 'Estonian', code
=> 'et' },
198 { language
=> 'Basque', code
=> 'eu' },
199 { language
=> 'Finnish', code
=> 'fi' },
200 { language
=> 'French', code
=> 'fr' },
201 { language
=> 'Frisian', code
=> 'fy-NL' },
202 { language
=> 'Irish', code
=> 'ga-IE' },
203 { language
=> 'Gaelic (Scotland)', code
=> 'gd' },
204 { language
=> 'Galician', code
=> 'gl' },
205 { language
=> 'Hebrew', code
=> 'he' },
206 { language
=> 'Hungarian', code
=> 'hu' },
207 { language
=> 'Indonesian', code
=> 'id' },
208 { language
=> 'Icelandic', code
=> 'is' },
209 { language
=> 'Italian', code
=> 'it' },
210 { language
=> 'Japanese', code
=> 'ja' },
211 { language
=> 'Korean', code
=> 'ko' },
212 { language
=> 'Lithuanian', code
=> 'lt' },
213 { language
=> 'Norwegian (Bokmal)', code
=> 'nb-NO' },
214 { language
=> 'Dutch', code
=> 'nl' },
215 { language
=> 'Norwegian (Nynorsk)', code
=> 'nn-NO' },
216 { language
=> 'Punjabi', code
=> 'pa-IN' },
217 { language
=> 'Polish', code
=> 'pl' },
218 { language
=> 'Portuguese (Brazil)', code
=> 'pt-BR' },
219 { language
=> 'Portuguese (Portugal)', code
=> 'pt-PT' },
220 { language
=> 'Romansh', code
=> 'rm' },
221 { language
=> 'Romanian', code
=> 'ro' },
222 { language
=> 'Russian', code
=> 'ru' },
223 { language
=> 'Sinhalese', code
=> 'si' },
224 { language
=> 'Slovak', code
=> 'sk' },
225 { language
=> 'Slovenian', code
=> 'sl' },
226 { language
=> 'Albanian', code
=> 'sq' },
227 { language
=> 'Serbian', code
=> 'sr' },
228 { language
=> 'Swedish', code
=> 'sv-SE' },
229 { language
=> 'Tamil (Sri Lanka)', code
=> 'ta-LK' },
230 { language
=> 'Turkish', code
=> 'tr' },
231 { language
=> 'Ukrainan', code
=> 'uk' },
232 { language
=> 'Vietnamese', code
=> 'vi' },
233 { language
=> 'Chinese (Simplified)', code
=> 'zh-CN' },
234 { language
=> 'Chinese (Traditional)', code
=> 'zh-TW' },
237 ( $pkg eq 'ff' ) ?
( @u_i18n = @ff_i18n ) : (@u_i18n = @tb_i18n );
238 my @i18n = sort { $a->{language
} cmp $b->{language
} } @u_i18n;
239 my $size = scalar @i18n;
241 for (my $i = 0; $i < $size; $i++ )
243 say '[', $i + 1, "] $i18n[$i]{language}";
246 print "\n:: please select your language (type corresponding number)\n> ";
248 while ( $choice = <STDIN
> )
254 last if $choice ~~ [ 1 .. $size ];
255 print ":: WRONG SELECTION!\n:: please select your language (type corresponding number)\n> ";
257 $LANG = $i18n[$choice - 1]{code
};
258 say ":: \"$i18n[$choice - 1]{language}\" selected\n::";
259 say qq{:: HINT
: put
"$pkg=$LANG" (without quotes
) in $HOME/.ff
-downloader to avoid being asked about your language
each time you build the
package\n::};
264 $| = 1; # turn on autoflush;
266 my $ff_path = "/pub/${PACKAGE}/releases/${VER}/linux-${ARCH}/${LANG}/${PACKAGE}-${VER}.tar.bz2";
267 my $ff_url = URI
->new('ftp://ftp.mozilla.org');
268 $ff_url->path($ff_path);
270 ##Downloading firefox##
271 get_url
( $ff_url, "${PACKAGE}-${VER}.tar.bz2" ) or die qq(:: ERROR
- can
't download "${PACKAGE}-${VER}.tar.bz2"\n);
273 ##downloading signature##
274 $ff_url->path("${ff_path}.asc");
275 get_url( $ff_url, "$PACKAGE-${VER}.tar.bz2.asc" ) or die qq(:: ERROR - can't download
"${PACKAGE}-${VER}.tar.bz2.asc"\n);
277 ##downloading public key
278 $ff_url->path("pub/${PACKAGE}/releases/${VER}/KEY");
279 get_url
( $ff_url, "KEY" ) or die qq(:: ERROR
- can
't download 'KEY
'\n);
281 print ':: verifying gnupg signature
... ';
282 my $gpg = new GnuPG();
283 $gpg->import_keys( keys => 'KEY
');
284 $gpg->verify ( signature => "${PACKAGE}-${VER}.tar.bz2.asc", file => "${PACKAGE}-${VER}.tar.bz2");