s4

view s4-newworld.sh @ 796:8646ec4bd6fc

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