summaryrefslogtreecommitdiffstats
path: root/pki/dogtag/scripts/remove_ds_instance
blob: d81326c63f9e55346d6daa6b2397fc3ea9cd7943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh 
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
# 
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# 
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#

##  Always switch into this base directory
##  prior to script execution so that all
##  of its output is written to this directory

cd `dirname $0`


##
##  This script MUST be run as root!
##

ROOTUID=0

OS=`uname`
if [ "${OS}" = "Linux" ] ; then
    MY_EUID=`/usr/bin/id -u`
    MY_UID=`/usr/bin/id -ur`
    USERNAME=`/usr/bin/id -un`
else
    printf "ERROR:  Unsupported operating system '${OS}'!\n"
    exit 255
fi

if [ "${MY_UID}"  != "${ROOTUID}" ] &&
   [ "${MY_EUID}" != "${ROOTUID}" ] ; then
    printf "ERROR:  The '$0' script must be run as root!\n"
    exit 255
fi


##  First, check for the existence of a directory server on this machine.
if [ ! -e /etc/init.d/dirsrv ]; then
    printf "The Directory Server package does NOT exist on this machine!\n"
    exit 255
fi


##  Second, check for the existence of a directory server administration server 
##  on this machine.
if [ -e /usr/sbin/ds_removal ]    &&
   [ -d /usr/lib/dirsrv/cgi-bin ] ||
   [ -d /usr/lib64/dirsrv/cgi-bin ]; then
    printf "This machine contains a Directory Server Administration\n" 
    printf "Server which means that Directory Server instances may\n"
    printf "have been registered with the Administration Server.\n\n"
    while :
    do
        printf "Do you wish to use the '/usr/sbin/ds_removal' tool\n"
        printf "instead of '$0'?  [yn]  "
        read ANSWER
        printf "\n"
        if [ "${ANSWER}" = "Y" ] ||
           [ "${ANSWER}" = "y" ] ; then
            printf "\n"
            printf "Please RUN the '/usr/sbin/ds_removal' tool to remove\n"
            printf "the desired DS instance instead of '$0'.\n\n"
            exit 255
        elif [ "${ANSWER}" = "N" ] ||
             [ "${ANSWER}" = "n" ] ; then
            printf "\n"
            break
        else
            continue
        fi
    done
fi


Usage()
{
    printf "Usage:  $0 -s server_id\n"
    printf "        server_id:  Directory server identifier; slapd-<server_id>\n"
}

error=""
server_id=""
ds_server=""
ds_remove_cgi=""

while [ "$1" != "" ]
do
    if [ "$1" = "-s" ]; then
        shift
        server_id=$1
        shift
    elif [ "$1" = "-h" -o "$1" = "-H" -o "$1" = "--help" ]; then
        Usage
        exit 0
    else
        printf "ERROR:  Option '$1' is not supported!\n"
        Usage
        exit 1
    fi
done

if [ "$server_id" = "" ]; then
    error="Directory Server identifier is missing!"
else
    if [ -d "/usr/lib/dirsrv/slapd-${server_id}" ]; then
        ds_server="/usr/lib/dirsrv/slapd-${server_id}"
        ds_remove_cgi="./ds_remove_cgi_32"
    elif [ -d "/usr/lib64/dirsrv/slapd-${server_id}" ]; then
        ds_server="/usr/lib64/dirsrv/slapd-${server_id}"
        ds_remove_cgi="./ds_remove_cgi_64"
    else
        error="Directory server identifier 'slapd-${server_id}' does not exist!"
    fi
fi

if [ "$error" != "" ]; then
    printf "ERROR:  ${error}\n"
    Usage
    exit 1
fi

QUERY_STRING="InstanceName=slapd-${server_id}"; export QUERY_STRING
REQUEST_METHOD=GET; export REQUEST_METHOD

if [ -c /dev/null ]; then
    NULL=/dev/null
else
    NULL=/tmp/ds_remove.out
fi

${ds_remove_cgi} > $NULL << EOF
EOF

if [ -d "${ds_server}" ]; then
    printf "FAILED to remove '${ds_server}'!\n"
else
    printf "Successfully removed '${ds_server}'!\n"
    printf "NOTE:  Copies of your security databases have been saved\n"
    printf "       in '/etc/dirsrv/slapd-${server_id}.removed'!\n"
fi

exit $?