s4
changeset 771:b97f1c84bdb1 feature-world
New script s4-newworld supports NewWorld creation
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 09 Jun 2020 12:26:15 +0900 |
parents | c06c2df8a25a |
children | 825646678e33 |
files | s4-funcs.sh s4-newworld.sh s4-world.sh |
diffstat | 3 files changed, 133 insertions(+), 30 deletions(-) [+] |
line diff
1.1 --- a/s4-funcs.sh Mon Jun 08 20:23:42 2020 +0900 1.2 +++ b/s4-funcs.sh Tue Jun 09 12:26:15 2020 +0900 1.3 @@ -2,7 +2,7 @@ 1.4 # Here's global variable table. Do not use this names. 1.5 # $HGid$ 1.6 1.7 -test -n "$HTTP_HOST" && isCGI=true 1.8 +test -n "$HTTP_HOST" && isCGI=true || isCGI=false 1.9 if $isCGI; then 1.10 case "$SCRIPT_NAME" in 1.11 *-world-*) 1.12 @@ -20,6 +20,7 @@ 1.13 fi 1.14 myname=`basename ${SCRIPT_NAME:-$0}` 1.15 mydir=`dirname ${SCRIPT_FILENAME:-$0}` 1.16 +cgiext=${CGIEXT:-.cgi} 1.17 myargs="$@" 1.18 PATH=/usr/local/sqlite3/bin:/usr/local/vim7/bin:/usr/iekei/ImageMagick/bin:/usr/local/ImageMagick/bin:$PATH 1.19 tmpdir=${TMPDIR:-tmp} 1.20 @@ -93,19 +94,46 @@ 1.21 if [ -n "$S4MASTERDB" -a -s "$S4MASTERDB" ]; then 1.22 . ./s4-world.sh 2>> tmp/debug.out 1.23 fi 1.24 -v="" 1.25 -for i in $S4WORLDLIST; do 1.26 - _aname=${i%:*}; _apath=${i##*:} 1.27 - v=${v}"<tr><td>⇒ <a href=\"$_apath\">$_aname</a></td></tr>$nl" 1.28 -done 1.29 -if [ -n "$v" ]; then 1.30 - err S4MASTERURL=$S4MASTERURL 1.31 - i="<tr><th>World List</th></tr>$nl" 1.32 - if [ -n "$S4MASTERURL" ]; then 1.33 - i="$i<tr><td>⇒ <a href=\"$S4MASTERURL\">Base</a></td></tr>$nl" 1.34 - fi 1.35 - S4WORLDS="${touchpanel:+ : ▼}<div><table>$i$v</table></div>" 1.36 -fi 1.37 +case "$S4WORLDLIST" in 1.38 + *:*:*) 1.39 + worldlistfile=cache/worldlist 1.40 + worldoptionfile=cache/worldoption 1.41 + if [ ! -e $worldlistfile -o $worldlistfile -ot s4-config.sh \ 1.42 + -o ! -e $worldoptionfile -o $worldoptionfile -ot s4-config.sh ] 1.43 + then 1.44 + echo S4MASTERURL=$S4MASTERURL >> tmp/debug.out 1.45 + cat <<-EOF > $worldlistfile 1.46 + ${touchpanel:+ : ▼}<div><table> 1.47 + <tr><th>World List</th></tr> 1.48 + <tr><td>⇒ <a href="$S4MASTERURL">Base</a></td></tr> 1.49 + EOF 1.50 + true > $worldoptionfile 1.51 + for i in $S4WORLDLIST; do 1.52 + echo $i | { 1.53 + IFS=: read name short d 1.54 + cgi="s4-world-$short$cgiext" 1.55 + conf="s4-config-$short.sh" 1.56 + cat<<-EOF >>$worldlistfile 1.57 + <tr><td title="$d">⇒ <a href="$cgi">$name</a></td></tr> 1.58 + EOF 1.59 + cat<<-EOF >>$worldoptionfile 1.60 + <option title="$d" value="$conf">$name</option> 1.61 + EOF 1.62 + } 1.63 + if [ -n "$S4MASTERDB" ]; then 1.64 + echo "<option value=\"s4-config.sh\">Base</option>" \ 1.65 + >> $worldoptionfile 1.66 + fi 1.67 + done 1.68 + if [ -s "$worldoptionfile" ]; then 1.69 + echo "</table>$nl</div>" >> $worldlistfile 1.70 + S4WORLDS=": spaste(\`$worldlistfile')" 1.71 + else 1.72 + true > $worldoptionfile; true > $worldlistfile # Remove contents 1.73 + fi 1.74 + fi 1.75 + ;; 1.76 +esac 1.77 1.78 1.79 [ -f ./s4-cgi.sh ] && . ./s4-cgi.sh 1.80 @@ -411,7 +439,7 @@ 1.81 #tail -f $sqi | sq $db & # "tail -f" is too heavy. DO NOT USE!! 1.82 sq $db < $sqi & 1.83 sq3pid="`jobs -p` $!" 1.84 - if [ -n "$isCGI" ]; then 1.85 + if $isCGI; then 1.86 exec 2>> $tmpdir/error.out 1.87 fi 1.88 exec 5> $sqi # Turning $sqi access through fd5 for continuous open state 1.89 @@ -463,7 +491,7 @@ 1.90 _m4() { 1.91 #S4NAME=f,f,f 1.92 m4 ${S4NAME:+"-D_S4NAME_=${S4NAME}"} ${S4CSS:+-D_S4CSS_="$S4CSS"} \ 1.93 - -D_S4WORLDS_="${S4WORLDS}" "$@" 1.94 + -D_S4WORLDS_="$S4WORLDS" "$@" 1.95 } 1.96 ismember() { 1.97 # $1=user, $2=group 1.98 @@ -1865,17 +1893,7 @@ 1.99 GF_STAGE="groupupdate" edittable "$formdir/grp.def" "grp" "$rowid" 1.100 if [ -z "$STOPCLONEMSG" ]; then 1.101 ## Setup migration menu 1.102 - v="" 1.103 - for i in $S4WORLDLIST; do 1.104 - _aname=${i%:*}; _apath=${i##*:} 1.105 - conf=`echo $_apath | sed -e 's/-world-/-config-/;s/\..*$/.sh/'` 1.106 - if [ x"$myname" != x"$_apath" ]; then 1.107 - v=${v}"<option value=\"$conf\">$_aname</option>$nl" 1.108 - fi 1.109 - done 1.110 - if [ -n "$S4MASTERDB" ]; then 1.111 - v=${v}"<option value=\"s4-config.sh\">Base</option>$nl" 1.112 - fi 1.113 + v=`fgrep -v "value=\"$worldconf\"" $worldoptionfile` 1.114 err v=$v 1.115 if [ -n "$v" ]; then 1.116 migrate=$(cat<<-EOF
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/s4-newworld.sh Tue Jun 09 12:26:15 2020 +0900 2.3 @@ -0,0 +1,84 @@ 2.4 +#!/bin/ksh 2.5 +#!/bin/sh 2.6 +# Create New Wolrd in s4 2.7 +# Arguments: 2.8 +# $1 = World Display Name in UTF-8 2.9 +# $2 = World ShortName in alpha-numeric 2.10 +# $3 = World Description in UTF-8 2.11 +. `dirname $0`/s4-config.sh 2.12 +if ! type htmlescape >/dev/null 2>&1; then 2.13 + . `dirname $0`/s4-funcs.sh ### > /dev/null 2>&1 2.14 +fi 2.15 +dispname=$1 2.16 +shortname=$2 2.17 +desc=$3 2.18 + 2.19 +readvar() { # $1=varname $2=PromptString 2.20 + echo -n "${2:-$1=:} " 2.21 + read $1 2.22 +} 2.23 + 2.24 +echo db=$db URL=$URL isCGI=$isCGI 2.25 +if ! $isCGI; then 2.26 + while true; do 2.27 + dispname=`echo $dispname | tr -d ': \t\n"' | fold -w 28 | head -1` 2.28 + test -n "$dispname" && break 2.29 + readvar dispname "分かりやすいWorld名14字以内" 2.30 + done 2.31 + while true; do 2.32 + shortname=`echo $shortname | tr -c -d '_0-9A-Za-z.-' | colrm 11` 2.33 + test -n "$shortname" && break 2.34 + readvar shortname "英数字のみ10字以内のWorldシンボル(URLの一部)" 2.35 + done 2.36 + while true; do 2.37 + desc=`echo $desc | tr -d ': \t\n"'` 2.38 + test -n "$desc" && break 2.39 + readvar desc "概要(どのような基準でこのWorldを使うかなど)" 2.40 + done 2.41 +fi 2.42 +echo "wl=$S4WORLDLIST" 2.43 +echo "$dispname:$shortname:$desc" 2.44 +newworld=$( 2.45 + { echo "$S4WORLDLIST" | tr ' ' '\n' \ 2.46 + | awk -F: "\$2 != \"$shortname\"{print}" 2.47 + echo "$dispname:$shortname:$desc" 2.48 + } | tr '\n' ' ' | tr -d '"' 2.49 + ) 2.50 +if [ -z "$newworld" ]; then 2.51 + exit 2.52 +fi 2.53 + 2.54 +# Create config 2.55 +bgcolor=$( 2.56 + od -An -tu1 -N3 < /dev/urandom \ 2.57 + | { read r g b 2.58 + r=$((192+r/4)); g=$((192+g/4)); b=$((192+b/4)) 2.59 + printf "#%x%x%x" $r $g $b 2.60 + }) 2.61 +cat<<-EOF > s4-config-$shortname.sh 2.62 + S4MASTERURL=\$URL 2.63 + URL=`dirname $URL`/s4-world-$shortname$cgiext 2.64 + S4COLOR="$bgcolor" # Change this! 2.65 + DB=$dbdir/$shortname.sq3 2.66 + SESSDB=$dbdir/sess.sq3 2.67 + S4MASTERDB=$db 2.68 + S4CSS=$shortname.css 2.69 + TMPDIR=$tmpdir/$shortname 2.70 +EOF 2.71 +# Create CSS 2.72 +cat<<-EOF > $shortname.css 2.73 + body {background: $bgcolor;} 2.74 + body.moderated {background: $bgcolor; border: 3px gold solid;} 2.75 +EOF 2.76 +mkdir -m 1775 $tmpdir/$shortname 2.77 +# Update s4-config.sh 2.78 +cat<<-EOF | ed s4-config.sh 2.79 + g/^S4WORLDLIST=/d 2.80 + \$a 2.81 + S4WORLDLIST="`echo $newworld`" 2.82 + . 2.83 + wq 2.84 +EOF 2.85 +DB=db/$shortname.sq3 `dirname $0`/s4-init.sh 2.86 +(cd `dirname $0`; ln -s s4$cgiext s4-world-$shortname$cgiext) 2.87 +echo $newworld added
3.1 --- a/s4-world.sh Mon Jun 08 20:23:42 2020 +0900 3.2 +++ b/s4-world.sh Tue Jun 09 12:26:15 2020 +0900 3.3 @@ -10,9 +10,9 @@ 3.4 # Now Another world is ACTIVE 3.5 # sessdb=`dirname $S4MASTERDB`/sess.sq3 3.6 ## skey="skey-`basename $mydir`" 3.7 -S4NAME="[$S4WORLD]$S4NAME" 3.8 syncflag=${db%.*}.synctime 3.9 userupdateflag=`dirname $S4MASTERDB`/`basename $userupdateflag` 3.10 +err SYNCFLAG=$syncflag 3.11 test ! -e "$userupdateflag" && return 3.12 test "$syncflag" -nt "$userupdateflag" && return 3.13 3.14 @@ -27,7 +27,8 @@ 3.15 ## sqlite3 -cmd '.timer 1' -cmd '.echo 1' $db <<EOF 3.16 err "Starting account synchronization" 3.17 err "db=$db mas=$S4MASTERDB sessdb=$sessdb" 3.18 -num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db <<EOF 3.19 +# num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db <<EOF 3.20 +cat > tmp/sql <<EOF 3.21 ATTACH DATABASE "$S4MASTERDB" AS m; 3.22 CREATE TABLE IF NOT EXISTS user(name, primary key(name)); 3.23 BEGIN; 3.24 @@ -65,7 +66,7 @@ 3.25 -- SELECT rowid,* FROM user WHERE rowid NOT IN (SELECT rowid FROM m.user); 3.26 DETACH DATABASE m; 3.27 EOF 3.28 -) 3.29 +num=$(sqlite3 -bail -cmd 'PRAGMA FOREIGN_KEYS=on' $db < tmp/sql ) 3.30 if [ $num -eq 0 ]; then 3.31 touch $syncflag 3.32 fi