<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.8.4" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>http://blog.sLajax.com</title>
	<link>http://blog.slajax.com</link>
	<description>secure lightweight ajax solutions</description>
	<pubDate>Wed, 16 Dec 2009 07:39:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
			<item>
		<title>Bash Installation Script</title>
		<link>http://blog.slajax.com/2007/07/30/bash-installation-script/</link>
        <customfield>bash.gif</customfield>
		<comments>http://blog.slajax.com/2007/07/30/bash-installation-script/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 21:53:05 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://slajax.com/blog/2007/07/30/bash-installation-script/</guid>
		<description><![CDATA[So I got bored of always manually installing the content management system, so i wrote a little bash script to take care of all the good stuff. I haven't written bash in a long time, but I really like it. It's some of the most useful code I've ever written. So powerful.


# !/bin/sh
# @title: CMS bash install script
# @dev: Kyle Campbell - kc@slajax.com
# @purpose: -simple walk through of cms installation tasks
#           -delete plesk generated directories and extract latest cms tar
#     -connect to mysql and load clean data structure
#     -generate unique lib/includes/db.php file for specific install
##################################################

##########################
# Step 1:  get domain for install #
########################

echo "[setup]: Please enter the domain you are configuring the cms for:"
 read domain

#####################
# Step 2: confirm spelling #
####################

echo "[setup]: Ok, installing for for domain: $domain, right? (y/n)"
 read confirmDomain

################################################
# Step 3: echo out the install path and confirm this install path #
################################################

if [ $confirmDomain == "y" ]
 then
         echo "[setup]: ok, here we go, installing to /var/www/vhosts/$domain/httpdocs/, ready? (y/n)"
 else
         echo "[setup]: installation aborted. go rtfm already."
  exit
fi
 read confirmDir

#####################################################################
# Step 4: if install path is confirmed, remove plesk generated files and dirs, then install cms #
#####################################################################

if [ $confirmDir == "y" ]
 then
  if [ -d "/var/www/vhosts/$domain/httpdocs" ]
   then
    echo "[setup]: cleaning directory and unpacking latest cms archive."

    if [ -f "/var/www/vhosts/$domain/httpdocs/index.html" ]
     then
                                                echo "[setup]: deleting file: index.html"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/index.html
    fi
    if [ -f "/var/www/vhosts/$domain/httpdocs/favicon.ico" ]
     then
                                                echo "[setup]: deleting file: favicon.ico"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/favicon.ico
    fi
    if [ -d "/var/www/vhosts/$domain/httpdocs/css/" ]
     then
                                                echo "[setup]: deleting dir: /css/"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/css/
    fi
                         if [ -d "/var/www/vhosts/$domain/httpdocs/img/" ]
     then
                                                echo "[setup]: deleting dir: /img/"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/img/
    fi
                                if [ -d "/var/www/vhosts/$domain/httpdocs/picture_library/" ]
     then
                                                echo "[setup]: deleting dir: /picture-library/"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/picture_library/
    fi
                                if [ -d "/var/www/vhosts/$domain/httpdocs/plesk-stat/" ]
     then
                                                echo "[setup]: deleting dir: /plesk-stat/"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/plesk-stat/
    fi
                                if [ -d "/var/www/vhosts/$domain/httpdocs/test/" ]
     then
                                                echo "[setup]: deleting dir: /test/"
      sudo rm -R /var/www/vhosts/$domain/httpdocs/test/
    fi
    if [ -f "/home/KyleC/cms/installCms.tar" ]
     then
      echo "[setup]: unpacking cms files..."
      sudo tar -xvf /home/KyleC/cms/installCms.tar
     else
      echo "[setup]: cms install archive not present. exiting."
      exit
    fi
   else
    echo "[setup]: this directory does not exist. have the domain created first."
    echo "[setup]: installation aborted. go rtfm already.  please continue manually."
    exit
  fi
 else
  echo "[setup]: installation aborted. go rtfm already. please continue manually."
  exit
fi


################################################
# Step 5:  set ownerships and permissions for new install path #
###############################################

echo "[setup]: ok done unpacking, now we need to set the correct permissions. Please provide directory user:"
 read userPerms

if [ $userPerms != "" ]
 then
  if [ -d "/var/www/vhosts/$domain/httpdocs/" ]
   then
    echo "[setup]: setting permissions $userPerms.psacln for core files"
     sudo chown -R $userPerms.psacln /var/www/vhosts/$domain/httpdocs/*
     sudo chown -R $userPerms.psacln /var/www/vhosts/$domain/httpdocs/.htaccess
     sudo chmod -R 0777 /var/www/vhosts/$domain/httpdocs/sql/
        sudo chmod -R 0777 /var/www/vhosts/$domain/httpdocs/uploaded/
     sudo chmod -R 0777 /var/www/vhosts/$domain/httpdocs/lib/includes/db.php

    echo "[setup]: done setting permissions."
  fi
 else
  echo "[setup]: invalid input, please continue manually from permissions step."
                echo "[setup]: installation aborted. go rtfm already.  please continue manually."
fi


######################################################
# Step 6: installing database and configuring constants for application #
#####################################################
echo "[setup]: please enter database name:"
 read database

echo "[setup]: please enter user name for database '$database':"
 read username

echo "[setup]: please enter password for databas user '$username':"
 read dbpass

echo "[setup]: ok, lets import the database structure now..."

 sudo mysql --verbose --host=mysql-host --user=$username --password=$dbpass $database < /var/www/vhosts/$domain/httpdocs/sql/installCms.sql

echo "[setup]: database configured, creating config file for cms now..."


sudo cat > /var/www/vhosts/$domain/httpdocs/lib/includes/db.php 
]]></description>
			<content:encoded><![CDATA[So I got bored of always manually installing the content management system, so i wrote a little bash script to take care of all the good stuff. I haven&#8217;t written bash in a long time, but I really like it. It&#8217;s some of the most useful code I&#8217;ve ever written. So powerful.

<div class='codeWrapper'><div class='codeTitle'>bash<span class='codeInstruct'>hover edges to scroll</span></div><code><pre>&nbsp;
<span style="color: #808080; font-style: italic;"># !/bin/sh</span>
<span style="color: #808080; font-style: italic;"># @title: CMS bash install script</span>
<span style="color: #808080; font-style: italic;"># @dev: Kyle Campbell - kc@slajax.com</span>
<span style="color: #808080; font-style: italic;"># @purpose: -simple walk through of cms installation tasks</span>
<span style="color: #808080; font-style: italic;">#           -delete plesk generated directories and extract latest cms tar</span>
<span style="color: #808080; font-style: italic;">#     -connect to mysql and load clean data structure</span>
<span style="color: #808080; font-style: italic;">#     -generate unique lib/includes/db.php file for specific install</span>
<span style="color: #808080; font-style: italic;">##################################################</span>
&nbsp;
<span style="color: #808080; font-style: italic;">##########################</span>
<span style="color: #808080; font-style: italic;"># Step 1:  get domain for install #</span>
<span style="color: #808080; font-style: italic;">########################</span>
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: Please enter the domain you are configuring the cms for:"</span>
 <span style="color: #000066;">read</span> domain
&nbsp;
<span style="color: #808080; font-style: italic;">#####################</span>
<span style="color: #808080; font-style: italic;"># Step 2: confirm spelling #</span>
<span style="color: #808080; font-style: italic;">####################</span>
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: Ok, installing for for domain: $domain, right? (y/n)"</span>
 <span style="color: #000066;">read</span> confirmDomain
&nbsp;
<span style="color: #808080; font-style: italic;">################################################</span>
<span style="color: #808080; font-style: italic;"># Step 3: echo out the install path and confirm this install path #</span>
<span style="color: #808080; font-style: italic;">################################################</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> <span style="color: #0000ff;">$confirmDomain</span> == <span style="color: #ff0000;">"y"</span> <span style="color: #66cc66;">&#93;</span>
 <span style="color: #b1b100;">then</span>
         <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: ok, here we go, installing to /var/www/vhosts/$domain/httpdocs/, ready? (y/n)"</span>
 <span style="color: #b1b100;">else</span>
         <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: installation aborted. go rtfm already."</span>
  <span style="color: #000066;">exit</span>
<span style="color: #b1b100;">fi</span>
 <span style="color: #000066;">read</span> confirmDir
&nbsp;
<span style="color: #808080; font-style: italic;">#####################################################################</span>
<span style="color: #808080; font-style: italic;"># Step 4: if install path is confirmed, remove plesk generated files and dirs, then install cms #</span>
<span style="color: #808080; font-style: italic;">#####################################################################</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> <span style="color: #0000ff;">$confirmDir</span> == <span style="color: #ff0000;">"y"</span> <span style="color: #66cc66;">&#93;</span>
 <span style="color: #b1b100;">then</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs"</span> <span style="color: #66cc66;">&#93;</span>
   <span style="color: #b1b100;">then</span>
    <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: cleaning directory and unpacking latest cms archive."</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -f <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/index.html"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting file: index.html"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/index.html
    <span style="color: #b1b100;">fi</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -f <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/favicon.ico"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting file: favicon.ico"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/favicon.ico
    <span style="color: #b1b100;">fi</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/css/"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting dir: /css/"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/css/
    <span style="color: #b1b100;">fi</span>
                         <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/img/"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting dir: /img/"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/img/
    <span style="color: #b1b100;">fi</span>
                                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/picture_library/"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting dir: /picture-library/"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/picture_library/
    <span style="color: #b1b100;">fi</span>
                                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/plesk-stat/"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting dir: /plesk-stat/"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/plesk-stat/
    <span style="color: #b1b100;">fi</span>
                                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/test/"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
                                                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: deleting dir: /test/"</span>
      sudo rm -R /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/<span style="color: #000066;">test</span>/
    <span style="color: #b1b100;">fi</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -f <span style="color: #ff0000;">"/home/KyleC/cms/installCms.tar"</span> <span style="color: #66cc66;">&#93;</span>
     <span style="color: #b1b100;">then</span>
      <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: unpacking cms files..."</span>
      sudo tar -xvf /home/KyleC/cms/installCms.tar
     <span style="color: #b1b100;">else</span>
      <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: cms install archive not present. exiting."</span>
      <span style="color: #000066;">exit</span>
    <span style="color: #b1b100;">fi</span>
   <span style="color: #b1b100;">else</span>
    <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: this directory does not exist. have the domain created first."</span>
    <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: installation aborted. go rtfm already.  please continue manually."</span>
    <span style="color: #000066;">exit</span>
  <span style="color: #b1b100;">fi</span>
 <span style="color: #b1b100;">else</span>
  <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: installation aborted. go rtfm already. please continue manually."</span>
  <span style="color: #000066;">exit</span>
<span style="color: #b1b100;">fi</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">################################################</span>
<span style="color: #808080; font-style: italic;"># Step 5:  set ownerships and permissions for new install path #</span>
<span style="color: #808080; font-style: italic;">###############################################</span>
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: ok done unpacking, now we need to set the correct permissions. Please provide directory user:"</span>
 <span style="color: #000066;">read</span> userPerms
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> <span style="color: #0000ff;">$userPerms</span> != <span style="color: #ff0000;">""</span> <span style="color: #66cc66;">&#93;</span>
 <span style="color: #b1b100;">then</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> -d <span style="color: #ff0000;">"/var/www/vhosts/$domain/httpdocs/"</span> <span style="color: #66cc66;">&#93;</span>
   <span style="color: #b1b100;">then</span>
    <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: setting permissions $userPerms.psacln for core files"</span>
     sudo chown -R <span style="color: #0000ff;">$userPerms</span>.psacln /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/*
     sudo chown -R <span style="color: #0000ff;">$userPerms</span>.psacln /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/.htaccess
     sudo chmod -R <span style="color: #cc66cc;">0777</span> /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/sql/
        sudo chmod -R <span style="color: #cc66cc;">0777</span> /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/uploaded/
     sudo chmod -R <span style="color: #cc66cc;">0777</span> /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/lib/includes/db.php
&nbsp;
    <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: done setting permissions."</span>
  <span style="color: #b1b100;">fi</span>
 <span style="color: #b1b100;">else</span>
  <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: invalid input, please continue manually from permissions step."</span>
                <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: installation aborted. go rtfm already.  please continue manually."</span>
<span style="color: #b1b100;">fi</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">######################################################</span>
<span style="color: #808080; font-style: italic;"># Step 6: installing database and configuring constants for application #</span>
<span style="color: #808080; font-style: italic;">#####################################################</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: please enter database name:"</span>
 <span style="color: #000066;">read</span> database
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: please enter user name for database '$database':"</span>
 <span style="color: #000066;">read</span> username
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: please enter password for databas user '$username':"</span>
 <span style="color: #000066;">read</span> dbpass
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: ok, lets import the database structure now..."</span>
&nbsp;
 sudo mysql --verbose --<span style="color: #0000ff;">host=</span>mysql-host --<span style="color: #0000ff;">user=</span><span style="color: #0000ff;">$username</span> --<span style="color: #0000ff;">password=</span><span style="color: #0000ff;">$dbpass</span> <span style="color: #0000ff;">$database</span> &lt; /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/sql/installCms.sql
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"[setup]: database configured, creating config file for cms now..."</span>
&nbsp;
&nbsp;
sudo cat &gt; /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/lib/includes/db.php &lt;&lt;End-of-message
&lt;?
        global \<span style="color: #0000ff;">$db</span>;
        \<span style="color: #0000ff;">$database_server</span> = <span style="color: #ff0000;">'mysql-host'</span>;
        \<span style="color: #0000ff;">$database_user</span> = <span style="color: #ff0000;">'$username'</span>;
        \<span style="color: #0000ff;">$database_password</span> = <span style="color: #ff0000;">'$dbpass'</span>;
        \<span style="color: #0000ff;">$database_name</span> = <span style="color: #ff0000;">'$database'</span>;
        global \<span style="color: #0000ff;">$tbl_prefix</span>;
        \<span style="color: #0000ff;">$tbl_prefix</span> = <span style="color: #ff0000;">'cxcmscore_'</span>;
?&gt;
End-of-message
&nbsp;
sudo chmod -R <span style="color: #cc66cc;">0644</span> /var/www/vhosts/<span style="color: #0000ff;">$domain</span>/httpdocs/lib/includes/db.php
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">""</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">""</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"###############################################################################"</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"#"</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"# [setup]: configurationa file generated at: /var/www/vhosts/$domain/httpdocs/lib/includes/db.php"</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"# [setup]: The CMS is now installed. if you have questions about this script please email kyle@slajax.com"</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"#"</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"###############################################################################"</span>
&nbsp;
<span style="color: #000066;">exit</span>
&nbsp;</pre></code></div>

There you have it. Not only can I write pretty AJAX scripts, but I&#8217;m a damn good system administrator too!]]></content:encoded>
			<wfw:commentRss>http://blog.slajax.com/2007/07/30/bash-installation-script/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
