setup-webconf.in 1.9 KB
Newer Older
Natanael Copa's avatar
Natanael Copa committed
1 2
#!/bin/sh

3
PROGRAM=setup-acf
4
VERSION=@VERSION@
Natanael Copa's avatar
Natanael Copa committed
5

6 7
PREFIX=
. $PREFIX/lib/libalpine.sh
Natanael Copa's avatar
Natanael Copa committed
8

9
usage() {
10
	echo "$PROGRAM [-ah] [-l address] [PACKAGE...]"
11 12
	exit 0;
}
Natanael Copa's avatar
Natanael Copa committed
13

14
pkgs="acf-core acf-alpine-baselayout acf-apk-tools"
15

16
while getopts "ahl:" opt ; do
17 18 19
	case $opt in
		a) pkgs=`apk_fetch -l | grep ^acf-`;;
		h) usage;;
Natanael Copa's avatar
Natanael Copa committed
20
		l) address="$OPTARG";;
21 22 23 24 25 26 27 28 29 30 31 32 33 34
		*) usage;;
	esac
done
shift `expr $OPTIND - 1`

while [ $# -gt 0 ]; do
	pkgs="$pkgs acf-$1"
	shift
done

# install packages 
apk_add mini_httpd $pkgs || exit 1

# setup mini_httpd and start it
35 36 37
if [ -d /var/www/localhost/htdocs ]; then
	mv /var/www/localhost/htdocs /var/www/localhost/htdocs.old
fi
38 39
mkdir -p /var/www/localhost/
ln -s /usr/share/acf/www/ /var/www/localhost/htdocs
40
lbu add /var/www/localhost/htdocs
41 42 43


SSLDIR=/etc/ssl/mini_httpd
44
SSLCNF=$SSLDIR/mini_httpd.cnf
45 46 47 48 49 50 51
KEYFILE=$SSLDIR/server.key
CRTFILE=$SSLDIR/server.crt
PEMFILE=$SSLDIR/server.pem

if [ -f $PEMFILE ]; then
	echo "$PEMFILE already exist."
else
52
	mkdir -p $SSLDIR
Natanael Copa's avatar
Natanael Copa committed
53
cat >$SSLCNF <<EOF
54 55 56 57 58 59 60 61 62
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
OU=HTTPS server
63
CN=$(hostname)
64 65 66 67 68
emailAddress=postmaster@example.com

[ cert_type ]
nsCertType = server
EOF
69 70
	echo "Generating certificates for HTTPS..."
	openssl genrsa 2048 > $KEYFILE
71 72
	openssl req -new -x509 -nodes -sha1 -days 3650 -key $KEYFILE \
		-config $SSLCNF > $CRTFILE
73 74 75 76 77
	cat $KEYFILE >> $CRTFILE
	rm $KEYFILE
	mv $CRTFILE $PEMFILE
fi

Natanael Copa's avatar
Natanael Copa committed
78
cat >/etc/mini_httpd.conf <<EOF
Natanael Copa's avatar
Natanael Copa committed
79
nochroot
80
dir=/var/www/localhost/htdocs
81
user=nobody
Natanael Copa's avatar
Natanael Copa committed
82 83
logfile=/var/log/mini_httpd.log
cgipat=cgi-bin**
84 85 86 87
certfile=$PEMFILE
port=443
ssl
EOF
Natanael Copa's avatar
Natanael Copa committed
88 89 90
if [ -n "$address" ]; then
	echo "host=$address" >> /etc/mini_httpd.conf
fi
Natanael Copa's avatar
Natanael Copa committed
91

Natanael Copa's avatar
Natanael Copa committed
92
cat >/etc/conf.d/mini_httpd <<EOF
93 94
MINI_HTTPD_OPTS="-C /etc/mini_httpd.conf"
MINI_HTTPD_DOCROOT=/var/www/localhost/htdocs
Natanael Copa's avatar
Natanael Copa committed
95 96
EOF

97
pidof mini_httpd >/dev/null && /etc/init.d/mini_httpd stop
98
rc-update add mini_httpd default
Natanael Copa's avatar
Natanael Copa committed
99
/etc/init.d/mini_httpd start
100