1if [ ! "$_MEDIA_HTTP_SUBR" ]; then _MEDIA_HTTP_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/http.subr 257795 2013-11-07 12:40:42Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/http.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr
--- 36 unchanged lines hidden (view full) ---
72#
73f_dialog_menu_media_http()
74{
75 f_dialog_title "$msg_please_select_a_freebsd_http_distribution_site"
76 local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
77 f_dialog_title_restore
78 local prompt="$msg_please_select_the_site_closest_to_you_or_other"
79 local menu_list="
80 'dist $msg_main_site' 'ftp.freebsd.org'
81 'pkg $msg_main_site' 'pkg.freebsd.org'
82 'URL' '$msg_specify_some_other_http_site'
83 " # END-QUOTE
84 local hline="$msg_select_a_site_thats_close"
85
86 local height width rows
87 eval f_dialog_menu_size height width rows \
88 \"\$title\" \
89 \"\$btitle\" \
--- 227 unchanged lines hidden (view full) ---
317
318 setvar $VAR_HTTP_HOST "$hostname"
319 setvar $VAR_HTTP_PORT "$port"
320 setvar $VAR_HTTP_DIR "$dir"
321
322 device_http set type $DEVICE_TYPE_HTTP
323 device_http set init f_media_init_http
324 device_http set get f_media_get_http
325 device_http set shutdown f_media_shutdown_http
326 device_http set private network
327 f_struct_copy device_http device_media
328 f_struct_free device_http
329
330 return $SUCCESS
331}
332
333# f_http_check_access [$connect_only]
--- 114 unchanged lines hidden (view full) ---
448# The [possibly] adjusted VAR_HTTP_PATH that was found to contain
449# a valid FreeBSD repository.
450#
451f_media_init_http()
452{
453 local dev="$1"
454 f_dprintf "Init routine called for HTTP device. dev=[%s]" "$dev"
455
456 if [ "$HTTP_INITIALIZED" ]; then
457 f_dprintf "HTTP device already initialized."
458 return $SUCCESS
459 fi
460
461 #
462 # First verify access
463 #
464 local connect_only=1
465 f_http_check_access $connect_only
466
467 local http_host
468 f_getvar $VAR_HTTP_HOST http_host
--- 25 unchanged lines hidden (view full) ---
494 *)
495 #
496 # Ok, since we have a release variable, let's walk
497 # through the list of directories looking for a release
498 # directory. First successful path wins.
499 #
500 local fdir hp
501 f_getvar $VAR_HTTP_PATH%/ hp
502 setvar $VAR_HTTP_PATH \
503 "$hp/freebsd:${UNAME_R%%.*}:$UNAME_PKG/latest"
504 if f_http_check_access; then
505 http_found=$SUCCESS
506 else
507 for fdir in $HTTP_DIRS; do
508 setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
509 if f_http_check_access; then
510 http_found=$SUCCESS
511 break
512 fi
513 done
514 fi
515 esac
516
517 if [ $http_found -eq $SUCCESS ]; then
518 HTTP_INITIALIZED=YES
519 break
520 fi
521
522 f_getvar $VAR_HTTP_PATH http_path
523 f_show_msg "$msg_please_check_the_url_and_try_again" \
524 "$http_path"
525
526 unset HTTP_INITIALIZED $VAR_HTTP_PATH
527 f_media_set_http || break
528 done
529
530 return $http_found
531}
532
533# f_media_get_http $device $file [$probe_type]
534#
--- 33 unchanged lines hidden (view full) ---
568
569 f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
570 "$dev" "$file" "$probe_type"
571
572 local http_host http_port
573 f_getvar $VAR_HTTP_HOST http_host
574 f_getvar $VAR_HTTP_PORT http_port
575
576 if [ ! "$HTTP_INITIALIZED" ]; then
577 f_dprintf "No HTTP connection open, can't get file %s" "$file"
578 return $FAILURE
579 fi
580
581 if ! {
582 f_validate_ipaddr "$http_host" ||
583 f_validate_ipaddr6 "$http_host" ||
584 {
585 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
586 "f_media_get_http" "$http_host"
587 f_host_lookup "$http_host" hosts
588 }
--- 77 unchanged lines hidden (view full) ---
666 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
667 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
668 4) f_show_msg "$msg_client_error" ;;
669 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
670 esac
671 return $FAILURE
672}
673
674# f_media_shutdown_http $device
675#
676# Shuts down the HTTP device. Return status should be ignored. Note that since
677# we don't maintain an open connection to the HTTP server, nothing to do.
678#
679f_media_shutdown_http()
680{
681 [ "$HTTP_INITIALIZED" ] || return $SUCCESS
682
683 unset HTTP_INITIALIZED
684}
685
686############################################################ MAIN
687
688f_dprintf "%s: Successfully loaded." media/http.subr
689
690fi # ! $_MEDIA_HTTP_SUBR
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/http.subr 257795 2013-11-07 12:40:42Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/http.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr
--- 36 unchanged lines hidden (view full) ---
72#
73f_dialog_menu_media_http()
74{
75 f_dialog_title "$msg_please_select_a_freebsd_http_distribution_site"
76 local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
77 f_dialog_title_restore
78 local prompt="$msg_please_select_the_site_closest_to_you_or_other"
79 local menu_list="
80 'dist $msg_main_site' 'ftp.freebsd.org'
81 'pkg $msg_main_site' 'pkg.freebsd.org'
82 'URL' '$msg_specify_some_other_http_site'
83 " # END-QUOTE
84 local hline="$msg_select_a_site_thats_close"
85
86 local height width rows
87 eval f_dialog_menu_size height width rows \
88 \"\$title\" \
89 \"\$btitle\" \
--- 227 unchanged lines hidden (view full) ---
317
318 setvar $VAR_HTTP_HOST "$hostname"
319 setvar $VAR_HTTP_PORT "$port"
320 setvar $VAR_HTTP_DIR "$dir"
321
322 device_http set type $DEVICE_TYPE_HTTP
323 device_http set init f_media_init_http
324 device_http set get f_media_get_http
325 device_http set shutdown f_media_shutdown_http
326 device_http set private network
327 f_struct_copy device_http device_media
328 f_struct_free device_http
329
330 return $SUCCESS
331}
332
333# f_http_check_access [$connect_only]
--- 114 unchanged lines hidden (view full) ---
448# The [possibly] adjusted VAR_HTTP_PATH that was found to contain
449# a valid FreeBSD repository.
450#
451f_media_init_http()
452{
453 local dev="$1"
454 f_dprintf "Init routine called for HTTP device. dev=[%s]" "$dev"
455
456 if [ "$HTTP_INITIALIZED" ]; then
457 f_dprintf "HTTP device already initialized."
458 return $SUCCESS
459 fi
460
461 #
462 # First verify access
463 #
464 local connect_only=1
465 f_http_check_access $connect_only
466
467 local http_host
468 f_getvar $VAR_HTTP_HOST http_host
--- 25 unchanged lines hidden (view full) ---
494 *)
495 #
496 # Ok, since we have a release variable, let's walk
497 # through the list of directories looking for a release
498 # directory. First successful path wins.
499 #
500 local fdir hp
501 f_getvar $VAR_HTTP_PATH%/ hp
502 setvar $VAR_HTTP_PATH \
503 "$hp/freebsd:${UNAME_R%%.*}:$UNAME_PKG/latest"
504 if f_http_check_access; then
505 http_found=$SUCCESS
506 else
507 for fdir in $HTTP_DIRS; do
508 setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
509 if f_http_check_access; then
510 http_found=$SUCCESS
511 break
512 fi
513 done
514 fi
515 esac
516
517 if [ $http_found -eq $SUCCESS ]; then
518 HTTP_INITIALIZED=YES
519 break
520 fi
521
522 f_getvar $VAR_HTTP_PATH http_path
523 f_show_msg "$msg_please_check_the_url_and_try_again" \
524 "$http_path"
525
526 unset HTTP_INITIALIZED $VAR_HTTP_PATH
527 f_media_set_http || break
528 done
529
530 return $http_found
531}
532
533# f_media_get_http $device $file [$probe_type]
534#
--- 33 unchanged lines hidden (view full) ---
568
569 f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
570 "$dev" "$file" "$probe_type"
571
572 local http_host http_port
573 f_getvar $VAR_HTTP_HOST http_host
574 f_getvar $VAR_HTTP_PORT http_port
575
576 if [ ! "$HTTP_INITIALIZED" ]; then
577 f_dprintf "No HTTP connection open, can't get file %s" "$file"
578 return $FAILURE
579 fi
580
581 if ! {
582 f_validate_ipaddr "$http_host" ||
583 f_validate_ipaddr6 "$http_host" ||
584 {
585 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
586 "f_media_get_http" "$http_host"
587 f_host_lookup "$http_host" hosts
588 }
--- 77 unchanged lines hidden (view full) ---
666 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
667 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
668 4) f_show_msg "$msg_client_error" ;;
669 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
670 esac
671 return $FAILURE
672}
673
674# f_media_shutdown_http $device
675#
676# Shuts down the HTTP device. Return status should be ignored. Note that since
677# we don't maintain an open connection to the HTTP server, nothing to do.
678#
679f_media_shutdown_http()
680{
681 [ "$HTTP_INITIALIZED" ] || return $SUCCESS
682
683 unset HTTP_INITIALIZED
684}
685
686############################################################ MAIN
687
688f_dprintf "%s: Successfully loaded." media/http.subr
689
690fi # ! $_MEDIA_HTTP_SUBR