s4

view s4-start.sh @ 528:d1382384261b

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