ftp.subr (255991) | ftp.subr (263791) |
---|---|
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: stable/9/usr.sbin/bsdconfig/share/media/ftp.subr 255991 2013-10-02 16:32:07Z dteske $ | 27# $FreeBSD: stable/9/usr.sbin/bsdconfig/share/media/ftp.subr 263791 2014-03-27 03:20:47Z 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 --- 172 unchanged lines hidden (view full) --- 208 --backtitle \"\$btitle\" \ 209 --hline \"\$hline\" \ 210 --ok-label \"\$msg_ok\" \ 211 --cancel-label \"\$msg_cancel\" \ 212 --menu \"\$prompt\" \ 213 $height $width $rows \ 214 $menu_list \ 215 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD | 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 --- 172 unchanged lines hidden (view full) --- 208 --backtitle \"\$btitle\" \ 209 --hline \"\$hline\" \ 210 --ok-label \"\$msg_ok\" \ 211 --cancel-label \"\$msg_cancel\" \ 212 --menu \"\$prompt\" \ 213 $height $width $rows \ 214 $menu_list \ 215 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD |
216 ) || return $FAILURE | 216 ) || return $DIALOG_CANCEL |
217 f_dialog_data_sanitize mtag 218 219 case "$mtag" in 220 URL) setvar $VAR_FTP_PATH "other" ;; 221 *) 222 local value 223 value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list ) 224 setvar $VAR_FTP_PATH "ftp://$value" 225 esac 226 | 217 f_dialog_data_sanitize mtag 218 219 case "$mtag" in 220 URL) setvar $VAR_FTP_PATH "other" ;; 221 *) 222 local value 223 value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list ) 224 setvar $VAR_FTP_PATH "ftp://$value" 225 esac 226 |
227 return $SUCCESS | 227 return $DIALOG_OK |
228} 229 230# f_media_set_ftp 231# 232# Return success if we both found and set the media type to be an FTP server. 233# Variables from variable.subr that can be used to script user input: 234# 235# VAR_FTP_PATH --- 499 unchanged lines hidden (view full) --- 735 ' ); then 736 setvar $VAR_FTP_DIR "$fdir" 737 setvar $VAR_FTP_PATH "ftp://$ftp_host$fdir" 738 FTP_INITIALIZED=YES 739 return $SUCCESS 740 else 741 f_yesno "$msg_cant_find_distribution" \ 742 "$rel" "$ftp_host" | 228} 229 230# f_media_set_ftp 231# 232# Return success if we both found and set the media type to be an FTP server. 233# Variables from variable.subr that can be used to script user input: 234# 235# VAR_FTP_PATH --- 499 unchanged lines hidden (view full) --- 735 ' ); then 736 setvar $VAR_FTP_DIR "$fdir" 737 setvar $VAR_FTP_PATH "ftp://$ftp_host$fdir" 738 FTP_INITIALIZED=YES 739 return $SUCCESS 740 else 741 f_yesno "$msg_cant_find_distribution" \ 742 "$rel" "$ftp_host" |
743 if [ $? -eq $SUCCESS ]; then | 743 if [ $? -eq $DIALOG_OK ]; then |
744 unset $VAR_FTP_PATH 745 f_media_set_ftp && continue 746 fi 747 fi 748 esac 749 break # to failure 750 done 751 752 unset FTP_INITIALIZED $VAR_FTP_PATH 753 f_device_network_down $dev 754 return $FAILURE 755} 756 | 744 unset $VAR_FTP_PATH 745 f_media_set_ftp && continue 746 fi 747 fi 748 esac 749 break # to failure 750 done 751 752 unset FTP_INITIALIZED $VAR_FTP_PATH 753 f_device_network_down $dev 754 return $FAILURE 755} 756 |
757# f_media_get_ftp $device $file [$probe_only] | 757# f_media_get_ftp $device $file [$probe_type] |
758# 759# Returns data from $file on an FTP server using ftp(1). Please note that 760# $device is unused but must be present (even if null). Information is instead | 758# 759# Returns data from $file on an FTP server using ftp(1). Please note that 760# $device is unused but must be present (even if null). Information is instead |
761# gathered from the environment. If $probe_only is present and non-NULL, 762# returns success if $file exists. | 761# gathered from the environment. If $probe_type is present and non-NULL, 762# returns success if $file exists. If $probe_type is equal to $PROBE_SIZE, 763# prints the size of $file in bytes to standard-out. |
763# 764# Variables from variable.subr used to configure the connection are as follows 765# (all of which are configured by f_media_set_ftp above): 766# 767# VAR_FTP_HOST 768# FTP host to connect to. Can be an IPv4 address, IPv6 address, 769# or DNS hostname of your choice. 770# VAR_FTP_PORT --- 17 unchanged lines hidden (view full) --- 788# See variable.subr for additional information. 789# 790# Example usage: 791# f_media_set_ftp 792# f_media_get_ftp media $file 793# 794f_media_get_ftp() 795{ | 764# 765# Variables from variable.subr used to configure the connection are as follows 766# (all of which are configured by f_media_set_ftp above): 767# 768# VAR_FTP_HOST 769# FTP host to connect to. Can be an IPv4 address, IPv6 address, 770# or DNS hostname of your choice. 771# VAR_FTP_PORT --- 17 unchanged lines hidden (view full) --- 789# See variable.subr for additional information. 790# 791# Example usage: 792# f_media_set_ftp 793# f_media_get_ftp media $file 794# 795f_media_get_ftp() 796{ |
796 local dev="$1" file="$2" probe_only="$3" hosts= | 797 local funcname=f_media_get_ftp 798 local dev="$1" file="$2" probe_type="$3" hosts= |
797 | 799 |
798 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \ 799 "$dev" "$file" "$probe_only" | 800 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_type=%s" \ 801 "$dev" "$file" "$probe_type" |
800 801 local ftp_host ftp_port 802 f_getvar $VAR_FTP_HOST ftp_host 803 f_getvar $VAR_FTP_PORT ftp_port 804 805 if [ ! "$FTP_INITIALIZED" ]; then 806 f_dprintf "No FTP connection open, can't get file %s" "$file" 807 return $FAILURE --- 53 unchanged lines hidden (view full) --- 861 f_getvar $VAR_FTP_DIR\#/ dir 862 f_getvar $VAR_FTP_STATE mode 863 864 local port="${ftp_port:+:$ftp_port}" 865 case "$host" in *:*) host="[$host]"; esac 866 867 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file" 868 | 802 803 local ftp_host ftp_port 804 f_getvar $VAR_FTP_HOST ftp_host 805 f_getvar $VAR_FTP_PORT ftp_port 806 807 if [ ! "$FTP_INITIALIZED" ]; then 808 f_dprintf "No FTP connection open, can't get file %s" "$file" 809 return $FAILURE --- 53 unchanged lines hidden (view full) --- 863 f_getvar $VAR_FTP_DIR\#/ dir 864 f_getvar $VAR_FTP_STATE mode 865 866 local port="${ftp_port:+:$ftp_port}" 867 case "$host" in *:*) host="[$host]"; esac 868 869 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file" 870 |
869 if [ "$probe_only" ]; then 870 local url="ftp://$userpass$host$port/$dir/$file" | 871 if [ "$probe_type" ]; then 872 local url="ftp://$userpass$host$port/$dir/$file" size |
871 [ "$use_anon" ] && url="ftp://$host$port/$dir/$file" | 873 [ "$use_anon" ] && url="ftp://$host$port/$dir/$file" |
872 if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size" | 874 if ! f_eval_catch -dk size $funcname fetch \ 875 'fetch -s "%s"' "$url" || ! f_isinteger "$size" |
873 then | 876 then |
874 f_dprintf "request failed! size response=[%s]" "$size" | 877 f_dprintf "size request failed!" 878 [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1" |
875 return $FAILURE 876 fi | 879 return $FAILURE 880 fi |
881 [ "$probe_type" = "$PROBE_SIZE" ] && echo "$size" |
|
877 return $SUCCESS 878 fi 879 880 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \ 881 ftp -V ${use_anon:+-a} -o - \ 882 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null 883 local retval=$? 884 --- 21 unchanged lines hidden --- | 882 return $SUCCESS 883 fi 884 885 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \ 886 ftp -V ${use_anon:+-a} -o - \ 887 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null 888 local retval=$? 889 --- 21 unchanged lines hidden --- |