source: trunk/server/common/oursrc/accountadm/vhostadd @ 2331

Last change on this file since 2331 was 892, checked in by andersk, 16 years ago
Avoid getpwnam in vhostadd so that it works from outside scripts.
  • Property svn:executable set to *
File size: 1.5 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 -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
35
36tmpfile=$(mktemp -t vhostadd.XXXXXX) || exit $?
37trap 'rm -f "$tmpfile"' EXIT
38
39cat <<EOF > "$tmpfile"
40dn: apacheServerName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
41objectClass: apacheConfig
42objectClass: top
43apacheServerName: $host
44EOF
45
46if [ "${host%mit.edu}" != "$host" ]; then
47    cat <<EOF >> "$tmpfile"
48apacheServerAlias: ${host%.mit.edu}
49EOF
50fi
51
52cat <<EOF >> "$tmpfile"
53apacheDocumentRoot: $home/web_scripts$subdir
54apacheSuexecUid: $uid
55apacheSuexecGid: $gid
56
57dn: scriptsVhostName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
58objectClass: scriptsVhost
59objectClass: top
60scriptsVhostName: $host
61EOF
62
63if [ "${host%mit.edu}" != "$host" ]; then
64    cat <<EOF >> "$tmpfile"
65scriptsVhostAlias: ${host%.mit.edu}
66EOF
67fi
68
69cat <<EOF >> "$tmpfile"
70scriptsVhostAccount: $user_dn
71scriptsVhostDirectory: ${subdir#/}
72EOF
73
74exec ldapvi --add --in "$tmpfile"
Note: See TracBrowser for help on using the repository browser.