Mercurial > hgrepos > hgweb.cgi > s4
annotate s4-world.sh @ 797:56adb6e5ee68 feature-world
Add world-links to Grps entry of topmenu
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sun, 14 Jun 2020 11:15:45 +0900 |
parents | 8646ec4bd6fc |
children | ba11fd987baf |
rev | line source |
---|---|
752 | 1 #!/bin/sh |
2 | |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
3 # Setup variables for running time |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
4 if $isCGI; then |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
5 case "$S4WORLDLIST" in |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
6 *:*:*) |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
7 worldlistfile=cache/worldlist |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
8 worldgrpfile=cache/worldgrps |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
9 worldoptionfile=cache/worldoption |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
10 worldnamefile=cache/worldname |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
11 if [ ! -e $worldlistfile -o $worldlistfile -ot s4-config.sh \ |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
12 -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
|
13 -o s4-world.sh -nt $worldoptionfile ] |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
14 then |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
15 echo S4MASTERURL=$S4MASTERURL >> tmp/debug.out |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
16 cat <<-EOF > $worldlistfile |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
17 <div><table> |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
18 <tr><th>World List</th></tr> |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
19 <tr><td title="Base World$nl拠点となるWorldです">⇒ |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
20 <a href="${S4MASTERURL:-$URL}">Base</a></td></tr> |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
21 EOF |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
22 true > $worldoptionfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
23 for i in $S4WORLDLIST; do |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
24 echo $i | { |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
25 IFS=: read name short d |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
26 cgi="s4-world-$short$cgiext" |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
27 conf="s4-config-$short.sh" |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
28 cat<<-EOF >>$worldlistfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
29 <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
|
30 EOF |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
31 cat<<-EOF >>$worldoptionfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
32 <option title="$d" value="$conf">$name</option> |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
33 EOF |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
34 echo "$name" > $worldnamefile.$short |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
35 } |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
36 done |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
37 if [ -s "$worldoptionfile" ]; then |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
38 echo "<option value=\"s4-config.sh\">Base</option>" >> $worldoptionfile |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
39 echo "</table>$nl</div>" >> $worldlistfile |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
40 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
|
41 > $worldgrpfile |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
42 else |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
43 true > $worldoptionfile; true > $worldlistfile # Remove contents |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
44 rm -f ${worldnamefile}.* |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
45 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
46 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
47 if [ -s "$worldlistfile" ]; then |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
48 S4WORLDS="▼spaste(\`$worldlistfile')" |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
49 S4WORLDNAME=${S4WORLD:+`cat $worldnamefile.$S4WORLD`} |
797
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
50 S4WORLDGRPS="▼spaste(\`$worldgrpfile')" |
56adb6e5ee68
Add world-links to Grps entry of topmenu
HIROSE Yuuji <yuuji@gentei.org>
parents:
796
diff
changeset
|
51 err S4WORLDGRPS=$S4WORLDGRPS |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
52 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
53 ;; |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
54 esac |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
55 fi |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
56 |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
57 err "db=$db mas=$S4MASTERDB sessdb=$sessdb" |
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
58 # If in parent world, no need to do rest of jobs |
752 | 59 if [ -z "$S4MASTERDB" -o ! -s "$S4MASTERDB" ]; then |
60 return | |
61 fi | |
791
567980314463
World and Migration structures refined
HIROSE Yuuji <yuuji@gentei.org>
parents:
771
diff
changeset
|
62 # Confim child |
752 | 63 if [ "$db" -ef "$S4MASTERDB" ]; then |
64 return # Points to the same file | |
65 fi | |
66 | |
756 | 67 # Now Another world is ACTIVE |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
68 # sessdb=`dirname $S4MASTERDB`/sess.sq3 |
754
5bab8644024a
Annex-test: sessdb = main-sessdb
HIROSE Yuuji <yuuji@gentei.org>
parents:
752
diff
changeset
|
69 ## skey="skey-`basename $mydir`" |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
70 syncflag=${db%.*}.synctime |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
71 runflag=${db%.*}.run |
752 | 72 userupdateflag=`dirname $S4MASTERDB`/`basename $userupdateflag` |
771
b97f1c84bdb1
New script s4-newworld supports NewWorld creation
HIROSE Yuuji <yuuji@gentei.org>
parents:
756
diff
changeset
|
73 err SYNCFLAG=$syncflag |
752 | 74 test ! -e "$userupdateflag" && return |
75 test "$syncflag" -nt "$userupdateflag" && return | |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
76 if [ -s "$runflag" ]; then |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
77 limit=`cat $runflag|tr -c -d 0-9` |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
78 if [ -n "$limit" -a "$limit" -gt `date +%s` ]; then |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
79 err "World $S4WORLD account sync withholded by process $$" |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
80 return # Running sync by other process not leaching timeout |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
81 fi |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
82 fi |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
83 echo $((`date +%s` + 10)) > $runflag # Setting running flag by timeout 10s |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
84 |
752 | 85 # for sub.sq3 |
86 # | |
87 # main: user: 'taro', 'hanako', 'shige' | |
88 # sub: user: 'taro', 'hanako', 'shige' | |
89 # sub2: user_s: ('taro', 't'), ('hanako', 'h'), ('shige', 's') | |
90 # then update | |
91 # | |
92 | |
93 ## sqlite3 -cmd '.timer 1' -cmd '.echo 1' $db <<EOF | |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
94 err "`gdate +%S.%3N` Starting account synchronization[$$]" |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
95 ## cat > tmp/sql <<EOF |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
96 num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db <<EOF |
752 | 97 ATTACH DATABASE "$S4MASTERDB" AS m; |
98 CREATE TABLE IF NOT EXISTS user(name, primary key(name)); | |
99 BEGIN; | |
100 DElETE FROM main.user WHERE rowid NOT IN (SELECT rowid FROM m.user); | |
101 INSERT INTO main.user(rowid, name) | |
102 SELECT rowid, name FROM m.user | |
103 WHERE m.user.rowid NOT IN (SELECT rowid FROM user); | |
104 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
|
105 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
|
106 REPLACE INTO main.user_s(rowid, name, key, type, val, bin) |
752 | 107 SELECT rowid,* FROM m.user_s; |
755
1a8291d7fa3d
Annex strategy shifted to World strategy
HIROSE Yuuji <yuuji@gentei.org>
parents:
754
diff
changeset
|
108 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
|
109 REPLACE INTO main.user_m(rowid, name, key, type, val, bin) |
752 | 110 SELECT rowid,* FROM m.user_m |
111 WHERE key NOT LIKE '%cache%'; | |
112 END; | |
113 | |
114 /* Compare user tables */ | |
115 WITH master AS ( | |
116 SELECT p.rowid,* FROM m.user p | |
117 NATURAL LEFT JOIN m.user_s | |
118 NATURAL LEFT JOIN m.user_m | |
756 | 119 ), thisworld AS ( |
752 | 120 SELECT p.rowid,* FROM user p |
121 NATURAL LEFT JOIN user_s | |
122 NATURAL LEFT JOIN user_m | |
123 ), m_a AS ( | |
756 | 124 SELECT * FROM master EXCEPT SELECT * FROM thisworld |
752 | 125 ), a_m AS ( |
756 | 126 SELECT * FROM thisworld EXCEPT SELECT * FROM master |
752 | 127 ) SELECT (SELECT count(*) FROM m_a) + (SELECT count(*) FROM a_m); |
128 DETACH DATABASE m; | |
129 EOF | |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
130 ) |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
131 ### num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db < tmp/sql ) |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
132 if [ -n "$num" -a $num -eq 0 ]; then |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
133 err "`gdate +%S.%3N` Account synchronization[$$] done in difference $num" |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
134 echo "`date '+%F %T'`: Sync done by process $$" >> $syncflag |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
135 else |
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
136 err "Account synch[$$] failed or bailed with num=[$num]" |
754
5bab8644024a
Annex-test: sessdb = main-sessdb
HIROSE Yuuji <yuuji@gentei.org>
parents:
752
diff
changeset
|
137 fi |
794
8448724f69e3
Account sync-ing and migration fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
791
diff
changeset
|
138 test -e "$runflag" && rm -f "$runflag" |
754
5bab8644024a
Annex-test: sessdb = main-sessdb
HIROSE Yuuji <yuuji@gentei.org>
parents:
752
diff
changeset
|
139 return $num |