-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrh-install.sh
289 lines (218 loc) · 7.28 KB
/
rh-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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/sh
#
# AvantFAX install script for RH/CentOS/Fedora
# This script will configure /etc/sudoers and the HylaFAX hyla.conf, config, config.<devid> files
# Only run once
#
# CHECK IF HYLAFAX IS INSTALLED
echo "Checking for HylaFAX installation"
hyla=`which sendfax`
if [ "$?" -ne "0" ]; then
echo You must install and configure HylaFAX first
exit
fi
. rh-prefs.txt
if [ -z "$ROOTMYSQLPWD" -a -x /etc/init.d/mysqld ]; then
echo "Warning: ROOTMYSQLPWD is not set but MySQL server is installed"
echo "Pausing 10 seconds to give time to set ROOTMYSQL in rh-prefs.txt"
echo "Hit Ctrl-C to quit"
sleep 10
fi
# INSTALL REQUIRED PACKAGES
RPMS="$RPMS httpd"
RPMS="$RPMS php"
RPMS="$RPMS php-pear"
RPMS="$RPMS php-mysql"
RPMS="$RPMS php-mbstring"
RPMS="$RPMS mysql-server"
RPMS="$RPMS netpbm-progs"
#RPMS="$RPMS php-pecl-Fileinfo"
RPMS="$RPMS ImageMagick-devel"
RPMS="$RPMS libungif"
RPMS="$RPMS libpng"
RPMS="$RPMS sudo"
RPMS="$RPMS libtiff"
RPMS="$RPMS ghostscript"
RPMS="$RPMS ghostscript-fonts"
RPMS="$RPMS ImageMagick"
RPMS="$RPMS vixie-cron"
RPMS="$RPMS rsync"
# Added to get Pear packages from RPM, *NOT* from Pear downloads
RPMS="$RPMS php-pear-Mail-Mime"
RPMS="$RPMS php-pear-Mail"
RPMS="$RPMS php-pear-Net-SMTP"
RPMS="$RPMS php-pear-MDB2-Driver-mysql"
yum -y install $RPMS
rpm -q --whatprovides $RPMS | grep 'no package provides'
if [ $? -eq 0 ]; then
echo "Error: failed to provide necessary RPM tools, exiting"
exit 1
fi
#pear channel-update pear.php.net
#pear upgrade-all
#pear install Mail Net_SMTP Mail_mime MDB2_driver_mysql
echo "Installing AvantFAX and configuring HylaFAX"
## SETUP SMARTY
chmod 0770 \
avantfax/includes/templates/admin_theme/templates_c/ \
avantfax/includes/templates/admin_theme/cache/ \
avantfax/includes/templates/main_theme/templates_c/ \
avantfax/includes/templates/main_theme/cache/
chown $HTTPDUSER:$HTTPDGROUP \
avantfax/includes/templates/admin_theme/templates_c/ \
avantfax/includes/templates/admin_theme/cache/ \
avantfax/includes/templates/main_theme/templates_c/ \
avantfax/includes/templates/main_theme/cache/
chmod 0755 \
avantfax/includes/faxcover.php \
avantfax/includes/faxrcvd.php \
avantfax/includes/notify.php \
avantfax/tools/update_contacts.php \
avantfax/tools/faxcover.php \
avantfax/includes/avantfaxcron.php \
avantfax/includes/dynconf.php
cp avantfax/includes/local_config-example.php avantfax/includes/local_config.php
if [ -f /etc/mail/trusted-users ]; then
grep ^$HTTPDUSER$ /etc/mail/trusted-users || \
echo $HTTPDUSER >> /etc/mail/trusted-users
fi
# SETUP AVANTFAX JOBFMT
HYLACONF=/etc/hylafax/hyla.conf
if [ -f /var/lib/hylafax/hfaxd.conf ]; then
HYLACONF=/var/lib/hylafax/hfaxd.conf
fi
cat >> $HYLACONF << EOF
#
## JobFmt for AvantFAX
#
JobFmt: "%-3j %3i %1a %15o %40M %-12.12e %5P %5D %7z %.25s"
EOF
# START SERVICES ON BOOT
/sbin/chkconfig httpd on
/sbin/chkconfig mysqld on
/sbin/chkconfig hylafax on
# INSTALL AVANTFAX
mkdir -p $INSTDIR
cp -a avantfax/. $INSTDIR/.
chown -R $HTTPDUSER.$HTTPDGROUP $INSTDIR
chmod -R 0770 $INSTDIR/tmp $INSTDIR/faxes
chown -R $HTTPDUSER.uucp $INSTDIR/tmp $INSTDIR/faxes
# DISABLE SELINUX FOR APACHE
echo "Disabling SELinux for Apache"
setsebool -P httpd_disable_trans 1
# CONFIGURE AVANTFAX VIRTUALHOST
cat > /etc/httpd/conf.d/avantfax.conf << EOF
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot $INSTDIR
ServerName avantfax
ErrorLog logs/avantfax-error_log
CustomLog logs/avantfax-access_log common
# PHP OPTIONS
php_admin_value file_uploads 1
php_admin_value upload_max_filesize 40M
php_admin_value post_max_size 40M
</VirtualHost>
EOF
# START MYSQL AND APACHE
/sbin/service mysqld restart
/sbin/service httpd restart
# IMPORT MYSQL DATABASE
echo "## Creating AvantFAX MySQL database ##"
# mysql --user=root --password=$ROOTMYSQLPWD -e "GRANT ALL ON $DB.* TO $USER@localhost IDENTIFIED BY \"$PASS\"" mysql
# mysqladmin --default-character-set=utf8 --user=$USER --password=$PASS create $DB
# mysql --user=$USER --password=$PASS $DB < create_tables.sql
# mysqlshow --user=$USER --password=$PASS $DB
echo "### Testing root access for MySQL"
userexists=`mysql --user=root --password=$ROOTMYSQLPWD -sNe "select count(*) existe from user where User = '$USER'" mysql`
if [ ! $? -eq 0 ]; then
echo << EOF
Is there a root password set for MySQL?
EOF
exit 1
fi
if [ ! -d /var/lib/mysql/$DB ]; then # if database doesn't exist, create it
echo "### Creating MySQL database for web"
mysqladmin --default-character-set=utf8 --user=root --password=$ROOTMYSQLPWD create $DB
if [ $? -eq 0 ]; then
if [ "$userexists" -eq "0" ]; then
echo "### Creating $USER account with password $PASS for DB $DB"
mysql --user=root --password=$ROOTMYSQLPWD -e "GRANT ALL PRIVILEGES ON $DB.* TO '$USER'@'localhost' IDENTIFIED BY \"$PASS\"" mysql
echo "### Importing schema"
mysql --user=$USER --password=$PASS $DB < create_tables.sql
fi
fi
fi
# SYMLINK AVANTFAX SCRIPTS
ln -s $INSTDIR/includes/faxrcvd.php $SPOOL/bin/faxrcvd.php
ln -s $INSTDIR/includes/dynconf.php $SPOOL/bin/dynconf.php
ln -s $INSTDIR/includes/notify.php $SPOOL/bin/notify.php
echo "CoverCmd: $INSTDIR/includes/faxcover.php" >> /etc/hylafax/sendfax.conf
# FIX FILEINFO
ln -s /usr/share/file/magic* /usr/share/misc/
# SETUP SUDO PERMISSIONS
echo "Setting up sudo"
cat /etc/sudoers | grep -v requiretty > /tmp/sudoers
echo "$HTTPDUSER ALL= NOPASSWD: /sbin/reboot, /sbin/halt, /usr/sbin/faxdeluser, /usr/sbin/faxadduser -u * -p * *" >> /tmp/sudoers
if [ ! -f /etc/sudoers.orig ]; then
mv /etc/sudoers /etc/sudoers.orig
fi
mv /tmp/sudoers /etc/sudoers
chmod 0440 /etc/sudoers
chown root.root /etc/sudoers
# Make backup of HylaFAX configuration
mkdir $SPOOL/etc/abackup
cp $SPOOL/etc/config* $SPOOL/etc/abackup/
# CONFIGURE MODEMS TO USE AVANTFAX
for i in `ls $SPOOL/etc/config.*`; do
if [ "$i" != "$SPOOL/etc/config.sav" ]; then
if [ "$i" != "$SPOOL/etc/config.devid" ]; then
tilde=`echo $i | grep '~'`
if [ "$?" -eq "1" ]; then
if [ ! -L $i ]; then
cat >> $i << EOF
#
## AvantFAX
#
FaxRcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true
EOF
fi
fi
fi
fi
done
cat >> $SPOOL/etc/config << EOF
#
## AvantFAX
#
NotifyCmd: bin/notify.php
EOF
# ADD MODEMS TO DATABASE
for i in `ls $SPOOL/etc/config.*`; do
if [ "$i" != "$SPOOL/etc/config.sav" ]; then
if [ "$i" != "$SPOOL/etc/config.devid" ]; then
tilde=`echo $i | grep '~'`
if [ "$?" -eq "1" ]; then
if [ -f $i ]; then
modem=`echo $i | awk -F'/' '{print $6}' | awk -F'.' '{print $2}'`
exists=`mysql --user=$USER --password=$PASS $DB -sNe "select count(*) existe from Modems where device='$modem'"`
if [ "$exists" -eq "0" ]; then
# ADD MODEMS TO AVANTFAX DATABASE
mysql --user=$USER --password=$PASS -e "INSERT INTO Modems SET device='$modem', alias ='$modem'" $DB
echo "Configuring $modem for AvantFAX"
fi
fi
fi
fi
fi
done
# ADD CRONTAB ENTRIES
echo "Setting up /etc/cron.d/avantfax"
printf "0 0 * * *\t$INSTDIR/includes/avantfaxcron.php -t 2\n" > /etc/cron.d/avantfax
echo -e "Installation complete\n\n"
IP=`/sbin/ifconfig eth0 | grep "inet addr" | awk -F' ' '{print $2}' | awk -F':' '{print $2}'`
echo -e "Log into the Administrative interface at: http://$IP/admin/"
echo -e "Username: admin\nPassword: password"
# DONE #