functions-ftp.sh revision 225467
1#!/bin/sh 2#- 3# Copyright (c) 2010 iXsystems, Inc. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24# SUCH DAMAGE. 25# 26# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-ftp.sh 225467 2011-09-10 09:40:00Z brueffer $ 27 28# Functions which runs commands on the system 29 30. ${BACKEND}/functions.sh 31. ${BACKEND}/functions-parse.sh 32 33DEFAULT_FTP_SERVER="ftp.freebsd.org" 34 35MAIN_FTP_SERVERS="\ 36Main Site: ftp.freebsd.org" 37 38IPV6_FTP_SERVERS="\ 39IPv6 Main Site: ftp.freebsd.org|\ 40IPv6 Ireland: ftp3.ie.freebsd.org|\ 41IPv6 Israel: ftp.il.freebsd.org|\ 42IPv6 Japan: ftp2.jp.freebsd.org|\ 43IPv6 Sweden: ftp4.se.freebsd.org|\ 44IPv6 USA: ftp4.us.freebsd.org|\ 45IPv6 Turkey: ftp2.tr.freebsd.org" 46 47PRIMARY_FTP_SERVERS="\ 48Primary: ftp1.freebsd.org|\ 49Primary #2: ftp2.freebsd.org|\ 50Primary #3: ftp3.freebsd.org|\ 51Primary #4: ftp4.freebsd.org|\ 52Primary #5: ftp5.freebsd.org|\ 53Primary #6: ftp6.freebsd.org|\ 54Primary #7: ftp7.freebsd.org|\ 55Primary #8: ftp8.freebsd.org|\ 56Primary #9: ftp9.freebsd.org|\ 57Primary #10: ftp10.freebsd.org|\ 58Primary #11: ftp11.freebsd.org|\ 59Primary #12: ftp12.freebsd.org|\ 60Primary #13: ftp13.freebsd.org|\ 61Primary #14: ftp14.freebsd.org" 62 63ARGENTINA_FTP_SERVERS="\ 64Argentina: ftp.ar.freebsd.org" 65 66AUSTRALIA_FTP_SERVERS="\ 67Australia: ftp.au.freebsd.org|\ 68Australia #2: ftp2.au.freebsd.org|\ 69Australia #3: ftp3.au.freebsd.org" 70 71AUSTRIA_FTP_SERVERS="\ 72Austria: ftp.at.freebsd.org|\ 73Austria #2: ftp2.at.freebsd.org" 74 75BRAZIL_FTP_SERVERS="\ 76Brazil: ftp.br.freebsd.org|\ 77Brazil #2: ftp2.br.freebsd.org|\ 78Brazil #3: ftp3.br.freebsd.org|\ 79Brazil #4: ftp4.br.freebsd.org|\ 80Brazil #5: ftp5.br.freebsd.org|\ 81Brazil #6: ftp6.br.freebsd.org|\ 82Brazil #7: ftp7.br.freebsd.org" 83 84CANADA_FTP_SERVERS="\ 85Canada: ftp.ca.freebsd.org" 86 87CHINA_FTP_SERVERS="\ 88China: ftp.cn.freebsd.org|\ 89China #2: ftp2.cn.freebsd.org" 90 91CROATIA_FTP_SERVERS="\ 92Croatia: ftp.hr.freebsd.org" 93 94CZECH_REPUBLIC_FTP_SERVERS="\ 95Czech Republic: ftp.cz.freebsd.org" 96 97DENMARK_FTP_SERVERS="\ 98Denmark: ftp.dk.freebsd.org|\ 99Denmark #2: ftp2.dk.freebsd.org" 100 101ESTONIA_FTP_SERVERS="\ 102Estonia: ftp.ee.freebsd.org" 103 104FINLAND_FTP_SERVERS="\ 105Finland: ftp.fi.freebsd.org" 106 107FRANCE_FTP_SERVERS="\ 108France: ftp.fr.freebsd.org|\ 109France #2: ftp2.fr.freebsd.org|\ 110France #3: ftp3.fr.freebsd.org|\ 111France #5: ftp5.fr.freebsd.org|\ 112France #6: ftp6.fr.freebsd.org|\ 113France #8: ftp8.fr.freebsd.org" 114 115GERMANY_FTP_SERVERS="\ 116Germany: ftp.de.freebsd.org|\ 117Germany #2: ftp2.de.freebsd.org|\ 118Germany #3: ftp3.de.freebsd.org|\ 119Germany #4: ftp4.de.freebsd.org|\ 120Germany #5: ftp5.de.freebsd.org|\ 121Germany #6: ftp6.de.freebsd.org|\ 122Germany #7: ftp7.de.freebsd.org|\ 123Germany #8: ftp8.de.freebsd.org" 124 125GREECE_FTP_SERVERS="\ 126Greece: ftp.gr.freebsd.org|\ 127Greece #2: ftp2.gr.freebsd.org" 128 129HUNGARY_FTP_SERVERS="\ 130Hungary: ftp.hu.freebsd.org" 131 132ICELAND_FTP_SERVERS="\ 133Iceland: ftp.is.freebsd.org" 134 135IRELAND_FTP_SERVERS="\ 136Ireland: ftp.ie.freebsd.org|\ 137Ireland #2: ftp2.ie.freebsd.org|\ 138Ireland #3: ftp3.ie.freebsd.org" 139 140ISRAEL_FTP_SERVERS="\ 141Israel: ftp.il.freebsd.org" 142 143ITALY_FTP_SERVERS="\ 144Italy: ftp.it.freebsd.org" 145 146JAPAN_FTP_SERVERS="\ 147Japan: ftp.jp.freebsd.org|\ 148Japan #2: ftp2.jp.freebsd.org|\ 149Japan #3: ftp3.jp.freebsd.org|\ 150Japan #4: ftp4.jp.freebsd.org|\ 151Japan #5: ftp5.jp.freebsd.org|\ 152Japan #6: ftp6.jp.freebsd.org|\ 153Japan #7: ftp7.jp.freebsd.org|\ 154Japan #8: ftp8.jp.freebsd.org|\ 155Japan #9: ftp9.jp.freebsd.org" 156 157KOREA_FTP_SERVERS="\ 158Korea: ftp.kr.freebsd.org|\ 159Korea #2: ftp2.kr.freebsd.org" 160 161LITHUANIA_FTP_SERVERS="\ 162Lithuania: ftp.lt.freebsd.org" 163 164NETHERLANDS_FTP_SERVERS="\ 165Netherlands: ftp.nl.freebsd.org|\ 166Netherlands #2: ftp2.nl.freebsd.org" 167 168NORWAY_FTP_SERVERS="\ 169Norway: ftp.no.freebsd.org|\ 170Norway #3: ftp3.no.freebsd.org" 171 172POLAND_FTP_SERVERS="\ 173Poland: ftp.pl.freebsd.org|\ 174Poland #2: ftp2.pl.freebsd.org|\ 175Poland #5: ftp5.pl.freebsd.org" 176 177PORTUGAL_FTP_SERVERS="\ 178Portugal: ftp.pt.freebsd.org|\ 179Portugal #2: ftp2.pt.freebsd.org|\ 180Portugal #4: ftp4.pt.freebsd.org" 181 182ROMANIA_FTP_SERVERS="\ 183Romania: ftp.ro.freebsd.org" 184 185RUSSIA_FTP_SERVERS="\ 186Russia: ftp.ru.freebsd.org|\ 187Russia #2: ftp2.ru.freebsd.org|\ 188Russia #3: ftp3.ru.freebsd.org|\ 189Russia #4: ftp4.ru.freebsd.org" 190 191SINGAPORE_FTP_SERVERS="\ 192Singapore: ftp.sg.freebsd.org" 193 194SLOVAK_REPUBLIC_FTP_SERVERS="\ 195Slovak Republic: ftp.sk.freebsd.org" 196 197SLOVENIA_FTP_SERVERS="\ 198Slovenia: ftp.si.freebsd.org|\ 199Slovenia #2: ftp2.si.freebsd.org" 200 201SOUTH_AFRICA_FTP_SERVERS="\ 202South Africa: ftp.za.freebsd.org|\ 203South Africa #2: ftp2.za.freebsd.org|\ 204South Africa #3: ftp3.za.freebsd.org|\ 205South Africa #4: ftp4.za.freebsd.org" 206 207SPAIN_FTP_SERVERS="\ 208Spain: ftp.es.freebsd.org|\ 209Spain #2: ftp2.es.freebsd.org|\ 210Spain #3: ftp3.es.freebsd.org" 211 212SWEDEN_FTP_SERVERS="\ 213Sweden: ftp.se.freebsd.org|\ 214Sweden #2: ftp2.se.freebsd.org|\ 215Sweden #3: ftp3.se.freebsd.org|\ 216Sweden #4: ftp4.se.freebsd.org|\ 217Sweden #5: ftp5.se.freebsd.org" 218 219SWITZERLAND_FTP_SERVERS="\ 220Switzerland: ftp.ch.freebsd.org|\ 221Switzerland #2: ftp2.ch.freebsd.org" 222 223TAIWAN_FTP_SERVERS="\ 224Taiwan: ftp.tw.freebsd.org|\ 225Taiwan #2: ftp2.tw.freebsd.org|\ 226Taiwan #3: ftp3.tw.freebsd.org|\ 227Taiwan #4: ftp4.tw.freebsd.org|\ 228Taiwan #6: ftp6.tw.freebsd.org|\ 229Taiwan #11: ftp11.tw.freebsd.org" 230 231TURKEY_FTP_SERVERS="\ 232Turkey: ftp.tr.freebsd.org|\ 233Turkey #2: ftp2.tr.freebsd.org" 234 235UK_FTP_SERVERS="\ 236UK: ftp.uk.freebsd.org|\ 237UK #2: ftp2.uk.freebsd.org|\ 238UK #3: ftp3.uk.freebsd.org|\ 239UK #4: ftp4.uk.freebsd.org|\ 240UK #5: ftp5.uk.freebsd.org|\ 241UK #6: ftp6.uk.freebsd.org" 242 243UKRAINE_FTP_SERVERS="\ 244Ukraine: ftp.ua.freebsd.org|\ 245Ukraine #2: ftp2.ua.freebsd.org|\ 246Ukraine #5: ftp5.ua.freebsd.org|\ 247Ukraine #6: ftp6.ua.freebsd.org|\ 248Ukraine #7: ftp7.ua.freebsd.org|\ 249Ukraine #8: ftp8.ua.freebsd.org" 250 251USA_FTP_SERVERS="\ 252USA #1: ftp1.us.freebsd.org|\ 253USA #2: ftp2.us.freebsd.org|\ 254USA #3: ftp3.us.freebsd.org|\ 255USA #4: ftp4.us.freebsd.org|\ 256USA #5: ftp5.us.freebsd.org|\ 257USA #6: ftp6.us.freebsd.org|\ 258USA #7: ftp7.us.freebsd.org|\ 259USA #8: ftp8.us.freebsd.org|\ 260USA #9: ftp9.us.freebsd.org|\ 261USA #10: ftp10.us.freebsd.org|\ 262USA #11: ftp11.us.freebsd.org|\ 263USA #12: ftp12.us.freebsd.org|\ 264USA #13: ftp13.us.freebsd.org|\ 265USA #14: ftp14.us.freebsd.org|\ 266USA #15: ftp15.us.freebsd.org" 267 268show_mirrors() 269{ 270 MIRRORS="${1}" 271 if [ -n "${MIRRORS}" ] 272 then 273 SAVE_IFS="${IFS}" 274 IFS="|" 275 for m in ${MIRRORS} 276 do 277 echo "$m" 278 done 279 IFS="${SAVE_IFS}" 280 fi 281}; 282 283set_ftp_mirror() 284{ 285 MIRROR="${1}" 286 echo "${MIRROR}" > "${CONFDIR}/mirrors.conf" 287}; 288 289get_ftp_mirror() 290{ 291 MIRROR="${DEFAULT_FTP_SERVER}" 292 if [ -f "${CONFDIR}/mirrors.conf" ] 293 then 294 MIRROR=`cat "${CONFDIR}/mirrors.conf"` 295 fi 296 297 export VAL="${MIRROR}" 298}; 299 300 301get_ftpHost() 302{ 303 get_value_from_cfg ftpPath 304 ftpPath="$VAL" 305 306 ftpHost=`echo "${ftpPath}" | sed -E 's|^(ftp://)([^/]*)(.*)|\2|'` 307 export VAL="${ftpHost}" 308}; 309 310get_ftpDir() 311{ 312 get_value_from_cfg ftpPath 313 ftpPath="$VAL" 314 315 ftpDir=`echo "${ftpPath}" | sed -E 's|^(ftp://)([^/]*)(.*)|\3|'` 316 export VAL="${ftpDir}" 317}; 318 319get_ftp_mirrors() 320{ 321 COUNTRY="${1}" 322 if [ -n "$COUNTRY" ] 323 then 324 COUNTRY=`echo $COUNTRY|tr A-Z a-z` 325 case "${COUNTRY}" in 326 argentina*) VAL="${ARGENTINA_FTP_SERVERS}" ;; 327 australia*) VAL="${AUSTRALIA_FTP_SERVERS}" ;; 328 austria*) VAL="${AUSTRIA_FTP_SERVERS}" ;; 329 brazil*) VAL="${BRAZIL_FTP_SERVERS}" ;; 330 canada*) VAL="${CANADA_FTP_SERVERS}" ;; 331 china*) VAL="${CHINA_FTP_SERVERS}" ;; 332 croatia*) VAL="${CROATIA_FTP_SERVERS}" ;; 333 czech*) VAL="${CZECH_REPUBLIC_FTP_SERVERS}" ;; 334 denmark*) VAL="${DENMARK_FTP_SERVERS}" ;; 335 estonia*) VAL="${ESTONIA_FTP_SERVERS}" ;; 336 finland*) VAL="${FINLAND_FTP_SERVERS}" ;; 337 france*) VAL="${FRANCE_FTP_SERVERS}" ;; 338 germany*) VAL="${GERMANY_FTP_SERVERS}" ;; 339 greece*) VAL="${GREECE_FTP_SERVERS}" ;; 340 hungary*) VAL="${HUNGARY_FTP_SERVERS}" ;; 341 iceland*) VAL="${ICELAND_FTP_SERVERS}" ;; 342 ireland*) VAL="${IRELAND_FTP_SERVERS}" ;; 343 israel*) VAL="${ISRAEL_FTP_SERVERS}" ;; 344 italy*) VAL="${ITALY_FTP_SERVERS}" ;; 345 japan*) VAL="${JAPAN_FTP_SERVERS}" ;; 346 korea*) VAL="${KOREA_FTP_SERVERS}" ;; 347 lithuania*) VAL="${LITHUANIA_FTP_SERVERS}" ;; 348 netherlands*) VAL="${NETHERLANDS_FTP_SERVERS}" ;; 349 norway*) VAL="${NORWAY_FTP_SERVERS}" ;; 350 poland*) VAL="${POLAND_FTP_SERVERS}" ;; 351 portugal*) VAL="${PORTUGAL_FTP_SERVERS}" ;; 352 romania*) VAL="${ROMAINIA_FTP_SERVERS}" ;; 353 russia*) VAL="${RUSSIA_FTP_SERVERS}" ;; 354 singapore*) VAL="${SINGAPORE_FTP_SERVERS}" ;; 355 slovak*) VAL="${SLOVAK_REPUBLIC_FTP_SERVERS}" ;; 356 slovenia*) VAL="${SLOVENIA_FTP_SERVERS}" ;; 357 *africa*) VAL="${SOUTH_AFRICA_FTP_SERVERS}" ;; 358 spain*) VAL="${SPAIN_FTP_SERVERS}" ;; 359 sweden*) VAL="${SWEDEN_FTP_SERVERS}" ;; 360 switzerland*) VAL="${SWITZERLAND_FTP_SERVERS}" ;; 361 taiwan*) VAL="${TAIWAN_FTP_SERVERS}" ;; 362 turkey*) VAL="${TURKEY_FTP_SERVERS}" ;; 363 ukraine*) VAL="${UKRAINE_FTP_SERVERS}" ;; 364 uk*) VAL="${UK_FTP_SERVERS}" ;; 365 usa*) VAL="${USA_FTP_SERVERS}" ;; 366 esac 367 else 368 VAL="${MAIN_FTP_SERVERS}" 369 VAL="${VAL}|${IPV6_FTP_SERVERS}" 370 VAL="${VAL}|${PRIMARY_FTP_SERVERS}" 371 VAL="${VAL}|${ARGENTINA_FTP_SERVERS}" 372 VAL="${VAL}|${AUSTRALIA_FTP_SERVERS}" 373 VAL="${VAL}|${AUSTRIA_FTP_SERVERS}" 374 VAL="${VAL}|${BRAZIL_FTP_SERVERS}" 375 VAL="${VAL}|${CANADA_FTP_SERVERS}" 376 VAL="${VAL}|${CHINA_FTP_SERVERS}" 377 VAL="${VAL}|${CROATIA_FTP_SERVERS}" 378 VAL="${VAL}|${CZECH_REPUBLIC_FTP_SERVERS}" 379 VAL="${VAL}|${DENMARK_FTP_SERVERS}" 380 VAL="${VAL}|${ESTONIA_FTP_SERVERS}" 381 VAL="${VAL}|${FINLAND_FTP_SERVERS}" 382 VAL="${VAL}|${FRANCE_FTP_SERVERS}" 383 VAL="${VAL}|${GERMANY_FTP_SERVERS}" 384 VAL="${VAL}|${GREECE_FTP_SERVERS}" 385 VAL="${VAL}|${HUNGARY_FTP_SERVERS}" 386 VAL="${VAL}|${ICELAND_FTP_SERVERS}" 387 VAL="${VAL}|${IRELAND_FTP_SERVERS}" 388 VAL="${VAL}|${ISRAEL_FTP_SERVERS}" 389 VAL="${VAL}|${ITALY_FTP_SERVERS}" 390 VAL="${VAL}|${JAPAN_FTP_SERVERS}" 391 VAL="${VAL}|${KOREA_FTP_SERVERS}" 392 VAL="${VAL}|${LITHUANIA_FTP_SERVERS}" 393 VAL="${VAL}|${NETHERLANDS_FTP_SERVERS}" 394 VAL="${VAL}|${NORWAY_FTP_SERVERS}" 395 VAL="${VAL}|${POLAND_FTP_SERVERS}" 396 VAL="${VAL}|${PORTUGAL_FTP_SERVERS}" 397 VAL="${VAL}|${ROMANIA_FTP_SERVERS}" 398 VAL="${VAL}|${RUSSIA_FTP_SERVERS}" 399 VAL="${VAL}|${SINGAPORE_FTP_SERVERS}" 400 VAL="${VAL}|${SLOVAK_REPUBLIC_FTP_SERVERS}" 401 VAL="${VAL}|${SLOVENIA_FTP_SERVERS}" 402 VAL="${VAL}|${SOUTH_AFRICA_FTP_SERVERS}" 403 VAL="${VAL}|${SPAIN_FTP_SERVERS}" 404 VAL="${VAL}|${SWEDEN_FTP_SERVERS}" 405 VAL="${VAL}|${SWITZERLAND_FTP_SERVERS}" 406 VAL="${VAL}|${TAIWAN_FTP_SERVERS}" 407 VAL="${VAL}|${TURKEY_FTP_SERVERS}" 408 VAL="${VAL}|${UKRAINE_FTP_SERVERS}" 409 VAL="${VAL}|${UK_FTP_SERVERS}" 410 VAL="${VAL}|${USA_FTP_SERVERS}" 411 fi 412 413 export VAL 414}; 415