Mercurial > hgrepos > hgweb.cgi > s4
annotate s4-init.sh @ 536:83a9550ad564
Remove debugging switch
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 06 Apr 2019 18:51:18 +0900 |
parents | d63b9b287ae9 |
children | 6daa70fbf97c |
rev | line source |
---|---|
536 | 1 #!/bin/sh |
534
ce6d0f04f520
Do not read s4-funcs.sh twice
HIROSE Yuuji <yuuji@gentei.org>
parents:
279
diff
changeset
|
2 type cgiinit >/dev/null 2.&1 || . `dirname $0`/s4-funcs.sh |
0
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
3 |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
4 create() { |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
5 # $1=type $2=obj $3=defs... |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
6 target=$1; shift |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
7 name=$1; shift |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
8 [ "$debug" ] && echo "create $target if not exists $name $@" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
9 sq $db "create $target if not exists $name $@" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
10 } |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
11 |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
12 create table $conftbl '(tbl,col,keytype,objtype, primary key(tbl, col))' |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
13 |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
14 create_struct() { |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
15 # $1=struct-def |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
16 def=`basename $1` |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
17 tmain=${def%.*} |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
18 ts=${tmain}_s |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
19 tm=${tmain}_m |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
20 ct=$conftbl |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
21 cat $1 | \ |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
22 (cols="" pkey="" uniq="" fkey="" fkey2="" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
23 while IFS=: read prompt col keytype objtype args; do |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
24 addcol="" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
25 case $keytype in |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
26 *p*|*f*) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
27 addcol=$col |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
28 case $keytype in |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
29 *pf*|*fp*) |
13 | 30 pkey="$pkey${pkey:+, }$col" |
0
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
31 fkey="${fkey}, foreign key($col) references $objtype on delete cascade on update cascade" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
32 fkey2="${fkey2}, foreign key($col) references $objtype on delete cascade on update cascade" ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
33 *p*) |
8 | 34 pkey="$pkey${pkey:+, }$col" |
0
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
35 fkey2="${fkey2}, foreign key($col) references $tmain($col) on delete cascade on update cascade" ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
36 esac |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
37 ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
38 *u*) uniq="$uniq${uniq:+, }$col" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
39 addcol=$col |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
40 ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
41 esac |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
42 case $objtype in |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
43 author) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
44 addcol=$col |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
45 fkey="${fkey}, foreign key($col) references user(name) on delete cascade on update cascade" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
46 keytype=f # blogの場合はuserのほうがいい?? |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
47 ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
48 owner) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
49 ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
50 serial) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
51 addcol=$addcol" varchar(20)" ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
52 hidden) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
53 continue ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
54 user) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
55 |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
56 ;; |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
57 group) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
58 esac |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
59 [ "$addcol" ] && cols="$cols${cols:+, }"$addcol |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
60 typevals="(\"/$tmain\", \"$col\", \"$keytype\", \"$objtype\")" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
61 sq $db "replace into $ct values $typevals" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
62 done |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
63 pk=${pkey:+", primary key($pkey)"} |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
64 uq=${uniq:+", unique($uniq)"} |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
65 create table $tmain "($cols$pk$uq$fkey)" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
66 create table $ts "($pkey, key, type, val, bin blob, primary key($pkey, key)$fkey2)" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
67 create table $tm "($pkey, key, type, val, bin blob, unique($pkey, key, val)$fkey2)" |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
68 ) |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
69 } |
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
70 |
5
067d42b98182
Add creation of par, session, cookie
HIROSE Yuuji <yuuji@gentei.org>
parents:
4
diff
changeset
|
71 create table par '(sessid text, var text, type text, val text, primary key(sessid, var, val) foreign key(sessid) references session(id) on update cascade on delete cascade);' |
067d42b98182
Add creation of par, session, cookie
HIROSE Yuuji <yuuji@gentei.org>
parents:
4
diff
changeset
|
72 create table session '(id text primary key, expire text);' |
067d42b98182
Add creation of par, session, cookie
HIROSE Yuuji <yuuji@gentei.org>
parents:
4
diff
changeset
|
73 create table cookie '(sessid text, var text, type text, val text, primary key(sessid, var) foreign key(sessid) references session(id) on update cascade on delete cascade);' |
279 | 74 |
75 # For compatibility | |
278
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
76 tblacc=`query "select name from sqlite_master where name='tblaccesses';"` |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
77 acc=`query "select name from sqlite_master where name='acclog';"` |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
78 create table tblaccesses "(user, tbl, tblrowid, time, \ |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
79 unique(user, tbl, tblrowid, time), \ |
0
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
80 foreign key(user) references user(name))" |
278
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
81 if [ -z "$tblacc" -a -n "$acc" ]; then |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
82 echo Regenerating... |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
83 query "INSERT INTO tblaccesses SELECT * FROM acclog; |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
84 DROP TABLE acclog;" |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
85 fi |
279 | 86 # Ver.2 of acclog |
278
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
87 create view acclog "AS |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
88 SELECT user, tbl, tblrowid, max(time) time FROM tblaccesses |
2f1607d8b56b
New access log schema started
HIROSE Yuuji <yuuji@gentei.org>
parents:
277
diff
changeset
|
89 GROUP by user, tbl, tblrowid;" |
0
b8a890828283
add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff
changeset
|
90 |
535
d63b9b287ae9
Define VIEW gecoses after all table construction
HIROSE Yuuji <yuuji@gentei.org>
parents:
534
diff
changeset
|
91 for f in $formdir/*def; do |
d63b9b287ae9
Define VIEW gecoses after all table construction
HIROSE Yuuji <yuuji@gentei.org>
parents:
534
diff
changeset
|
92 echo -n Creating form of $f... |
d63b9b287ae9
Define VIEW gecoses after all table construction
HIROSE Yuuji <yuuji@gentei.org>
parents:
534
diff
changeset
|
93 create_struct $f && echo Done || echo FAILED |
d63b9b287ae9
Define VIEW gecoses after all table construction
HIROSE Yuuji <yuuji@gentei.org>
parents:
534
diff
changeset
|
94 done |
d63b9b287ae9
Define VIEW gecoses after all table construction
HIROSE Yuuji <yuuji@gentei.org>
parents:
534
diff
changeset
|
95 |
172
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
96 create view gecoses "AS |
276
1966552d05a9
Add rowid column to view:gecoses
HIROSE Yuuji <yuuji@gentei.org>
parents:
174
diff
changeset
|
97 SELECT rowid, |
1966552d05a9
Add rowid column to view:gecoses
HIROSE Yuuji <yuuji@gentei.org>
parents:
174
diff
changeset
|
98 name, |
172
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
99 coalesce( |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
100 case when (SELECT name FROM user u WHERE u.name=name) IS NOT NULL |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
101 then (SELECT val FROM user_s u |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
102 WHERE u.name=a.name AND key='gecos') |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
103 else (SELECT val FROM grp_s g |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
104 WHERE g.gname=name AND key='gecos') |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
105 end, |
e9f9c72bfa48
create view "gecoses", through which gecos name can be retrieved
HIROSE Yuuji <yuuji@gentei.org>
parents:
103
diff
changeset
|
106 name) gecos |
277
cfbedd0686dd
Add `type' column to view:gecoses
HIROSE Yuuji <yuuji@gentei.org>
parents:
276
diff
changeset
|
107 FROM (SELECT rowid,'user' type,name FROM user |
cfbedd0686dd
Add `type' column to view:gecoses
HIROSE Yuuji <yuuji@gentei.org>
parents:
276
diff
changeset
|
108 UNION ALL |
cfbedd0686dd
Add `type' column to view:gecoses
HIROSE Yuuji <yuuji@gentei.org>
parents:
276
diff
changeset
|
109 SELECT rowid,'group' type, gname FROM grp) a;" |