-
Notifications
You must be signed in to change notification settings - Fork 1
/
synclib.r
108 lines (95 loc) · 2.3 KB
/
synclib.r
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Sync library & configuration */
exit
/* --- SyncConfig --- */
SyncConfig:
parse source . . prg .
last = lastpos("/",prg)-1
if last > 0 then
PRGDIR = left(prg, lastpos("/",prg)-1)
else
RPGDIR = "."
SYNCPATH = getenv("HOME")"/.local/sync"
/* RSYNCPATH = getenv("HOME")"/.local/sync"*/
RSYNCPATH = "/home/bnv/.local/sync"
"mkdir -p" SYNCPATH
LOGFILE = "sync.log"
RSH = "ssh"
RCOPY = "scp -C"
RSYNC = 'rsync -avpP -e "ssh -C"'
TEE = "tee -a"
SYNCDIFF = PRGDIR"/syncdiff.r"
FILEINFO = PRGDIR"/fileinfo"
RMFILES = PRGDIR"/rmfiles"
LOCALHOST = "hostname"()||"-"||"uname"()
TMP = getenv("TEMP")
RTMP = "/tmp"
CHKUSER = 0
CHKGROUP = 0
/* Allow time jitter of few sec */
timeJitter = 1 /* sec */
/* correct variables */
if right(SYNCPATH,1)^='/' then SYNCPATH=SYNCPATH'/'
logfile = SYNCPATH||logfile
return
/* --- ReadDir --- */
ReadDir: procedure
trace o
parse arg f,array,base
call value array"0","0",-1
n = 0
pos = seek(f)
line = read(f)
CHKUSER = value("CHKUSER",,0)
CHKGROUP = value("CHKGROUP",,0)
/* Check if the base has changed */
if word(line,1)=="Base:" then do
if value(base,,-1)^=="" then do
call seek f,pos
return 0
end
call value base,subword(line,2),-1
pos = seek(f)
line = read(f)
end
if eof(f) | word(line,1)=="Base:" then do
call seek f,pos
return 0
end
/* Must be a directory entry */
parse var line type date size user group file
if type<'A' | type>'Z' then do
say "ERROR:" line
return 0
end
n = 1
call value array||n,file,-1
info = date size
if CHKUSER then info = info user
else info = info "-"
if CHKGROUP then info = info group
else info = info "-"
call value array||n".@INFO",info,-1
/*call value array||n".@INFO",date size user group,-1*/
call value array||n".@TYPE",type,-1
do forever
pos = seek(f)
line = read(f)
if eof(f) then leave
parse var line type date size user group file
if type>='A' & type<='Z' then do
call seek f,pos
leave
end
n = n + 1
call value array||n,file,-1
info = date size
if CHKUSER then info = info user
else info = info "-"
if CHKGROUP then info = info group
else info = info "-"
call value array||n".@INFO",info,-1
/*call value array||n".@INFO",date size user group,-1*/
call value array||n".@TYPE",type,-1
end
call value array"0",n,-1
return n