forked from amooma/GS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
1163 lines (952 loc) · 34 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# (c) 2009-2010 AMOOMA GmbH - http://www.amooma.de
# Lizenz: CC-by-nc-nd 3.0
# http://creativecommons.org/licenses/by-nc-nd/3.0/de/
echo -e "\n
This is an old Version of Gemeinschaft!\n \
No support at all.\n \
Use allways stable version for production.\n \
This installer might be broken.
If you agree please type 'yes'.\n"
read answer
case $answer in
yes)
;;
*)
echo "Good bye";
exit 0;
;;
esac
GEMEINSCHAFT_VERS="master"
#GEMEINSCHAFT_VERS="3.1-rc3"
#GEMEINSCHAFT_TGZ_URL_DIR="https://github.com/amooma/GS3/tarball"
GEMEINSCHAFT_CLONE_URL_DIR="https://github.com/amooma/GS3.git"
GEMEINSCHAFT_SIEMENS_VERS="trunk-r00358"
GEMEINSCHAFT_SIEMENS_TGZ_IN_TGZ_DIR="misc/provisioning/siemens"
# File: ${GEMEINSCHAFT_SIEMENS_TGZ_IN_TGZ_DIR}/gemeinschaft-siemens-${GEMEINSCHAFT_SIEMENS_VERS}.tgz
GEMEINSCHAFT_SOUNDS_DE_WAV_VERS="current"
GEMEINSCHAFT_SOUNDS_DE_WAV_TGZ_IN_TGZ_DIR="misc/voiceprompts"
# File: ${GEMEINSCHAFT_SOUNDS_DE_WAV_TGZ_IN_TGZ_DIR}/gemeinschaft-sounds-de-wav-${GEMEINSCHAFT_SOUNDS_DE_WAV_VERS}.tar.gz
#ASTERISK_SOUNDS_DE_ALAW_VERS="current"
ASTERISK_SOUNDS_DE_ALAW_TGZ_IN_TGZ_DIR="misc/voiceprompts"
# File: ${ASTERISK_SOUNDS_DE_ALAW_TGZ_IN_TGZ_DIR}/asterisk-core-sounds-de-alaw.tar.gz
# language
L2=`echo $LANG | head -c 2 | tr 'A-Z' 'a-z'`
if [ -z $L2 ]; then L2='xx'; fi
err()
{
ERRMSG="$*"
echo '' >&2
echo '*****************************************************************' >&2
echo '' >&2
if [ "$L2" == "de" ]; then
echo ' FEHLER!' >&2
else
echo ' ERROR!' >&2
fi
if [ ! -z "$ERRMSG" ]; then echo -e "$ERRMSG" >&2 ; fi
echo '' >&2
echo '*****************************************************************' >&2
echo '' >&2
exit 1
}
trap "(echo ''; echo '***** ABORTED!') >&2; exit 130" INT TERM QUIT HUP
trap "err; exit 1" ERR
# check system
#
if [ ! -e /etc/debian_version ]; then
if [ "$L2" == "de" ]; then
err " Ihr System ist kein Debian."
else
err " Your system is not Debian."
fi
fi
if [ "`id -un`" != "root" ]; then
if [ "$L2" == "de" ]; then
err " Dieses Skript muss als Benutzer \"root\" ausgeführt werden."
else
err " This script must be run as user \"root\"."
fi
fi
if ( ! cat /etc/debian_version | head -n 1 | grep '^6.' 1>>/dev/null ) \
&& ( ! cat /etc/debian_version | head -n 1 | grep 'squeeze' 1>>/dev/null )
then
if [ "$L2" == "de" ]; then
err " Ihr Debian ist nicht Version 6 (\"Squeeze\").\n" \
" Bitte laden Sie einen Debian-Installer herunter:\n" \
" http://cdimage.debian.org/cdimage/daily-builds/squeeze_d-i/current/"
else
err " Your Debian is not version 6 (\"Squeeze\").\n" \
" Please download a Debian installer from\n" \
" http://cdimage.debian.org/cdimage/daily-builds/squeeze_d-i/current/"
fi
fi
# set PATH
#
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:${PATH}"
if ( which asterisk 1>>/dev/null 2>>/dev/null ); then
if ( ! aptitude search asterisk | grep '^i' | grep -Ee '\sasterisk\s' 1>>/dev/null 2>>/dev/null ); then
if [ "$L2" == "de" ]; then
err " Auf diesem System ist bereits eine andere, möglicherweise\n" \
" nicht kompatible Version von Asterisk installiert."
else
err " This system already has a version of Astersik which might\n" \
" not be compatible."
fi
fi
fi
# setup basic stuff
#
clear
echo ""
echo "*** Now we start to install and setup stuff we need for"
echo "*** Gemeinschaft. Better get yourself a cup of coffee."
cat <<\HEREDOC
)
(
)
,.----------.
((| |
.--\ /--.
'._ '========' _.'
`""""""""""""`
HEREDOC
#sleep 1
#echo "***"
#echo "*** Setting up basic stuff ..."
#echo "***"
type apt-get 1>>/dev/null 2>>/dev/null
type aptitude 1>>/dev/null 2>>/dev/null || apt-get -y install aptitude
#APTITUDE_INSTALL="aptitude -y --allow-new-upgrades --allow-new-installs install"
APTITUDE_INSTALL="aptitude -y --safe-resolver"
APTITUDE_REMOVE="aptitude -y purge"
APTITUDE_INSTALL="${APTITUDE_INSTALL} --allow-new-upgrades --allow-new-installs"
APTITUDE_INSTALL="${APTITUDE_INSTALL} install"
#echo "APTITUDE_INSTALL = ${APTITUDE_INSTALL}"
# very cheap hack to wait for the DHCP-client
#
COUNTER=0
while [ $COUNTER -lt 5 ]; do
echo -n "."
sleep 1
let COUNTER=COUNTER+1
done
echo ""
#make local directories
LOCAL_DIRS="vm-rec sys-rec sounds htdocs/prov/ringtones/"
LOCAL_PATH="/opt/gemeinschaft-local"
for i in $LOCAL_DIRS;
do
echo $LOCAL_PATH/$i
test -d $LOCAL_PATH/$i || mkdir -p $LOCAL_PATH/$i;
done
# update package lists
#
echo ""
echo "***"
echo "*** Updating package lists ..."
echo "***"
aptitude update
# install and configure local nameserver
#
echo ""
echo "***"
echo "*** Installing local caching nameserver ..."
echo "***"
if ( ! which named 1>>/dev/null 2>>/dev/null ); then
echo "*** Installing bind9 ..."
${APTITUDE_INSTALL} bind9
fi
if [ ! -e /etc/init.d/bind9 ]; then
echo "*** Installing bind9 ..."
${APTITUDE_INSTALL} bind9
fi
${APTITUDE_INSTALL} dnsutils
# install dnsutils so we can use dig later
#aptitude clean
if [ -e /etc/resolv.conf ]; then
if [[ `grep -Ee "^nameserver[ \t]+" /etc/resolv.conf | head -n 1 | grep -Ee "127\.0\.0\.1"` ]]; then
echo "nameserver 127.0.0.1 already configured."
else
[ -e /tmp/resolv.conf ] && rm -f /tmp/resolv.conf || true
echo "nameserver 127.0.0.1" > /tmp/resolv.conf
cat /etc/resolv.conf >> /tmp/resolv.conf
mv -fT /tmp/resolv.conf /etc/resolv.conf
fi
if [ -e /etc/bind/named.conf.local ]; then
if [ -e /etc/bind/zones.rfc1918 ]; then
if [[ `grep "^include" /etc/bind/named.conf.local | grep "zones\.rfc1918"` ]]; then
echo "/etc/bind/named.conf.local already includes /etc/bind/zones.rfc1918"
else
echo 'include "/etc/bind/zones.rfc1918";' >> /etc/bind/named.conf.local
fi
if [[ `grep "OPTIONS" /etc/default/bind9 | grep -e "-4"` ]]; then
echo "/etc/default/bind9 already has -4 option for named."
else
sed -i 's/OPTIONS.*/OPTIONS="-4 -u bind"/' /etc/default/bind9
fi
fi
fi
/etc/init.d/bind9 restart || true
fi
# try to fill the DNS cache to speed up things later:
for server in \
"www.amooma.de" \
"www.amooma.com" \
"www.gemeinschaft.de" \
"github.com" \
"download.github.com" \
"nodeload.github.com" \
"downloads.digium.com" \
"downloads.asterisk.org" \
"downloads.sourceforge.net" \
"0.debian.pool.ntp.org" \
"1.debian.pool.ntp.org" \
"ftp.de.debian.org" \
"security.debian.org" \
"ftp.debian.org" \
"ftp.sangoma.com" \
"example.com" \
"example.net" \
"example.org" \
; do
dig +short ${server} >>/dev/null 2>>/dev/null &
sleep 0.01 2>>/dev/null || true
done
sleep 1
# wait for internet access
#
echo "Checking Internet access ..."
while ! ( wget -O - -T 30 --spider http://ftp.debian.org/ >>/dev/null ); do sleep 5; done
MY_MAC_ADDR=`LANG=C ifconfig | grep -oE '[0-9a-fA-F]{1,2}\:[0-9a-fA-F]{1,2}\:[0-9a-fA-F]{1,2}\:[0-9a-fA-F]{1,2}\:[0-9a-fA-F]{1,2}\:[0-9a-fA-F]{1,2}' | head -n 1`
# install basic stuff
#
echo ""
echo "***"
echo "*** Installing basic stuff ..."
echo "***"
${APTITUDE_INSTALL} \
coreutils lsb-base grep findutils sudo wget curl cron \
expect dialog logrotate hostname net-tools ifupdown iputils-ping netcat \
udev psmisc dnsutils iputils-arping pciutils bzip2 \
console-data console-tools \
vim less git
#${APTITUDE_INSTALL} ssh
# No ssh by default.
#aptitude clean
# now that we have vim, enable syntax highlighting by default:
if ( which vim 1>>/dev/null 2>>/dev/null ); then
sed -i -r -e 's/^"(syntax) on/\1 on/' /etc/vim/vimrc || true
fi
# set EDITOR to "vim"
if ( which vim 1>>/dev/null 2>>/dev/null ); then
echo "" >> /root/.bashrc || true
echo "export EDITOR=\"vim\"" >> /root/.bashrc || true
echo "" >> /root/.bashrc || true
#if [ "x${SHELL}" = "x/bin/bash" ]; then
# source /root/.bashrc
#fi
fi
# and add ls colors and some useful bash aliases:
cat <<\HEREDOC >> /root/.bashrc
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias l='ls $LS_OPTIONS -lF'
alias ll='ls $LS_OPTIONS -lFA'
HEREDOC
#if [ "x${SHELL}" = "x/bin/bash" ]; then
# source /root/.bashrc
#fi
WGET="wget"
WGET_ARGS="-c -T 60 --no-check-certificate"
DOWNLOAD="${WGET} ${WGET_ARGS}"
# set up lang enviroment
#
echo ""
echo "***"
echo "*** Setting up language environment ..."
echo "***"
if ( ! which locale-gen 1>>/dev/null 2>>/dev/null ); then
${APTITUDE_INSTALL} locales
elif [ ! -e /usr/share/i18n/locales/. ]; then
${APTITUDE_INSTALL} locales
elif [ ! -e /usr/share/locale/. ]; then
${APTITUDE_INSTALL} locales
fi
if [ -e /etc/locale.gen ]; then
grep -e "^de_DE\.UTF-8 UTF-8" /etc/locale.gen || echo "de_DE.UTF-8 UTF-8" >> /etc/locale.gen
grep -e "^en_US\.UTF-8 UTF-8" /etc/locale.gen || echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
fi
if ( type locale-gen 2>>/dev/null ); then
locale-gen
else
echo "WARNING: locale-gen not found!" >&2
fi
# install ntp
#
echo ""
echo "***"
echo "*** Installing NTP ..."
echo "***"
if ( ! which ntpd 1>>/dev/null 2>>/dev/null ); then
${APTITUDE_INSTALL} ntp
fi
if ( ! which ntpdate 1>>/dev/null 2>>/dev/null ); then
${APTITUDE_INSTALL} ntpdate
fi
/etc/init.d/ntp stop 2>>/dev/null || true
ntpdate 0.debian.pool.ntp.org || true
ntpdate 1.debian.pool.ntp.org || true
/etc/init.d/ntp start || true
sleep 3
# make /var/run/ available as a ram file system (tmpfs).
#
sed -i -r -e 's/^(RAMRUN=)no/\1yes/' /etc/default/rcS || true
# install dahdi (//FIXME - do we need Dahdi? it requires a build
# environment!)
#
echo ""
echo "***"
echo "*** Installing Dahdi ..."
echo "***"
if ( aptitude search dahdi | grep '^i' | grep -e '\sdahdi\s' 1>>/dev/null 2>>/dev/null ) \
&& ( aptitude search dahdi-modules-`uname -r` | grep '^i' | grep -e '\sdahdi-modules-' 1>>/dev/null 2>>/dev/null )
then
echo "*** Dahdi base already installed."
HAVE_DAHDI_USER=YES
else
echo "*** Dahdi base yet to install ..."
HAVE_DAHDI_USER=NO
fi
if [ "$HAVE_DAHDI_USER" != "YES" ]; then
${APTITUDE_INSTALL} dahdi dahdi-modules
fi
if [ ! -e /lib/modules/`uname -r`/dahdi/dahdi.ko ]; then
${APTITUDE_INSTALL} dahdi-source
echo ""
echo "***"
echo "*** Building Dahdi drivers ..."
echo "***"
m-a a-i -i -f dahdi
# now we have dahdi-modules-`uname -r` (e.g. dahdi-modules-2.6.32-3-686)
# which provides dahdi-modules
# /lib/modules/`uname -r`/dahdi/...
aptitude -y markauto dahdi-source \
linux-headers-`uname -r` linux-kernel-headers
#aptitude -y markauto debhelper module-assistant
aptitude clean
fi
# generate /etc/dahdi/system.conf:
dahdi_genconf || true
# install libpri, asterisk
#
echo ""
echo "***"
echo "*** Installing Asterisk ..."
echo "***"
${APTITUDE_INSTALL} libpri1.4 asterisk \
asterisk-mysql \
vpb-driver-source-
# asterisk depends on libvpb0 which recommends vpb-driver-source.
# Don't install that because that in turn pulls a complete build
# environment.
aptitude clean
# create directory for call-files
#
mkdir -p /var/spool/asterisk/outgoing
chmod a+rwx /var/spool/asterisk/outgoing
chmod a+rwx /var/spool/asterisk/tmp
# sudo permissions for Asterisk
#
echo "asterisk ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/gemeinschaft-asterisk
chmod 0440 /etc/sudoers.d/gemeinschaft-asterisk
# install lame
#
if ( ! which lame 1>>/dev/null 2>>/dev/null ); then
echo ""
echo "***"
echo "*** Installing Lame ..."
echo "***"
echo 'deb http://www.debian-multimedia.org squeeze main non-free' \
> /etc/apt/sources.list.d/debian-multimedia.list
aptitude update --allow-untrusted || true
${APTITUDE_INSTALL} --allow-untrusted debian-multimedia-keyring || true
#${APTITUDE_INSTALL} lame || true
${APTITUDE_INSTALL} --allow-untrusted lame || true
fi
# install misc packages
#
echo ""
echo "***"
echo "*** Installing other packages ..."
echo "***"
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
${APTITUDE_INSTALL} \
perl perl-modules libnet-daemon-perl libnet-netmask-perl libio-interface-perl libio-socket-multicast-perl \
sipsak \
mysql-client mysql-server \
apache2 \
php5-cli libapache2-mod-php5 php5-mysql php5-ldap \
python2.6 \
python-mysqldb \
sox libsox-fmt-all mpg123
unset DEBIAN_FRONTEND
unset DEBIAN_PRIORITY
#aptitude clean
# install music on hold (MOH) for Asterisk
#
echo ""
echo "***"
echo "*** Installing music on hold (MOH) for Asterisk ..."
echo "***"
#cd /var/lib/asterisk/moh/
mkdir -p /usr/share/asterisk/moh
cd /usr/share/asterisk/moh/
for fmt in alaw; do
#F=asterisk-moh-freeplay-${fmt}
F=asterisk-moh-opsound-${fmt}-current
${DOWNLOAD} http://downloads.asterisk.org/pub/telephony/sounds/${F}.tar.gz
tar -xzf ${F}.tar.gz
rm ${F}.tar.gz || true
done
# install Gemeinschaft
#
echo ""
echo "***"
echo "*** Installing Gemeinschaft ..."
echo "***"
cd /opt/
# Get tarball from GitHub {
#
git clone -b ${GEMEINSCHAFT_VERS} ${GEMEINSCHAFT_CLONE_URL_DIR}
#${DOWNLOAD} "${GEMEINSCHAFT_TGZ_URL_DIR}/${GEMEINSCHAFT_VERS}" -O amooma-GS3.tar.gz
#tar -xvzf amooma-GS3*.tar.gz
#rm -f amooma-GS3*.tar.gz
mv GS3 \
gemeinschaft-${GEMEINSCHAFT_VERS}
echo -n ${GEMEINSCHAFT_VERS} > gemeinschaft-${GEMEINSCHAFT_VERS}/etc/gemeinschaft/.gemeinschaft-version
mv "gemeinschaft-${GEMEINSCHAFT_VERS}" \
"gemeinschaft-source-${GEMEINSCHAFT_VERS}"
ln -snf gemeinschaft-source-${GEMEINSCHAFT_VERS} gemeinschaft-source
#
# Get tarball from GitHub }
# main Gemeinschaft dir link
#
cd /opt/
rm -rf gemeinschaft 2>>/dev/null || true
ln -snf gemeinschaft-source/opt/gemeinschaft gemeinschaft
# fix MOH location for Debian:
#
#sed -i -r -e 's#^( *;? *directory *= *)/var/lib/asterisk(/moh)#\1/usr/share/asterisk\2#g' /etc/asterisk/musiconhold.conf
# install German voice prompts for Asterisk
#
echo ""
echo "***"
echo "*** Installing German voice prompts for Asterisk ..."
echo "***"
cd /usr/share/asterisk/sounds/
[ -e de ] && rm -rf de || true
# Get tarball from within Gemeinschaft {
cp "/opt/gemeinschaft-source/${ASTERISK_SOUNDS_DE_ALAW_TGZ_IN_TGZ_DIR}/asterisk-core-sounds-de-alaw.tar.gz" ./
# Get tarball from within Gemeinschaft }
tar -xzf asterisk-core-sounds-de-alaw.tar.gz
rm -f asterisk-core-sounds-de-alaw.tar.gz
# voice prompts for Gemeinschaft
#
echo "Installing Voiceprompts for Gemeinschaft ..."
[ -e /opt/gemeinschaft-local/sounds ]
cd /opt/gemeinschaft-local/sounds
if [ -e de-DE ]; then
rm -rf de-DE || true
fi
if [ -e de-DE-tts ]; then
rm -rf de-DE-tts || true
fi
# Get tarball from within Gemeinschaft {
cp "/opt/gemeinschaft-source/${GEMEINSCHAFT_SOUNDS_DE_WAV_TGZ_IN_TGZ_DIR}/gemeinschaft-sounds-de-wav-${GEMEINSCHAFT_SOUNDS_DE_WAV_VERS}.tar.gz" ./
# Get tarball from within Gemeinschaft }
tar -xzf gemeinschaft-sounds-de-wav-${GEMEINSCHAFT_SOUNDS_DE_WAV_VERS}.tar.gz
rm -f gemeinschaft-sounds-de-wav-${GEMEINSCHAFT_SOUNDS_DE_WAV_VERS}.tar.gz || true
if [ -e de-DE ]; then
mv de-DE de-DE-tts
fi
ln -s de-DE-tts de-DE
#if [ -e de-DE-tts ]; then
# ln -snf de-DE-tts de-DE
#fi
#cd de-DE-tts
#/opt/gemeinschaft/sbin/sounds-wav-to-alaw.sh || true
# //FIXME: "sox: invalid option -- w"
# see man sox. -b 16 ? -b 8 ?
#rm *.wav || true
cd
# MySQL: add gemeinschaft user
#
echo ""
echo "***"
echo "*** Creating Gemeinschaft database ..."
echo "***"
GEMEINSCHAFT_DB_PASS=`head -c 20 /dev/urandom | md5sum -b - | cut -d ' ' -f 1 | head -c 30`
[ -e /tmp/mysql-gemeinschaft-grant.sql ] && rm -f /tmp/mysql-gemeinschaft-grant.sql || true
touch /tmp/mysql-gemeinschaft-grant.sql
chmod go-rwx /tmp/mysql-gemeinschaft-grant.sql
echo "GRANT ALL ON \`asterisk\`.* TO 'gemeinschaft'@'localhost' IDENTIFIED BY '${GEMEINSCHAFT_DB_PASS}';" >> /tmp/mysql-gemeinschaft-grant.sql
echo "GRANT ALL ON \`asterisk\`.* TO 'gemeinschaft'@'%' IDENTIFIED BY '${GEMEINSCHAFT_DB_PASS}';" >> /tmp/mysql-gemeinschaft-grant.sql
echo "FLUSH PRIVILEGES;" >> /tmp/mysql-gemeinschaft-grant.sql
cat /tmp/mysql-gemeinschaft-grant.sql | mysql --batch
rm -f /tmp/mysql-gemeinschaft-grant.sql
mysql --batch --user=gemeinschaft --password="${GEMEINSCHAFT_DB_PASS}" -e "SELECT 'test'" > /dev/null
# Gemeinschaft database
#
cd /opt/gemeinschaft-source/usr/share/doc/gemeinschaft/
sed -i -e 's/DEFINER *= *[^ ]*/DEFINER=CURRENT_USER()/g' asterisk.sql
mysql --batch --user=gemeinschaft --password="${GEMEINSCHAFT_DB_PASS}" < asterisk.sql
cd
# Apache configuration
#
echo ""
echo "***"
echo "*** Setting up Apache web server ..."
echo "***"
cd /etc/apache2/conf.d/
ln -snf /opt/gemeinschaft-source/etc/apache2/conf.d/gemeinschaft.conf gemeinschaft.conf
if [ -e /opt/gemeinschaft-source/etc/apache2/sites-available/gemeinschaft ]; then
cd /etc/apache2/sites-available/
ln -snf /opt/gemeinschaft-source/etc/apache2/sites-available/gemeinschaft gemeinschaft
a2dissite default
a2ensite gemeinschaft
else
cd /etc/apache2/sites-available/
cat default | sed -e 's/AllowOverride None/AllowOverride All/i' > gemeinschaft
a2dissite default
a2ensite gemeinschaft
fi
a2enmod rewrite
a2enmod alias
a2enmod mime
a2enmod php5
a2enmod headers || true
# PHP-APC
#
echo ""
#echo "***"
#echo "*** Installing PHP-APC ..."
#echo "***"
${APTITUDE_INSTALL} php-apc || true
/etc/init.d/apache2 stop
invoke-rc.d apache2 restart
# sudo permissions for Apache
#
echo "www-data ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/gemeinschaft-apache
chmod 0440 /etc/sudoers.d/gemeinschaft-apache
# configure Asterisk
#
echo ""
echo "***"
echo "*** Setting up Gemeinschaft ..."
echo "***"
cd /etc/
mv asterisk asterisk.DEBIAN
cp -r /opt/gemeinschaft-source/etc/asterisk ./
#ln -snf /opt/gemeinschaft-source/etc/asterisk
# Replace astdatadir "/var/lib/asterisk" by "/usr/share/asterisk"
# (the default on Debian):
sed -i -r -e 's#^(astdatadir\s*).*#\1=> /usr/share/asterisk#' /etc/asterisk/asterisk.conf || true
# Replace astrundir "/var/run" by "/var/run/asterisk"
# (the default on Debian):
sed -i -r -e 's#^(astrundir\s*).*#\1=> /var/run/asterisk#' /etc/asterisk/asterisk.conf || true
# change owner of /opt/gemeinschaft/etc/asterisk/* to asterisk
chown -h -R asterisk:asterisk /etc/asterisk
# add Apache user (www-data) to the Asterisk group (asterisk) so
# voicemails can be played via the web GUI:
adduser www-data asterisk
invoke-rc.d apache2 restart
# configure Gemeinschaft
#
cd /etc/
#ln -snf /opt/gemeinschaft-source/etc/gemeinschaft
mkdir -p /etc/gemeinschaft
cd /etc/gemeinschaft
if [ ! -e gemeinschaft.php ]; then
cp /opt/gemeinschaft-source/etc/gemeinschaft/gemeinschaft.php ./
fi
cp /opt/gemeinschaft-source/etc/gemeinschaft/.gemeinschaft-version ./ || true
mkdir -p /etc/gemeinschaft/asterisk
cd /etc/gemeinschaft/asterisk
cp -R /opt/gemeinschaft-source/etc/gemeinschaft/asterisk/* ./
if [ -e /etc/gemeinschaft/asterisk/manager.conf.d-available/phonesuite.conf ]; then
AMI_PASS=`head -c 20 /dev/urandom | md5sum -b - | cut -d ' ' -f 1 | head -c 9`
sed -i "s/^\(\s*secret\s*=\s*\)[^; \t]*\(.*\)/\1${AMI_PASS}\2/g" /etc/gemeinschaft/asterisk/manager.conf.d-available/phonesuite.conf
fi
# find IP address
#
MY_IP_ADDR=`LANG=C ifconfig | grep inet | grep -v 'inet6' | grep -v '127\.0\.0\.1' | head -n 1 | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -v '^255' | head -n 1`
if [ "x$?" != "x0" ] || [ -z ${MY_IP_ADDR} ]; then
echo "***** Failed to find your IP address." 2>&1
MY_IP_ADDR="192.168.1.130"
fi
MY_NETMASK=`LANG=C ifconfig | grep inet | grep -v 'inet6' | grep -v '127\.0\.0\.1' | head -n 1 | grep -io 'mask.*' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep '^255' | sort -n | head -n 1`
if [ "x$?" != "x0" ] || [ -z ${MY_NETMASK} ]; then
echo "***** Failed to find your netmask." 2>&1
MY_NETMASK="255.0.0.0"
fi
# configure gemeinschaft.php - IP address, DB password etc.
#
sed -i "s/\(^[\s#\/]*\$INSTALLATION_TYPE\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'single';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_MASTER_HOST\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'127.0.0.1';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_SLAVE_HOST\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'127.0.0.1';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_MASTER_USER\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'gemeinschaft';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_SLAVE_USER\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'gemeinschaft';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_MASTER_PWD\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'${GEMEINSCHAFT_DB_PASS}';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_SLAVE_PWD\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'${GEMEINSCHAFT_DB_PASS}';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_MASTER_DB\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'asterisk';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$DB_SLAVE_DB\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'asterisk';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$PROV_HOST\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'${MY_IP_ADDR}';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$CALL_INIT_FROM_NET\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'${MY_IP_ADDR}\/${MY_NETMASK}';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$MONITOR_FROM_NET\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'${MY_IP_ADDR}\/${MY_NETMASK}';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$EMAIL_DELIVERY\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\1'sendmail';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\$LOG_GMT\s*=\s*\)[^a-z0-9]*\s*;/\1false;/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_ENABLED\s*=\s*\)\([A-Za-z0-9']\)*\s*;/\2true;/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_PREFIX\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\2'*96';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_TSI_PREFIX\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\2'';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_TSI\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\2 @\$CANONIZE_NATL_PREFIX.@\$CANONIZE_AREA_CODE.@\$CANONIZE_LOCAL_BRANCH.'0';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_HYLAFAX_HOST\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\2'127.0.0.1';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_HYLAFAX_PORT\s*=\s*\)\([0-9']\)*\s*;/\2 4559;/g" /etc/gemeinschaft/gemeinschaft.php
HFAXADM_PASS=`head -c 20 /dev/urandom | md5sum -b - | cut -d ' ' -f 1 | head -c 12`
sed -i "s/\(^[\s#\/]*\)\(\$FAX_HYLAFAX_ADMIN\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\2'hfaxadm';/g" /etc/gemeinschaft/gemeinschaft.php
sed -i "s/\(^[\s#\/]*\)\(\$FAX_HYLAFAX_PASS\s*=\s*\)\([\"']\)[^\"']*[\"']\s*;/\2'${HFAXADM_PASS}';/g" /etc/gemeinschaft/gemeinschaft.php
#sed -i -e 's/^\s*[^#].*//g' /opt/gemeinschaft/etc/listen-to-ip
#( echo ; echo $MY_IP_ADDR ; echo ) >> /opt/gemeinschaft/etc/listen-to-ip
mysql --batch --user=gemeinschaft --password="${GEMEINSCHAFT_DB_PASS}" -e "USE \`asterisk\`; UPDATE \`hosts\` SET \`host\`='${MY_IP_ADDR}' WHERE \`id\`=1;" || true
mysql --batch --user=gemeinschaft --password="${GEMEINSCHAFT_DB_PASS}" -e "USE \`asterisk\`; UPDATE \`hosts\` SET \`host\`='${MY_IP_ADDR}';" || true
# gemeinschaft-siemens installation here because gemeinschaft has to be configured before generating the SSL cert
# install gemeinschaft-siemens addon
#
echo "Installing Siemens addon for Gemeinschaft (Openstage provisoning) ..."
cd /opt/
# Get tarball from within Gemeinschaft {
cp "/opt/gemeinschaft-source/${GEMEINSCHAFT_SIEMENS_TGZ_IN_TGZ_DIR}/gemeinschaft-siemens-${GEMEINSCHAFT_SIEMENS_VERS}.tgz" ./
# Get tarball from within Gemeinschaft }
tar -xzf gemeinschaft-siemens-${GEMEINSCHAFT_SIEMENS_VERS}.tgz
rm -f gemeinschaft-siemens-${GEMEINSCHAFT_SIEMENS_VERS}.tgz
mv gemeinschaft-siemens-${GEMEINSCHAFT_SIEMENS_VERS} gemeinschaft-siemens-source-${GEMEINSCHAFT_SIEMENS_VERS}
ln -snf gemeinschaft-siemens-source-${GEMEINSCHAFT_SIEMENS_VERS} gemeinschaft-siemens-source
cd /opt/
ln -snf /opt/gemeinschaft-siemens-source/opt/gemeinschaft-siemens gemeinschaft-siemens
cd
# configure gemeinschaft-siemens
#
${APTITUDE_INSTALL} openssl
a2enmod rewrite
a2enmod ssl
cd /etc/apache2/
[ -e ssl ] && rm -rf ssl || true
ln -snf /opt/gemeinschaft-siemens-source/doc/etc-apache2-ssl ssl
cd /etc/apache2/ssl/
./gen-cert.sh >>/dev/null
chown root:root openstage-*.pem
chmod 640 openstage-*.pem
cd /etc/apache2/sites-available/
ln -snf /opt/gemeinschaft-siemens-source/doc/httpd-vhost.conf.example gemeinschaft-siemens
a2ensite gemeinschaft-siemens
invoke-rc.d apache2 restart
cd
# documentation
#
cd /usr/share/doc
ln -snf /opt/gemeinschaft-source/usr/share/doc/gemeinschaft
# log dir
#
mkdir -p /var/log/gemeinschaft
chmod a+rwx /var/log/gemeinschaft
# logrotate rules
#
cd /etc/logrotate.d/
ln -snf /opt/gemeinschaft-source/etc/logrotate.d/asterisk
ln -snf /opt/gemeinschaft-source/etc/logrotate.d/gemeinschaft
# web dir
#
cd /var/www/
ln -snf /opt/gemeinschaft-source/var/www/gemeinschaft
ln -snf /opt/gemeinschaft-source/var/www/.htaccess
# misc
#
cd /var/lib/
ln -snf /opt/gemeinschaft-source/var/lib/gemeinschaft
# gs-sip-ua-config-responder fuer Snom
#
if [ -e /opt/gemeinschaft-source/etc/init.d/gs-sip-ua-config-responder ]; then
cd /etc/init.d/
ln -snf /opt/gemeinschaft-source/etc/init.d/gs-sip-ua-config-responder
update-rc.d gs-sip-ua-config-responder defaults 92 8
invoke-rc.d gs-sip-ua-config-responder start
fi
# Gemeinschaft/Asterisk extension state daemon
#
if [ -e /opt/gemeinschaft-source/etc/init.d/gs-extstated ]; then
ln -snf /opt/gemeinschaft-source/etc/init.d/gs-extstated /etc/init.d/gs-extstated
update-rc.d gs-extstated defaults 92 08
invoke-rc.d gs-extstated start
fi
# cron jobs
#
cd /etc/cron.d/
ln -snf /opt/gemeinschaft-source/etc/cron.d/gs-cc-guardian || true
ln -snf /opt/gemeinschaft-source/etc/cron.d/gs-queuelog-to-db || true
ln -snf /opt/gemeinschaft-source/etc/cron.d/gs-queues-refresh || true
cd
# fix permissions
chown -h asterisk:asterisk /opt/gemeinschaft/vm-rec
chmod 0777 /opt/gemeinschaft/vm-rec
chmod 0777 /opt/gemeinschaft/sys-rec
# remove build environment
#
echo ""
echo "***"
echo "*** Removing build environment ..."
echo "***"
aptitude -y markauto linux-headers-`uname -r` linux-kernel-headers
aptitude clean
# add /opt/gemeinschaft/scripts to PATH
#
echo "" >> /root/.bashrc || true
echo "export PATH=\"\$PATH:/opt/gemeinschaft/scripts\"" >> /root/.bashrc || true
echo "" >> /root/.bashrc || true
#if [ "x${SHELL}" = "x/bin/bash" ]; then
# source /root/.bashrc
#fi
# motd
#
(
echo "***"
echo "*** _____ _____"
echo "*** (.---.) GEMEINSCHAFT $(printf "% -7s" $GEMEINSCHAFT_VERS) (.---.)"
echo "*** /:::\\ _.-----------------------------------------._/:::\\"
echo "*** ----- -----"
echo "***"
echo "*** Need help with Gemeinschaft? We have an excellent free mailinglist"
echo "*** and offer the best support and consulting money can buy. Have a"
echo "*** look at http://www.gemeinschaft.de for more information."
echo "***"
) > /etc/motd.static
[ -e /etc/motd ] && rm -rf /etc/motd || true
ln -s /etc/motd.static /etc/motd
# fax installation starts here
#
HF_CONF_SRC="/usr/share/doc/gemeinschaft/misc/fax-integration"
echo ""
echo "***"
echo "*** Installing IAXmodem ..."
echo "***"
${APTITUDE_INSTALL} iaxmodem
# iaxmodem config
#
cp "${HF_CONF_SRC}/ttyIAX0" /etc/iaxmodem/ttyIAX0
cp "${HF_CONF_SRC}/ttyIAX1" /etc/iaxmodem/ttyIAX1
# add iaxmodem entries to iax.conf
#
#cat "${HF_CONF_SRC}/iax.conf.template" >> /etc/asterisk/iax.conf
# add faxgetty entries to inittab
# //FIXME? - set USE_FAXGETTY=yes or USE_FAXGETTY=init in
# /etc/default/hylafax instead?
#
echo "" >> /etc/inittab
echo "# HylaFax getty" >> /etc/inittab
echo "mo00:23:respawn:/usr/sbin/faxgetty ttyIAX0" >> /etc/inittab
echo "mo01:23:respawn:/usr/sbin/faxgetty ttyIAX1" >> /etc/inittab
# adding these lines to /etc/inittab makes /etc/default/hylafax
# default to USE_FAXGETTY=init instead of USE_FAXGETTY=yes
# make init reload /etc/inittab
/sbin/init q
echo ""
echo "***"
echo "*** Installing HylaFax ..."
echo "***"
# hylafax-server (/usr/sbin/faxsetup) needs /usr/sbin/sendmail but
# does not depend on mail-transfer-agent
if ( ! which postfix 1>>/dev/null 2>>/dev/null ); then
${APTITUDE_INSTALL} postfix
fi
${APTITUDE_INSTALL} hylafax-server
if [ ! -e /etc/hylafax/getty-link ]; then
ln -sn /usr/sbin/faxgetty /etc/hylafax/getty-link
fi
# make tmp directory world accessible
chmod 777 /var/spool/hylafax/tmp/
# sudo permissions for FaxDispatch
#
echo "uucp ALL = NOPASSWD: /bin/chgrp" > /etc/sudoers.d/gemeinschaft-hylafax
chmod 0440 /etc/sudoers.d/gemeinschaft-hylafax
# run HylaFax config script
#
#/usr/sbin/faxsetup -nointeractive
# is run automatically by post-install script of hylafax-server
# fax modem config
#
cp "${HF_CONF_SRC}/config.ttyIAX0" /var/spool/hylafax/etc/config.ttyIAX0
cp "${HF_CONF_SRC}/config.ttyIAX0" /var/spool/hylafax/etc/config.ttyIAX1
# fax daemon config
#
cp "${HF_CONF_SRC}/hfaxd.conf" /etc/hylafax/hfaxd.conf
# fax dispatch config
#
cp "${HF_CONF_SRC}/FaxDispatch" /var/spool/hylafax/etc/
# make hylafax run on boot
#
sed -i -r -e 's/^ *# *(RUN_HYLAFAX)=.*/\1=1/g' /etc/default/hylafax
# delete example users, queues etc.
#
for user in "anna" "hans" "lisa" "peter"; do
/opt/gemeinschaft/scripts/gs-user-del --user="${user}" || true
done
for queue in "5000"; do
/opt/gemeinschaft/scripts/gs-queue-del --queue="${queue}" || true
done
mysql --batch --user=gemeinschaft --password="${GEMEINSCHAFT_DB_PASS}" -e \
"USE \`asterisk\`; DELETE FROM \`phones\`;" 1>>/dev/null 2>>/dev/null || true
# Add sample admin and user
#
ADMIN_NAME="admin"
ADMIN_FNAME="System"
ADMIN_LNAME="Administrator"
ADMIN_EXTEN="9999"
let "PIN = $RANDOM % 9999"
ADMIN_PIN=`printf "%04d\n" "$PIN"`
USER_NAME="user"
USER_FNAME="Ordinary"
USER_LNAME="User"
USER_EXTEN="9998"
let "PIN = $RANDOM % 9999"
USER_PIN=`printf "%04d\n" "$PIN"`
#TODO: Loop on error!
# Add admin account
/opt/gemeinschaft/scripts/gs-user-add \
--user="$ADMIN_NAME" \
--ext="$ADMIN_EXTEN" \