s4

view s4-newworld.sh @ 776:d773042e923d

merged
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 11 Jun 2020 10:39:51 +0900
parents
children 1f310d682c07
line source
1 #!/bin/ksh
2 #!/bin/sh
3 # Create New Wolrd in s4
4 # Arguments:
5 # $1 = World Display Name in UTF-8
6 # $2 = World ShortName in alpha-numeric
7 # $3 = World Description in UTF-8
8 . `dirname $0`/s4-config.sh
9 if ! type htmlescape >/dev/null 2>&1; then
10 . `dirname $0`/s4-funcs.sh ### > /dev/null 2>&1
11 fi
12 dispname=$1
13 shortname=$2
14 desc=$3
16 readvar() { # $1=varname $2=PromptString
17 echo -n "${2:-$1=:} "
18 read $1
19 }
21 echo db=$db URL=$URL isCGI=$isCGI
22 if ! $isCGI; then
23 while true; do
24 dispname=`echo $dispname | tr -d ': \t\n"' | fold -w 28 | head -1`
25 test -n "$dispname" && break
26 readvar dispname "分かりやすいWorld名14字以内"
27 done
28 while true; do
29 shortname=`echo $shortname | tr -c -d '_0-9A-Za-z.-' | colrm 11`
30 test -n "$shortname" && break
31 readvar shortname "英数字のみ10字以内のWorldシンボル(URLの一部)"
32 done
33 while true; do
34 desc=`echo $desc | tr -d ': \t\n"'`
35 test -n "$desc" && break
36 readvar desc "概要(どのような基準でこのWorldを使うかなど)"
37 done
38 fi
39 echo "wl=$S4WORLDLIST"
40 echo "$dispname:$shortname:$desc"
41 newworld=$(
42 { echo "$S4WORLDLIST" | tr ' ' '\n' \
43 | awk -F: "\$2 != \"$shortname\"{print}"
44 echo "$dispname:$shortname:$desc"
45 } | tr '\n' ' ' | tr -d '"'
46 )
47 if [ -z "$newworld" ]; then
48 exit
49 fi
51 # Create config
52 bgcolor=$(
53 od -An -tu1 -N3 < /dev/urandom \
54 | { read r g b
55 r=$((192+r/4)); g=$((192+g/4)); b=$((192+b/4))
56 printf "#%x%x%x" $r $g $b
57 })
58 cat<<-EOF > s4-config-$shortname.sh
59 S4MASTERURL=\$URL
60 URL=`dirname $URL`/s4-world-$shortname$cgiext
61 S4COLOR="$bgcolor" # Change this!
62 DB=$dbdir/$shortname.sq3
63 SESSDB=$dbdir/sess.sq3
64 S4MASTERDB=$db
65 S4CSS=$shortname.css
66 TMPDIR=$tmpdir/$shortname
67 EOF
68 # Create CSS
69 cat<<-EOF > $shortname.css
70 body {background: $bgcolor;}
71 body.moderated {background: $bgcolor; border: 3px gold solid;}
72 EOF
73 mkdir -m 1775 $tmpdir/$shortname
74 # Update s4-config.sh
75 cat<<-EOF | ed s4-config.sh
76 g/^S4WORLDLIST=/d
77 \$a
78 S4WORLDLIST="`echo $newworld`"
79 .
80 wq
81 EOF
82 DB=db/$shortname.sq3 `dirname $0`/s4-init.sh
83 (cd `dirname $0`; ln -s s4$cgiext s4-world-$shortname$cgiext)
84 echo $newworld added