aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/netfiles/netfilelib.rc
blob: 4ea314959ae09dfeeaa04ca68059c075de780880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

ns=`{namespace}
if(</dev/null dial 'unix!'^$ns/$1 >[2]/dev/null)
	f=$f^9p

t=/tmp/netfilexxx.$pid.$USER
fn sigexit { rm -f $t $t.* }

fn runsftp {
	eflag=no
	if(~ $1 -e){
		eflag=yes
		shift
	}
	if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
		sftpcache -D $1 </dev/null >[1=2]
	}
	{
		if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
			sed 's/^/-/' | sftp -b /dev/stdin $1 && echo DONE
		}
		if not{
			{cat; echo DONE} | dial -e 'unix!'^$ns/$1.sftp
		}
	} >$t.sftp1 >[2=1]
	sed '/^sftp> /d
		/^Connecting to /d
		/^Fetching /d
		/^Uploading /d
		/^DONE$/d
	' $t.sftp1 >$t.sftp
	if(! 9 grep -s '^DONE$' $t.sftp1){
		echo sftp did not finish: >[1=2]
		sed 's/^/	/g' $t.sftp1 >[1=2]
		exit 1
	}
	if(~ $eflag yes && test -s $t.sftp){
		echo sftp error output: >[1=2]
		sed '/^DONE$/d; s/^/	/g' $t.sftp1 >[1=2]
		exit 1
	}
	status=''
}