setup-acf.in 2.16 KB
Newer Older
1 2
#!/bin/sh

3
PROGRAM=setup-acf
4
VERSION=@VERSION@
5

6 7
PREFIX=
. $PREFIX/lib/libalpine.sh
8

9
usage() {
10
	echo "$PROGRAM [-ahn] [-e email] [-l address] [PACKAGE...]"
11 12
	exit 0;
}
13

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

16
while getopts "ae:hl:n" opt ; do
17
	case $opt in
Natanael Copa's avatar
Natanael Copa committed
18
		a) pkgs=$(apk search --quiet --exact 'acf-*');;
19
		e) EMAIL="$OPTARG";;
20
		h) usage;;
Natanael Copa's avatar
Natanael Copa committed
21
		l) address="$OPTARG";;
22
		n) create_passwd=no;;
23 24 25
		*) usage;;
	esac
done
26
shift $(expr $OPTIND - 1)
27 28 29 30 31 32

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

33
# install packages
34 35
apk add mini_httpd $pkgs || exit 1

36
if [ "$create_passwd" != "no" ]; then
37
	mkdir -p /etc/acf
38 39 40
	if [ -f /etc/acf/passwd ]; then
		mv /etc/acf/passwd /etc/acf/passwd.backup
	fi
41
	echo "root:x:Admin account:ADMIN" >/etc/acf/passwd
42
	chmod 600 /etc/acf/passwd
43
	acfpasswd -s root
44 45
fi

46
# setup mini_httpd and start it
47 48 49
if [ -d /var/www/localhost/htdocs ]; then
	mv /var/www/localhost/htdocs /var/www/localhost/htdocs.old
fi
50 51
mkdir -p /var/www/localhost/
ln -s /usr/share/acf/www/ /var/www/localhost/htdocs
52
lbu add /var/www/localhost/htdocs
53 54 55


SSLDIR=/etc/ssl/mini_httpd
56
SSLCNF=$SSLDIR/mini_httpd.cnf
57 58 59 60 61 62 63
KEYFILE=$SSLDIR/server.key
CRTFILE=$SSLDIR/server.crt
PEMFILE=$SSLDIR/server.pem

if [ -f $PEMFILE ]; then
	echo "$PEMFILE already exist."
else
64
	mkdir -p $SSLDIR
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
	cat >$SSLCNF <<-__EOF__
		[ req ]
		default_bits = 1024
		encrypt_key = yes
		distinguished_name = req_dn
		x509_extensions = cert_type
		prompt = no

		[ req_dn ]
		OU=HTTPS server
		CN=$(hostname -f || hostname)
		emailAddress=${EMAIL:-postmaster@example.com}

		[ cert_type ]
		nsCertType = server
	__EOF__
81 82
	echo "Generating certificates for HTTPS..."
	openssl genrsa 2048 > $KEYFILE
83 84
	openssl req -new -x509 -nodes -sha1 -days 3650 -key $KEYFILE \
		-config $SSLCNF > $CRTFILE
85 86 87 88 89
	cat $KEYFILE >> $CRTFILE
	rm $KEYFILE
	mv $CRTFILE $PEMFILE
fi

90 91 92 93 94 95 96 97 98
cat >/etc/mini_httpd/mini_httpd.conf <<-__EOF__
	nochroot
	dir=/var/www/localhost/htdocs
	user=nobody
	cgipat=cgi-bin**
	certfile=$PEMFILE
	port=443
	ssl
__EOF__
Natanael Copa's avatar
Natanael Copa committed
99
if [ -n "$address" ]; then
100
	echo "host=$address" >> /etc/mini_httpd/mini_httpd.conf
Natanael Copa's avatar
Natanael Copa committed
101
fi
102

103 104
rc-update -q add mini_httpd default
/etc/init.d/mini_httpd restart
105 106
# force update of dependency cache
rc-update -q --update
107