forked from bggo/Zmbkpose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·196 lines (172 loc) · 5.85 KB
/
install.sh
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# install.sh
# This script installs zmbkpose on a ZCS server. It also makes sure
# the script's dependencies are present.
#
# LIMITATIONS: This script assumes you're doing a local install and requires the
# user zimbra to exist on your server. While not strictly necessary this is
# enforced due to the way the current zmbkpose script works.
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
# Zmbkpose Defaults - Where the script will be placed and look for its settings
OSE_SRC="/usr/local/bin"
OSE_CONF="/etc/zmbkpose"
# Zimbra Defaults - Change these if you compiled zimbra yourself with different
# settings
ZIMBRA_USER="zimbra"
ZIMBRA_DIR="/opt/zimbra"
ZIMBRA_BKPDIR="" # Leave empty to autodetect
ZIMBRA_HOSTNAME="" # Leave empty to autodetect
ZIMBRA_ADDRESS="" # Leave empty to autodetect
ZIMBRA_LDAPPASS="" # Leave empty to autodetect
# Exit codes
ERR_OK="0" # No error (normal exit)
ERR_NOBKPDIR="1" # No backup directory could be found
ERR_NOROOT="2" # Script was run without root privileges
ERR_DEPNOTFOUND="3" # Missing dependency
# Try to guess missing settings as best as we can
test -z $ZIMBRA_HOSTNAME && ZIMBRA_HOSTNAME=`su - zimbra -c zmhostname`
test -z $ZIMBRA_ADDRESS && ZIMBRA_ADDRESS=`grep $ZIMBRA_HOSTNAME /etc/hosts|awk '{print $1}'`
test -z $ZIMBRA_LDAPPASS && ZIMBRA_LDAPPASS=`su - zimbra -c "zmlocalconfig -s zimbra_ldap_password"|awk '{print $3}'`
if [ -z $ZIMBRA_BKPDIR ]; then
test -d $ZIMBRA_DIR/backup && ZIMBRA_BKPDIR=$ZIMBRA_DIR/backup
test -d /backup && ZIMBRA_BKPDIR=/backup
test -d /opt/backup && ZIMBRA_BKPDIR=/opt/backup
fi
if [ -z $ZIMBRA_BKPDIR ]; then
echo "No backup directory could be found! Please edit this script and declare it manually."
exit $ERR_NOBKPDIR
fi
clear
echo "This will install zmbkpose, a script aimed at creating backups for ZCS Community Edition."
read -p "What is the password for Zimbra's \"admin\" user? " ZIMBRA_ADMPASS
echo ""
echo "Here is a Summary of your settings:"
echo ""
echo "Zimbra User: $ZIMBRA_USER"
echo "Zimbra Hostname: $ZIMBRA_HOSTNAME"
echo "Zimbra IP Address: $ZIMBRA_ADDRESS"
echo "Zimbra LDAP Password: $ZIMBRA_LDAPPASS"
echo "Zimbra Admin Password: $ZIMBRA_ADMPASS"
echo "Zimbra Install Directory: $ZIMBRA_DIR"
echo "Zimbra Backup Directory: $ZIMBRA_BKPDIR"
echo "Zmbkpose Install Directory: $OSE_SRC"
echo "Zmbkpose Settings Directory: $OSE_CONF"
echo ""
echo "Press ENTER to continue or CTRL+C to cancel."
read tmp
# Check if we have root before doing anything
if [ $(id -u) -ne 0 ]; then
echo "You need root privileges to install zmbkpose"
exit $ERR_NOROOT
fi
# Check for missing installer files
# TODO: MD5 check of the files
printf "Checking installer integrity... "
STATUS=0
MYDIR=`dirname $0`
test -f $MYDIR/src/zmbkpose || STATUS=$ERR_MISSINGFILES
test -f $MYDIR/etc/zmbkpose.conf || STATUS=$ERR_MISSINGFILES
if ! [ $STATUS = 0 ]; then
printf '[ERROR]\n'
echo "Some files are missing. Please re-download the Zmbkpose installer."
exit $STATUS
else
printf '[OK]\n'
fi
# Check for missing dependencies
STATUS=0
echo "Checking system for dependencies..."
## Zimbra Mailbox
printf " ZCS Mailbox Control... "
su - $ZIMBRA_USER -c "which zmmailboxdctl" > /dev/null 2>&1
if [ $? = 0 ]; then
printf "[OK]\n"
else
printf "[NOT FOUND]\n"
STATUS=$ERR_DEPNOTFOUND
fi
## LDAP utils
printf " ldapsearch... "
su - $ZIMBRA_USER -c "which ldapsearch" > /dev/null 2>&1
if [ $? = 0 ]; then
printf "[OK]\n"
else
printf "[NOT FOUND]\n"
STATUS=$ERR_DEPNOTFOUND
fi
## Curl
printf " curl... "
su - $ZIMBRA_USER -c "which curl" > /dev/null 2>&1
if [ $? = 0 ]; then
printf "[OK]\n"
else
printf "[NOT FOUND]\n"
STATUS=$ERR_DEPNOTFOUND
fi
## mktemp
printf " mktemp... "
su - $ZIMBRA_USER -c "which mktemp" > /dev/null 2>&1
if [ $? = 0 ]; then
printf "[OK]\n"
else
printf "[NOT FOUND]\n"
STATUS=$ERR_DEPNOTFOUND
fi
## date
printf " date... "
su - $ZIMBRA_USER -c "which date" > /dev/null 2>&1
if [ $? = 0 ]; then
printf "[OK]\n"
else
printf "[NOT FOUND]\n"
STATUS=$ERR_DEPNOTFOUND
fi
## egrep
printf " egrep... "
su - $ZIMBRA_USER -c "which egrep" > /dev/null 2>&1
if [ $? = 0 ]; then
printf "[OK]\n"
else
printf "[NOT FOUND]\n"
STATUS=$ERR_DEPNOTFOUND
fi
if ! [ $STATUS = 0 ]; then
echo ""
echo "You're missing some dependencies OR they are not on $ZIMBRA_USER's PATH."
echo "Please correct the problem and run the installer again."
exit $STATUS
fi
# Done checking deps
echo "Installing..."
# Create directories if needed
test -d $OSE_CONF || mkdir -p $OSE_CONF
test -d $OSE_SRC || mkdir -p $OSE_SRC
# Copy files
install -o $ZIMBRA_USER -m 700 $MYDIR/src/zmbkpose $OSE_SRC
install --backup=numbered -o $ZIMBRA_USER -m 600 $MYDIR/etc/zmbkpose.conf $OSE_CONF
# Add custom settings
sed -i "s|{ZIMBRA_BKPDIR}|${ZIMBRA_BKPDIR}|g" $OSE_CONF/zmbkpose.conf
sed -i "s|{ZIMBRA_ADDRESS}|${ZIMBRA_ADDRESS}|g" $OSE_CONF/zmbkpose.conf
sed -i "s|{ZIMBRA_ADMINPASS}|${ZIMBRA_ADMPASS}|g" $OSE_CONF/zmbkpose.conf
sed -i "s|{ZIMBRA_LDAPPASS}|${ZIMBRA_LDAPPASS}|g" $OSE_CONF/zmbkpose.conf
# Fix backup dir permissions (owner MUST be $ZIMBRA_USER)
chown $ZIMBRA_USER $ZIMBRA_BKPDIR
# We're done!
read -p "Install completed. Do you want to display the README file? (Y/n)" tmp
case "$tmp" in
y|Y|Yes|"") less $MYDIR/README;;
*) echo "Done!";;
esac
exit $ERR_OK