s4

view s4-newworld.sh @ 1037:634fee6a6bd2

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