Last change
on this file since 844 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
|
Rev | Line | |
---|
[765] | 1 | #!/bin/bash |
---|
| 2 | set -e |
---|
| 3 | |
---|
| 4 | printf "Host name: " >&2 |
---|
| 5 | if [ "$1" ]; then |
---|
| 6 | host="$1"; shift |
---|
| 7 | echo "$host" |
---|
| 8 | else |
---|
| 9 | read host |
---|
| 10 | fi |
---|
| 11 | |
---|
| 12 | if ! grep -Fq "." <<< "$host"; then host=$host.mit.edu; fi |
---|
| 13 | |
---|
| 14 | printf "User: " >&2 |
---|
| 15 | if [ "$1" ]; then |
---|
| 16 | user="$1"; shift |
---|
| 17 | echo "$user" |
---|
| 18 | else |
---|
| 19 | read user |
---|
| 20 | fi |
---|
| 21 | |
---|
[844] | 22 | pw=$(perl -e '$, = ":"; print getpwnam($ARGV[0]);' -- "$user") |
---|
[765] | 23 | if [ $? -ne 0 ]; then |
---|
| 24 | echo "User not found." >&2 |
---|
| 25 | exit $? |
---|
| 26 | fi |
---|
[844] | 27 | IFS=: read user x uid gid x x x home x <<< "$pw" |
---|
[765] | 28 | |
---|
[833] | 29 | user_dn=$(ldapsearch -LLL -x -b ou=People,dc=scripts,dc=mit,dc=edu "(uid=$user)" dn | perl -0pe 's/\n //g; s/^dn: //') |
---|
[827] | 30 | |
---|
[765] | 31 | printf "Docroot: $home/web_scripts" >&2 |
---|
| 32 | read subdir |
---|
| 33 | |
---|
| 34 | tmpfile=$(mktemp -t vhostadd.XXXXXX) || exit $? |
---|
| 35 | trap 'rm -f "$tmpfile"' EXIT |
---|
| 36 | |
---|
| 37 | cat <<EOF > "$tmpfile" |
---|
| 38 | dn: apacheServerName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu |
---|
| 39 | objectClass: apacheConfig |
---|
| 40 | objectClass: top |
---|
| 41 | apacheServerName: $host |
---|
| 42 | EOF |
---|
| 43 | |
---|
| 44 | if [ "${host%mit.edu}" != "$host" ]; then |
---|
| 45 | cat <<EOF >> "$tmpfile" |
---|
| 46 | apacheServerAlias: ${host%.mit.edu} |
---|
| 47 | EOF |
---|
| 48 | fi |
---|
| 49 | |
---|
| 50 | cat <<EOF >> "$tmpfile" |
---|
| 51 | apacheDocumentRoot: $home/web_scripts$subdir |
---|
| 52 | apacheSuexecUid: $uid |
---|
| 53 | apacheSuexecGid: $gid |
---|
[827] | 54 | |
---|
| 55 | dn: scriptsVhostName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu |
---|
| 56 | objectClass: scriptsVhost |
---|
| 57 | objectClass: top |
---|
| 58 | scriptsVhostName: $host |
---|
[765] | 59 | EOF |
---|
| 60 | |
---|
[827] | 61 | if [ "${host%mit.edu}" != "$host" ]; then |
---|
| 62 | cat <<EOF >> "$tmpfile" |
---|
| 63 | scriptsVhostAlias: ${host%.mit.edu} |
---|
| 64 | EOF |
---|
| 65 | fi |
---|
| 66 | |
---|
| 67 | cat <<EOF >> "$tmpfile" |
---|
| 68 | scriptsVhostAccount: $user_dn |
---|
| 69 | scriptsVhostDirectory: ${subdir#/} |
---|
| 70 | EOF |
---|
| 71 | |
---|
[765] | 72 | exec ldapvi --add --in "$tmpfile" |
---|
Note: See
TracBrowser
for help on using the repository browser.