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

Last change on this file since 2740 was 2735, checked in by andersk, 8 years ago
Replace empty scriptsVhostPath with ‘.’ Trac: #167
  • Property svn:executable set to *
File size: 1.6 KB
RevLine 
[765]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
[892]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;')
[765]32
33printf "Docroot: $home/web_scripts" >&2
34read subdir
[2735]35subdir=${subdir%/}
36docroot=$home/web_scripts$subdir
37path=${subdir#/}
38path=${path:-.}
[765]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"
[2735]57apacheDocumentRoot: $docroot
[765]58apacheSuexecUid: $uid
59apacheSuexecGid: $gid
[827]60
61dn: scriptsVhostName=$host,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
62objectClass: scriptsVhost
63objectClass: top
64scriptsVhostName: $host
[765]65EOF
66
[827]67if [ "${host%mit.edu}" != "$host" ]; then
68    cat <<EOF >> "$tmpfile"
69scriptsVhostAlias: ${host%.mit.edu}
70EOF
71fi
72
73cat <<EOF >> "$tmpfile"
74scriptsVhostAccount: $user_dn
[2735]75scriptsVhostDirectory: $path
[827]76EOF
77
[765]78exec ldapvi --add --in "$tmpfile"
Note: See TracBrowser for help on using the repository browser.