s4

view s4-start.sh @ 538:1c784b64d9f0

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