This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Auto Installer for ZPX on Ubuntu 12.04

By: deniszb on Jul 24th, 2013  |  syntax: None  |  size: 15.53 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. clear
  4.  
  5. ## set install log path to home dir
  6. INSTALLLOG=~/zpx_install.log
  7. apt-get install apache2 php5 mysql-server-core-5.5 mysql-server-5.5
  8. echo ""
  9. echo "==================================================="
  10. echo "= Starting Auto Installer for ZPX on Ubuntu 12.04 ="
  11. echo "==================================================="
  12. echo "=-------------------------------------------------="
  13. echo "=       By Xengulai (xengulai@xengulai.com)       ="
  14. echo "=-------------------------------------------------="
  15. echo "==================================================="
  16. echo ""
  17.  
  18.  
  19. ## disable/remove AppArmor
  20. [ -f /etc/init.d/apparmor ]
  21.         if [ $? = "0" ]; then
  22.  
  23.         echo ""
  24.         echo -n "Stopping and Removing AppArmor: "
  25.  
  26.         /etc/init.d/apparmor stop &> /dev/null
  27.         update-rc.d -f apparmor remove &> /dev/null
  28.         apt-get -y remove apparmor &> /dev/null
  29.         mv /etc/init.d/apparmor /etc/init.d/apparmpr.removed &> /dev/null
  30.  
  31.         echo "Done."
  32.         echo ""
  33.         echo "REBOOT THE SERVER AND RUN THE SCRIPT AGAIN"
  34.         echo ""
  35.         echo ""
  36.         exit
  37.         fi
  38.  
  39.  
  40. ## collect variables for use in script
  41. echo "Variable collection:"
  42.  
  43. echo -n "Enter Server Public IP Address: "
  44. read SERVER_IP
  45. echo "Enter server name:"
  46. echo "(this should be the reverse lookup of $SERVER_IP)"
  47. echo -n "(ex. zeus.zpanelcp.com): "
  48. read SERVER_NAME
  49. echo -n "Enter FQDN for ZPX (ex. panel.zpanelcp.com): "
  50. read SERVER_CP_NAME
  51. echo -n "Enter MySQL root password: "
  52. read MYSQL_PASS
  53.  
  54.  
  55. ## pipe output to the install log
  56. exec &>$INSTALLLOG
  57.  
  58.  
  59.  
  60. echo -ne "\nUpdating Aptitude Repos: " >/dev/tty
  61.  
  62. apt-get update
  63. apt-get -y install unzip debconf-utils
  64.  
  65. echo "Done." >/dev/tty
  66.  
  67.  
  68.  
  69. echo -n "Creating initial folder structure: " >/dev/tty
  70.  
  71. mkdir /etc/zpanel
  72. mkdir /etc/zpanel/configs
  73. mkdir /etc/zpanel/panel
  74. mkdir /etc/zpanel/docs
  75. mkdir /var/zpanel
  76. mkdir /var/zpanel/hostdata
  77. mkdir /var/zpanel/hostdata/zadmin
  78. mkdir /var/zpanel/hostdata/zadmin/public_html
  79. mkdir /var/zpanel/logs
  80. mkdir /var/zpanel/backups
  81. mkdir /var/zpanel/temp
  82. ## why are we setting to 777 ???
  83. chmod -R 777 /etc/zpanel/
  84. chmod -R 777 /var/zpanel/
  85.  
  86. echo "Done." >/dev/tty
  87.  
  88.  
  89.  
  90. echo -n "Downloading / Extracting ZPX From SF to Temp Directory at /opt/zpanel: " >/dev/tty
  91.  
  92. echo "wget -q -O /opt/ZPX.zip http://sourceforge.net/projects/zpanelcp/files/releases/10.0.0/zpanelx-1_0_0.zip/download"
  93. wget -q -O /opt/ZPX.zip http://sourceforge.net/projects/zpanelcp/files/releases/10.0.0/zpanelx-1_0_0.zip/download
  94. unzip /opt/ZPX.zip -d /opt/zpanel
  95.  
  96. echo "Done." >/dev/tty
  97.  
  98.  
  99.  
  100. echo -n "Copying ZpanelX files to /etc/zpanel: " >/dev/tty
  101.  
  102. cp -fr /opt/zpanel/* /etc/zpanel/panel
  103. ## why are we setting to 777 ???
  104. chmod -R 777 /etc/zpanel/
  105. chmod -R 777 /var/zpanel/
  106. chmod 644 /etc/zpanel/panel/etc/apps/phpmyadmin/config.inc.php
  107. cp -fr /etc/zpanel/panel/etc/build/config_packs/ubuntu_11_10/* /etc/zpanel/configs/
  108.  
  109. echo "Done." >/dev/tty
  110.  
  111.  
  112.  
  113. echo -n "Registering 'zppy' client: " >/dev/tty
  114.  
  115. ln -sf /etc/zpanel/panel/bin/zppy /usr/bin/zppy
  116. chmod +x /usr/bin/zppy
  117. ln -sf /etc/zpanel/panel/bin/setso /usr/bin/setso
  118. chmod +x /usr/bin/setso
  119.  
  120. echo "Done." >/dev/tty
  121.  
  122.  
  123.  
  124. echo -n "Installing main packages: " >/dev/tty
  125.  
  126.  
  127. ## preload mysql variables to suppress prompts
  128. echo mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS | debconf-set-selections
  129. echo mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS | debconf-set-selections
  130. apt-get -y install mysql-server mysql-server apache2 libapache2-mod-php5 libapache2-mod-bw php5-common php5-suhosin php5-cli php5-mysql php5-gd php5-mcrypt php5-curl php-pear php5-imap php5-xmlrpc php5-xsl db4.7-util zip webalizer build-essential
  131.  
  132. echo "Done." >/dev/tty
  133.  
  134.  
  135.  
  136. echo -n "Setting Zpanel MySQL access: " >/dev/tty
  137.  
  138. cp /opt/zpanel/cnf/db.php /etc/zpanel/panel/cnf/db.php
  139. sed -i "s/\$pass = \"\";/\$pass = \"$MYSQL_PASS\";/g" /etc/zpanel/panel/cnf/db.php
  140. echo "Done." >/dev/tty
  141.  
  142.  
  143.  
  144. echo -n "Importing Zpanel Core Database: " >/dev/tty
  145.  
  146. mysql -uroot -p$MYSQL_PASS < /etc/zpanel/configs/zpanel_core.sql
  147. mysql -uroot -p$MYSQL_PASS -e "USE zpanel_core; UPDATE x_settings SET so_value_tx = 209715200, so_desc_tx = 'Maximum size in bytes allowed for mailboxes. Default = 209715200 (200 MB)' WHERE so_name_vc = 'max_mail_size' LIMIT 1;"
  148.  
  149. echo "Done." >/dev/tty
  150.  
  151.  
  152.  
  153. echo -n "Setting up Apache configuration to work with ZPX: " >/dev/tty
  154.  
  155. DOC_ROOT_LINE=`grep 'sites-enabled' /etc/apache2/apache2.conf  -n | cut -d ":" -f1`
  156. LINE_NO=`expr $DOC_ROOT_LINE + 1`
  157. sed -i "$DOC_ROOT_LINE s/^/#/" /etc/apache2/apache2.conf
  158. echo "Include /etc/zpanel/configs/apache/httpd.conf" >> /etc/apache2/apache2.conf
  159.  
  160. echo "Done." >/dev/tty
  161.  
  162.  
  163.  
  164. echo -n "Setting up Network info for ZPX and Compiling Default VHOST: " >/dev/tty
  165.  
  166. /etc/zpanel/panel/bin/setso --set zpanel_domain $SERVER_CP_NAME
  167. /etc/zpanel/panel/bin/setso --set server_ip $SERVER_IP
  168. php /etc/zpanel/panel/bin/daemon.php
  169.  
  170. echo "Done." >/dev/tty
  171.  
  172.  
  173.  
  174. echo -n "Configuring Postfix and Dovecot: " >/dev/tty
  175.  
  176. ## build vda support into postfix 2.9.1-4
  177. cd /usr/src
  178. apt-get install linux-headers-$(uname -r)
  179. apt-get -y build-dep postfix
  180. apt-get -y source postfix
  181. cd postfix-2.9.1
  182. wget -q http://vda.sourceforge.net/VDA/postfix-vda-v11-2.9.1.patch
  183. patch -p1 < postfix-vda-v11-2.9.1.patch
  184. sed -i "s/export DEB_BUILD_HARDENING=1/export DEB_BUILD_HARDENING=0/g" /usr/src/postfix-2.9.1/debian/rules
  185. dpkg-buildpackage
  186. cd ..
  187.  
  188. ## preload postfix variables to suppress prompts
  189. echo postfix postfix/mailname string $SERVER_NAME | debconf-set-selections
  190. echo postfix postfix/main_mailer_type select Internet Site | debconf-set-selections
  191. ## install patched postfix redundant for i386/amd64..
  192. dpkg -i postfix_2.9.1-4_amd64.deb postfix-mysql_2.9.1-4_amd64.deb
  193. dpkg -i postfix_2.9.1-4_i386.deb postfix-mysql_2.9.1-4_i386.deb
  194.  
  195. apt-get -y install dovecot-mysql dovecot-imapd dovecot-pop3d dovecot-common libsasl2-modules-sql libsasl2-modules
  196. ## (old way, not compatible with 12.04) ## apt-get -y install postfix postfix-mysql dovecot-mysql dovecot-imapd dovecot-pop3d dovecot-common libsasl2-modules-sql libsasl2-modules
  197. mkdir -p /var/zpanel/vmail
  198. ## why are we setting to 777 ???
  199. chmod -R 777 /var/zpanel/vmail
  200. chmod -R g+s /var/zpanel/vmail
  201. groupadd -g 5000 vmail
  202. useradd -g vmail -u 5000 -d /var/zpanel/vmail -s /bin/bash vmail
  203. chown -R vmail.vmail /var/zpanel/vmail
  204. mysql -uroot -p$MYSQL_PASS < /etc/zpanel/configs/postfix/zpanel_postfix.sql
  205. echo "# Dovecot LDA" >> /etc/postfix/master.cf
  206. echo "dovecot   unix  -       n       n       -       -       pipe" >> /etc/postfix/master.cf
  207. echo '  flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/deliver -d ${recipient}' >> /etc/postfix/master.cf
  208. ## add MYSQL_PASS to the config files
  209. sed -i "2 i connect = host=127.0.0.1 dbname=zpanel_postfix user=root password=$MYSQL_PASS" /etc/zpanel/configs/postfix/conf/dovecot-sql.conf
  210. sed -i "2 i password = $MYSQL_PASS" /etc/zpanel/configs/postfix/conf/mysql_relay_domains_maps.cf
  211. sed -i "2 i password = $MYSQL_PASS" /etc/zpanel/configs/postfix/conf/mysql_virtual_alias_maps.cf
  212. sed -i "2 i password = $MYSQL_PASS" /etc/zpanel/configs/postfix/conf/mysql_virtual_domains_maps.cf
  213. sed -i "2 i password = $MYSQL_PASS" /etc/zpanel/configs/postfix/conf/mysql_virtual_mailbox_limit_maps.cf
  214. sed -i "2 i password = $MYSQL_PASS" /etc/zpanel/configs/postfix/conf/mysql_virtual_mailbox_maps.cf
  215. sed -i "2 i password = $MYSQL_PASS" /etc/zpanel/configs/postfix/conf/mysql_virtual_transport.cf
  216. ## force account to be active for mail to be delivered
  217. sed -i "s/#additional_/additional_/g" /etc/zpanel/configs/postfix/conf/mysql_virtual_mailbox_maps.cf
  218. ## create cf to allow for deletion of accounts and still allow forwards to function
  219. echo "user = root"                       > /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  220. echo "password = $MYSQL_PASS"           >> /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  221. echo "hosts = 127.0.0.1"                >> /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  222. echo "dbname = zpanel_core"             >> /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  223. echo "table = x_forwarders"             >> /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  224. echo "select_field = fw_destination_vc" >> /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  225. echo "where_field = fw_address_vc"      >> /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  226. chmod +x /etc/zpanel/configs/postfix/conf/mysql_virtual_forwardings_maps.cf
  227.  
  228. ## make postfix look at zpanel dir instead of its own
  229. mv /etc/postfix/main.cf /etc/postfix/main.old
  230. ln -s /etc/zpanel/configs/postfix/conf/main.cf /etc/postfix/main.cf
  231.  
  232. ## make dovecot look at zpanel dir instead of its own
  233. mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.old
  234. ln -s /etc/zpanel/configs/dovecot2/dovecot.conf /etc/dovecot/dovecot.conf
  235.  
  236. ## set SERVER_NAME in postfix configs
  237. sed -i "s/control.yourdomain.com/$SERVER_NAME/g" /etc/zpanel/configs/postfix/conf/main.cf
  238. sed -i "s/control.youromain.com/$SERVER_NAME/g" /etc/zpanel/configs/postfix/conf/main.cf
  239.  
  240. ## set cf to to allow for deletion of accounts and still allow forwards to function
  241. sed -i "/^virtual_alias_maps/ s/\$/ mysql:\/etc\/zpanel\/configs\/postfix\/conf\/mysql_virtual_forwardings_maps.cf/" /etc/zpanel/configs/postfix/conf/main.cf
  242.  
  243. ## remove virtual quota info that's not supported in postfix 2.9.1
  244. sed -i '/virtual_create_maildirsize/d' /etc/zpanel/configs/postfix/conf/main.cf
  245.  
  246. ## change mailbox quota to maildir quoata
  247. sed -i 's/virtual_mailbox_extended/virtual_maildir_extended/g' /etc/zpanel/configs/postfix/conf/main.cf
  248.  
  249.  
  250. echo "Done." >/dev/tty
  251.  
  252.  
  253.  
  254. echo -n "Configuring Roundcube: " >/dev/tty
  255.  
  256. mysql -uroot -p$MYSQL_PASS < /etc/zpanel/configs/roundcube/zpanel_roundcube.sql
  257. MYSQL_LINE=`grep "mysql:" /etc/zpanel/panel/etc/apps/webmail/config/db.inc.php -n | cut -d ":" -f1`
  258. MYSQL_LINE_NO=`expr $MYSQL_LINE + 1`
  259. sed -i "$MYSQL_LINE_NO i \$rcmail_config['db_dsnw'] = 'mysql://root:$MYSQL_PASS@localhost/zpanel_roundcube';" /etc/zpanel/panel/etc/apps/webmail/config/db.inc.php
  260.  
  261. echo "Done." >/dev/tty
  262.  
  263.  
  264.  
  265. echo -n "Installing and Configuring ProFTPD: " >/dev/tty
  266.  
  267. ## preload proftpd variables to suppress prompts
  268. echo proftpd-basic shared/proftpd/inetd_or_standalone select standalone | debconf-set-selections
  269. apt-get -y install proftpd-mod-mysql
  270. mysql -uroot -p$MYSQL_PASS < /etc/zpanel/configs/proftpd/zpanel_proftpd.sql
  271. groupadd -g 2001 ftpgroup
  272. useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
  273. SQL_LINE=`grep "SQLConnectInfo" /etc/zpanel/configs/proftpd/proftpd-mysql.conf -n | cut -d ":" -f1`
  274. SQL_LINE_NO=`expr $SQL_LINE + 1`
  275. sed -i "$SQL_LINE s/^/#/" /etc/zpanel/configs/proftpd/proftpd-mysql.conf
  276. sed -i "$SQL_LINE_NO i SQLConnectInfo  zpanel_proftpd@localhost root $MYSQL_PASS" /etc/zpanel/configs/proftpd/proftpd-mysql.conf
  277. mv /etc/proftpd/proftpd.conf /etc/proftpd/proftpd.old
  278. touch /etc/proftpd/proftpd.conf
  279. echo "include /etc/zpanel/configs/proftpd/proftpd-mysql.conf" >> /etc/proftpd/proftpd.conf
  280. mkdir /var/zpanel/logs/proftpd
  281. chmod -R 644 /var/zpanel/logs/proftpd
  282.  
  283. echo "Done." >/dev/tty
  284.  
  285.  
  286.  
  287. echo -n "Installing and Configuring BIND: " >/dev/tty
  288.  
  289. apt-get -y install bind9 bind9utils
  290. mkdir /var/zpanel/logs/bind
  291. touch /var/zpanel/logs/bind/bind.log
  292. chmod -R 777 /var/zpanel/logs/bind/bind.log
  293. echo "include \"/etc/zpanel/configs/bind/etc/log.conf\";" >> /etc/bind/named.conf
  294. echo "include \"/etc/zpanel/configs/bind/etc/named.conf\";" >> /etc/bind/named.conf
  295. ln -s /usr/sbin/named-checkconf /usr/bin/named-checkconf
  296. ln -s /usr/sbin/named-checkzone /usr/bin/named-checkzone
  297. ln -s /usr/sbin/named-compilezone /usr/bin/named-compilezone
  298.  
  299. echo "Done." >/dev/tty
  300.  
  301.  
  302.  
  303. echo -n "Compiling zsudo: " >/dev/tty
  304.  
  305. cc -o /etc/zpanel/panel/bin/zsudo /etc/zpanel/configs/bin/zsudo.c
  306. chown root /etc/zpanel/panel/bin/zsudo
  307. chmod +s /etc/zpanel/panel/bin/zsudo
  308.  
  309. echo "Done." >/dev/tty
  310.  
  311.  
  312.  
  313. echo -n "Setting cron for daemon.php: " >/dev/tty
  314.  
  315. touch /etc/cron.d/zdaemon
  316. echo "*/5 * * * * root /usr/bin/php -q /etc/zpanel/panel/bin/daemon.php >> /dev/null 2>&1" >> /etc/cron.d/zdaemon
  317. chmod 644 /etc/cron.d/zdaemon
  318.  
  319. echo "Done." >/dev/tty
  320.  
  321.  
  322.  
  323. echo -n "Registering ZPPY Client: " >/dev/tty
  324.  
  325. ln -sf /etc/zpanel/panel/bin/zppy /usr/bin/zppy
  326.  
  327. echo "Done." >/dev/tty
  328.  
  329.  
  330.  
  331. echo -n "Removing temp files: " >/dev/tty
  332.  
  333. rm -rf /opt/zpanel
  334.  
  335. echo "Done." >/dev/tty
  336.  
  337.  
  338.  
  339. echo "Restarting all necessary services: " >/dev/tty
  340.  
  341. if [ $? = "0" ]; then
  342.         echo "-- Apache2 Web Server Restarted Successfully" >/dev/tty
  343. fi
  344. sleep 1
  345.  
  346. /etc/init.d/postfix restart
  347. if [ $? = "0" ]; then
  348.         echo "-- Postfix Server Restarted Successfully" >/dev/tty
  349. fi
  350. sleep 1
  351.  
  352. /etc/init.d/dovecot restart
  353. if [ $? = "0" ]; then
  354.         echo "-- Dovecot Server Restarted Successfully" >/dev/tty
  355. fi
  356. sleep 1
  357.  
  358. /etc/init.d/proftpd restart
  359. if [ $? = "0" ]; then
  360.         echo "-- ProFTPD Server Restarted Successfully" >/dev/tty
  361. fi
  362. sleep 1
  363.  
  364. /etc/init.d/mysql restart
  365. if [ $? = "0" ]; then
  366.         echo "-- MySQL Server Restarted Successfully" >/dev/tty
  367. fi
  368. sleep 1
  369.  
  370. /etc/init.d/bind9 restart
  371. if [ $? = "0" ]; then
  372.         echo "-- Bind9 Server Restarted Successfully" >/dev/tty
  373. fi
  374.  
  375.  
  376.  
  377. echo -e "\nInstalling ballen/rustus zppy repo and modules: " >/dev/tty
  378.  
  379. zppy repo add rustus.txt-clan.com
  380. zppy repo add ballen.co.uk
  381. zppy update
  382.  
  383. echo -n "-- gatekeeper: " >/dev/tty
  384. zppy install gatekeeper
  385. echo "installed" >/dev/tty
  386.  
  387. echo -n "-- system_logviewer: " >/dev/tty
  388. zppy install system_logviewer
  389. echo "installed" >/dev/tty
  390.  
  391. echo -n "-- kfm: " >/dev/tty
  392. zppy install kfm
  393. echo "installed" >/dev/tty
  394.  
  395. echo -n "-- ftp_browser: " >/dev/tty
  396. zppy install ftp_browser
  397. echo "installed" >/dev/tty
  398.  
  399. echo -n "-- visitor_stats: " >/dev/tty
  400. zppy install visitor_stats
  401. echo "installed" >/dev/tty
  402.  
  403.  
  404.  
  405.  
  406. ## turn output back on
  407. exec 1>/dev/tty
  408.  
  409.  
  410.  
  411. echo ""
  412. echo "====================================================================="
  413. echo "= Installation and Configuration of ZPX on Ubuntu 12.04 is Complete ="
  414. echo "====================================================================="
  415. echo ""
  416. echo "====================================================================="
  417. echo "=    Install Log can be found at $INSTALLLOG"
  418. echo "====================================================================="
  419. echo ""
  420. echo "====================================================================="
  421. echo "=    Please REBOOT the server and open:                             ="
  422. echo "=         http://$SERVER_CP_NAME/zpanel"
  423. echo "=              or                                                   ="
  424. echo "=         http://$SERVER_IP/zpanel"
  425. echo "=                                                                   ="
  426. echo "=         USER: zadmin                                              ="
  427. echo "=         PASS: password (Change on 1st login!)                     ="
  428. echo "====================================================================="
  429. echo ""
  430. echo ""
  431. echo "====================================================================="
  432. echo "=        This script is not written by official ZPX Support         ="
  433. echo "=        Please do not ask them for official support on this        ="
  434. echo "====================================================================="
  435. echo ""
  436. echo ""
  437. echo "=...................................................................="
  438. echo "=                By Xengulai (xengulai@xengulai.com)                ="
  439. echo "=...................................................................="
  440. echo ""
  441. echo ""
clone this paste RAW Paste Data