]> git.ipfire.org Git - people/ms/ipfire-dit.git/blame - install.sh
Initial import.
[people/ms/ipfire-dit.git] / install.sh
CommitLineData
741b05c6
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 IPFire Development Team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22BASEDIR="/usr/share/ipfire-dit"
23TEMPLATE="${BASEDIR}/template.ldif"
24
25DOMAIN=${HOSTNAME#*.}
26PASSWORD=
27
28function parse_cli() {
29 while [ $# -gt 0 ]; do
30 case "${1}" in
31 -p)
32 PASSWORD=${2}
33 shift
34 ;;
35 *)
36 DOMAIN=${1}
37 ;;
38 esac
39 shift
40 done
41
42 while [ -z "${PASSWORD}" ]; do
43 echo -n "Enter password: "
44 read -s PASSWORD
45 echo
46 done
47
48 # Check for valid input data.
49
50 if [ ${#PASSWORD} -lt 8 ]; then
51 echo "Using weak password. Must at least have 8 characters!" >&2
52 exit 1
53 fi
54
55 if [ -z "${DOMAIN}" ]; then
56 echo "Domain is empty." >&2
57 exit 1
58 fi
59
60 # XXX check domain for invalid characters
61}
62
63function substitude_ldif() {
64 local output=${1}
65
66 local suffix bit dc
67 for bit in ${DOMAIN//./ }; do
68 if [ -n "${suffix}" ]; then
69 suffix="${suffix},dc=${bit}"
70 else
71 dc="${bit}"
72 suffix="dc=${bit}"
73 fi
74 done
75
76 sed \
77 -e "s/@DC@/${dc}/g" \
78 -e "s/@SUFFIX@/${suffix}/g" \
79 < ${TEMPLATE} > ${output}
80}
81
82function load_database() {
83 local new_ldif=$(mktemp)
84 trap "rm -f ${new_ldif}" EXIT KILL TERM
85
86 substitude_ldif ${new_ldif}
87
88 slapadd < ${new_ldif}
89}
90
91function generate_pwhash() {
92 local password="${PASSWORD}"
93
94 slappasswd -h "{SSHA}" -s "${password}"
95}
96
97# Hello to this wonderful script.
98# Firstly, let's see what we need to do.
99parse_cli $@
100
101# Now, we got all the information we need, we
102# can load the database.
103load_database