| Last change
                  on this file since 2739 was
                  2735,
                  checked in by andersk, 10 years ago | 
        
          | Replace empty scriptsVhostPath with ‘.’
Trac: #167 | 
        
          | 
              
                  Property svn:executable set to
                  * | 
        | File size:
            1.6 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 |  | 
|---|
| [892] | 22 | while 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 | 
|---|
|  | 31 | done < <(ldapsearch -LLL -x -b ou=People,dc=scripts,dc=mit,dc=edu "(uid=$user)" dn uid uidNumber gidNumber homeDirectory | perl -0pe 's/\n //g;') | 
|---|
| [765] | 32 |  | 
|---|
|  | 33 | printf "Docroot: $home/web_scripts" >&2 | 
|---|
|  | 34 | read subdir | 
|---|
| [2735] | 35 | subdir=${subdir%/} | 
|---|
|  | 36 | docroot=$home/web_scripts$subdir | 
|---|
|  | 37 | path=${subdir#/} | 
|---|
|  | 38 | path=${path:-.} | 
|---|
| [765] | 39 |  | 
|---|
|  | 40 | tmpfile=$(mktemp -t vhostadd.XXXXXX) || exit $? | 
|---|
|  | 41 | trap 'rm -f "$tmpfile"' EXIT | 
|---|
|  | 42 |  | 
|---|
|  | 43 | cat <<EOF > "$tmpfile" | 
|---|
|  | 44 | dn: apacheServerName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu | 
|---|
|  | 45 | objectClass: apacheConfig | 
|---|
|  | 46 | objectClass: top | 
|---|
|  | 47 | apacheServerName: $host | 
|---|
|  | 48 | EOF | 
|---|
|  | 49 |  | 
|---|
|  | 50 | if [ "${host%mit.edu}" != "$host" ]; then | 
|---|
|  | 51 | cat <<EOF >> "$tmpfile" | 
|---|
|  | 52 | apacheServerAlias: ${host%.mit.edu} | 
|---|
|  | 53 | EOF | 
|---|
|  | 54 | fi | 
|---|
|  | 55 |  | 
|---|
|  | 56 | cat <<EOF >> "$tmpfile" | 
|---|
| [2735] | 57 | apacheDocumentRoot: $docroot | 
|---|
| [765] | 58 | apacheSuexecUid: $uid | 
|---|
|  | 59 | apacheSuexecGid: $gid | 
|---|
| [827] | 60 |  | 
|---|
|  | 61 | dn: scriptsVhostName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu | 
|---|
|  | 62 | objectClass: scriptsVhost | 
|---|
|  | 63 | objectClass: top | 
|---|
|  | 64 | scriptsVhostName: $host | 
|---|
| [765] | 65 | EOF | 
|---|
|  | 66 |  | 
|---|
| [827] | 67 | if [ "${host%mit.edu}" != "$host" ]; then | 
|---|
|  | 68 | cat <<EOF >> "$tmpfile" | 
|---|
|  | 69 | scriptsVhostAlias: ${host%.mit.edu} | 
|---|
|  | 70 | EOF | 
|---|
|  | 71 | fi | 
|---|
|  | 72 |  | 
|---|
|  | 73 | cat <<EOF >> "$tmpfile" | 
|---|
|  | 74 | scriptsVhostAccount: $user_dn | 
|---|
| [2735] | 75 | scriptsVhostDirectory: $path | 
|---|
| [827] | 76 | EOF | 
|---|
|  | 77 |  | 
|---|
| [765] | 78 | exec ldapvi --add --in "$tmpfile" | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.