1if [ ! "$_MEDIA_FTP_SUBR" ]; then _MEDIA_FTP_SUBR=1 2# 3# Copyright (c) 2012-2013 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/ftp.subr 264840 2014-04-23 22:04:04Z dteske $ |
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/ftp.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/dialog.subr --- 287 unchanged lines hidden (view full) --- 323 # Set the name of the FTP device to the URL 324 f_struct_new DEVICE device_ftp 325 device_ftp set name "$url" 326 327 if ! f_struct device_network || 328 ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration" 329 then 330 f_struct device_network && |
331 f_device_shutdown device_network |
332 if ! f_device_select_tcp; then 333 unset $VAR_FTP_PATH 334 return $FAILURE 335 fi |
336 local dev if 337 f_getvar $VAR_NETWORK_DEVICE if 338 f_device_find -1 "$if" $DEVICE_TYPE_NETWORK dev 339 f_struct_copy "$dev" device_network |
340 fi |
341 if ! f_device_init device_network; then |
342 f_dprintf "f_media_set_ftp: %s" "$msg_net_device_init_failed" 343 unset $VAR_FTP_PATH 344 return $FAILURE 345 fi 346 347 local hostname="${url#*://}" port=21 dir=/ 348 case "$hostname" in 349 # --- 66 unchanged lines hidden (view full) --- 416 f_validate_ipaddr6 "$hostname" 417 }; then 418 f_show_info "$msg_looking_up_host" "$hostname" 419 f_dprintf "%s: Looking up hostname, %s, using host(1)" \ 420 "f_media_set_ftp" "$hostname" 421 if ! f_quietly f_host_lookup "$hostname"; then 422 f_show_msg "$msg_cannot_resolve_hostname" "$hostname" 423 f_struct device_network && |
424 f_device_shutdown device_network |
425 f_struct_free device_network 426 unset $VAR_FTP_PATH 427 return $FAILURE 428 fi 429 f_dprintf "Found DNS entry for %s successfully." "$hostname" 430 fi 431 432 setvar $VAR_FTP_HOST "$hostname" 433 setvar $VAR_FTP_PORT "$port" 434 setvar $VAR_FTP_DIR "$dir" 435 436 device_ftp set type $DEVICE_TYPE_FTP 437 device_ftp set init f_media_init_ftp 438 device_ftp set get f_media_get_ftp 439 device_ftp set shutdown f_media_shutdown_ftp |
440 device_ftp set private device_network |
441 f_struct_copy device_ftp device_media 442 f_struct_free device_ftp 443 444 return $SUCCESS 445} 446 447# f_media_set_ftp_active 448# --- 50 unchanged lines hidden (view full) --- 499 500# f_device_network_up $device 501# 502# Brings up attached network device, if any - takes FTP device as arg. 503# 504f_device_network_up() 505{ 506 local dev="$1" netDev |
507 f_struct "$dev" || return $FAILURE 508 $dev get private netDev || return $SUCCESS # No net == happy net 509debug=1 f_dprintf "netDev=[$netDev]" |
510 f_device_init $netDev 511} 512 513# f_device_network_down $device 514# 515# Brings down attached network device, if any - takes FTP device as arg. 516# 517f_device_network_down() 518{ 519 local dev="$1" netDev |
520 f_struct "$dev" || return $FAILURE 521 $dev get private netDev || return $SUCCESS |
522 f_device_shutdown $netDev 523} 524 525# f_media_init_ftp $device 526# 527# Initializes the FTP media device. Returns success if both able to log into 528# the FTP server and confirm the existence of at least one known release path 529# using ftp(1). --- 43 unchanged lines hidden (view full) --- 573# taken as the absolute path to the release and no further 574# searching is done (see FTP_DIRS above in the GLOBALS section 575# for a list of well known paths that are used when searching for 576# a VAR_RELNAME sub-directory). 577# 578f_media_init_ftp() 579{ 580 local dev="$1" |
581 local url |
582 583 $dev get name url |
584 f_dprintf "Init routine called for FTP device. url=[%s]" "$url" 585 586 if [ "$FTP_INITIALIZED" ]; then 587 f_dprintf "FTP device already initialized." 588 return $SUCCESS 589 fi 590 591 # If we can't initialize the network, bag it! --- 129 unchanged lines hidden (view full) --- 721 ); then 722 f_show_msg "$msg_couldnt_open_ftp_connection" \ 723 "$ftp_host" "$rx" 724 break # to failure 725 fi 726 727 local fdir 728 if fdir=$( echo "$rx" | awk ' |
729 /^Remote directory: / { 730 sub(/^[^:]*:[[:space:]]*/, "") 731 if ($0 == "/") next 732 # Exit after the first dir 733 found++; print; exit 734 } 735 END { exit ! found } 736 ' ); then --- 175 unchanged lines hidden --- |