s4

view s4-start.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 6e24f1ecf13e
children
line source
1 #!/bin/sh
2 # 愛
3 # Start s4 - Generate s4.cgi
4 mydir=`dirname $0`
5 myname=`basename $0`
6 dp="password"
7 # Default password: "$dp of $ADMIN"
9 script_dir=${SCRIPT_DIR:-scripts}
11 ADMIN=""
12 TYPE="form1"
13 ex=examples
15 usage() {
16 cat<<EOF
17 $myname `sed -n 3p $0`
18 Usage: $myname [Options]
19 Options are as follows:
20 -h Show this help
21 -a ADM Set ADMIN email address to ADM
22 -f Force overwriting
23 -g Guestonly mode(No login required)
24 -t TYPE Construction type (defaults to $TYPE)
25 -w Create CGI wrapper
27 TYPEs are one of directory names in examples except \`common'.
28 EOF
29 exit 0
30 }
31 while getopts a:fght:w f; do
32 case $f in
33 a) ADMIN=$OPTARG;;
34 g) guest=1;;
35 f) force=1;;
36 w) wrap=1;;
37 t) TYPE=$OPTARG;;
38 \?|h) usage; exit 1;;
39 esac
40 done
41 shift $(expr $OPTIND - 1)
43 if [ ! -d $ex/$TYPE ]; then
44 cat<<EOF 1>&2
45 Invalid type($TYPE).
46 Types are one of as follows.
47 `ls $ex|grep -v common | sed 's/^/ /'`
48 EOF
49 exit 1
50 fi
52 if [ -z "$ADMIN" ]; then
53 cat<<EOF 1>&2
54 Administrator's email not specified.
55 Please feed administrator email with \`-a' option.
56 EOF
57 exit 1
58 fi
60 if ! cd $mydir; then
61 echo "Script(s4-funcs.sh) not found in \`$mydir'." 1>&2
62 exit 1
63 fi
65 test -d tmp || mkdir -m 1750 tmp
66 test -d cache || mkdir -m 1755 cache
67 . ./s4-funcs.sh
68 if ! checkdomain $ADMIN; then
69 cat<<EOF 1>&2
70 Administrator's email - $ADMIN - is invalid(host not found).
71 Please specify existing email address.
72 EOF
73 exit 3
74 fi
76 if [ -d templ/form ]; then
77 if [ -z "$force" ]; then
78 echo "templ/ directory already exists. Remove it, then try again." 1>&2
79 exit 4
80 fi
81 rm -rf templ/*
82 fi
83 mkdir templ
84 if (cd templ && cp -rL ../examples/$TYPE/* .); then
85 if ./s4-init.sh; then
86 cat<<EOF
87 -------- The s4 System Successfully Installed --------
88 EOF
89 if [ -s scripts/s4-$TYPE.case ]; then
90 casefile=scripts/s4-$TYPE.case
91 else
92 casefile=scripts/s4-default.case
93 fi
94 m4 -P -I scripts -D_SHELL_=`which sh` \
95 -D__NOEDIT__="DO NOT EDIT THIS FILE MANUALLY -> scripts/s4-*.case" \
96 -D_CASE_=$casefile s4.cgi.m4 > index.cgi && chmod +x index.cgi
97 if [ "$wrap" ]; then
98 mv -f index.cgi s4.cgi
99 fi
100 (echo "ADMIN=$ADMIN"
101 echo "S4TYPE=$TYPE"
102 [ "$guest" ] && echo "guestonlymode=1") >> s4-config.sh
103 sqlite3 -cmd "pragma FOREIGH_KEYS=ON" $db \
104 "REPLACE INTO user VALUES('$ADMIN');"
105 dbsetbyid user "$ADMIN" pswd "`echo $dp of $ADMIN|mypwhash`"
106 cat > .htaccess <<-EOF
107 DirectoryIndex index.cgi
108 AddHandler cgi-script .cgi
109 EOF
110 if [ -n "$wrap" ]; then
111 type cc >/dev/null 2>&1 && CC=cc
112 ${CC:-gcc} -o index.cgi pwrap.c \
113 && chmod u+s index.cgi \
114 && rc=0
115 fi
116 else
117 echo Calling s4-init.sh 'FAILED!!'
118 fi
119 else
120 echo Failed
121 fi 1>&2
123 exit ${rc:-5}