Bash Installation Script

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.
bashhover edges to scroll
 
# !/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 <<End-of-message
<?
        global \$db;
        \$database_server = 'mysql-host';
        \$database_user = '$username';
        \$database_password = '$dbpass';
        \$database_name = '$database';
        global \$tbl_prefix;
        \$tbl_prefix = 'cxcmscore_';
?>
End-of-message
 
sudo chmod -R 0644 /var/www/vhosts/$domain/httpdocs/lib/includes/db.php
echo ""
echo ""
echo "###############################################################################"
echo "#"
echo "# [setup]: configurationa file generated at: /var/www/vhosts/$domain/httpdocs/lib/includes/db.php"
echo "# [setup]: The CMS is now installed. if you have questions about this script please email kyle@slajax.com"
echo "#"
echo "###############################################################################"
 
exit
 
There you have it. Not only can I write pretty AJAX scripts, but I’m a damn good system administrator too!
Share and Enjoy:
  • Digg
  • del.icio.us
  • Slashdot
  • Technorati
  • Taggly
  • blinkbits
  • Gwar
  • Spurl
  • Netvouz
  • description
  • SphereIt
  • blogmarks
  • blogtercimlap
  • Linkter

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post

28 queries in 0.550 seconds | Code is Poetry | sLajax.com