s4

view s4-start.sh @ 971:0ac251f04f21

fix
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 22 May 2022 12:19:15 +0900
parents 10803d78f07c
children 6e24f1ecf13e
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 . ./s4-funcs.sh
67 if ! checkdomain $ADMIN; then
68 cat<<EOF 1>&2
69 Administrator's email - $ADMIN - is invalid(host not found).
70 Please specify existing email address.
71 EOF
72 exit 3
73 fi
75 if [ -d templ/form ]; then
76 if [ -z "$force" ]; then
77 echo "templ/ directory already exists. Remove it, then try again." 1>&2
78 exit 4
79 fi
80 rm -rf templ/*
81 fi
82 mkdir templ
83 if (cd templ && cp -r ../examples/$TYPE/* .); then
84 if ./s4-init.sh; then
85 cat<<EOF
86 -------- The s4 System Successfully Installed --------
87 EOF
88 if [ -s scripts/s4-$TYPE.case ]; then
89 casefile=scripts/s4-$TYPE.case
90 else
91 casefile=scripts/s4-default.case
92 fi
93 m4 -P -I scripts -D_SHELL_=`which sh` \
94 -D__NOEDIT__="DO NOT EDIT THIS FILE MANUALLY -> scripts/s4-*.case" \
95 -D_CASE_=$casefile s4.cgi.m4 > index.cgi && chmod +x index.cgi
96 if [ "$wrap" ]; then
97 mv -f index.cgi s4.cgi
98 fi
99 (echo "ADMIN=$ADMIN"
100 echo "S4TYPE=$TYPE"
101 [ "$guest" ] && echo "guestonlymode=1") >> s4-config.sh
102 sqlite3 -cmd "pragma FOREIGH_KEYS=ON" $db \
103 "REPLACE INTO user VALUES('$ADMIN');"
104 dbsetbyid user "$ADMIN" pswd "`echo $dp of $ADMIN|mypwhash`"
105 cat > .htaccess <<-EOF
106 DirectoryIndex index.cgi
107 AddHandler cgi-script .cgi
108 EOF
109 if [ -n "$wrap" ]; then
110 type cc >/dev/null 2>&1 && CC=cc
111 ${CC:-gcc} -o index.cgi pwrap.c \
112 && chmod u+s index.cgi \
113 && rc=0
114 fi
115 else
116 echo Calling s4-init.sh 'FAILED!!'
117 fi
118 else
119 echo Failed
120 fi 1>&2
122 exit ${rc:-5}