Deleted Added
sdiff udiff text old ( 259054 ) new ( 264840 )
full compact
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 259054 2013-12-07 00:31:01Z 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 network
332 if ! f_device_select_tcp; then
333 unset $VAR_FTP_PATH
334 return $FAILURE
335 fi
336 local dev
337 f_getvar $VAR_NETWORK_DEVICE dev
338 f_struct_copy "device_$dev" device_network
339 fi
340 if ! f_device_init network; then
341 f_dprintf "f_media_set_ftp: %s" "$msg_net_device_init_failed"
342 unset $VAR_FTP_PATH
343 return $FAILURE
344 fi
345
346 local hostname="${url#*://}" port=21 dir=/
347 case "$hostname" in
348 #

--- 66 unchanged lines hidden (view full) ---

415 f_validate_ipaddr6 "$hostname"
416 }; then
417 f_show_info "$msg_looking_up_host" "$hostname"
418 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
419 "f_media_set_ftp" "$hostname"
420 if ! f_quietly f_host_lookup "$hostname"; then
421 f_show_msg "$msg_cannot_resolve_hostname" "$hostname"
422 f_struct device_network &&
423 f_device_shutdown network
424 f_struct_free device_network
425 unset $VAR_FTP_PATH
426 return $FAILURE
427 fi
428 f_dprintf "Found DNS entry for %s successfully." "$hostname"
429 fi
430
431 setvar $VAR_FTP_HOST "$hostname"
432 setvar $VAR_FTP_PORT "$port"
433 setvar $VAR_FTP_DIR "$dir"
434
435 device_ftp set type $DEVICE_TYPE_FTP
436 device_ftp set init f_media_init_ftp
437 device_ftp set get f_media_get_ftp
438 device_ftp set shutdown f_media_shutdown_ftp
439 device_ftp set private network
440 f_struct_copy device_ftp device_media
441 f_struct_free device_ftp
442
443 return $SUCCESS
444}
445
446# f_media_set_ftp_active
447#

--- 50 unchanged lines hidden (view full) ---

498
499# f_device_network_up $device
500#
501# Brings up attached network device, if any - takes FTP device as arg.
502#
503f_device_network_up()
504{
505 local dev="$1" netDev
506 f_struct device_$dev || return $FAILURE
507 device_$dev get private netDev || return $SUCCESS # No net == happy net
508 f_device_init $netDev
509}
510
511# f_device_network_down $device
512#
513# Brings down attached network device, if any - takes FTP device as arg.
514#
515f_device_network_down()
516{
517 local dev="$1" netDev
518 f_struct device_$dev || return $FAILURE
519 device_$dev get private netDev || return $SUCCESS
520 f_device_shutdown $netDev
521}
522
523# f_media_init_ftp $device
524#
525# Initializes the FTP media device. Returns success if both able to log into
526# the FTP server and confirm the existence of at least one known release path
527# using ftp(1).

--- 43 unchanged lines hidden (view full) ---

571# taken as the absolute path to the release and no further
572# searching is done (see FTP_DIRS above in the GLOBALS section
573# for a list of well known paths that are used when searching for
574# a VAR_RELNAME sub-directory).
575#
576f_media_init_ftp()
577{
578 local dev="$1"
579
580 local url
581 device_$dev get name url
582 f_dprintf "Init routine called for FTP device. url=[%s]" "$url"
583
584 if [ "$FTP_INITIALIZED" ]; then
585 f_dprintf "FTP device already initialized."
586 return $SUCCESS
587 fi
588
589 # If we can't initialize the network, bag it!

--- 129 unchanged lines hidden (view full) ---

719 ); then
720 f_show_msg "$msg_couldnt_open_ftp_connection" \
721 "$ftp_host" "$rx"
722 break # to failure
723 fi
724
725 local fdir
726 if fdir=$( echo "$rx" | awk '
727 BEGIN { found = 0 }
728 /^Remote directory: / {
729 sub(/^[^:]*:[[:space:]]*/, "")
730 if ($0 == "/") next
731 # Exit after the first dir
732 found++; print; exit
733 }
734 END { exit ! found }
735 ' ); then

--- 175 unchanged lines hidden ---