Deleted Added
full compact
ftp.subr (251236) ftp.subr (251264)
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:
9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INLUDING, 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:
9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INLUDING, 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 251236 2013-06-01 23:58:44Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/ftp.subr 251264 2013-06-02 20:02:50Z 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/struct.subr
35f_include $BSDCFG_SHARE/device.subr
36f_include $BSDCFG_SHARE/dialog.subr
37f_include $BSDCFG_SHARE/strings.subr
38f_include $BSDCFG_SHARE/variable.subr
39f_include $BSDCFG_SHARE/media/common.subr
40f_include $BSDCFG_SHARE/media/tcpip.subr
41f_include $BSDCFG_SHARE/media/network.subr
42
43BSDCFG_LIBE="/usr/libexec/bsdconfig"
44f_include_lang $BSDCFG_LIBE/include/messages.subr
45
46############################################################ GLOBALS
47
48FTP_SKIP_RESOLV=
49
50URL_MAX=261261 # according to actual fetch(1) test-results
51
52FTP_DIRS="
53 .
54 releases/$UNAME_P
55 snapshots/$UNAME_P
56 pub/FreeBSD
57 pub/FreeBSD/releases/$UNAME_P
58 pub/FreeBSD/snapshots/$UNAME_P
59 pub/FreeBSD-Archive/old-releases/$UNAME_P
60" # END-QUOTE
61
62############################################################ FUNCTIONS
63
64# f_dialog_menu_media_ftp
65#
66# Prompt the user to select from a range of ``built-in'' FTP servers or specify
67# their own. If the user makes a choice and doesn't cancel or press Esc, stores
68# the user's choice in VAR_FTP_PATH (see variables.subr) and returns success.
69#
70f_dialog_menu_media_ftp()
71{
72 f_dialog_title "$msg_please_select_a_freebsd_ftp_distribution_site"
73 local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
74 f_dialog_title_restore
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/struct.subr
35f_include $BSDCFG_SHARE/device.subr
36f_include $BSDCFG_SHARE/dialog.subr
37f_include $BSDCFG_SHARE/strings.subr
38f_include $BSDCFG_SHARE/variable.subr
39f_include $BSDCFG_SHARE/media/common.subr
40f_include $BSDCFG_SHARE/media/tcpip.subr
41f_include $BSDCFG_SHARE/media/network.subr
42
43BSDCFG_LIBE="/usr/libexec/bsdconfig"
44f_include_lang $BSDCFG_LIBE/include/messages.subr
45
46############################################################ GLOBALS
47
48FTP_SKIP_RESOLV=
49
50URL_MAX=261261 # according to actual fetch(1) test-results
51
52FTP_DIRS="
53 .
54 releases/$UNAME_P
55 snapshots/$UNAME_P
56 pub/FreeBSD
57 pub/FreeBSD/releases/$UNAME_P
58 pub/FreeBSD/snapshots/$UNAME_P
59 pub/FreeBSD-Archive/old-releases/$UNAME_P
60" # END-QUOTE
61
62############################################################ FUNCTIONS
63
64# f_dialog_menu_media_ftp
65#
66# Prompt the user to select from a range of ``built-in'' FTP servers or specify
67# their own. If the user makes a choice and doesn't cancel or press Esc, stores
68# the user's choice in VAR_FTP_PATH (see variables.subr) and returns success.
69#
70f_dialog_menu_media_ftp()
71{
72 f_dialog_title "$msg_please_select_a_freebsd_ftp_distribution_site"
73 local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
74 f_dialog_title_restore
75
76 local prompt="$msg_please_select_the_site_closest_to_you_or_other"
75 local prompt="$msg_please_select_the_site_closest_to_you_or_other"
77 local hline="$msg_select_a_site_thats_close"
78 local menu_list="
79 '$msg_main_site' 'ftp.freebsd.org'
80 'URL' '$msg_specify_some_other_ftp_site'
81 '$msg_snapshots_server_japan'
82 'snapshots.jp.freebsd.org'
83 '$msg_snapshots_server_sweden'
84 'snapshots.se.freebsd.org'
85 'IPv6 $msg_main_site' 'ftp.freebsd.org'
86 ' IPv6 $msg_ireland' 'ftp3.ie.freebsd.org'
87 ' IPv6 $msg_israel' 'ftp.il.freebsd.org'
88 ' IPv6 $msg_japan' 'ftp2.jp.freebsd.org'
89 ' IPv6 $msg_usa' 'ftp4.us.freebsd.org'
90 ' IPv6 $msg_turkey' 'ftp2.tr.freebsd.org'
91 '$msg_primary' 'ftp1.freebsd.org'
92 ' $msg_primary #2' 'ftp2.freebsd.org'
93 ' $msg_primary #3' 'ftp3.freebsd.org'
94 ' $msg_primary #4' 'ftp4.freebsd.org'
95 ' $msg_primary #5' 'ftp5.freebsd.org'
96 ' $msg_primary #6' 'ftp6.freebsd.org'
97 ' $msg_primary #7' 'ftp7.freebsd.org'
98 ' $msg_primary #8' 'ftp8.freebsd.org'
99 ' $msg_primary #9' 'ftp9.freebsd.org'
100 ' $msg_primary #10' 'ftp10.freebsd.org'
101 ' $msg_primary #11' 'ftp11.freebsd.org'
102 ' $msg_primary #12' 'ftp12.freebsd.org'
103 ' $msg_primary #13' 'ftp13.freebsd.org'
104 ' $msg_primary #14' 'ftp14.freebsd.org'
105 '$msg_argentina' 'ftp.ar.freebsd.org'
106 '$msg_australia' 'ftp.au.freebsd.org'
107 ' $msg_australia #2' 'ftp2.au.freebsd.org'
108 ' $msg_australia #3' 'ftp3.au.freebsd.org'
109 '$msg_austria' 'ftp.at.freebsd.org'
110 ' $msg_austria #2' 'ftp2.at.freebsd.org'
111 '$msg_brazil' 'ftp.br.freebsd.org'
112 ' $msg_brazil #2' 'ftp2.br.freebsd.org'
113 ' $msg_brazil #3' 'ftp3.br.freebsd.org'
114 ' $msg_brazil #4' 'ftp4.br.freebsd.org'
115 ' $msg_brazil #5' 'ftp5.br.freebsd.org'
116 ' $msg_brazil #6' 'ftp6.br.freebsd.org'
117 ' $msg_brazil #7' 'ftp7.br.freebsd.org'
118 '$msg_canada' 'ftp.ca.freebsd.org'
119 '$msg_china' 'ftp.cn.freebsd.org'
120 ' $msg_china #2' 'ftp2.cn.freebsd.org'
121 '$msg_croatia' 'ftp.hr.freebsd.org'
122 '$msg_czech_republic' 'ftp.cz.freebsd.org'
123 '$msg_denmark' 'ftp.dk.freebsd.org'
124 ' $msg_denmark #2' 'ftp2.dk.freebsd.org'
125 '$msg_estonia' 'ftp.ee.freebsd.org'
126 '$msg_finland' 'ftp.fi.freebsd.org'
127 '$msg_france' 'ftp.fr.freebsd.org'
128 ' $msg_france #2' 'ftp2.fr.freebsd.org'
129 ' $msg_france #3' 'ftp3.fr.freebsd.org'
130 ' $msg_france #5' 'ftp5.fr.freebsd.org'
131 ' $msg_france #6' 'ftp6.fr.freebsd.org'
132 ' $msg_france #8' 'ftp8.fr.freebsd.org'
133 '$msg_germany' 'ftp.de.freebsd.org'
134 ' $msg_germany #2' 'ftp2.de.freebsd.org'
135 ' $msg_germany #3' 'ftp3.de.freebsd.org'
136 ' $msg_germany #4' 'ftp4.de.freebsd.org'
137 ' $msg_germany #5' 'ftp5.de.freebsd.org'
138 ' $msg_germany #6' 'ftp6.de.freebsd.org'
139 ' $msg_germany #7' 'ftp7.de.freebsd.org'
140 ' $msg_germany #8' 'ftp8.de.freebsd.org'
141 '$msg_greece' 'ftp.gr.freebsd.org'
142 ' $msg_greece #2' 'ftp2.gr.freebsd.org'
143 '$msg_hungary' 'ftp.hu.freebsd.org'
144 '$msg_iceland' 'ftp.is.freebsd.org'
145 '$msg_ireland' 'ftp.ie.freebsd.org'
146 ' $msg_ireland #2' 'ftp2.ie.freebsd.org'
147 ' $msg_ireland #3' 'ftp3.ie.freebsd.org'
148 '$msg_israel' 'ftp.il.freebsd.org'
149 '$msg_italy' 'ftp.it.freebsd.org'
150 '$msg_japan' 'ftp.jp.freebsd.org'
151 ' $msg_japan #2' 'ftp2.jp.freebsd.org'
152 ' $msg_japan #3' 'ftp3.jp.freebsd.org'
153 ' $msg_japan #4' 'ftp4.jp.freebsd.org'
154 ' $msg_japan #5' 'ftp5.jp.freebsd.org'
155 ' $msg_japan #6' 'ftp6.jp.freebsd.org'
156 ' $msg_japan #7' 'ftp7.jp.freebsd.org'
157 ' $msg_japan #8' 'ftp8.jp.freebsd.org'
158 ' $msg_japan #9' 'ftp9.jp.freebsd.org'
159 '$msg_korea' 'ftp.kr.freebsd.org'
160 ' $msg_korea #2' 'ftp2.kr.freebsd.org'
161 '$msg_lithuania' 'ftp.lt.freebsd.org'
162 '$msg_netherlands' 'ftp.nl.freebsd.org'
163 ' $msg_netherlands #2' 'ftp2.nl.freebsd.org'
164 '$msg_norway' 'ftp.no.freebsd.org'
165 ' $msg_norway #3' 'ftp3.no.freebsd.org'
166 '$msg_poland' 'ftp.pl.freebsd.org'
167 ' $msg_poland #2' 'ftp2.pl.freebsd.org'
168 ' $msg_poland #5' 'ftp5.pl.freebsd.org'
169 '$msg_portugal' 'ftp.pt.freebsd.org'
170 ' $msg_portugal #2' 'ftp2.pt.freebsd.org'
171 ' $msg_portugal #4' 'ftp4.pt.freebsd.org'
172 '$msg_romania' 'ftp.ro.freebsd.org'
173 '$msg_russia' 'ftp.ru.freebsd.org'
174 ' $msg_russia #2' 'ftp2.ru.freebsd.org'
175 ' $msg_russia #3' 'ftp3.ru.freebsd.org'
176 ' $msg_russia #4' 'ftp4.ru.freebsd.org'
177 '$msg_singapore' 'ftp.sg.freebsd.org'
178 '$msg_slovak_republic' 'ftp.sk.freebsd.org'
179 '$msg_slovenia' 'ftp.si.freebsd.org'
180 ' $msg_slovenia #2' 'ftp2.si.freebsd.org'
181 '$msg_south_africa' 'ftp.za.freebsd.org'
182 ' $msg_south_africa #2' 'ftp2.za.freebsd.org'
183 ' $msg_south_africa #3' 'ftp3.za.freebsd.org'
184 ' $msg_south_africa #4' 'ftp4.za.freebsd.org'
185 '$msg_spain' 'ftp.es.freebsd.org'
186 ' $msg_spain #2' 'ftp2.es.freebsd.org'
187 ' $msg_spain #3' 'ftp3.es.freebsd.org'
188 '$msg_sweden' 'ftp.se.freebsd.org'
189 ' $msg_sweden #2' 'ftp2.se.freebsd.org'
190 ' $msg_sweden #3' 'ftp3.se.freebsd.org'
191 ' $msg_sweden #4' 'ftp4.se.freebsd.org'
192 ' $msg_sweden #5' 'ftp5.se.freebsd.org'
193 '$msg_switzerland' 'ftp.ch.freebsd.org'
194 ' $msg_switzerland #2' 'ftp2.ch.freebsd.org'
195 '$msg_taiwan' 'ftp.tw.freebsd.org'
196 ' $msg_taiwan #2' 'ftp2.tw.freebsd.org'
197 ' $msg_taiwan #3' 'ftp3.tw.freebsd.org'
198 ' $msg_taiwan #4' 'ftp4.tw.freebsd.org'
199 ' $msg_taiwan #6' 'ftp6.tw.freebsd.org'
200 ' $msg_taiwan #11' 'ftp11.tw.freebsd.org'
201 '$msg_turkey' 'ftp.tr.freebsd.org'
202 ' $msg_turkey #2' 'ftp2.tr.freebsd.org'
203 '$msg_uk' 'ftp.uk.freebsd.org'
204 ' $msg_uk #2' 'ftp2.uk.freebsd.org'
205 ' $msg_uk #3' 'ftp3.uk.freebsd.org'
206 ' $msg_uk #4' 'ftp4.uk.freebsd.org'
207 ' $msg_uk #5' 'ftp5.uk.freebsd.org'
208 ' $msg_uk #6' 'ftp6.uk.freebsd.org'
209 '$msg_ukraine' 'ftp.ua.freebsd.org'
210 ' $msg_ukraine #2' 'ftp2.ua.freebsd.org'
211 ' $msg_ukraine #5' 'ftp5.ua.freebsd.org'
212 ' $msg_ukraine #6' 'ftp6.ua.freebsd.org'
213 ' $msg_ukraine #7' 'ftp7.ua.freebsd.org'
214 ' $msg_ukraine #8' 'ftp8.ua.freebsd.org'
215 '$msg_usa #1' 'ftp1.us.freebsd.org'
216 ' $msg_usa #2' 'ftp2.us.freebsd.org'
217 ' $msg_usa #3' 'ftp3.us.freebsd.org'
218 ' $msg_usa #4' 'ftp4.us.freebsd.org'
219 ' $msg_usa #5' 'ftp5.us.freebsd.org'
220 ' $msg_usa #6' 'ftp6.us.freebsd.org'
221 ' $msg_usa #7' 'ftp7.us.freebsd.org'
222 ' $msg_usa #8' 'ftp8.us.freebsd.org'
223 ' $msg_usa #9' 'ftp9.us.freebsd.org'
224 ' $msg_usa #10' 'ftp10.us.freebsd.org'
225 ' $msg_usa #11' 'ftp11.us.freebsd.org'
226 ' $msg_usa #12' 'ftp12.us.freebsd.org'
227 ' $msg_usa #13' 'ftp13.us.freebsd.org'
228 ' $msg_usa #14' 'ftp14.us.freebsd.org'
229 ' $msg_usa #15' 'ftp15.us.freebsd.org'
230 " # END-QUOTE
76 local menu_list="
77 '$msg_main_site' 'ftp.freebsd.org'
78 'URL' '$msg_specify_some_other_ftp_site'
79 '$msg_snapshots_server_japan'
80 'snapshots.jp.freebsd.org'
81 '$msg_snapshots_server_sweden'
82 'snapshots.se.freebsd.org'
83 'IPv6 $msg_main_site' 'ftp.freebsd.org'
84 ' IPv6 $msg_ireland' 'ftp3.ie.freebsd.org'
85 ' IPv6 $msg_israel' 'ftp.il.freebsd.org'
86 ' IPv6 $msg_japan' 'ftp2.jp.freebsd.org'
87 ' IPv6 $msg_usa' 'ftp4.us.freebsd.org'
88 ' IPv6 $msg_turkey' 'ftp2.tr.freebsd.org'
89 '$msg_primary' 'ftp1.freebsd.org'
90 ' $msg_primary #2' 'ftp2.freebsd.org'
91 ' $msg_primary #3' 'ftp3.freebsd.org'
92 ' $msg_primary #4' 'ftp4.freebsd.org'
93 ' $msg_primary #5' 'ftp5.freebsd.org'
94 ' $msg_primary #6' 'ftp6.freebsd.org'
95 ' $msg_primary #7' 'ftp7.freebsd.org'
96 ' $msg_primary #8' 'ftp8.freebsd.org'
97 ' $msg_primary #9' 'ftp9.freebsd.org'
98 ' $msg_primary #10' 'ftp10.freebsd.org'
99 ' $msg_primary #11' 'ftp11.freebsd.org'
100 ' $msg_primary #12' 'ftp12.freebsd.org'
101 ' $msg_primary #13' 'ftp13.freebsd.org'
102 ' $msg_primary #14' 'ftp14.freebsd.org'
103 '$msg_argentina' 'ftp.ar.freebsd.org'
104 '$msg_australia' 'ftp.au.freebsd.org'
105 ' $msg_australia #2' 'ftp2.au.freebsd.org'
106 ' $msg_australia #3' 'ftp3.au.freebsd.org'
107 '$msg_austria' 'ftp.at.freebsd.org'
108 ' $msg_austria #2' 'ftp2.at.freebsd.org'
109 '$msg_brazil' 'ftp.br.freebsd.org'
110 ' $msg_brazil #2' 'ftp2.br.freebsd.org'
111 ' $msg_brazil #3' 'ftp3.br.freebsd.org'
112 ' $msg_brazil #4' 'ftp4.br.freebsd.org'
113 ' $msg_brazil #5' 'ftp5.br.freebsd.org'
114 ' $msg_brazil #6' 'ftp6.br.freebsd.org'
115 ' $msg_brazil #7' 'ftp7.br.freebsd.org'
116 '$msg_canada' 'ftp.ca.freebsd.org'
117 '$msg_china' 'ftp.cn.freebsd.org'
118 ' $msg_china #2' 'ftp2.cn.freebsd.org'
119 '$msg_croatia' 'ftp.hr.freebsd.org'
120 '$msg_czech_republic' 'ftp.cz.freebsd.org'
121 '$msg_denmark' 'ftp.dk.freebsd.org'
122 ' $msg_denmark #2' 'ftp2.dk.freebsd.org'
123 '$msg_estonia' 'ftp.ee.freebsd.org'
124 '$msg_finland' 'ftp.fi.freebsd.org'
125 '$msg_france' 'ftp.fr.freebsd.org'
126 ' $msg_france #2' 'ftp2.fr.freebsd.org'
127 ' $msg_france #3' 'ftp3.fr.freebsd.org'
128 ' $msg_france #5' 'ftp5.fr.freebsd.org'
129 ' $msg_france #6' 'ftp6.fr.freebsd.org'
130 ' $msg_france #8' 'ftp8.fr.freebsd.org'
131 '$msg_germany' 'ftp.de.freebsd.org'
132 ' $msg_germany #2' 'ftp2.de.freebsd.org'
133 ' $msg_germany #3' 'ftp3.de.freebsd.org'
134 ' $msg_germany #4' 'ftp4.de.freebsd.org'
135 ' $msg_germany #5' 'ftp5.de.freebsd.org'
136 ' $msg_germany #6' 'ftp6.de.freebsd.org'
137 ' $msg_germany #7' 'ftp7.de.freebsd.org'
138 ' $msg_germany #8' 'ftp8.de.freebsd.org'
139 '$msg_greece' 'ftp.gr.freebsd.org'
140 ' $msg_greece #2' 'ftp2.gr.freebsd.org'
141 '$msg_hungary' 'ftp.hu.freebsd.org'
142 '$msg_iceland' 'ftp.is.freebsd.org'
143 '$msg_ireland' 'ftp.ie.freebsd.org'
144 ' $msg_ireland #2' 'ftp2.ie.freebsd.org'
145 ' $msg_ireland #3' 'ftp3.ie.freebsd.org'
146 '$msg_israel' 'ftp.il.freebsd.org'
147 '$msg_italy' 'ftp.it.freebsd.org'
148 '$msg_japan' 'ftp.jp.freebsd.org'
149 ' $msg_japan #2' 'ftp2.jp.freebsd.org'
150 ' $msg_japan #3' 'ftp3.jp.freebsd.org'
151 ' $msg_japan #4' 'ftp4.jp.freebsd.org'
152 ' $msg_japan #5' 'ftp5.jp.freebsd.org'
153 ' $msg_japan #6' 'ftp6.jp.freebsd.org'
154 ' $msg_japan #7' 'ftp7.jp.freebsd.org'
155 ' $msg_japan #8' 'ftp8.jp.freebsd.org'
156 ' $msg_japan #9' 'ftp9.jp.freebsd.org'
157 '$msg_korea' 'ftp.kr.freebsd.org'
158 ' $msg_korea #2' 'ftp2.kr.freebsd.org'
159 '$msg_lithuania' 'ftp.lt.freebsd.org'
160 '$msg_netherlands' 'ftp.nl.freebsd.org'
161 ' $msg_netherlands #2' 'ftp2.nl.freebsd.org'
162 '$msg_norway' 'ftp.no.freebsd.org'
163 ' $msg_norway #3' 'ftp3.no.freebsd.org'
164 '$msg_poland' 'ftp.pl.freebsd.org'
165 ' $msg_poland #2' 'ftp2.pl.freebsd.org'
166 ' $msg_poland #5' 'ftp5.pl.freebsd.org'
167 '$msg_portugal' 'ftp.pt.freebsd.org'
168 ' $msg_portugal #2' 'ftp2.pt.freebsd.org'
169 ' $msg_portugal #4' 'ftp4.pt.freebsd.org'
170 '$msg_romania' 'ftp.ro.freebsd.org'
171 '$msg_russia' 'ftp.ru.freebsd.org'
172 ' $msg_russia #2' 'ftp2.ru.freebsd.org'
173 ' $msg_russia #3' 'ftp3.ru.freebsd.org'
174 ' $msg_russia #4' 'ftp4.ru.freebsd.org'
175 '$msg_singapore' 'ftp.sg.freebsd.org'
176 '$msg_slovak_republic' 'ftp.sk.freebsd.org'
177 '$msg_slovenia' 'ftp.si.freebsd.org'
178 ' $msg_slovenia #2' 'ftp2.si.freebsd.org'
179 '$msg_south_africa' 'ftp.za.freebsd.org'
180 ' $msg_south_africa #2' 'ftp2.za.freebsd.org'
181 ' $msg_south_africa #3' 'ftp3.za.freebsd.org'
182 ' $msg_south_africa #4' 'ftp4.za.freebsd.org'
183 '$msg_spain' 'ftp.es.freebsd.org'
184 ' $msg_spain #2' 'ftp2.es.freebsd.org'
185 ' $msg_spain #3' 'ftp3.es.freebsd.org'
186 '$msg_sweden' 'ftp.se.freebsd.org'
187 ' $msg_sweden #2' 'ftp2.se.freebsd.org'
188 ' $msg_sweden #3' 'ftp3.se.freebsd.org'
189 ' $msg_sweden #4' 'ftp4.se.freebsd.org'
190 ' $msg_sweden #5' 'ftp5.se.freebsd.org'
191 '$msg_switzerland' 'ftp.ch.freebsd.org'
192 ' $msg_switzerland #2' 'ftp2.ch.freebsd.org'
193 '$msg_taiwan' 'ftp.tw.freebsd.org'
194 ' $msg_taiwan #2' 'ftp2.tw.freebsd.org'
195 ' $msg_taiwan #3' 'ftp3.tw.freebsd.org'
196 ' $msg_taiwan #4' 'ftp4.tw.freebsd.org'
197 ' $msg_taiwan #6' 'ftp6.tw.freebsd.org'
198 ' $msg_taiwan #11' 'ftp11.tw.freebsd.org'
199 '$msg_turkey' 'ftp.tr.freebsd.org'
200 ' $msg_turkey #2' 'ftp2.tr.freebsd.org'
201 '$msg_uk' 'ftp.uk.freebsd.org'
202 ' $msg_uk #2' 'ftp2.uk.freebsd.org'
203 ' $msg_uk #3' 'ftp3.uk.freebsd.org'
204 ' $msg_uk #4' 'ftp4.uk.freebsd.org'
205 ' $msg_uk #5' 'ftp5.uk.freebsd.org'
206 ' $msg_uk #6' 'ftp6.uk.freebsd.org'
207 '$msg_ukraine' 'ftp.ua.freebsd.org'
208 ' $msg_ukraine #2' 'ftp2.ua.freebsd.org'
209 ' $msg_ukraine #5' 'ftp5.ua.freebsd.org'
210 ' $msg_ukraine #6' 'ftp6.ua.freebsd.org'
211 ' $msg_ukraine #7' 'ftp7.ua.freebsd.org'
212 ' $msg_ukraine #8' 'ftp8.ua.freebsd.org'
213 '$msg_usa #1' 'ftp1.us.freebsd.org'
214 ' $msg_usa #2' 'ftp2.us.freebsd.org'
215 ' $msg_usa #3' 'ftp3.us.freebsd.org'
216 ' $msg_usa #4' 'ftp4.us.freebsd.org'
217 ' $msg_usa #5' 'ftp5.us.freebsd.org'
218 ' $msg_usa #6' 'ftp6.us.freebsd.org'
219 ' $msg_usa #7' 'ftp7.us.freebsd.org'
220 ' $msg_usa #8' 'ftp8.us.freebsd.org'
221 ' $msg_usa #9' 'ftp9.us.freebsd.org'
222 ' $msg_usa #10' 'ftp10.us.freebsd.org'
223 ' $msg_usa #11' 'ftp11.us.freebsd.org'
224 ' $msg_usa #12' 'ftp12.us.freebsd.org'
225 ' $msg_usa #13' 'ftp13.us.freebsd.org'
226 ' $msg_usa #14' 'ftp14.us.freebsd.org'
227 ' $msg_usa #15' 'ftp15.us.freebsd.org'
228 " # END-QUOTE
229 local hline="$msg_select_a_site_thats_close"
231
232 local height width rows
233 eval f_dialog_menu_size height width rows \
234 \"\$title\" \
235 \"\$btitle\" \
236 \"\$prompt\" \
237 \"\$hline\" \
238 $menu_list
239
240 local mtag
241 mtag=$( eval $DIALOG \
242 --title \"\$title\" \
243 --backtitle \"\$btitle\" \
244 --hline \"\$hline\" \
245 --ok-label \"\$msg_ok\" \
246 --cancel-label \"\$msg_cancel\" \
247 --menu \"\$prompt\" \
248 $height $width $rows \
249 $menu_list \
250 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
251 ) || return $FAILURE
252 f_dialog_data_sanitize mtag
253
254 case "$mtag" in
255 URL) setvar $VAR_FTP_PATH "other" ;;
256 *)
257 local value
258 value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list )
259 setvar $VAR_FTP_PATH "ftp://$value"
260 esac
261
262 return $SUCCESS
263}
264
265# f_media_set_ftp
266#
267# Return success if we both found and set the media type to be an FTP server.
268# Variables from variable.subr that can be used to script user input:
269#
270# VAR_FTP_PATH
271# Can be a URL (including "ftp://" protocol-prefix) or "other"
272# (user is prompted to enter FTP URL). If a URL, can optionally
273# contain directory prefix after hostname/port. Valid examples
274# include:
275# ftp://myhost
276# ftp://somename:21/pub/
277# ftp://192.168.2.3/pub/
278# ftp://[::1]:21/
279# The default port if not specified is 21.
280# VAR_NAMESERVER [Optional]
281# If set, overrides resolv.conf(5) and sets the nameserver that
282# is used to convert names into addresses (when a name converts
283# into multiple addresses, the first address to successfully
284# connect is used).
285#
286# Meanwhile, the following variables from variable.subr are set after
287# successful execution:
288#
289# VAR_FTP_HOST
290# The FTP host to connect to, parsed from VAR_FTP_PATH. In the
291# example case of IPv6 where VAR_FTP_PATH is a "ftp://[::1]" this
292# variable will be set to "::1" (the outer brackets are removed).
293# VAR_FTP_PORT
294# The TCP port to connect to, parsed from VAR_FTP_PATH. Usually
295# 21 unless VAR_FTP_PATH was of one of the following forms:
296# ftp://hostname:OTHER_PORT
297# ftp://hostname:OTHER_PORT/*
298# ftp://ip:OTHER_PORT
299# ftp://ip:OTHER_PORT/*
300# ftp://[ip6]:OTHER_PORT
301# ftp://[ip6]:OTHER_PORT/*
302# VAR_FTP_DIR
303# If VAR_FTP_PATH contained a directory element (e.g.,
304# "ftp://localhost/pub") this variable contains only the
305# directory element (e.g., "/pub").
306#
307f_media_set_ftp()
308{
309 f_media_close
310
311 local url
312 f_getvar $VAR_FTP_PATH url
313
314 # If we've been through here before ...
315 if f_struct device_network && [ "${url#$msg_other}" ]; then
316 f_dialog_yesno "$msg_reuse_old_ftp_site_selection_values" ||
317 url=
318 fi
319
320 if [ ! "$url" ]; then
321 f_dialog_menu_media_ftp || return $FAILURE
322 f_getvar $VAR_FTP_PATH url
323 fi
324 [ "$url" ] || return $FAILURE
325
326 case "$url" in
327 other)
328 setvar $VAR_FTP_PATH "ftp://"
329 f_variable_get_value $VAR_FTP_PATH \
330 "$msg_please_specify_url_of_a_freebsd_distribution"
331 f_getvar $VAR_FTP_PATH url
332 if [ ! "${url#ftp://}" ]; then
333 unset $VAR_FTP_PATH
334 return $FAILURE
335 fi
336 if [ ${#url} -gt ${URL_MAX:-261261} ]; then
337 f_show_msg "$msg_length_of_specified_url_is_too_long" \
338 ${#url} ${URL_MAX:-261261}
339 unset $VAR_FTP_PATH
340 return $FAILURE
341 fi
342 case "$url" in
343 ftp://*) : valid URL ;;
344 *)
345 f_show_msg "$msg_sorry_invalid_url" "$url"
346 unset $VAR_FTP_PATH
347 return $FAILURE
348 esac
349 esac
350 case "$url" in
351 ftp://*) : valid URL ;;
352 *)
353 f_show_msg "$msg_sorry_invalid_url" "$url"
354 unset $VAR_FTP_PATH
355 return $FAILURE
356 esac
357
358 # Set the name of the FTP device to the URL
359 f_struct_new DEVICE device_ftp
360 device_ftp set name "$url"
361
362 if ! f_struct device_network ||
363 ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration"
364 then
365 f_struct device_network &&
366 f_device_shutdown network
367 if ! f_device_select_tcp; then
368 unset $VAR_FTP_PATH
369 return $FAILURE
370 fi
371 local dev
372 f_getvar $VAR_NETWORK_DEVICE dev
373 f_struct_copy "device_$dev" device_network
374 fi
375 if ! f_device_init network; then
376 f_dprintf "f_media_set_ftp: %s" "$msg_net_device_init_failed"
377 unset $VAR_FTP_PATH
378 return $FAILURE
379 fi
380
381 local hostname="${url#*://}" port=21 dir=/
382 case "$hostname" in
383 "["*"]")
384 hostname="${hostname#\[}"
385 hostname="${hostname%%\]*}"
386 ;;
387 "["*"]/"*)
388 hostname="${hostname#\[}"
389 dir="/${hostname#*/}"
390 hostname="${hostname%%\]*}"
391 ;;
392 *"/"*)
393 dir="/${hostname#*/}"
394 hostname="${hostname%%/*}"
395 ;;
396 "["*"]:"*)
397 hostname="${hostname#\[}"
398 port="${hostname#*\]:}"
399 port="${port%%[!0-9]*}"
400 hostname="${hostname%%\]:*}"
401 ;;
402 *)
403 hostname="${hostname%%/*}"
404 esac
405
406 f_dprintf "hostname = \`%s'" "$hostname"
407 f_dprintf "dir = \`%s'" "$dir"
408 f_dprintf "port \# = \`%d'" "$port"
409
410 local ns
411 f_getvar $VAR_NAMESERVER ns
412 [ "$ns" ] || f_resolv_conf_nameservers ns
413 if [ "$ns" -a ! "$FTP_SKIP_RESOLV" ] && ! {
414 f_validate_ipaddr "$hostname" ||
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#
448# Wrapper to f_media_set_ftp to access FTP servers actively.
449#
450f_media_set_ftp_active()
451{
452 setvar $VAR_FTP_STATE "active"
453 f_media_set_ftp
454}
455
456# f_media_set_ftp_passive
457#
458# Wrapper to f_media_set_ftp to access FTP servers passively.
459#
460f_media_set_ftp_passive()
461{
462 setvar $VAR_FTP_STATE "passive"
463 f_media_set_ftp
464}
465
466# f_media_set_ftp_userpass
467#
468# Prompt the user to enter/confirm the username/password variables that will
469# be used to communicate with the FTP servers. Returns success if the user does
470# not cancel or press Esc to either username or password.
471#
472# Variables from variable.subr that can be used to script user input:
473#
474# VAR_FTP_USER
475# The username to send via ftp(1) when connecting to an FTP
476# server.
477# VAR_FTP_PASS
478# The password to send with the above username.
479#
480# Does not prompt for confirmation of values if VAR_NONINTERACTIVE is set (see
481# variable.subr for more information).
482#
483f_media_set_ftp_userpass()
484{
485 local user pass
486 f_variable_get_value $VAR_FTP_USER \
487 "$msg_please_enter_the_username_you_wish_to_login_as"
488 f_getvar $VAR_FTP_USER user
489 if [ "$user" ]; then
490 f_variable_get_value $VAR_FTP_PASS \
491 "$msg_please_enter_the_password_for_this_user"
492 f_getvar $VAR_FTP_PASS pass
493 else
494 pass=
495 fi
496 [ "$pass" ] # Return status
497}
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 device_$dev get private netDev || return $SUCCESS # No net == happy net
507 f_device_init $netDev
508}
509
510# f_device_network_down $device
511#
512# Brings down attached network device, if any - takes FTP device as arg.
513#
514f_device_network_down()
515{
516 local dev="$1" netDev
517 device_$dev get private netDev || return $SUCCESS
518 f_device_shutdown $netDev
519}
520
521# f_media_init_ftp $device
522#
523# Initializes the FTP media device. Returns success if both able to log into
524# the FTP server and confirm the existence of at least one known release path
525# using ftp(1).
526#
527# Variables from variable.subr used to initialize the connection are as follows
528# (all of which are configured by f_media_set_ftp above):
529#
530# VAR_FTP_PATH
531# The unparsed FTP URL representing the server to contact.
532# Usually "ftp://server" for example. Can contain TCP port number
533# and/or directory path (but should not contain username/password
534# info).
535# VAR_FTP_HOST
536# The FTP host to connect to. Can be an IPv4 address (e.g.,
537# 127.0.0.1), IPv6 address (e.g., ::1), or DNS hostname. Usually
538# set automatically in f_media_set_ftp() by parsing VAR_FTP_PATH.
539# VAR_FTP_PORT
540# The TCP port to connect to. Usually set automatically in
541# f_media_set_ftp() by parsing VAR_FTP_PATH.
542# VAR_FTP_DIR
543# The base FTP directory to use when downloading files from the
544# FTP server. Usually set automatically in f_media_set_ftp() by
545# parsing VAR_FTP_PATH.
546# VAR_FTP_USER [Optional]
547# If unset, defaults to using anonymous access.
548# VAR_FTP_PASS [Optional]
549# If unset, defaults to a sensible value.
550#
551# In addition, the following (managed either manually or by f_media_set_ftp_*):
552#
553# VAR_FTP_STATE
554# Sets FTPMODE for ftp(1) and can be one of:
555# active active mode FTP only
556# auto automatic determination of passive or active
557# (this is the default)
558# gate gate-ftp mode
559# passive passive mode FTP only
560# See ftp(1) for additional information.
561#
562# And last, but not least (managed automatically or manually):
563#
564# VAR_RELNAME
565# Defaults to being set to $(uname -r) but can be overridden.
566# This sets the name of a release to look for as part of a well
567# known set of paths to search for release data once connected
568# via FTP. If set to "__RELEASE" or "any" then the VAR_FTP_DIR is
569# taken as the absolute path to the release and no further
570# searching is done (see FTP_DIRS above in the GLOBALS section
571# for a list of well known paths that are used when searching for
572# a VAR_RELNAME sub-directory).
573#
574f_media_init_ftp()
575{
576 local dev="$1"
577
578 local url
579 device_$dev get name url
580 f_dprintf "Init routine called for FTP device. url=[%s]" "$url"
581
582 if [ "$FTP_INITIALIZED" ]; then
583 f_dprintf "FTP device already initialized."
584 return $SUCCESS
585 fi
586
587 # If we can't initialize the network, bag it!
588 f_device_network_up $dev || return $FAILURE
589
590 local cp
591 while :; do
592 f_getvar $VAR_FTP_PATH cp
593 if [ ! "$cp" ]; then
594 if ! f_media_set_ftp ||
595 ! f_getvar $VAR_FTP_PATH cp ||
596 [ ! "$cp" ]
597 then
598 f_dialog_msgbox \
599 "$msg_unable_to_get_proper_ftp_path"
600 f_device_network_down $dev
601 return $FAILURE
602 fi
603 fi
604
605 local ftp_host ftp_dir
606 if ! {
607 f_getvar $VAR_FTP_HOST ftp_host &&
608 f_getvar $VAR_FTP_DIR ftp_dir
609 }; then
610 f_dialog_msgbox "$msg_missing_ftp_host_or_directory"
611 f_device_network_down $dev
612 return $FAILURE
613 fi
614
615 local ftp_port
616 f_getvar $VAR_FTP_PORT ftp_port
617 local host="$ftp_host" port="${ftp_port:+:$ftp_port}"
618 case "$host" in *:*) host="[$host]"; esac
619
620 local user pass use_anon=
621 f_getvar $VAR_FTP_USER user
622 if [ ! "$user" ]; then
623 user="anonymous"
624 use_anon=1
625 fi
626 if ! f_getvar $VAR_FTP_PASS pass; then
627 f_getvar $VAR_HOSTNAME cp
628 if f_running_as_init; then
629 pass="installer@$cp"
630 else
631 local name="$( id -un 2> /dev/null )"
632 pass="${name:-ftp}@$cp"
633 fi
634 fi
635
636 f_show_info "$msg_logging_in_to_user_at_host" \
637 "$user" "$ftp_host"
638
639 local userpass=""
640 if [ ! "$use_anon" ] && [ "$user" -o "$pass" ]; then
641 userpass="$user${pass:+:$( f_uriencode "$pass" )}"
642 userpass="$userpass${userpass:+@}"
643 fi
644
645 local mode rx
646 f_getvar $VAR_FTP_STATE mode
647
648 if [ "$ftp_dir" ]; then
649 if ! rx=$(
650 printf 'cd "%s"\npwd\n' "$ftp_dir" | eval \
651 FTPMODE=\"\$mode\" \
652 ${use_anon:+FTPANONPASS=\"\$pass\"} \
653 ftp -V ${use_anon:+-a} \
654 \"ftp://\$userpass\$host\$port\" \
655 2>&1
656 ); then
657 f_show_msg "$msg_couldnt_open_ftp_connection" \
658 "$ftp_host" "$rx"
659 break # to failure
660 fi
661 if echo "$rx" | awk -v dir="/${ftp_dir#/}" '
662 BEGIN { found = 0 }
663 /^Remote directory: / {
664 sub(/^[^:]*:[[:space:]]*/, "")
665 if ($0 != dir) next
666 found = 1; exit
667 }
668 END { exit ! found }
669 '; then
670 setvar $VAR_FTP_DIR "$ftp_dir"
671 setvar $VAR_FTP_PATH \
672 "ftp://$ftp_host/${ftp_dir#/}"
673 else
674 f_show_msg \
675 "$msg_please_check_the_url_and_try_again" \
676 "ftp://$ftp_host/${ftp_dir#/}"
677 break # to failure
678 fi
679 fi
680
681 #
682 # Now that we've verified that the path we're given is ok,
683 # let's try to be a bit intelligent in locating the release we
684 # are looking for. First off, if the release is specified as
685 # "__RELEASE" or "any", then just assume that the current
686 # directory is the one we want and give up.
687 #
688 local rel
689 f_getvar $VAR_RELNAME rel
690 f_dprintf "f_media_init_ftp: rel=[%s]" "$rel"
691
692 case "$rel" in
693 __RELEASE|any)
694 FTP_INITIALIZED=YES
695 return $SUCCESS
696 ;;
697 *)
698 #
699 # Ok, since we have a release variable, let's walk
700 # through the list of directories looking for a release
701 # directory. First successful CWD wins.
702 #
703 if ! rx=$(
704 for dir in $FTP_DIRS; do
705 # Avoid confusing some servers
706 [ "$dir" = "." ] && continue
707 printf 'cd "/%s/%s"\npwd\n' \
708 "$dir" "$rel"
709 done | eval \
710 FTPMODE=\"\$mode\" \
711 ${use_anon:+FTPANONPASS=\"\$pass\"} \
712 ftp -V ${use_anon:+-a} \
713 \"ftp://\$userpass\$host\$port\" \
714 2>&1
715 ); then
716 f_show_msg "$msg_couldnt_open_ftp_connection" \
717 "$ftp_host" "$rx"
718 break # to failure
719 fi
720
721 local fdir
722 if fdir=$( echo "$rx" | awk '
723 BEGIN { found = 0 }
724 /^Remote directory: / {
725 sub(/^[^:]*:[[:space:]]*/, "")
726 if ($0 == "/") next
727 # Exit after the first dir
728 found++; print; exit
729 }
730 END { exit ! found }
731 ' ); then
732 setvar $VAR_FTP_DIR "$fdir"
733 setvar $VAR_FTP_PATH "ftp://$ftp_host$fdir"
734 FTP_INITIALIZED=YES
735 return $SUCCESS
736 else
737 f_yesno "$msg_cant_find_distribution" \
738 "$rel" "$ftp_host"
739 if [ $? -eq $SUCCESS ]; then
740 unset $VAR_FTP_PATH
741 f_media_set_ftp && continue
742 fi
743 fi
744 esac
745 break # to failure
746 done
747
748 unset FTP_INITIALIZED $VAR_FTP_PATH
749 f_device_network_down $dev
750 return $FAILURE
751}
752
753# f_media_get_ftp $device $file [$probe_only]
754#
755# Returns data from $file on an FTP server using ftp(1). Please note that
756# $device is unused but must be present (even if null). Information is instead
757# gathered from the environment. $probe_only is currently unused by this media
758# type.
759#
760# Variables from variable.subr used to configure the connection are as follows
761# (all of which are configured by f_media_set_ftp above):
762#
763# VAR_FTP_HOST
764# FTP host to connect to. Can be an IPv4 address, IPv6 address,
765# or DNS hostname of your choice.
766# VAR_FTP_PORT
767# TCP port to connect on; see f_media_set_ftp() above.
768# VAR_FTP_USER [Optional]
769# If unset, defaults to using anonymous access.
770# VAR_FTP_PASS [Optional]
771# If unset, defaults to a sensible value.
772#
773# In addition, the following (managed either manually or by f_media_set_ftp_*):
774#
775# VAR_FTP_STATE
776# Sets FTPMODE for ftp(1) and can be one of:
777# active active mode FTP only
778# auto automatic determination of passive or active
779# (this is the default)
780# gate gate-ftp mode
781# passive passive mode FTP only
782# See ftp(1) for additional information.
783#
784# See variable.subr for additional information.
785#
786# Example usage:
787# f_media_set_ftp
788# f_media_get_ftp media $file
789#
790f_media_get_ftp()
791{
792 local dev="$1" file="$2" probe_only="$3"
793
794 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \
795 "$dev" "$file" "$probe_only"
796
797 local ftp_host ftp_port
798 f_getvar $VAR_FTP_HOST ftp_host
799 f_getvar $VAR_FTP_PORT ftp_port
800
801 if [ ! "$FTP_INITIALIZED" ]; then
802 f_dprintf "No FTP connection open, can't get file %s" "$file"
803 return $FAILURE
804 fi
805
806 if ! {
807 f_validate_ipaddr "$ftp_host" ||
808 f_validate_ipaddr6 "$ftp_host" ||
809 {
810 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
811 "f_media_get_ftp" "$ftp_host"
812 f_host_lookup "$ftp_host" hosts
813 }
814 }; then
815 # All the above validations failed
816 [ "$hosts" ] && f_dialog_msgbox "$hosts"
817 return $FAILURE
818 elif [ ! "$hosts" ]; then
819 # One of the first two validations passed
820 hosts="$ftp_host"
821 fi
822
823 local host connected=
824 for host in $hosts; do
825 f_quietly nc -nz "$host" "$ftp_port" || continue
826 connected=1; break
827 done
828 if [ ! "$connected" ]; then
829 f_show_msg "$msg_couldnt_connect_to_ftp_server %s:%s" \
830 "$ftp_host" "$ftp_port"
831 return $FAILURE
832 fi
833
834 local user pass use_anon=
835 f_getvar $VAR_FTP_USER user
836 if [ ! "$user" ]; then
837 user="anonymous"
838 use_anon=1
839 fi
840 if ! f_getvar $VAR_FTP_PASS pass; then
841 f_getvar $VAR_HOSTNAME cp
842 if f_running_as_init; then
843 pass="installer@$cp"
844 else
845 local name="$( id -un 2> /dev/null )"
846 pass="${name:-ftp}@$cp"
847 fi
848 fi
849
850 local userpass=""
851 if [ ! "$use_anon" ] && [ "$user" -o "$pass" ]; then
852 userpass="$user${pass:+:$( f_uriencode "$pass" )}"
853 userpass="$userpass${userpass:+@}"
854 fi
855
856 local ftp_dir mode rx
857 f_getvar $VAR_FTP_DIR ftp_dir
858 f_getvar $VAR_FTP_STATE mode
859
860 local dir="${ftp_dir#/}"
861 local port="${ftp_port:+:$ftp_port}"
862 case "$host" in *:*) host="[$host]"; esac
863
864 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
865
866 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
867 ftp -V ${use_anon:+-a} -o - \
868 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
869 local retval=$?
870
871 [ $retval -eq $SUCCESS ] || f_dprintf "request failed!"
872 return $retval
873}
874
875# f_media_shutdown_ftp $device
876#
877# Shuts down the FTP device. Return status should be ignored. Note that since
878# we don't maintain an open connection to the FTP server there's nothing to do.
879#
880f_media_shutdown_ftp()
881{
882 [ "$FTP_INITIALIZED" ] || return $SUCCESS
883
884 unset FTP_INITIALIZED
885}
886
887############################################################ MAIN
888
889f_dprintf "%s: Successfully loaded." media/ftp.subr
890
891fi # ! $_MEDIA_FTP_SUBR
230
231 local height width rows
232 eval f_dialog_menu_size height width rows \
233 \"\$title\" \
234 \"\$btitle\" \
235 \"\$prompt\" \
236 \"\$hline\" \
237 $menu_list
238
239 local mtag
240 mtag=$( eval $DIALOG \
241 --title \"\$title\" \
242 --backtitle \"\$btitle\" \
243 --hline \"\$hline\" \
244 --ok-label \"\$msg_ok\" \
245 --cancel-label \"\$msg_cancel\" \
246 --menu \"\$prompt\" \
247 $height $width $rows \
248 $menu_list \
249 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
250 ) || return $FAILURE
251 f_dialog_data_sanitize mtag
252
253 case "$mtag" in
254 URL) setvar $VAR_FTP_PATH "other" ;;
255 *)
256 local value
257 value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list )
258 setvar $VAR_FTP_PATH "ftp://$value"
259 esac
260
261 return $SUCCESS
262}
263
264# f_media_set_ftp
265#
266# Return success if we both found and set the media type to be an FTP server.
267# Variables from variable.subr that can be used to script user input:
268#
269# VAR_FTP_PATH
270# Can be a URL (including "ftp://" protocol-prefix) or "other"
271# (user is prompted to enter FTP URL). If a URL, can optionally
272# contain directory prefix after hostname/port. Valid examples
273# include:
274# ftp://myhost
275# ftp://somename:21/pub/
276# ftp://192.168.2.3/pub/
277# ftp://[::1]:21/
278# The default port if not specified is 21.
279# VAR_NAMESERVER [Optional]
280# If set, overrides resolv.conf(5) and sets the nameserver that
281# is used to convert names into addresses (when a name converts
282# into multiple addresses, the first address to successfully
283# connect is used).
284#
285# Meanwhile, the following variables from variable.subr are set after
286# successful execution:
287#
288# VAR_FTP_HOST
289# The FTP host to connect to, parsed from VAR_FTP_PATH. In the
290# example case of IPv6 where VAR_FTP_PATH is a "ftp://[::1]" this
291# variable will be set to "::1" (the outer brackets are removed).
292# VAR_FTP_PORT
293# The TCP port to connect to, parsed from VAR_FTP_PATH. Usually
294# 21 unless VAR_FTP_PATH was of one of the following forms:
295# ftp://hostname:OTHER_PORT
296# ftp://hostname:OTHER_PORT/*
297# ftp://ip:OTHER_PORT
298# ftp://ip:OTHER_PORT/*
299# ftp://[ip6]:OTHER_PORT
300# ftp://[ip6]:OTHER_PORT/*
301# VAR_FTP_DIR
302# If VAR_FTP_PATH contained a directory element (e.g.,
303# "ftp://localhost/pub") this variable contains only the
304# directory element (e.g., "/pub").
305#
306f_media_set_ftp()
307{
308 f_media_close
309
310 local url
311 f_getvar $VAR_FTP_PATH url
312
313 # If we've been through here before ...
314 if f_struct device_network && [ "${url#$msg_other}" ]; then
315 f_dialog_yesno "$msg_reuse_old_ftp_site_selection_values" ||
316 url=
317 fi
318
319 if [ ! "$url" ]; then
320 f_dialog_menu_media_ftp || return $FAILURE
321 f_getvar $VAR_FTP_PATH url
322 fi
323 [ "$url" ] || return $FAILURE
324
325 case "$url" in
326 other)
327 setvar $VAR_FTP_PATH "ftp://"
328 f_variable_get_value $VAR_FTP_PATH \
329 "$msg_please_specify_url_of_a_freebsd_distribution"
330 f_getvar $VAR_FTP_PATH url
331 if [ ! "${url#ftp://}" ]; then
332 unset $VAR_FTP_PATH
333 return $FAILURE
334 fi
335 if [ ${#url} -gt ${URL_MAX:-261261} ]; then
336 f_show_msg "$msg_length_of_specified_url_is_too_long" \
337 ${#url} ${URL_MAX:-261261}
338 unset $VAR_FTP_PATH
339 return $FAILURE
340 fi
341 case "$url" in
342 ftp://*) : valid URL ;;
343 *)
344 f_show_msg "$msg_sorry_invalid_url" "$url"
345 unset $VAR_FTP_PATH
346 return $FAILURE
347 esac
348 esac
349 case "$url" in
350 ftp://*) : valid URL ;;
351 *)
352 f_show_msg "$msg_sorry_invalid_url" "$url"
353 unset $VAR_FTP_PATH
354 return $FAILURE
355 esac
356
357 # Set the name of the FTP device to the URL
358 f_struct_new DEVICE device_ftp
359 device_ftp set name "$url"
360
361 if ! f_struct device_network ||
362 ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration"
363 then
364 f_struct device_network &&
365 f_device_shutdown network
366 if ! f_device_select_tcp; then
367 unset $VAR_FTP_PATH
368 return $FAILURE
369 fi
370 local dev
371 f_getvar $VAR_NETWORK_DEVICE dev
372 f_struct_copy "device_$dev" device_network
373 fi
374 if ! f_device_init network; then
375 f_dprintf "f_media_set_ftp: %s" "$msg_net_device_init_failed"
376 unset $VAR_FTP_PATH
377 return $FAILURE
378 fi
379
380 local hostname="${url#*://}" port=21 dir=/
381 case "$hostname" in
382 "["*"]")
383 hostname="${hostname#\[}"
384 hostname="${hostname%%\]*}"
385 ;;
386 "["*"]/"*)
387 hostname="${hostname#\[}"
388 dir="/${hostname#*/}"
389 hostname="${hostname%%\]*}"
390 ;;
391 *"/"*)
392 dir="/${hostname#*/}"
393 hostname="${hostname%%/*}"
394 ;;
395 "["*"]:"*)
396 hostname="${hostname#\[}"
397 port="${hostname#*\]:}"
398 port="${port%%[!0-9]*}"
399 hostname="${hostname%%\]:*}"
400 ;;
401 *)
402 hostname="${hostname%%/*}"
403 esac
404
405 f_dprintf "hostname = \`%s'" "$hostname"
406 f_dprintf "dir = \`%s'" "$dir"
407 f_dprintf "port \# = \`%d'" "$port"
408
409 local ns
410 f_getvar $VAR_NAMESERVER ns
411 [ "$ns" ] || f_resolv_conf_nameservers ns
412 if [ "$ns" -a ! "$FTP_SKIP_RESOLV" ] && ! {
413 f_validate_ipaddr "$hostname" ||
414 f_validate_ipaddr6 "$hostname"
415 }; then
416 f_show_info "$msg_looking_up_host" "$hostname"
417 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
418 "f_media_set_ftp" "$hostname"
419 if ! f_quietly f_host_lookup "$hostname"; then
420 f_show_msg "$msg_cannot_resolve_hostname" "$hostname"
421 f_struct device_network &&
422 f_device_shutdown network
423 f_struct_free device_network
424 unset $VAR_FTP_PATH
425 return $FAILURE
426 fi
427 f_dprintf "Found DNS entry for %s successfully." "$hostname"
428 fi
429
430 setvar $VAR_FTP_HOST "$hostname"
431 setvar $VAR_FTP_PORT "$port"
432 setvar $VAR_FTP_DIR "$dir"
433
434 device_ftp set type $DEVICE_TYPE_FTP
435 device_ftp set init f_media_init_ftp
436 device_ftp set get f_media_get_ftp
437 device_ftp set shutdown f_media_shutdown_ftp
438 device_ftp set private network
439 f_struct_copy device_ftp device_media
440 f_struct_free device_ftp
441
442 return $SUCCESS
443}
444
445# f_media_set_ftp_active
446#
447# Wrapper to f_media_set_ftp to access FTP servers actively.
448#
449f_media_set_ftp_active()
450{
451 setvar $VAR_FTP_STATE "active"
452 f_media_set_ftp
453}
454
455# f_media_set_ftp_passive
456#
457# Wrapper to f_media_set_ftp to access FTP servers passively.
458#
459f_media_set_ftp_passive()
460{
461 setvar $VAR_FTP_STATE "passive"
462 f_media_set_ftp
463}
464
465# f_media_set_ftp_userpass
466#
467# Prompt the user to enter/confirm the username/password variables that will
468# be used to communicate with the FTP servers. Returns success if the user does
469# not cancel or press Esc to either username or password.
470#
471# Variables from variable.subr that can be used to script user input:
472#
473# VAR_FTP_USER
474# The username to send via ftp(1) when connecting to an FTP
475# server.
476# VAR_FTP_PASS
477# The password to send with the above username.
478#
479# Does not prompt for confirmation of values if VAR_NONINTERACTIVE is set (see
480# variable.subr for more information).
481#
482f_media_set_ftp_userpass()
483{
484 local user pass
485 f_variable_get_value $VAR_FTP_USER \
486 "$msg_please_enter_the_username_you_wish_to_login_as"
487 f_getvar $VAR_FTP_USER user
488 if [ "$user" ]; then
489 f_variable_get_value $VAR_FTP_PASS \
490 "$msg_please_enter_the_password_for_this_user"
491 f_getvar $VAR_FTP_PASS pass
492 else
493 pass=
494 fi
495 [ "$pass" ] # Return status
496}
497
498# f_device_network_up $device
499#
500# Brings up attached network device, if any - takes FTP device as arg.
501#
502f_device_network_up()
503{
504 local dev="$1" netDev
505 device_$dev get private netDev || return $SUCCESS # No net == happy net
506 f_device_init $netDev
507}
508
509# f_device_network_down $device
510#
511# Brings down attached network device, if any - takes FTP device as arg.
512#
513f_device_network_down()
514{
515 local dev="$1" netDev
516 device_$dev get private netDev || return $SUCCESS
517 f_device_shutdown $netDev
518}
519
520# f_media_init_ftp $device
521#
522# Initializes the FTP media device. Returns success if both able to log into
523# the FTP server and confirm the existence of at least one known release path
524# using ftp(1).
525#
526# Variables from variable.subr used to initialize the connection are as follows
527# (all of which are configured by f_media_set_ftp above):
528#
529# VAR_FTP_PATH
530# The unparsed FTP URL representing the server to contact.
531# Usually "ftp://server" for example. Can contain TCP port number
532# and/or directory path (but should not contain username/password
533# info).
534# VAR_FTP_HOST
535# The FTP host to connect to. Can be an IPv4 address (e.g.,
536# 127.0.0.1), IPv6 address (e.g., ::1), or DNS hostname. Usually
537# set automatically in f_media_set_ftp() by parsing VAR_FTP_PATH.
538# VAR_FTP_PORT
539# The TCP port to connect to. Usually set automatically in
540# f_media_set_ftp() by parsing VAR_FTP_PATH.
541# VAR_FTP_DIR
542# The base FTP directory to use when downloading files from the
543# FTP server. Usually set automatically in f_media_set_ftp() by
544# parsing VAR_FTP_PATH.
545# VAR_FTP_USER [Optional]
546# If unset, defaults to using anonymous access.
547# VAR_FTP_PASS [Optional]
548# If unset, defaults to a sensible value.
549#
550# In addition, the following (managed either manually or by f_media_set_ftp_*):
551#
552# VAR_FTP_STATE
553# Sets FTPMODE for ftp(1) and can be one of:
554# active active mode FTP only
555# auto automatic determination of passive or active
556# (this is the default)
557# gate gate-ftp mode
558# passive passive mode FTP only
559# See ftp(1) for additional information.
560#
561# And last, but not least (managed automatically or manually):
562#
563# VAR_RELNAME
564# Defaults to being set to $(uname -r) but can be overridden.
565# This sets the name of a release to look for as part of a well
566# known set of paths to search for release data once connected
567# via FTP. If set to "__RELEASE" or "any" then the VAR_FTP_DIR is
568# taken as the absolute path to the release and no further
569# searching is done (see FTP_DIRS above in the GLOBALS section
570# for a list of well known paths that are used when searching for
571# a VAR_RELNAME sub-directory).
572#
573f_media_init_ftp()
574{
575 local dev="$1"
576
577 local url
578 device_$dev get name url
579 f_dprintf "Init routine called for FTP device. url=[%s]" "$url"
580
581 if [ "$FTP_INITIALIZED" ]; then
582 f_dprintf "FTP device already initialized."
583 return $SUCCESS
584 fi
585
586 # If we can't initialize the network, bag it!
587 f_device_network_up $dev || return $FAILURE
588
589 local cp
590 while :; do
591 f_getvar $VAR_FTP_PATH cp
592 if [ ! "$cp" ]; then
593 if ! f_media_set_ftp ||
594 ! f_getvar $VAR_FTP_PATH cp ||
595 [ ! "$cp" ]
596 then
597 f_dialog_msgbox \
598 "$msg_unable_to_get_proper_ftp_path"
599 f_device_network_down $dev
600 return $FAILURE
601 fi
602 fi
603
604 local ftp_host ftp_dir
605 if ! {
606 f_getvar $VAR_FTP_HOST ftp_host &&
607 f_getvar $VAR_FTP_DIR ftp_dir
608 }; then
609 f_dialog_msgbox "$msg_missing_ftp_host_or_directory"
610 f_device_network_down $dev
611 return $FAILURE
612 fi
613
614 local ftp_port
615 f_getvar $VAR_FTP_PORT ftp_port
616 local host="$ftp_host" port="${ftp_port:+:$ftp_port}"
617 case "$host" in *:*) host="[$host]"; esac
618
619 local user pass use_anon=
620 f_getvar $VAR_FTP_USER user
621 if [ ! "$user" ]; then
622 user="anonymous"
623 use_anon=1
624 fi
625 if ! f_getvar $VAR_FTP_PASS pass; then
626 f_getvar $VAR_HOSTNAME cp
627 if f_running_as_init; then
628 pass="installer@$cp"
629 else
630 local name="$( id -un 2> /dev/null )"
631 pass="${name:-ftp}@$cp"
632 fi
633 fi
634
635 f_show_info "$msg_logging_in_to_user_at_host" \
636 "$user" "$ftp_host"
637
638 local userpass=""
639 if [ ! "$use_anon" ] && [ "$user" -o "$pass" ]; then
640 userpass="$user${pass:+:$( f_uriencode "$pass" )}"
641 userpass="$userpass${userpass:+@}"
642 fi
643
644 local mode rx
645 f_getvar $VAR_FTP_STATE mode
646
647 if [ "$ftp_dir" ]; then
648 if ! rx=$(
649 printf 'cd "%s"\npwd\n' "$ftp_dir" | eval \
650 FTPMODE=\"\$mode\" \
651 ${use_anon:+FTPANONPASS=\"\$pass\"} \
652 ftp -V ${use_anon:+-a} \
653 \"ftp://\$userpass\$host\$port\" \
654 2>&1
655 ); then
656 f_show_msg "$msg_couldnt_open_ftp_connection" \
657 "$ftp_host" "$rx"
658 break # to failure
659 fi
660 if echo "$rx" | awk -v dir="/${ftp_dir#/}" '
661 BEGIN { found = 0 }
662 /^Remote directory: / {
663 sub(/^[^:]*:[[:space:]]*/, "")
664 if ($0 != dir) next
665 found = 1; exit
666 }
667 END { exit ! found }
668 '; then
669 setvar $VAR_FTP_DIR "$ftp_dir"
670 setvar $VAR_FTP_PATH \
671 "ftp://$ftp_host/${ftp_dir#/}"
672 else
673 f_show_msg \
674 "$msg_please_check_the_url_and_try_again" \
675 "ftp://$ftp_host/${ftp_dir#/}"
676 break # to failure
677 fi
678 fi
679
680 #
681 # Now that we've verified that the path we're given is ok,
682 # let's try to be a bit intelligent in locating the release we
683 # are looking for. First off, if the release is specified as
684 # "__RELEASE" or "any", then just assume that the current
685 # directory is the one we want and give up.
686 #
687 local rel
688 f_getvar $VAR_RELNAME rel
689 f_dprintf "f_media_init_ftp: rel=[%s]" "$rel"
690
691 case "$rel" in
692 __RELEASE|any)
693 FTP_INITIALIZED=YES
694 return $SUCCESS
695 ;;
696 *)
697 #
698 # Ok, since we have a release variable, let's walk
699 # through the list of directories looking for a release
700 # directory. First successful CWD wins.
701 #
702 if ! rx=$(
703 for dir in $FTP_DIRS; do
704 # Avoid confusing some servers
705 [ "$dir" = "." ] && continue
706 printf 'cd "/%s/%s"\npwd\n' \
707 "$dir" "$rel"
708 done | eval \
709 FTPMODE=\"\$mode\" \
710 ${use_anon:+FTPANONPASS=\"\$pass\"} \
711 ftp -V ${use_anon:+-a} \
712 \"ftp://\$userpass\$host\$port\" \
713 2>&1
714 ); then
715 f_show_msg "$msg_couldnt_open_ftp_connection" \
716 "$ftp_host" "$rx"
717 break # to failure
718 fi
719
720 local fdir
721 if fdir=$( echo "$rx" | awk '
722 BEGIN { found = 0 }
723 /^Remote directory: / {
724 sub(/^[^:]*:[[:space:]]*/, "")
725 if ($0 == "/") next
726 # Exit after the first dir
727 found++; print; exit
728 }
729 END { exit ! found }
730 ' ); then
731 setvar $VAR_FTP_DIR "$fdir"
732 setvar $VAR_FTP_PATH "ftp://$ftp_host$fdir"
733 FTP_INITIALIZED=YES
734 return $SUCCESS
735 else
736 f_yesno "$msg_cant_find_distribution" \
737 "$rel" "$ftp_host"
738 if [ $? -eq $SUCCESS ]; then
739 unset $VAR_FTP_PATH
740 f_media_set_ftp && continue
741 fi
742 fi
743 esac
744 break # to failure
745 done
746
747 unset FTP_INITIALIZED $VAR_FTP_PATH
748 f_device_network_down $dev
749 return $FAILURE
750}
751
752# f_media_get_ftp $device $file [$probe_only]
753#
754# Returns data from $file on an FTP server using ftp(1). Please note that
755# $device is unused but must be present (even if null). Information is instead
756# gathered from the environment. $probe_only is currently unused by this media
757# type.
758#
759# Variables from variable.subr used to configure the connection are as follows
760# (all of which are configured by f_media_set_ftp above):
761#
762# VAR_FTP_HOST
763# FTP host to connect to. Can be an IPv4 address, IPv6 address,
764# or DNS hostname of your choice.
765# VAR_FTP_PORT
766# TCP port to connect on; see f_media_set_ftp() above.
767# VAR_FTP_USER [Optional]
768# If unset, defaults to using anonymous access.
769# VAR_FTP_PASS [Optional]
770# If unset, defaults to a sensible value.
771#
772# In addition, the following (managed either manually or by f_media_set_ftp_*):
773#
774# VAR_FTP_STATE
775# Sets FTPMODE for ftp(1) and can be one of:
776# active active mode FTP only
777# auto automatic determination of passive or active
778# (this is the default)
779# gate gate-ftp mode
780# passive passive mode FTP only
781# See ftp(1) for additional information.
782#
783# See variable.subr for additional information.
784#
785# Example usage:
786# f_media_set_ftp
787# f_media_get_ftp media $file
788#
789f_media_get_ftp()
790{
791 local dev="$1" file="$2" probe_only="$3"
792
793 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \
794 "$dev" "$file" "$probe_only"
795
796 local ftp_host ftp_port
797 f_getvar $VAR_FTP_HOST ftp_host
798 f_getvar $VAR_FTP_PORT ftp_port
799
800 if [ ! "$FTP_INITIALIZED" ]; then
801 f_dprintf "No FTP connection open, can't get file %s" "$file"
802 return $FAILURE
803 fi
804
805 if ! {
806 f_validate_ipaddr "$ftp_host" ||
807 f_validate_ipaddr6 "$ftp_host" ||
808 {
809 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
810 "f_media_get_ftp" "$ftp_host"
811 f_host_lookup "$ftp_host" hosts
812 }
813 }; then
814 # All the above validations failed
815 [ "$hosts" ] && f_dialog_msgbox "$hosts"
816 return $FAILURE
817 elif [ ! "$hosts" ]; then
818 # One of the first two validations passed
819 hosts="$ftp_host"
820 fi
821
822 local host connected=
823 for host in $hosts; do
824 f_quietly nc -nz "$host" "$ftp_port" || continue
825 connected=1; break
826 done
827 if [ ! "$connected" ]; then
828 f_show_msg "$msg_couldnt_connect_to_ftp_server %s:%s" \
829 "$ftp_host" "$ftp_port"
830 return $FAILURE
831 fi
832
833 local user pass use_anon=
834 f_getvar $VAR_FTP_USER user
835 if [ ! "$user" ]; then
836 user="anonymous"
837 use_anon=1
838 fi
839 if ! f_getvar $VAR_FTP_PASS pass; then
840 f_getvar $VAR_HOSTNAME cp
841 if f_running_as_init; then
842 pass="installer@$cp"
843 else
844 local name="$( id -un 2> /dev/null )"
845 pass="${name:-ftp}@$cp"
846 fi
847 fi
848
849 local userpass=""
850 if [ ! "$use_anon" ] && [ "$user" -o "$pass" ]; then
851 userpass="$user${pass:+:$( f_uriencode "$pass" )}"
852 userpass="$userpass${userpass:+@}"
853 fi
854
855 local ftp_dir mode rx
856 f_getvar $VAR_FTP_DIR ftp_dir
857 f_getvar $VAR_FTP_STATE mode
858
859 local dir="${ftp_dir#/}"
860 local port="${ftp_port:+:$ftp_port}"
861 case "$host" in *:*) host="[$host]"; esac
862
863 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
864
865 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
866 ftp -V ${use_anon:+-a} -o - \
867 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
868 local retval=$?
869
870 [ $retval -eq $SUCCESS ] || f_dprintf "request failed!"
871 return $retval
872}
873
874# f_media_shutdown_ftp $device
875#
876# Shuts down the FTP device. Return status should be ignored. Note that since
877# we don't maintain an open connection to the FTP server there's nothing to do.
878#
879f_media_shutdown_ftp()
880{
881 [ "$FTP_INITIALIZED" ] || return $SUCCESS
882
883 unset FTP_INITIALIZED
884}
885
886############################################################ MAIN
887
888f_dprintf "%s: Successfully loaded." media/ftp.subr
889
890fi # ! $_MEDIA_FTP_SUBR