Mercurial > hgrepos > hgweb.cgi > s4
annotate s4-world.sh @ 835:fa23017ba273
Sync only latest entries in user_m
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 23 Jun 2020 12:47:34 +0900 |
parents | a87030974b99 |
children | ed9aae18fda9 |
rev | line source |
---|---|
752 | 1 #!/bin/sh |
2 | |
817
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
3 autoremovestop=2 |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
4 |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
5 # Setup variables for running time |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
6 if $isCGI; then |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
7 case "$S4WORLDLIST" in |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
8 *:*:*) |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
9 worldlistfile=cache/worldlist |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
10 worldgrpfile=cache/worldgrps |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
11 worldoptionfile=cache/worldoption |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
12 worldnamefile=cache/worldname |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
13 if [ ! -e $worldlistfile -o $worldlistfile -ot s4-config.sh \ |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
14 -o ! -e $worldoptionfile -o $worldoptionfile -ot s4-config.sh \ |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
15 -o s4-world.sh -nt $worldoptionfile ] |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
16 then |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
17 echo S4MASTERURL=$S4MASTERURL >> tmp/debug.out |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
18 cat <<-EOF > $worldlistfile |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
19 <div><table> |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
20 <tr><th>World List</th></tr> |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
21 <tr><td title="Base World$nl拠点となるWorldです">⇒ |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
22 <a href="${S4MASTERURL:-$URL}">Base</a></td></tr> |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
23 EOF |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
24 true > $worldoptionfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
25 for i in $S4WORLDLIST; do |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
26 echo $i | { |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
27 IFS=: read name short d |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
28 cgi="s4-world-$short$cgiext" |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
29 conf="s4-config-$short.sh" |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
30 cat<<-EOF >>$worldlistfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
31 <tr><td title="$d">⇒ <a href="$cgi">$name</a></td></tr> |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
32 EOF |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
33 cat<<-EOF >>$worldoptionfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
34 <option title="$d" value="$conf">$name</option> |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
35 EOF |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
36 echo "$name" > $worldnamefile.$short |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
37 } |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
38 done |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
39 if [ -s "$worldoptionfile" ]; then |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
40 echo "<option value=\"s4-config.sh\">Base</option>" >> $worldoptionfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
41 echo "</table>$nl</div>" >> $worldlistfile |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
42 sed 's/href="\([^>]*\)"/href="\1?grps"/' $worldlistfile \ |
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
43 > $worldgrpfile |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
44 else |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
45 true > $worldoptionfile; true > $worldlistfile # Remove contents |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
46 rm -f ${worldnamefile}.* |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
47 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
48 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
49 if [ -s "$worldlistfile" ]; then |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
50 S4WORLDS="▼spaste(\`$worldlistfile')" |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
51 S4WORLDNAME=${S4WORLD:+`cat $worldnamefile.$S4WORLD`} |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
52 S4WORLDGRPS="▼spaste(\`$worldgrpfile')" |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
53 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
54 ;; |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
55 esac |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
56 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
57 |
817
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
58 |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
59 syncaccount_1() { |
752 | 60 |
817
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
61 n_m=`query "SELECT printf('%d:%d',\ |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
62 (SELECT count(*) FROM m.user), \ |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
63 (SELECT count(*) FROM user));"` |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
64 n=${n_m%:*}; m=${n_m#*:} # n:m |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
65 if [ -z "$n" -o "$n" -lt 2 ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
66 err "Skipping account sync because m.user cannot be reached[n=$n]." |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
67 return -3 |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
68 fi |
817
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
69 if [ -z "$forceusersync" -a ! -f db/forceusersync ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
70 if [ $((m-n)) -le $((autoremovestop+0)) ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
71 # If if-condition evaluation fails, fall through to else-caluse |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
72 rm -f db/forceusersync |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
73 else |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
74 err "More than $autoremovestop users vanished($((m-n)))." |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
75 err "Automatic removal canceled. If you want to sync user accounts" |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
76 err "forcibly, touch db/forceusersync file each time of world update." |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
77 return -4 |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
78 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
79 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
80 err "`gdate +%S.%3N` Starting account synchronization[$$]" |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
81 |
835
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
82 prevsync=`tail -1 $syncflag|colrm 20` # 2020-06-21 12:30:00 = 19cols |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
83 syncall=${db%.*}.syncall |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
84 err syncallfile=$syncall |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
85 if [ -e $syncall ]; then |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
86 rm -f "$syncall" |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
87 err "Force update user_m for all users" |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
88 else |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
89 case "$prevsync" in |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
90 [2-9][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]\ [012][0-9]:??:??) |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
91 SYNCCOND="WHERE name in (SELECT name FROM m.user_s WHERE key='wtime' AND val > '$prevsync')" |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
92 err synccond limited to \ |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
93 `query "SELECT DISTINCT name FROM m.user_s $SYNCCOND;"` |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
94 err "Touch $syncall (owner=`id -un`) to update all user_m." |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
95 ;; |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
96 *) |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
97 echo arere ;; |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
98 esac |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
99 fi |
817
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
100 ## num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db <<EOF |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
101 num=$(query <<EOF |
752 | 102 BEGIN; |
103 DElETE FROM main.user WHERE rowid NOT IN (SELECT rowid FROM m.user); | |
104 INSERT INTO main.user(rowid, name) | |
105 SELECT rowid, name FROM m.user | |
106 WHERE m.user.rowid NOT IN (SELECT rowid FROM user); | |
107 UPDATE user SET name = (SELECT name FROM m.user WHERE main.user.rowid=m.user.rowid); | |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
108 DELETE FROM main.user_s WHERE rowid NOT IN (SELECT rowid FROM m.user_s); |
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
109 REPLACE INTO main.user_s(rowid, name, key, type, val, bin) |
752 | 110 SELECT rowid,* FROM m.user_s; |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
111 DELETE FROM main.user_m WHERE rowid NOT IN (SELECT rowid FROM m.user_m); |
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
112 REPLACE INTO main.user_m(rowid, name, key, type, val, bin) |
835
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
113 SELECT rowid,* FROM m.user_m $SYNCCOND |
834
a87030974b99
Detect defference between src/dest table using EXCEPT.
HIROSE Yuuji <yuuji@gentei.org>
parents:
833
diff
changeset
|
114 EXCEPT |
835
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
115 SELECT rowid,* FROM main.user_m $SYNCCOND |
fa23017ba273
Sync only latest entries in user_m
HIROSE Yuuji <yuuji@gentei.org>
parents:
834
diff
changeset
|
116 ; |
752 | 117 END; |
118 | |
119 /* Compare user tables */ | |
120 WITH master AS ( | |
121 SELECT p.rowid,* FROM m.user p | |
122 NATURAL LEFT JOIN m.user_s | |
123 NATURAL LEFT JOIN m.user_m | |
756 | 124 ), thisworld AS ( |
752 | 125 SELECT p.rowid,* FROM user p |
126 NATURAL LEFT JOIN user_s | |
127 NATURAL LEFT JOIN user_m | |
128 ), m_a AS ( | |
756 | 129 SELECT * FROM master EXCEPT SELECT * FROM thisworld |
752 | 130 ), a_m AS ( |
756 | 131 SELECT * FROM thisworld EXCEPT SELECT * FROM master |
752 | 132 ) SELECT (SELECT count(*) FROM m_a) + (SELECT count(*) FROM a_m); |
133 EOF | |
817
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
134 ) |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
135 if [ -n "$num" -a "$num" -eq 0 ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
136 err "`gdate +%S.%3N` Account synchronization[$$] done in difference $num" |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
137 echo "`date '+%F %T'`: Sync done by process $$" >> $syncflag |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
138 else |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
139 err "Account synch[$$] failed or bailed with num=[$num]" |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
140 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
141 return $num |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
142 } |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
143 |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
144 syncaccount() { |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
145 forceusersync=$1 |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
146 err "db=$db mas=$S4MASTERDB sessdb=$sessdb" |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
147 # If in parent world, no need to do rest of jobs |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
148 if [ -z "$S4MASTERDB" -o ! -s "$S4MASTERDB" ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
149 return |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
150 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
151 # Confim child |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
152 if [ "$db" -ef "$S4MASTERDB" ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
153 return # Points to the same file |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
154 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
155 # File based sync check precedes to DB count check for performance issue |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
156 syncflag=${db%.*}.synctime |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
157 runflag=${db%.*}.run |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
158 userupdateflag=`dirname $S4MASTERDB`/`basename $userupdateflag` |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
159 test ! -e "$userupdateflag" && return |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
160 [ -z "$forceusersync" -a "$syncflag" -nt "$userupdateflag" ] && return |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
161 if [ -s "$runflag" ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
162 limit=`cat $runflag|tr -c -d 0-9` |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
163 if [ -n "$limit" -a "$limit" -gt `date +%s` ]; then |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
164 err "World $S4WORLD account sync withholded by process $$" |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
165 return # Running sync by other process not leaching timeout |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
166 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
167 fi |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
168 echo $((`date +%s` + 10)) > $runflag # Setting running flag by timeout 10s |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
169 query<<-EOF |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
170 .bail ON |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
171 ATTACH DATABASE "$S4MASTERDB" AS m; |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
172 EOF |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
173 syncaccount_1 |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
174 rc=$? |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
175 test -e "$runflag" && rm -f "$runflag" |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
176 query<<-EOF |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
177 DETACH DATABASE m; |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
178 .bail OFF |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
179 EOF |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
180 return $rc |
d2c4c473e08e
Account synchronization more prudent
HIROSE Yuuji <yuuji@gentei.org>
parents:
811
diff
changeset
|
181 } |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
182 |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
183 getworldDB() { # $1=conf |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
184 (unset DB; . "$1"; echo ${DB:-$defaultdb}) |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
185 } |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
186 |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
187 worldnameDBlist() { |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
188 echo Base:Base:`getworldDB ./s4-config.sh` |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
189 for w in $S4WORLDLIST; do |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
190 case "$w" in |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
191 *:*:*:*) continue ;; |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
192 *:*:*) w=${w%:*}; name=${w%:*}; world=${w#*:} ;; |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
193 *) continue ;; |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
194 esac |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
195 d=`getworldDB "./s4-config-$world.sh"` |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
196 test -s "$d" && echo ${world}:${name}:$d |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
197 done |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
198 } |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
199 |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
200 grepgrpworld() { |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
201 world=$1; wname=$2; exp=$3; tdb=$4 |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
202 case $world in |
827 | 203 Base) cgi=${S4MASTERURL:-$URL} ;; |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
204 *) cgi=s4-world-$world$cgiext ;; |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
205 esac |
827 | 206 case $exp in |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
207 mem:*) |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
208 arg=${exp#*:} |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
209 cond="user = '$arg'" |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
210 guide="「${S4WORLDNAME:-Base}」以外の世界の所属グループ" |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
211 s="(<a href=\"$cgi?stage=grps&kwd=mem:$arg\">所属絞</a>)" ;; |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
212 *) |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
213 arg=`sqlquote "%$3%"` |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
214 cond="gname LIKE $arg" |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
215 guide="$exp を含むグループは別世界にもあります" |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
216 s="(<a href=\"$cgi?stage=grps&kwd=$exp\">絞込</a>)" ;; |
827 | 217 esac |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
218 query <<-EOF | |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
219 ATTACH DATABASE "$tdb" AS td; |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
220 SELECT DISTINCT td.grp.rowid,hex(gname) |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
221 FROM td.grp NATURAL JOIN td.grp_mem |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
222 WHERE $cond; |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
223 DETACH DATABASE td; |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
224 EOF |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
225 while IFS='|' read rowid hgname; do |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
226 # echo rowid=$rowid - `echo "$hgname"|unhexize|htmlescape` |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
227 htmlgn=`echo $hgname|unhexize|htmlescape` |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
228 printf '<a href="%s?grp+%d">%s</a> ' "$cgi" "$rowid" "$htmlgn" |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
229 done | { |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
230 read ans |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
231 if [ -n "$ans" ]; then |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
232 w=`echo $wname|htmlescape` |
826
f2d69fb3e038
Link to group list in other world with kwd
HIROSE Yuuji <yuuji@gentei.org>
parents:
825
diff
changeset
|
233 u="<a href=\"$cgi?grps\"><span class=\"pre\">$w</span></a>" |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
234 cat<<-EOF |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
235 GUIDE:<h2>`echo "$guide"|htmlescape`</h2> |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
236 <tr> |
826
f2d69fb3e038
Link to group list in other world with kwd
HIROSE Yuuji <yuuji@gentei.org>
parents:
825
diff
changeset
|
237 <tr><td>$u $s</td> |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
238 <td>$ans</td> |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
239 </dl> |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
240 EOF |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
241 fi |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
242 } |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
243 } |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
244 |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
245 peekgrpworlds() ( |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
246 # $1=(Pattern|mem:User) |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
247 # err "pgw-1=[$1]" |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
248 for wd in `worldnameDBlist`; do |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
249 world=${wd%%:*}; wd=${wd#*:} |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
250 worldname=${wd%:*} |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
251 d=${wd#*:} |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
252 if [ ! $db -ef $d -a -s $d ]; then |
827 | 253 grepgrpworld "$world" "$worldname" "$1" "$d" |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
254 fi |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
255 done | { |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
256 result=`cat` |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
257 if [ -n "$result" ]; then |
828
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
258 cat<<-EOF |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
259 `echo "$result"|sed 's/^GUIDE://;2q'` |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
260 <table class="b"> |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
261 `echo "$result"|grep -v '^GUIDE:'` |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
262 </table> |
476a70f667cf
Group search expression formula changed
HIROSE Yuuji <yuuji@gentei.org>
parents:
827
diff
changeset
|
263 EOF |
825
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
264 fi |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
265 } |
e9817a71f332
List groups in other worlds
HIROSE Yuuji <yuuji@gentei.org>
parents:
820
diff
changeset
|
266 ) |