Deleted Added
full compact
ftp.subr (259054) ftp.subr (264840)
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#
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 $
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 &&
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
331 f_device_shutdown device_network
332 if ! f_device_select_tcp; then
333 unset $VAR_FTP_PATH
334 return $FAILURE
335 fi
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
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
339 fi
340 fi
340 if ! f_device_init network; then
341 if ! f_device_init device_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 &&
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 &&
423 f_device_shutdown network
424 f_device_shutdown device_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
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
439 device_ftp set private network
440 device_ftp set private device_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
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
506 f_struct device_$dev || return $FAILURE
507 device_$dev get private netDev || return $SUCCESS # No net == happy net
507 f_struct "$dev" || return $FAILURE
508 $dev get private netDev || return $SUCCESS # No net == happy net
509debug=1 f_dprintf "netDev=[$netDev]"
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
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
518 f_struct device_$dev || return $FAILURE
519 device_$dev get private netDev || return $SUCCESS
520 f_struct "$dev" || return $FAILURE
521 $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"
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"
579
580 local url
581 local url
581 device_$dev get name url
582
583 $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 '
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 '
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 ---
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 ---