Guest User

Untitled

a guest
Feb 10th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.50 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #######################################################################
  4. #
  5. # This script builds a SOGo/OpenChange Server on Ubuntu 14.04
  6. #
  7. # 2015-07-09 - Gerald Brandt - Original Version
  8. #
  9. # This script is GPLv2 Licensed
  10. #
  11. #######################################################################
  12.  
  13. installback=""
  14. installstr=""
  15. hostname=""
  16. domainname=""
  17. ipaddress=""
  18. netmask=""
  19. gateway=""
  20. nameserver2=""
  21. dompart1=""
  22. dompart2=""
  23. workgroup=""
  24. password=""
  25. timezone=""
  26. upperdomain=""
  27. upperhost=""
  28. upperworkgroup=""
  29. genpassword=""
  30. cidr=""
  31. basenet=""
  32.  
  33. #######################################################################
  34. #
  35. #
  36. # @return 0 for failure
  37. # 1 for success
  38. #
  39. # @brief
  40. # configure the network
  41. #
  42. #######################################################################
  43. configure_network () {
  44.  
  45. # configure network
  46. installstr+="Preparing Network\n"
  47. dialog --title " Please Wait... " --backtitle "$installback" \
  48. --infobox $installstr 15 50 2>.tmp
  49.  
  50. echo "Configuring network" >> INSTALL-LOG
  51. echo "###################################################################################" >> INSTALL-LOG 2>&1
  52. echo " Configure Network" >> INSTALL-LOG 2>&1
  53. echo "###################################################################################" >> INSTALL-LOG 2>&1
  54. echo " "
  55.  
  56. # build a proper static ip network
  57. cp /etc/network/interfaces /etc/network/interfaces-orig >> INSTALL-LOG
  58. echo "
  59. auto lo
  60. iface lo inet loopback
  61.  
  62. auto eth0
  63. iface eth0 inet static
  64. address $ipaddress
  65. netmask $netmask
  66. gateway $gateway
  67. dns-nameservers $ipaddress
  68. dns-search $domainname
  69. " > /etc/network/interfaces
  70.  
  71. # add us to the hosts file
  72. apt-get -y install rpl >> INSTALL-LOG 2>&1
  73. response=$?
  74. case $response in
  75. 100)
  76. whiptail --title " ERROR " --backtitle "$installback" \
  77. --infobox "Failed to install rpl. See INSTALL-LOG" 10 50
  78.  
  79. exit
  80. ;;
  81.  
  82. esac
  83.  
  84. echo "Save old files..." >> INSTALL-LOG 2>&1
  85. cp /etc/hosts /etc/hosts-orig >> INSTALL-LOG 2>&1
  86. cp /etc/hostname /etc/hostname-orig >> INSTALL-LOG 2>&1
  87. cp /etc/resolv.conf /etc/resolv.conf-orig >> INSTALL-LOG 2>&1
  88. read oldhostname < /etc/hostname
  89. rpl $oldhostname $hostname /etc/hosts >> INSTALL-LOG 2>&1
  90. hostname $hostname >> INSTALL-LOG 2>&1
  91.  
  92. echo "$ipaddress $hostname.$domainname $hostname" >> /etc/hosts
  93. echo $hostname > /etc/hostname
  94.  
  95. echo "retstart the network"
  96.  
  97. # restart the network
  98. ifdown eth0 >> INSTALL-LOG 2>&1
  99. service resolvconf restart 2>&1
  100. ifup eth0 >> INSTALL-LOG 2>&1
  101.  
  102. # set the proper name resolution (temp, reboot will reset this properly)
  103. # we'll get rid of 8.8.8.8 after samba is up
  104. echo "nameserver $ipaddress" > /etc/resolv.conf
  105. echo "nameserver 8.8.8.8" >> /etc/resolv.conf
  106. echo "search $domainname" >> /etc/resolv.conf
  107. echo "domain $domainname" >> /etc/resolv.conf
  108.  
  109.  
  110. }
  111.  
  112.  
  113. #######################################################################
  114. #
  115. # @param none
  116. #
  117. # @return 0 for failure
  118. # 1 for success
  119. #
  120. # @brief
  121. # Modify the fstab for acl's and remount
  122. #
  123. #######################################################################
  124. modify_fstab () {
  125. installstr+="Modifying fstab\n"
  126. dialog --title " Please Wait... " --backtitle "$installback" \
  127. --infobox $installstr 15 50 2>.tmp
  128.  
  129. echo "###################################################################################" >> INSTALL-LOG 2>&1
  130. echo " Modifying fstab" >> INSTALL-LOG 2>&1
  131. echo "###################################################################################" >> INSTALL-LOG 2>&1
  132. echo " "
  133.  
  134. # modify the fstab for acl's
  135. cp /etc/fstab /etc/fstab-orig
  136. rpl -e "errors=remount-ro" "user_xattr,acl,barrier=1,errors=remount-ro,relatime" /etc/fstab >> INSTALL-LOG 2>&1
  137.  
  138. # remount /
  139. mount -o remount / >> INSTALL-LOG 2>&1
  140.  
  141. }
  142.  
  143.  
  144. #######################################################################
  145. #
  146. # @return 0 for failure
  147. # 1 for success
  148. #
  149. # @brief
  150. # We use samba 4 for user auth, so get it installed and running with the proper domain
  151. #
  152. #######################################################################
  153. install_samba () {
  154.  
  155. echo "###################################################################################" >> INSTALL-LOG 2>&1
  156. echo " INSTALL SAMBA" >> INSTALL-LOG 2>&1
  157. echo "###################################################################################" >> INSTALL-LOG 2>&1
  158. echo
  159.  
  160. installstr+="Samba : install"
  161. dialog --title " Please Wait... " --backtitle "$installback" \
  162. --infobox "$installstr" 15 50 2>.tmp
  163.  
  164. echo krb5-config krb5-config/admin_server string $hostname.$domainname > krb5-config
  165. echo krb5-config krb5-config/kerberos-servers string $hostname.$domainname >> krb5-config
  166. echo krb5-config krb5-config/default_realm string $domainname >> krb5-config
  167. echo krb5-config krb5-config/add_servers_realm string $domainname >> krb5-config
  168. echo krb5-config krb5-config/add_servers boolean false >> krb5-config
  169.  
  170. cat krb5-config | debconf-set-selections
  171.  
  172. apt-get -y install ntp acl samba samba-dev krb5-user attr smbclient dnsutils python-dnspython winbind ldap-utils >> INSTALL-LOG 2>&1
  173. #apt-get -y install ntp acl samba samba-dev krb5-user attr smbclient dnsutils python-dnspython winbind ldap-utils >> INSTALL-LOG 2>&1
  174. response=$?
  175. case $response in
  176. 100)
  177. whiptail --title " ERROR " --backtitle "$installback" \
  178. --infobox "Failed to install Samba. See INSTALL-LOG" 10 50
  179.  
  180. exit
  181. ;;
  182.  
  183. esac
  184.  
  185. installstr+=" - config"
  186. dialog --title " Please Wait... " --backtitle "$installback" \
  187. --infobox "$installstr" 15 50 2>.tmp
  188.  
  189. service samba stop >> INSTALL-LOG 2>&1
  190. service smbd stop >> INSTALL-LOG 2>&1
  191. service samba-ad-dc stop >> INSTALL-LOG 2>&1
  192.  
  193.  
  194. # sometimes, these don't stop
  195. killall -9 smbd >> INSTALL-LOG 2>&1
  196. killall -9 nmbd >> INSTALL-LOG 2>&1
  197. killall -9 samba >> INSTALL-LOG 2>&1
  198.  
  199. service ntp stop >> INSTALL-LOG 2>&1
  200. ntpdate -B ca.pool.ntp.org >> INSTALL-LOG 2>&1
  201. service ntp start >> INSTALL-LOG 2>&1
  202.  
  203.  
  204. mv /etc/samba/smb.conf /etc/samba/smb.conf-orig >> INSTALL-LOG 2>&1
  205.  
  206. #provision samba
  207. echo running: samba-tool domain provision --realm=$domainname --domain=$upperworkgroup --adminpass=$password --server-role=dc --use-rfc2307 --host-name=$hostname --host-ip=$ipaddress --use-xattrs=yes --dns-backend=SAMBA_INTERNAL >> INSTALL-LOG 2>&1
  208.  
  209. samba-tool domain provision --realm=$domainname --domain=$upperworkgroup --adminpass=$password --server-role=dc --use-rfc2307 --host-name=$hostname --host-ip=$ipaddress --use-xattrs=yes --dns-backend=SAMBA_INTERNAL >> INSTALL-LOG 2>&1
  210.  
  211. cp /var/lib/samba/private/krb5.conf /etc
  212.  
  213. # set the proper name resolution (in order to finish install)
  214. echo "nameserver $ipaddress" > /etc/resolv.conf
  215. echo "search $domainname" >> /etc/resolv.conf
  216.  
  217.  
  218. service samba-ad-dc restart >> INSTALL-LOG 2>&1
  219. samba-tool domain level raise --domain-level 2008_R2 --forest-level 2008_R2 >> INSTALL-LOG 2>&1
  220. samba-tool domain passwordsettings set --complexity=off >> INSTALL-LOG 2>&1
  221. samba-tool domain passwordsettings set --min-pwd-length=1 >> INSTALL-LOG 2>&1
  222.  
  223. #*****************************************************************
  224. # TODO TODO TODO
  225. #
  226. # figure out how to pass password in so it's not requested
  227. #
  228. #*****************************************************************
  229. samba-tool user setpassword Administrator <<< $password
  230. #expect -c "
  231. # spawn samba-tool user setpassword Administrator
  232. # expect "?assword: "
  233. # send $password
  234. # expect eof"
  235.  
  236. samba-tool user setexpiry Administrator --noexpiry >> INSTALL-LOG 2>&1
  237.  
  238. service samba-ad-dc restart >> INSTALL-LOG 2>&1
  239.  
  240. echo "
  241. # Global parameters
  242. [global]
  243. server role = active directory domain controller
  244. workgroup = $upperworkgroup
  245. realm = $domainname
  246. netbios name = $hostname
  247. passdb backend = samba4
  248. dns forwarder = $nameserver2
  249.  
  250. [netlogon]
  251. path = /var/lib/samba/sysvol/example.com/scripts
  252. read only = No
  253.  
  254. [sysvol]
  255. path = /var/lib/samba/sysvol
  256. read only = No
  257. " > /etc/samba/smb.conf
  258.  
  259. service samba-ad-dc stop >> INSTALL-LOG 2>&1
  260.  
  261. # sometimes, these don't stop
  262. killall -9 smbd >> INSTALL-LOG 2>&1
  263. killall -9 nmbd >> INSTALL-LOG 2>&1
  264. killall -9 samba >> INSTALL-LOG 2>&1
  265.  
  266. # none of this seems to work, smbd starts and samba-ad-dc doesn't. Neither does ocsmanager
  267. mv /etc/init/smbd.conf /etc/init/smbd.conf.disabled >> INSTALL-LOG 2>&1
  268. mv /etc/init/reload-smbd.conf /etc/init/reload-smbd.conf.disabled >> INSTALL-LOG 2>&1
  269. mv /etc/init/nmbd.conf /etc/init/nmbd.conf.disabled >> INSTALL-LOG 2>&1
  270. mv /etc/init/samba.conf /etc/init/samba.conf.disabled >> INSTALL-LOG 2>&1
  271.  
  272. update-rc.d -f smbd remove >> INSTALL-LOG 2>&1
  273. update-rc.d -f nmbd remove >> INSTALL-LOG 2>&1
  274. update-rc.d -f samba remove >> INSTALL-LOG 2>&1
  275.  
  276. update-rc.d samba-ad-dc defaults >> INSTALL-LOG 2>&1
  277.  
  278. service samba-ad-dc start >> INSTALL-LOG 2>&1
  279.  
  280. echo "nameserver $ipaddress" > /etc/resolv.conf
  281. echo "nameserver 8.8.8.8" >> /etc/resolv.conf
  282. echo "search $domainname" >> /etc/resolv.conf
  283. echo "domain $domainname" >> /etc/resolv.conf
  284.  
  285. installstr+=" - done\n"
  286. dialog --title " Please Wait... " --backtitle "$installback" \
  287. --infobox "$installstr" 15 50 2>.tmp
  288.  
  289. }
  290.  
  291. #######################################################################
  292. #
  293. # @param
  294. #
  295. # @return 0 for failure
  296. # 1 for success
  297. #
  298. # @brief
  299. # Install dovecot and config to authenticate against samba
  300. #
  301. #######################################################################
  302. install_dovecot () {
  303. echo "###################################################################################" >> INSTALL-LOG 2>&1
  304. echo " INSTALL DOVECOT" >> INSTALL-LOG 2>&1
  305. echo "###################################################################################" >> INSTALL-LOG 2>&1
  306. echo
  307. installstr+="Dovecot : install"
  308. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  309.  
  310. # create user
  311. groupadd -g 5000 vmail >> INSTALL-LOG 2>&1
  312. useradd -m -u 5000 -g 5000 -s /bin/bash -d /var/mail vmail >> INSTALL-LOG 2>&1
  313. adduser vmail mail >> INSTALL-LOG 2>&1
  314. chown -R vmail:vmail /var/mail >> INSTALL-LOG 2>&1
  315.  
  316. # preseed
  317. echo "dovecot-core dovecot-core/create-ssl-cert boolean true
  318. dovecot-core dovecot-core/ssl-cert-name string localhost" | debconf-set-selections
  319.  
  320. apt-get -y install dovecot-imapd dovecot-pop3d dovecot-ldap dovecot-managesieved dovecot-sieve dovecot-lmtpd >> INSTALL-LOG 2>&1
  321. response=$?
  322. case $response in
  323. 100)
  324. whiptail --title " ERROR " --backtitle "$installback" \
  325. --infobox "Failed to install Dovecot. See INSTALL-LOG" 10 50
  326.  
  327. exit
  328. ;;
  329.  
  330. esac
  331.  
  332. installstr+=" - config"
  333. dialog --title " Please Wait... " --backtitle "$installback" \
  334. --infobox "$installstr" 15 50 2>.tmp
  335.  
  336. echo -e "
  337. # Enable installed protocols
  338. !include_try /usr/share/dovecot/protocols.d/*.protocol
  339.  
  340. postmaster_address=administrator@$domainname
  341.  
  342. # AUTH
  343. disable_plaintext_auth = yes
  344. auth_master_user_separator = *
  345. auth_mechanisms = plain login
  346.  
  347. # master users
  348. #passdb {
  349. # driver = passwd-file
  350. # master = yes
  351. # args = /etc/dovecot/master-users
  352.  
  353. # Unless you're using PAM, you probably still want the destination user to
  354. # be looked up from passdb that it really exists. pass=yes does that.
  355. #pass = yes
  356. #}
  357.  
  358. # ldap users
  359. passdb {
  360. driver = ldap
  361. args = /etc/dovecot/dovecot-ldap.conf.ext
  362. }
  363.  
  364. userdb {
  365. driver = ldap
  366. args = /etc/dovecot/dovecot-ldap.conf.ext
  367. }
  368.  
  369. # trust on 127.0.0.1
  370. passdb {
  371. driver = static
  372. args = nopassword=y allow_nets=127.0.0.1/32
  373. }
  374.  
  375.  
  376. # LOGGING
  377. auth_verbose = yes
  378. mail_debug = no
  379. plugin {
  380. # Events to log. Also available: flag_change append
  381. #mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename
  382. # Available fields: uid, box, msgid, from, subject, size, vsize, flags
  383. # size and vsize are available only for expunge and copy events.
  384. #mail_log_fields = uid box msgid size
  385. }
  386.  
  387. # MAIL and NAMESPACES
  388. mail_location = maildir:~/maildir
  389. mail_uid = vmail
  390. mail_gid = vmail
  391. mail_plugins = acl quota
  392.  
  393. namespace {
  394. type = private
  395. separator = /
  396. prefix =
  397. inbox = yes
  398.  
  399. mailbox INBOX {
  400. auto = create
  401. }
  402. }
  403. namespace {
  404. type = shared
  405. separator = /
  406. prefix = shared/%%u/
  407. location = maildir:%%h/maildir:INDEX=~/maildir/shared/%%u
  408. subscriptions = no
  409. list = children
  410. }
  411.  
  412.  
  413. # MASTER
  414. service imap-login {
  415. inet_listener imap {
  416. #port = 143
  417. }
  418. inet_listener imaps {
  419. #port = 993
  420. ssl = yes
  421. }
  422. # this is suboptimal since imap and imaps will also accept nopass
  423. inet_listener imap-nopass {
  424. port = 144
  425. }
  426.  
  427. }
  428. service pop3-login {
  429. inet_listener pop3 {
  430. #port = 110
  431. }
  432. inet_listener pop3s {
  433. #port = 995
  434. #ssl = yes
  435. }
  436. }
  437. service lmtp {
  438. unix_listener lmtp {
  439. #mode = 0666
  440. }
  441. # Create inet listener only if you can't use the above UNIX socket
  442. inet_listener lmtp {
  443. # Avoid making LMTP visible for the entire internet
  444. address = 127.0.0.1
  445. port = 24
  446. }
  447. }
  448. service imap {
  449. executable = imap postlogin
  450. }
  451. service auth {
  452. # auth_socket_path points to this userdb socket by default. It's typically
  453. # used by dovecot-lda, doveadm, possibly imap process, etc. Its default
  454. # permissions make it readable only by root, but you may need to relax these
  455. # permissions. Users that have access to this socket are able to get a list
  456. # of all usernames and get results of everyone's userdb lookups.
  457. unix_listener /var/spool/postfix/private/auth {
  458. mode = 0660
  459. user = postfix
  460. group = postfix
  461. }
  462. }
  463. service postlogin {
  464. executable = script-login -d rawlog
  465. unix_listener postlogin {
  466. }
  467. }
  468.  
  469. # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
  470. ssl = yes
  471. ssl_cert = </etc/ssl/certs/dovecot.pem
  472. ssl_key = </etc/ssl/private/dovecot.pem
  473.  
  474. # LDA
  475. quota_full_tempfail = yes
  476. protocol lda {
  477. # Space separated list of plugins to load (default is global mail_plugins).
  478. #mail_plugins = \$mail_plugins
  479. }
  480.  
  481. # PROTOCOLS
  482. protocol imap {
  483. mail_plugins = \$mail_plugins autocreate imap_acl imap_quota
  484. }
  485. protocol lmtp {
  486. mail_plugins = \$mail_plugins sieve
  487. }
  488.  
  489. service managesieve-login {
  490. inet_listener sieve {
  491. port = 4190
  492. address = 127.0.0.1
  493. }
  494. }
  495. service managesieve {
  496. }
  497. protocol sieve {
  498. }
  499.  
  500. plugin {
  501. acl = vfile
  502. acl_shared_dict = file:/var/spool/dovecot/shared-mailboxes.db
  503.  
  504. quota_rule = *:storage=2G
  505. quota_rule2 = Trash:storage=+100M
  506. quota = dict:::file:%h/dovecot-quota
  507.  
  508. sieve = ~/.dovecot.sieve
  509. sieve_dir = ~/sieve
  510.  
  511. autocreate = Trash
  512. autosubscribe = Trash
  513. autocreate2 = Drafts
  514. autosubscribe2 = Drafts
  515. autocreate3 = Sent
  516. }
  517.  
  518. " > /etc/dovecot/dovecot.conf
  519.  
  520. echo -e "
  521. hosts = 127.0.0.1:389
  522. dn = cn=administrator,cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  523. dnpass = $password
  524. base = cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  525. auth_bind = yes
  526. pass_filter = (cn=%n)
  527. user_filter = (cn=%n)
  528. user_attrs = cn=home=/var/spool/dovecot/%$
  529. " > /etc/dovecot/dovecot-ldap.conf.ext
  530.  
  531. rpl -e "#C=FI" "C=CA" /usr/share/doc/dovecot-core/dovecot/dovecot-openssl.cnf >> INSTALL-LOG 2>&1
  532. rpl -e "#ST=" "ST=Manitoba" /usr/share/doc/dovecot-core/dovecot/dovecot-openssl.cnf >> INSTALL-LOG 2>&1
  533. rpl -e "#L=Helsinki" "L=Winnipeg" /usr/share/doc/dovecot-core/dovecot/dovecot-openssl.cnf >> INSTALL-LOG 2>&1
  534. rpl -e "#O=Dovecot" "O=$workgroup" /usr/share/doc/dovecot-core/dovecot/dovecot-openssl.cnf >> INSTALL-LOG 2>&1
  535. rpl -e "CN=imap.example.com" "CN=*.$domainname" /usr/share/doc/dovecot-core/dovecot/dovecot-openssl.cnf >> INSTALL-LOG 2>&1
  536. rpl -e "emailAddress=postmaster@example.com" "emailAddress=postmaster@$domainname" /usr/share/doc/dovecot-core/dovecot/dovecot-openssl.cnf >> INSTALL-LOG 2>&1
  537.  
  538. pushd .
  539. cd /usr/share/doc/dovecot-core/dovecot >> INSTALL-LOG 2>&1
  540. chmod +x mkcert.sh >> INSTALL-LOG 2>&1
  541. ./mkcert.sh >> INSTALL-LOG 2>&1
  542. popd
  543. touch /var/log/dovecot.message
  544. chown vmail.vmail /var/log/dovecot.message
  545.  
  546.  
  547. mkdir /var/spool/dovecot
  548. chown vmail.vmail /var/spool/dovecot
  549.  
  550. service dovecot restart >> INSTALL-LOG 2>&1
  551.  
  552. installstr+=" - done\n"
  553. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  554.  
  555. }
  556.  
  557. #######################################################################
  558. #
  559. # @param
  560. #
  561. # @return 0 for failure
  562. # 1 for success
  563. #
  564. # @brief
  565. # Install imapproxy
  566. #
  567. #######################################################################
  568. install_imapproxy () {
  569. echo "###################################################################################" >> INSTALL-LOG 2>&1
  570. echo " INSTALL IMAPPROXY" >> INSTALL-LOG 2>&1
  571. echo "###################################################################################" >> INSTALL-LOG 2>&1
  572. echo " " >> INSTALL-LOG 2>&1
  573.  
  574. #just in case
  575. service dovecot restart >> INSTALL-LOG 2>&1
  576.  
  577.  
  578. installstr+="IMAP Proxy: install"
  579. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  580. apt-get -y install imapproxy >> INSTALL-LOG 2>&1
  581.  
  582. installstr+=" - config"
  583. dialog --title " Please Wait... " --backtitle "$installback" \
  584. --infobox "$installstr" 15 50 2>.tmp
  585.  
  586. echo -e "
  587. server_hostname localhost
  588. connect_retries 10
  589. connect_delay 5
  590. cache_size 3072
  591. listen_port 1143
  592. server_port 143
  593. cache_expiration_time 300
  594. proc_username nobody
  595. proc_groupname nogroup
  596. stat_filename /var/run/pimpstats
  597. protocol_log_filename /var/log/imapproxy_protocol.log
  598. syslog_facility LOG_MAIL
  599. send_tcp_keepalives no
  600. enable_select_cache no
  601. foreground_mode no
  602. force_tls no
  603. chroot_directory /var/lib/imapproxy/chroot
  604. enable_admin_commands no
  605. " > /etc/imapproxy.conf
  606.  
  607. installstr+=" - done\n"
  608. dialog --title " Please Wait... " --backtitle "$installback" \
  609. --infobox "$installstr" 15 50 2>.tmp
  610.  
  611. }
  612.  
  613.  
  614.  
  615. #######################################################################
  616. #
  617. # @param
  618. #
  619. # @return 0 for failure
  620. # 1 for success
  621. #
  622. # @brief
  623. # Install postfix and configure to autheticate against ldap
  624. #
  625. #######################################################################
  626. install_postfix () {
  627. echo "###################################################################################" >> INSTALL-LOG 2>&1
  628. echo " INSTALL POSTFIX" >> INSTALL-LOG 2>&1
  629. echo "###################################################################################" >> INSTALL-LOG 2>&1
  630. echo
  631. installstr+="Postfix : install"
  632. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  633.  
  634. echo postfix postfix/main_mailer_type select Internet Site > postfix-config
  635. echo postfix postfix/mailname string $domainname >> postfix-config
  636. echo postfix postfix/destinations string $domainname, localhost, localhost.localdomain >> postfix-config
  637.  
  638. cat postfix-config | debconf-set-selections
  639.  
  640. apt-get -y install postfix postfix-ldap >> INSTALL-LOG 2>&1
  641. response=$?
  642. case $response in
  643. 100)
  644. whiptail --title " ERROR " --backtitle "$installback" \
  645. --infobox "Failed to install Postfix. See INSTALL-LOG" 10 50
  646.  
  647. exit
  648. ;;
  649.  
  650. esac
  651.  
  652. installstr+=" - config"
  653. dialog --title " Please Wait... " --backtitle "$installback" \
  654. --infobox "$installstr" 15 50 2>.tmp
  655.  
  656. echo -e "
  657. # See /usr/share/postfix/main.cf.dist for a commented, more complete version
  658.  
  659.  
  660. # Debian specific: Specifying a file name will cause the first
  661. # line of that file to be used as the name. The Debian default
  662. # is /etc/mailname.
  663. #myorigin = /etc/mailname
  664.  
  665. smtpd_banner = \$myhostname ESMTP \$mail_name (Ubuntu)
  666. biff = no
  667.  
  668. # appending .domain is the MUA's job.
  669. append_dot_mydomain = no
  670.  
  671. # Uncomment the next line to generate "delayed mail" warnings
  672. #delay_warning_time = 4h
  673.  
  674. readme_directory = no
  675.  
  676. # TLS parameters
  677. smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
  678. smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
  679. smtpd_use_tls=yes
  680. smtpd_tls_session_cache_database = btree:\${data_directory}/smtpd_scache
  681. smtp_tls_session_cache_database = btree:\${data_directory}/smtp_scache
  682.  
  683. # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
  684. # information on enabling SSL in the smtp client.
  685.  
  686. smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
  687. myhostname = $hostname.$domainname
  688. alias_maps = hash:/etc/aliases
  689. alias_database = hash:/etc/aliases
  690. myorigin = /etc/mailname
  691. mydestination = localhost, \$myhostname, \$mydomain
  692. relayhost =
  693. mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 $basenet/$cidr
  694. mailbox_size_limit = 0
  695. recipient_delimiter = +
  696. inet_interfaces = all
  697. inet_protocols = all
  698. virtual_alias_maps = ldap:/etc/postfix/people.ldap
  699. mailbox_transport = lmtp:127.0.0.1:24
  700.  
  701. # SASL Auth
  702. smtpd_sasl_auth_enable = yes
  703. smtpd_sasl_security_options = noanonymous
  704. smtpd_sasl_type = dovecot
  705. smtpd_sasl_path = private/auth
  706. smtpd_sasl_local_domain = \$myorigin
  707. broken_sasl_auth_clients = yes
  708. " > /etc/postfix/main.cf
  709.  
  710. echo -e "
  711. version = 3
  712. server_port = 389
  713. timeout = 60
  714. search_base = cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  715. query_filter = (mail=%s)
  716. result_attribute = cn
  717. bind = yes
  718. bind_dn = cn=administrator,cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  719. bind_pw = $password
  720. server_host = ldap://127.0.0.1:389/
  721. " > /etc/postfix/people.ldap
  722.  
  723. #echo -e "\ndovecot unix - n n - - pipe
  724. # flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d \${user}" >> /etc/postfix/master.cf
  725.  
  726. service postfix restart >> INSTALL-LOG 2>&1
  727.  
  728. installstr+=" - done\n"
  729. dialog --title " Please Wait... " --backtitle "$installback" \
  730. --infobox "$installstr" 15 50 2>.tmp
  731.  
  732. }
  733.  
  734.  
  735. #######################################################################
  736. #
  737. # @param
  738. #
  739. # @return 0 for failure
  740. # 1 for success
  741. #
  742. # @brief
  743. # install mysql for sogos (and later on ocsmanagers) use
  744. #
  745. #######################################################################
  746. install_mysql () {
  747. echo "###################################################################################" >> INSTALL-LOG 2>&1
  748. echo " INSTALL MySQL" >> INSTALL-LOG 2>&1
  749. echo "###################################################################################" >> INSTALL-LOG 2>&1
  750. echo
  751. installstr+="MySQL : install"
  752. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  753.  
  754. # set up the preseed
  755. # we use the user supplied admin password for the mysql db
  756. echo "mysql-server-5.5 mysql-server/root_password password $password
  757. mysql-server-5.5 mysql-server/root_password seen true
  758. mysql-server-5.5 mysql-server/root_password_again password $password
  759. mysql-server-5.5 mysql-server/root_password_again seen true
  760. " | debconf-set-selections
  761.  
  762. apt-get -y install mysql-server mysql-client python-mysqldb >> INSTALL-LOG 2>&1
  763. response=$?
  764. case $response in
  765. 100)
  766. whiptail --title " ERROR " --backtitle "$installback" \
  767. --infobox "Failed to install MySQL. See INSTALL-LOG" 10 50
  768.  
  769. exit
  770. ;;
  771.  
  772. esac
  773.  
  774. installstr+=" - config"
  775. dialog --title " Please Wait... " --backtitle "$installback" \
  776. --infobox "$installstr" 15 50 2>.tmp
  777.  
  778.  
  779. service mysql restart >> INSTALL-LOG 2>&1
  780.  
  781. installstr+=" - done\n"
  782. dialog --title " Please Wait... " --backtitle "$installback" \
  783. --infobox "$installstr" 15 50 2>.tmp
  784.  
  785. }
  786.  
  787.  
  788. #######################################################################
  789. #
  790. # @param
  791. #
  792. # @return 0 for failure
  793. # 1 for success
  794. #
  795. # @brief
  796. # Install the SOGo server
  797. #
  798. #######################################################################
  799. install_sogo () {
  800. echo "###################################################################################" >> INSTALL-LOG 2>&1
  801. echo " INSTALL SOGo" >> INSTALL-LOG 2>&1
  802. echo "###################################################################################" >> INSTALL-LOG 2>&1
  803. echo
  804. installstr+="SOGo : install"
  805. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  806.  
  807. # set up the preseed
  808. echo "tmpreaper tmpreaper/TMPREAPER_TIME note
  809. tmpreaper tmpreaper/confignowexists note
  810. tmpreaper tmpreaper/readsecurity note
  811. tmpreaper tmpreaper/readsecurity_upgrading note" | debconf-set-selections
  812.  
  813. #apt-get -y install sogo sogo-activesync libwbxml2-0 python-mysqldb python-sievelib >> INSTALL-LOG 2>&1
  814. apt-get -y install sogo sogo-activesync >> INSTALL-LOG 2>&1
  815. response=$?
  816. case $response in
  817. 100)
  818. whiptail --title " ERROR " --backtitle "$installback" \
  819. --infobox "Failed to install SOGo. See INSTALL-LOG" 10 50
  820.  
  821. exit
  822. ;;
  823.  
  824. esac
  825.  
  826. mysql --password="$password" --user=root mysql -e "CREATE DATABASE sogo CHARACTER SET utf8 ; CREATE USER 'sogo'@'localhost' IDENTIFIED BY '$genpassword' ; GRANT ALL PRIVILEGES ON sogo.* TO 'sogo'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;" >> INSTALL-LOG 2>&1
  827.  
  828. installstr+=" - config"
  829. dialog --title " Please Wait... " --backtitle "$installback" \
  830. --infobox "$installstr" 15 50 2>.tmp
  831.  
  832. samba-tool user add sogo '$password' >> INSTALL-LOG 2>&1
  833.  
  834. #make a good sogo.conf
  835.  
  836. echo "
  837. {
  838. SOGoUserSources = (
  839. {
  840. CNFieldName = cn;
  841. IDFieldName = cn;
  842. UIDFieldName = sAMAccountName;
  843. baseDN = \"cn=Users,dc=${DOM[0]},dc=${DOM[1]}\";
  844. bindDN = \"cn=administrator,cn=Users,dc=${DOM[0]},dc=${DOM[1]}\";
  845. bindFields = (sAMAccountName);
  846. bindPassword = \"$password\";
  847. canAuthenticate = YES;
  848. displayName = \"Shared Addresses\";
  849. hostname = \"ldap://127.0.0.1:389/\";
  850. id = public;
  851. isAddressBook = YES;
  852. type = ldap;
  853. }
  854. );
  855. SOGoAppointmentSendEMailNotifications = YES;
  856. //SOGoSuperUsernames = (administrator);
  857.  
  858. SOGoProfileURL = mysql://sogo:$genpassword@127.0.0.1:3306/sogo/sogo_user_profile;
  859. OCSFolderInfoURL = mysql://sogo:$genpassword@127.0.0.1:3306/sogo/sogo_folder_info;
  860. OCSEMailAlarmsFolderURL = mysql://sogo:$genpassword@127.0.0.1:3306/sogo/sogo_alarms_folder;
  861. OCSSessionsFolderURL = mysql://sogo:$genpassword@127.0.0.1:3306/sogo/sogo_sessions_info;
  862.  
  863. SOGoSieveScriptsEnabled = YES;
  864. SOGoForwardEnabled = YES;
  865. SOGoVacationEnabled = YES;
  866. SOGoEnableEMailAlarms = YES;
  867. SOGoTimeZone = $timezone;
  868. SOGoIMAPServer = 127.0.0.1:1143;
  869. SOGoSieveServer = sieve://127.0.0.1:4190;
  870. SOGoMailingMechanism = smtp;
  871. SOGoSMTPServer = 127.0.0.1;
  872. SOGoCalendarDefaultRoles = (\"PublicDAndTViewer\");
  873.  
  874. /* Debugging */
  875. //LDAPDebugEnabled = YES;
  876. //MySQL4DebugEnabled = YES;
  877. //OCSFolderManagerSQLDebugEnabled = YES;
  878. //PGDebugEnabled = YES;
  879. //SOGoDebugRequests = YES;
  880. //WODebugTakeValues = YES;
  881. SOGoUIxDebugEnabled = YES;
  882. //SaxDebugReaderFactory = YES;
  883. //SaxObjectDecoderDebugEnabled = YES;
  884. //SoDebugObjectTraversal = YES;
  885. //SoSecurityManagerDebugEnabled = YES;
  886. //VSSaxDriverDebugEnabled = YES;
  887. //WODebugResourceLookup = YES;
  888. //WEResourceManagerDebugEnabled = YES;
  889. //WEResourceManagerComponentDebugEnabled = YES;
  890. }
  891.  
  892. " > /etc/sogo/sogo.conf
  893.  
  894.  
  895. # the Ubuntu startup scripts specifies the number of threads. The commndline overrides
  896. # the config, so we need to change that
  897. rpl -e "PREFORK=3" "PREFORK=10" /etc/init.d/sogo >> INSTALL-LOG 2>&1
  898.  
  899.  
  900. # get cronjobs installed
  901. echo "
  902. * * * * * sogo /usr/sbin/sogo-ealarms-notify
  903. 0 0 * * * sogo /usr/sbin/sogo-tool expire-autoreply -p /etc/sogo/sieve.creds
  904. " >> /etc/crontab
  905.  
  906.  
  907. echo "administrator:$password
  908. " > /etc/sogo/sieve.creds
  909.  
  910. service samba-ad-dc start >> INSTALL-LOG 2>&1
  911. service sogo restart >> INSTALL-LOG 2>&1
  912.  
  913. installstr+=" - done\n"
  914. dialog --title " Please Wait... " --backtitle "$installback" \
  915. --infobox "$installstr" 15 50 2>.tmp
  916.  
  917.  
  918. }
  919.  
  920. #######################################################################
  921. #
  922. # @param
  923. #
  924. # @return 0 for failure
  925. # 1 for success
  926. #
  927. # @brief
  928. # We use samba 4 for user auth, so get it installed and running with the proper domain
  929. #
  930. #######################################################################
  931. install_apache () {
  932. echo "###################################################################################" >> INSTALL-LOG 2>&1
  933. echo " INSTALL Apache" >> INSTALL-LOG 2>&1
  934. echo "###################################################################################" >> INSTALL-LOG 2>&1
  935. echo
  936. installstr+="Apache : install"
  937. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  938.  
  939. #apt-get -y install apache2 apache2-mpm-prefork apache2-utils libapache2-mod-wsgi apachetop >> INSTALL-LOG 2>&1
  940. apt-get -y install apache2 apache2-utils libapache2-mod-wsgi apachetop >> INSTALL-LOG 2>&1
  941. response=$?
  942. case $response in
  943. 100)
  944. whiptail --title " ERROR " --backtitle "$installback" \
  945. --infobox "Failed to install SOGo MySQL Connector. See INSTALL-LOG" 10 50
  946.  
  947. exit
  948. ;;
  949.  
  950. esac
  951.  
  952. installstr+=" - config"
  953. dialog --title " Please Wait... " --backtitle "$installback" \
  954. --infobox "$installstr" 15 50 2>.tmp
  955.  
  956. a2dismod mpm_event >> INSTALL-LOG 2>&1
  957.  
  958. a2enmod mpm_prefork >> INSTALL-LOG 2>&1
  959. a2enmod proxy >> INSTALL-LOG 2>&1
  960. a2enmod proxy_http >> INSTALL-LOG 2>&1
  961. a2enmod wsgi >> INSTALL-LOG 2>&1
  962. a2enmod headers >> INSTALL-LOG 2>&1
  963. a2enmod rewrite >> INSTALL-LOG 2>&1
  964. a2enmod ssl >> INSTALL-LOG 2>&1
  965.  
  966. a2dismod reqtimeout >> INSTALL-LOG 2>&1
  967.  
  968. a2ensite default-ssl >> INSTALL-LOG 2>&1
  969.  
  970. # temp for bad placment by the .debs
  971. mv /etc/apache2/conf.d/SOGo.conf /etc/apache2/conf-available >> INSTALL-LOG 2>&1
  972.  
  973.  
  974. rpl -e "443" "80" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  975. rpl -e "yourhostname" "$hostname.$domainname" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  976. rpl -e "http://yourhostname" "http://$hostname.$domainname" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  977.  
  978.  
  979. # turn on activesync
  980. rpl -e "#ProxyPass /Micro" "ProxyPass /Micro" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  981. rpl -e "# http://127.0.0.1:20000" " http://127.0.0.1:20000" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  982. rpl -e "# retry=60" " retry=60" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  983.  
  984. # add remote hosts
  985. rpl -e " RequestHeader unset" "# RequestHeader unset" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  986. rpl -e " AddDefaultCharset" " RequestHeader set "x-webobjects-remote-host" %{REMOTE_HOST}e env=REMOTE_HOST\n AddDefaultCharset" /etc/apache2/conf-available/SOGo.conf >> INSTALL-LOG 2>&1
  987.  
  988. a2enconf SOGo >> INSTALL-LOG 2>&1
  989.  
  990. echo -e "
  991. ## We use mod_rewrite to pass remote address to the SOGo proxy.
  992. # The remote address will appear in SOGo's log files and in the X-Forward
  993. # header of emails.
  994. RewriteEngine On
  995. RewriteRule ^/SOGo/(.*)$ /SOGo/$1 [env=REMOTE_HOST:%{REMOTE_ADDR},PT]
  996. " >> /etc/apache2/conf-available/SOGo.conf
  997.  
  998.  
  999. service apache2 restart >> INSTALL-LOG 2>&1
  1000. service sogo restart >> INSTALL-LOG 2>&1
  1001.  
  1002. installstr+=" - done\n"
  1003. dialog --title " Please Wait... " --backtitle "$installback" \
  1004. --infobox "$installstr" 15 50 2>.tmp
  1005.  
  1006. }
  1007.  
  1008. #######################################################################
  1009. #
  1010. # @param
  1011. #
  1012. # @return 0 for failure
  1013. # 1 for success
  1014. #
  1015. # @brief
  1016. # saslauthd and related tools
  1017. #
  1018. #######################################################################
  1019. install_saslauthd () {
  1020. echo "###################################################################################" >> INSTALL-LOG 2>&1
  1021. echo " INSTALL SASLAuthD" >> INSTALL-LOG 2>&1
  1022. echo "###################################################################################" >> INSTALL-LOG 2>&1
  1023. echo
  1024. installstr+="saslauthd : install"
  1025. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  1026.  
  1027. apt-get -y install sasl2-bin >> INSTALL-LOG 2>&1
  1028. response=$?
  1029. case $response in
  1030. 100)
  1031. whiptail --title " ERROR " --backtitle "$installback" \
  1032. --infobox "Failed to install saslauthd. See INSTALL-LOG" 10 50
  1033.  
  1034. exit
  1035. ;;
  1036.  
  1037. esac
  1038.  
  1039. installstr+=" - config"
  1040. dialog --title " Please Wait... " --backtitle "$installback" \
  1041. --infobox "$installstr" 15 50 2>.tmp
  1042.  
  1043. echo "
  1044. START=yes
  1045. DESC=\"SASL Authentication Daemon\"
  1046. NAME=\"saslauthd\"
  1047. MECHANISMS=\"ldap\"
  1048. MECH_OPTIONS=\"\"
  1049. THREADS=5
  1050. OPTIONS=\"-c -m /var/run/saslauthd\"
  1051. " > /etc/default/saslauthd
  1052.  
  1053. echo "
  1054. ldap_servers: ldap://127.0.0.1:389/
  1055. ldap_version: 3
  1056. ldap_auth_method: bind
  1057. ldap_bind_dn: cn=administrator,cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  1058. ldap_bind_pw: $password
  1059. ldap_search_base: cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  1060. ldap_filter: cn=%U
  1061. ldap_scope: sub
  1062. " > /etc/saslauthd.conf
  1063.  
  1064. service saslauthd start
  1065.  
  1066. installstr+=" - done\n"
  1067. dialog --title " Please Wait... " --backtitle "$installback" \
  1068. --infobox "$installstr" 15 50 2>.tmp
  1069.  
  1070.  
  1071. }
  1072.  
  1073. #######################################################################
  1074. #
  1075. # @param
  1076. #
  1077. # @return 0 for failure
  1078. # 1 for success
  1079. #
  1080. # @brief
  1081. # We use samba 4 for user auth, so get it installed and running with the proper domain
  1082. #
  1083. #######################################################################
  1084. install_openchange () {
  1085. echo "###################################################################################" >> INSTALL-LOG 2>&1
  1086. echo " INSTALL Openchange" >> INSTALL-LOG 2>&1
  1087. echo "###################################################################################" >> INSTALL-LOG 2>&1
  1088. echo
  1089. installstr+="OpenChange: install"
  1090. dialog --title " Please Wait... " --backtitle "$installback" --infobox "$installstr" 15 50 2>.tmp
  1091.  
  1092. apt-get -y install openchangeserver sogo-openchange openchangeproxy python-ocsmanager python-mysqldb openchange-ocsmanager openchange-rpcproxy python-sievelib python-spyne python-rpclib >> INSTALL-LOG 2>&1
  1093. response=$?
  1094. case $response in
  1095. 100)
  1096. whiptail --title " ERROR " --backtitle "$installback" \
  1097. --infobox "Failed to install OpenChange. See INSTALL-LOG" 10 50
  1098.  
  1099. exit
  1100. ;;
  1101.  
  1102. esac
  1103.  
  1104. installstr+=" - config"
  1105. dialog --title " Please Wait... " --backtitle "$installback" \
  1106. --infobox "$installstr" 15 50 2>.tmp
  1107.  
  1108. #create the ocsmanager file
  1109. echo "
  1110. [DEFAULT]
  1111. debug = true
  1112. email_to = administrator@$domainname
  1113. smtp_server = localhost
  1114. error_email_from = administrator@$domainname
  1115.  
  1116. [main]
  1117. auth = ldap
  1118. mapistore_root = /var/lib/samba/private
  1119. mapistore_data = /var/lib/samba/private/mapistore
  1120. debug = yes
  1121.  
  1122. [auth:file]
  1123.  
  1124. [auth:ldap]
  1125. host = ldap://127.0.0.1
  1126. port = 389
  1127. bind_dn = cn=administrator,cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  1128. bind_pw = $password
  1129. basedn = cn=Users,dc=${DOM[0]},dc=${DOM[1]}
  1130.  
  1131. [auth:single]
  1132. username = openchange
  1133. # password is test
  1134. password = {SSHA}I6Hy5Wv0wuxyXvMBFWFQDVVN12_CLaX9
  1135.  
  1136. [server:main]
  1137. use = egg:Paste#http
  1138. host = 127.0.0.1
  1139. port = 5000
  1140. protocol_version = HTTP/1.1
  1141.  
  1142. [app:main]
  1143. use = egg:ocsmanager
  1144. full_stack = true
  1145. static_files = true
  1146. cache_dir = %(here)s/data
  1147. beaker.session.key = ocsmanager
  1148. beaker.session.secret = SDyKK3dKyDgW0mlpqttTMGU1f
  1149. app_instance_uuid = {ee533ebc-f266-49d1-ae10-d017ee6aa98c}
  1150. NTLMAUTHHANDLER_WORKDIR = /var/cache/ntlmauthhandler
  1151. SAMBA_HOST = 127.0.0.1
  1152.  
  1153. [rpcproxy:ldap]
  1154. host = localhost
  1155. port = 389
  1156. basedn = CN=Users,DC=${DOM[0]},DC=${DOM[1]}
  1157. set debug = true
  1158.  
  1159. [autodiscover]
  1160.  
  1161. [autodiscover:rpcproxy]
  1162. enabled = true
  1163.  
  1164. [outofoffice]
  1165.  
  1166. [outofoffice:file]
  1167. sieve_script_path = /var/vmail/\$domain/\$user/sieve-script
  1168. sieve_script_path_mkdir = false
  1169.  
  1170. [outofoffice:managesieve]
  1171. secret = secret
  1172.  
  1173. # Logging configuration
  1174. [loggers]
  1175. keys = root
  1176.  
  1177. [handlers]
  1178. keys = console
  1179.  
  1180. [formatters]
  1181. keys = generic
  1182.  
  1183. [logger_root]
  1184. level = INFO
  1185. handlers = console
  1186.  
  1187. [handler_console]
  1188. class = StreamHandler
  1189. args = (sys.stderr,)
  1190. level = NOTSET
  1191. formatter = generic
  1192.  
  1193. [formatter_generic]
  1194. format = %(asctime)s %(levelname)-5.5s [%(name)s] [%(threadName)s] %(message)s
  1195. " > /etc/ocsmanager/ocsmanager.ini
  1196.  
  1197.  
  1198. # replace the smb.conf file with the one we need
  1199. echo "
  1200. # Global parameters
  1201. [global]
  1202. server role = active directory domain controller
  1203. workgroup = $upperworkgroup
  1204. realm = $domainname
  1205. netbios name = $hostname
  1206. passdb backend = samba4
  1207. dns forwarder = $nameserver2
  1208.  
  1209. ### Configuration required by OpenChange server ###
  1210. dsdb:schema update allowed = true
  1211. dcerpc endpoint servers = +epmapper, +mapiproxy, +dnsserver
  1212. dcerpc_mapiproxy:server = true
  1213. dcerpc_mapiproxy:interfaces = exchange_emsmdb, exchange_nsp, exchange_ds_rfr
  1214.  
  1215. mapistore:namedproperties = mysql
  1216. namedproperties:mysql_user = openchange-user
  1217. namedproperties:mysql_pass = $genpassword
  1218. namedproperties:mysql_host = localhost
  1219. namedproperties:mysql_db = openchange
  1220.  
  1221. mapistore:indexing_backend = mysql://openchange-user:$genpassword@localhost/openchange
  1222. mapiproxy:openchangedb = mysql://openchange-user:$genpassword@localhost/openchange
  1223. ### Configuration required by OpenChange server ###
  1224.  
  1225. [netlogon]
  1226. path = /var/lib/samba/sysvol/$domainname/scripts
  1227. read only = No
  1228.  
  1229. [sysvol]
  1230. path = /var/lib/samba/sysvol
  1231. read only = No
  1232. " > /etc/samba/smb.conf
  1233.  
  1234. #configure mysql for Openchnage
  1235. echo "running: mysql --password="$password" --user=root mysql -e \"CREATE USER 'openchange-user'@'localhost' IDENTIFIED BY '$genpassword';GRANT ALL PRIVILEGES ON openchange.* TO 'openchange-user'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;\"" >> INSTALL-LOG 2>&1
  1236.  
  1237. mysql --password="$password" --user=root mysql -e "CREATE USER 'openchange-user'@'localhost' IDENTIFIED BY '$genpassword';GRANT ALL PRIVILEGES ON openchange.* TO 'openchange-user'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;" >> INSTALL-LOG 2>&1
  1238.  
  1239.  
  1240. service samba-ad-dc start >> INSTALL-LOG 2>&1
  1241.  
  1242. openchange_provision --standalone >> INSTALL-LOG 2>&1
  1243. openchange_provision --openchangedb --openchangedb-uri mysql://openchange-user:$genpassword@localhost/openchange >> INSTALL-LOG 2>&1
  1244.  
  1245. # tell samba to use mysql backend
  1246. #rpl -e "[global]" "[global]\n\tmapistore:namedproperties = mysql\n\tnamedproperties:mysql_user = openchange-user\n\tnamedproperties:mysql_pass = $genpassword\n\tnamedproperties:mysql_host = localhost\n\tnamedproperties:mysql_db = openchange\n\n\tmapistore:indexing_backend = mysql://openchange-user:$genpassword@localhost/openchange\n\tmapiproxy:openchangedb = mysql://openchange-user:$genpassword@localhost/openchange\n" /etc/samba/smb.conf >> INSTALL-LOG 2>&1
  1247.  
  1248. # create new openchange users
  1249. openchange_newuser --create Administrator >> INSTALL-LOG 2>&1
  1250.  
  1251. # restart samba
  1252. service samba-ad-dc restart >> INSTALL-LOG 2>&1
  1253. service openchange-ocsmanager restart >> INSTALL-LOG 2>&1
  1254.  
  1255. # set the proper name resolution (temp, reboot will reset this properly)
  1256. # we'll get rid of 8.8.8.8 after samba is up
  1257. echo "nameserver $ipaddress" > /etc/resolv.conf
  1258. echo "nameserver 8.8.8.8" >> /etc/resolv.conf
  1259. echo "search $domainname" >> /etc/resolv.conf
  1260. echo "domain $domainname" >> /etc/resolv.conf
  1261.  
  1262. # temp for bad placment by the .debs
  1263. mv /etc/apache2/conf.d/ocsmanager.conf /etc/apache2/conf-available >> INSTALL-LOG 2>&1
  1264. mv /etc/apache2/conf.d/rpcproxy.conf /etc/apache2/conf-available >> INSTALL-LOG 2>&1
  1265.  
  1266. a2enconf ocsmanager >> INSTALL-LOG 2>&1
  1267. a2enconf rpcproxy >> INSTALL-LOG 2>&1
  1268.  
  1269. rpl -e "</Directory>" " Require all granted\n</Directory>" /etc/apache2/conf-available/rpcproxy.conf >> INSTALL-LOG 2>&1
  1270.  
  1271. update-rc.d openchange-ocsmanager defaults >> INSTALL-LOG 2>&1
  1272.  
  1273. service apache2 restart >> INSTALL-LOG 2>&1
  1274.  
  1275. service samba-ad-dc start >> INSTALL-LOG 2>&1
  1276. service openchange-ocsmanager restart >> INSTALL-LOG 2>&1
  1277. service sogo restart >> INSTALL-LOG 2>&1
  1278.  
  1279. installstr+=" - done\n"
  1280. dialog --title " Please Wait... " --backtitle "$installback" \
  1281. --infobox "$installstr" 15 50 2>.tmp
  1282.  
  1283. }
  1284.  
  1285. # Get the Network destination from the IP & Subnet mask
  1286. get_network_address() {
  1287. SaveIFS=$IFS
  1288. IFS=.
  1289. typeset -a IParr=($1)
  1290. typeset -a NMarr=($2)
  1291. IFS=$SaveIFS
  1292.  
  1293. echo $((${IParr[0]} & ${NMarr[0]})).$((${IParr[1]} & ${NMarr[1]})).$((${IParr[2]} & ${NMarr[2]})).$((${IParr[3]} & ${NMarr[3]}))
  1294. }
  1295.  
  1296. # Function calculates number of bit in a netmask
  1297. #
  1298. mask2cidr() {
  1299. nbits=0
  1300. IFS=.
  1301. for dec in $1 ; do
  1302. case $dec in
  1303. 255) let nbits+=8;;
  1304. 254) let nbits+=7;;
  1305. 252) let nbits+=6;;
  1306. 248) let nbits+=5;;
  1307. 240) let nbits+=4;;
  1308. 224) let nbits+=3;;
  1309. 192) let nbits+=2;;
  1310. 128) let nbits+=1;;
  1311. 0);;
  1312. *) echo "Error: $dec is not recognised"; exit 1
  1313. esac
  1314. done
  1315. echo "$nbits"
  1316. }
  1317.  
  1318. #######################################################################
  1319. #
  1320. # @param
  1321. #
  1322. # @return 0 for failure
  1323. # 1 for success
  1324. #
  1325. # @brief
  1326. #
  1327. #
  1328. #######################################################################
  1329. template () {
  1330. echo "hello"
  1331.  
  1332. }
  1333.  
  1334. echo Building an Active Directory Master and SOGo Server > INSTALL-LOG 2>&1
  1335. echo >> INSTALL-LOG 2>&1
  1336. echo Preparing install environment... >> INSTALL-LOG 2>&1
  1337.  
  1338. installstr=""
  1339. installback="Majentis Active Directory/SOGo/OpenChange Install v0.8.0"
  1340.  
  1341. whiptail --title " Please Wait... " --backtitle "$installback" \
  1342. --infobox "Preparing install environment" 15 50 2>.tmp
  1343.  
  1344. # Get the SOGo repo online
  1345. cp /etc/apt/sources.list /etc/apt/sources.list-orig
  1346. echo "deb http://inverse.ca/ubuntu trusty trusty" >> /etc/apt/sources.list
  1347. apt-key adv --keyserver keys.gnupg.net --recv-key 0x810273C4 >> INSTALL-LOG 2>&1
  1348. apt-get update >> INSTALL-LOG 2>&1
  1349.  
  1350. # I just prefer dialog, though I use whiptail for errors, since it changes the background color (whiptail doesn't work over ssh?)
  1351. apt-get -y install dialog debconf-utils joe htop expect >> INSTALL-LOG 2>&1
  1352. response=$?
  1353. case $response in
  1354. 100)
  1355. echo "Failed to prepare install environment. See INSTALL-LOG\n" >> INSTALL-LOG
  1356. whiptail --title " ERROR " --backtitle "$installback" \
  1357. --infobox "Failed to prepare install environment. See INSTALL-LOG" 10 50
  1358.  
  1359. exit
  1360. ;;
  1361.  
  1362. esac
  1363.  
  1364. # getting server information
  1365.  
  1366. dialog --title " Static IP Address " --backtitle "$installback" --inputbox "Enter this server's static IP address" 15 50 2>.tmp
  1367. ipaddress=`cat .tmp`
  1368.  
  1369. dialog --title " Netmask " --backtitle "$installback" --inputbox "Enter this server's netmask" 15 50 2>.tmp
  1370. netmask=`cat .tmp`
  1371.  
  1372. dialog --title " Gateway IP Address " --backtitle "$installback" --inputbox "Enter this server's gateway IP address" 15 50 2>.tmp
  1373. gateway=`cat .tmp`
  1374.  
  1375. dialog --title " External Nameserver IP Address " --backtitle "$installback" --inputbox "Enter this server's external namserver\n (i.e. 8.8.8.8)" 15 50 2>.tmp
  1376. nameserver2=`cat .tmp`
  1377.  
  1378. dialog --title " Domain Name " --backtitle "$installback" --inputbox "Enter this server's domain name\n (i.e. fisheye.com)" 15 50 2>.tmp
  1379. domainname=`cat .tmp`
  1380.  
  1381. dialog --title " Workgroup Name " --backtitle "$installback" --inputbox "Enter this server's workgroup / domain name\n (i.e. fisheye)" 15 50 2>.tmp
  1382. workgroup=`cat .tmp`
  1383.  
  1384. dialog --title " System Hostname " --backtitle "$installback" --inputbox "Enter this server's hostname\n (i.e. pdc)" 15 50 2>.tmp
  1385. hostname=`cat .tmp`
  1386.  
  1387. dialog --title " Administrator password " --backtitle "$installback" --inputbox "The password must contain lowercase letters,\nuppercase letters, and numbers.\n\nIf it doesn't, the install will fail." 0 0 2>.tmp
  1388. password=`cat .tmp`
  1389.  
  1390. timezone=`cat /etc/timezone`
  1391.  
  1392. dialog --title " Confirmation " --backtitle "$installback" --yesno "Is the following information correct:\n\n
  1393. System Name: $hostname.$domainname\n
  1394. Domain: $workgroup\n
  1395. IP address: $ipaddress/$netmask\n
  1396. Gateway: $gateway\n
  1397. External DNS Server: $nameserver2\n
  1398. Administrator password: $password\n
  1399. Timezone: $timezone" 0 0 2>.tmp
  1400. response=$?
  1401. case $response in
  1402. 1)
  1403. exit
  1404. ;;
  1405. 255)
  1406. exit
  1407. ;;
  1408. esac
  1409.  
  1410. echo -e "System Name: $hostname.$domainname\n
  1411. Domain: $workgroup\n
  1412. IP address: $ipaddress/$netmask\n
  1413. Gateway: $gateway\n
  1414. External DNS Server: $nameserver2\n
  1415. Administrator password: $password\n
  1416. Timezone: $timezone" >> INSTALL-LOG
  1417.  
  1418. # uppercase some info
  1419. upperdomain=${domainname^^}
  1420. upperhost=${hostname^^}
  1421. upperworkgroup=${workgroup^^}
  1422.  
  1423. # split domain up
  1424. OLDIFS="$IFS"
  1425. IFS='.'; DOM=($domainname)
  1426. IFS="$OLDIFS"
  1427.  
  1428. # generate the password used for DB access
  1429. genpassword=$(date +%s | sha256sum | base64 | head -c 16)
  1430.  
  1431. # get network info
  1432. basenet=$(get_network_address $ipaddress $netmask)
  1433. cidr=$(mask2cidr $netmask)
  1434.  
  1435. configure_network
  1436. modify_fstab
  1437. install_saslauthd
  1438. install_samba
  1439. install_dovecot
  1440. install_postfix
  1441. install_mysql
  1442. install_sogo
  1443. install_apache
  1444. install_openchange
  1445.  
  1446. install_imapproxy
Add Comment
Please, Sign In to add comment