source: server/common/oursrc/accountadm/vhostadd @ 875

Last change on this file since 875 was 844, checked in by andersk, 16 years ago
`getent passwd 2011` doesn’t work.
  • 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
22pw=$(perl -e '$, = ":"; print getpwnam($ARGV[0]);' -- "$user")
23if [ $? -ne 0 ]; then
24    echo "User not found." >&2
25    exit $?
26fi
27IFS=: read user x uid gid x x x home x <<< "$pw"
28
29user_dn=$(ldapsearch -LLL -x -b ou=People,dc=scripts,dc=mit,dc=edu "(uid=$user)" dn | perl -0pe 's/\n //g; s/^dn: //')
30
31printf "Docroot: $home/web_scripts" >&2
32read subdir
33
34tmpfile=$(mktemp -t vhostadd.XXXXXX) || exit $?
35trap 'rm -f "$tmpfile"' EXIT
36
37cat <<EOF > "$tmpfile"
38dn: apacheServerName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
39objectClass: apacheConfig
40objectClass: top
41apacheServerName: $host
42EOF
43
44if [ "${host%mit.edu}" != "$host" ]; then
45    cat <<EOF >> "$tmpfile"
46apacheServerAlias: ${host%.mit.edu}
47EOF
48fi
49
50cat <<EOF >> "$tmpfile"
51apacheDocumentRoot: $home/web_scripts$subdir
52apacheSuexecUid: $uid
53apacheSuexecGid: $gid
54
55dn: scriptsVhostName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
56objectClass: scriptsVhost
57objectClass: top
58scriptsVhostName: $host
59EOF
60
61if [ "${host%mit.edu}" != "$host" ]; then
62    cat <<EOF >> "$tmpfile"
63scriptsVhostAlias: ${host%.mit.edu}
64EOF
65fi
66
67cat <<EOF >> "$tmpfile"
68scriptsVhostAccount: $user_dn
69scriptsVhostDirectory: ${subdir#/}
70EOF
71
72exec ldapvi --add --in "$tmpfile"
Note: See TracBrowser for help on using the repository browser.