source: trunk/locker/sbin/vhostadd @ 2735

Last change on this file since 2735 was 2735, checked in by andersk, 8 years ago
Replace empty scriptsVhostPath with ‘.’ Trac: #167
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/bin/bash
2set -e
3
4printf "Host name: " >&2
5if [ "$1" ]; then
6    host="$1"; shift
7    echo "$host"
8else
9    read host
10fi
11
12if ! grep -Fq "." <<< "$host"; then host=$host.mit.edu; fi
13
14printf "User: " >&2
15if [ "$1" ]; then
16    user="$1"; shift
17    echo "$user"
18else
19    read user
20fi
21
22while read attr value; do
23    echo "$attr" "$value"
24    case "$attr" in
25        dn:) user_dn=$value;;
26        uid:) user=$value;;
27        uidNumber:) uid=$value;;
28        gidNumber:) gid=$value;;
29        homeDirectory:) home=$value;;
30    esac
31done < <(ldapsearch -LLL -x -h scripts.mit.edu -b ou=People,dc=scripts,dc=mit,dc=edu "(uid=$user)" dn uid uidNumber gidNumber homeDirectory | perl -0pe 's/\n //g;')
32
33printf "Docroot: $home/web_scripts" >&2
34read subdir
35subdir=${subdir%/}
36docroot=$home/web_scripts$subdir
37path=${subdir#/}
38path=${path:-.}
39
40tmpfile=$(mktemp -t vhostadd.XXXXXX) || exit $?
41trap 'rm -f "$tmpfile"' EXIT
42
43cat <<EOF > "$tmpfile"
44dn: apacheServerName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
45objectClass: apacheConfig
46objectClass: top
47apacheServerName: $host
48EOF
49
50if [ "${host%mit.edu}" != "$host" ]; then
51    cat <<EOF >> "$tmpfile"
52apacheServerAlias: ${host%.mit.edu}
53EOF
54fi
55
56cat <<EOF >> "$tmpfile"
57apacheDocumentRoot: $docroot
58apacheSuexecUid: $uid
59apacheSuexecGid: $gid
60
61dn: scriptsVhostName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
62objectClass: scriptsVhost
63objectClass: top
64scriptsVhostName: $host
65EOF
66
67if [ "${host%mit.edu}" != "$host" ]; then
68    cat <<EOF >> "$tmpfile"
69scriptsVhostAlias: ${host%.mit.edu}
70EOF
71fi
72
73cat <<EOF >> "$tmpfile"
74scriptsVhostAccount: $user_dn
75scriptsVhostDirectory: $path
76EOF
77
78exec ldapvi --bind sasl -Y GSSAPI -h scripts5.mit.edu -b dc=scripts,dc=mit,dc=edu --add --in "$tmpfile"
Note: See TracBrowser for help on using the repository browser.