07/30/07
Bash Installation Script
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


































Nice script, but the automated scrolling on the script window is damned annoying. Just thought you’d like to know.
F.
I agree the scrolling can be a bit much if your actually trying to read the code. I’ll see about refining it.
I could probably add a plain text option too. Usually a download link is accompanied, but in this case, It’s a bash script so I didn’t really want to link to it.
Thanks for your feedback!