Created
July 26, 2015 04:07
-
-
Save oblique63/68d6eb908974d5a82811 to your computer and use it in GitHub Desktop.
opencart bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# TODO: setup https://github.com/Beyond-IT/opencart-test-suite | |
IP_ADDRESS="$1" | |
PROJECT_ROOT="/vagrant" | |
OC_ROOT="$PROJECT_ROOT/opencart/upload" | |
# Apache Configuration | |
VHOST_CONF=" | |
<VirtualHost *:80> | |
ServerAdmin webmaster@localhost | |
DocumentRoot /var/www/opencart | |
<Directory /var/www/opencart> | |
AllowOverride All | |
</Directory> | |
ErrorLog /vagrant/logs/error.log | |
CustomLog /vagrant/logs/access.log combined | |
Alias /adminer.php /usr/share/adminer/adminer.php | |
Alias /adminer.css /usr/share/adminer/adminer.css | |
</VirtualHost> | |
" | |
# Stop mysql from showing popups during installation | |
export DEBIAN_FRONTEND="noninteractive" | |
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections | |
cd $PROJECT_ROOT | |
if [[ ! -e "$PROJECT_ROOT/config.sh" ]]; then | |
echo "======[ WARNING: No 'config.sh' file exists ]======" | |
echo "Copying 'config.default' over to 'config.sh'..." | |
cp config.default config.sh | |
echo "Be sure to adjust your settings inside 'config.sh' for future provisions." | |
fi | |
source config.sh | |
#---------------------------- | |
cd $PROJECT_ROOT | |
# Install Stuff | |
sudo apt-get update | |
sudo apt-get -q -y install git unzip \ | |
apache2 \ | |
mysql-server-5.6 mysql-client-5.6 \ | |
php5 php5-mysql php5-gd php5-curl php5-mcrypt \ | |
sendmail | |
# MySQL Setup | |
if [[ "$CLEAR_DATABASE" = "true" ]]; then | |
mysqladmin -f drop opencart -u root | |
fi | |
mysqladmin create opencart -u root | |
# PHP Modules | |
sudo php5enmod mcrypt | |
# Composer Install | |
if [ ! -x /usr/local/bin/composer ]; then | |
echo "#====> Installing Composer PHP Package Manager" | |
curl -sS https://getcomposer.org/installer | php | |
chmod +x composer.phar | |
mv composer.phar /usr/local/bin/composer | |
echo "Ignore that, just call 'composer' directly" | |
else | |
echo "Composer already installed" | |
fi | |
# Psysh Install | |
if [ ! -x /usr/local/bin/psysh ]; then | |
echo "#====> Installing Psysh PHP REPL" | |
wget -nv psysh.org/psysh -O /usr/local/bin/psysh | |
chmod +x /usr/local/bin/psysh | |
else | |
echo "Psysh already installed" | |
fi | |
cd $PROJECT_ROOT | |
# Adminer Install | |
if [ ! -d /usr/share/adminer ]; then | |
echo "#====> Installing Adminer" | |
sudo mkdir /usr/share/adminer | |
sudo wget -nv "http://www.adminer.org/latest-mysql.php" -O /usr/share/adminer/adminer.php | |
sudo wget -nv "https://raw.github.com/vrana/adminer/master/designs/pappu687/adminer.css" -O /usr/share/adminer/adminer.css | |
else | |
echo "Adminer already installed" | |
fi | |
# OpenCart Setup | |
cd "$PROJECT_ROOT" | |
if [ -e "$OC_ROOT/index.php" ]; then # Check existing OpenCart version | |
CURRENT_OC_VERSION="$( egrep -m 1 -o "[0-9]\.[0-9]\.[0-9]\.[0-9]" $OC_ROOT/index.php )" | |
if [ "$CURRENT_OC_VERSION" != "$OPENCART_VERSION" ]; then # Update OpenCart if it doesn't match the version we want | |
UPDATE_OC="true" | |
echo "#====> Updating OpenCart: v$CURRENT_OC_VERSION -> v$OPENCART_VERSION" | |
fi | |
fi | |
if [ ! -d "$OC_ROOT/install" ] || [ "$UPDATE_OC" = "true" ] || [ "$CLEAR_OPENCART_DIR" = "true" ]; then | |
if [ "$CLEAR_OPENCART_DIR" = "true" ]; then | |
echo "#====> Removing existing 'opencart' directory" | |
rm -rf $PROJECT_ROOT/opencart | |
fi | |
if [[ "$UPDATE_OC" != "true" ]]; then | |
echo "#====> Installing OpenCart $OPENCART_VERSION" | |
fi | |
if [ ! -e "opencart-$OPENCART_VERSION.tar.gz" ]; then | |
wget -nv "https://github.com/opencart/opencart/archive/$OPENCART_VERSION.tar.gz" -O "opencart-$OPENCART_VERSION.tar.gz" | |
else | |
echo "# Using existing 'opencart-$OPENCART_VERSION.tar.gz' archive" | |
fi | |
# Copy fresh opencart download to our actual hosted folder | |
mkdir -p opencart/upload | |
tar -xf "opencart-$OPENCART_VERSION.tar.gz" && cp -rf opencart-$OPENCART_VERSION/* opencart/ | |
rm -rf "opencart-$OPENCART_VERSION" | |
# OpenCart-specific Setup | |
mv "$OC_ROOT/config-dist.php" "$OC_ROOT/config.php" | |
mv "$OC_ROOT/admin/config-dist.php" "$OC_ROOT/admin/config.php" | |
mv "$OC_ROOT/.htaccess.txt" "$OC_ROOT/.htaccess" | |
if [[ "$USE_INNODB" = "true" ]]; then | |
cd "$OC_ROOT/install" | |
# Use InnoDB Storage Engine by default | |
sed -e "s/ENGINE=MyISAM/ENGINE=INNODB/g" opencart.sql > opencart.sql.tmp && mv opencart.sql.tmp opencart.sql | |
fi | |
cd $OC_ROOT | |
# Relative www link so that it can work outside of this VM | |
rm -f www | |
ln -s opencart/upload www | |
NEW_OC_INSTALL="true" | |
else | |
echo "OpenCart already set up" | |
fi | |
# Permissions | |
cd $OC_ROOT | |
sudo chmod -f 777 system/cache system/logs system/library system/download download image image/cache image/data image/catalog config.php admin/config.php | |
# Extension Installations | |
# Check for extensions in 'extensions' directory, otherwise download them | |
cd $PROJECT_ROOT | |
if [ ! -d extensions ]; then | |
mkdir extensions | |
fi | |
cd extensions | |
### vQmod Install | |
if [ ! -d "$OC_ROOT/vqmod" ]; then # Not installed in OpenCart? | |
echo "#====> Installing vQmod $VQMOD_VERSION" | |
if [ ! -d "vqmod-$VQMOD_VERSION" ]; then # Not cached in extensions directory? | |
echo "# Downloading vQmod..." | |
wget -nv "https://github.com/vqmod/vqmod/releases/download/v$VQMOD_VERSION-opencart.zip/vqmod-$VQMOD_VERSION-opencart.zip -O vqmod.zip" | |
unzip vqmod.zip | |
rm vqmod.zip | |
mv vqmod "vqmod-$VQMOD_VERSION" | |
else | |
echo "# Using cached version in 'extensions/vQmod-$VQMOD_VERSION'" | |
fi | |
cp -r "vqmod-$VQMOD_VERSION" "$OC_ROOT/vqmod" | |
rm "$OC_ROOT/vqmod/readme.txt" | |
sudo chmod -f 777 "$OC_ROOT/vqmod" "$OC_ROOT/vqmod/vqcache" | |
fi | |
if [[ "$NEW_OC_INSTALL" = "true" ]]; then | |
echo "# Visit 'http://$IP_ADDRESS/vqmod/install' to finish vQmod installation" | |
else | |
php "$OC_ROOT/vqmod/install/index.php" | |
echo '' | |
fi | |
# Install Extensions | |
cd $PROJECT_ROOT | |
for i in ${LOAD_EXTENSIONS[@]}; do | |
echo "#====> Loading $i extension" | |
cp -r extensions/$i/* opencart/upload/ | |
done | |
# ---------------------------- | |
# End Extension Installations | |
# Run SQL Queries | |
cd "$PROJECT_ROOT" | |
for i in ${RUN_SQL[@]}; do | |
echo "#====> Running $i.sql" | |
mysql -u root -D 'opencart' < db/$i.sql | |
done | |
# Vagrant Compatibility | |
cd "$OC_ROOT" | |
if [[ -e install/index.php ]]; then | |
# Set it up so that it uses the VM's direct IP address, because using localhost here interferes with POST requests... | |
cd install | |
sed -e "s/define('HTTP_OPENCART'/define('HTTP_OPENCART', 'http:\/\/${IP_ADDRESS}\/');\\n\/\/define('HTTP_OPENCART'/g" index.php > index.php.tmp && mv index.php.tmp index.php | |
fi | |
# Apache | |
cd "$PROJECT_ROOT" | |
sudo echo "$VHOST_CONF" > /etc/apache2/sites-enabled/000-default.conf | |
if [ ! -d "$PROJECT_ROOT/logs" ]; then | |
mkdir "$PROJECT_ROOT/logs" | |
fi | |
if [[ "$CLEAR_APACHE_LOGS" = "true" ]]; then | |
sudo rm -rf $PROJECT_ROOT/logs/* | |
fi | |
# Link opencart's log to the project's log folder | |
ln -sf opencart/upload/system/logs/error.log logs/opencart.log | |
sudo a2enmod rewrite | |
if [[ $(tail /home/vagrant/.profile | grep -c "cd /vagrant") = 0 ]]; then | |
sudo echo 'export PATH="/vagrant/bin:/home/vagrant/.composer/vendor/bin:$PATH"' >> /home/vagrant/.profile | |
sudo echo 'cd /vagrant' >> /home/vagrant/.profile | |
fi | |
source /home/vagrant/.profile | |
#---------------------------- | |
# Info | |
echo "#########################################" | |
if [ "$NEW_OC_INSTALL" = "true" ]; then | |
echo "Visit 'http://$IP_ADDRESS/ to complete OpenCart installation." | |
echo "Select the following configurations:" | |
echo " Username: root" | |
echo " Password: " | |
echo " Database: opencart" | |
echo "Remember to delete the 'opencart/upload/install' directory after going through the installation!" | |
else | |
echo "Visit 'http://$IP_ADDRESS/ to see your OpenCart site" | |
fi | |
echo "You can manage your database by visiting 'http://$IP_ADDRESS/adminer.php'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#------------------------------------------------------- | |
# Make A copy of this file, and name it 'config.sh' | |
# bootstrap.sh will take all of its settings from there. | |
#------------------------------------------------------- | |
# Project Info | |
OPENCART_VERSION="2.0.3.1" | |
USE_INNODB="true" | |
# Extensions | |
VQMOD_VERSION="2.5.1" | |
# Bootstrap Preferences | |
CLEAR_DATABASE="false" | |
CLEAR_OPENCART_DIR="true" | |
CLEAR_APACHE_LOGS="true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
LOCAL_PORT = 9999 | |
IP_ADDRESS = "192.168.50.4" | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.network "forwarded_port", guest: 80, host: LOCAL_PORT #, auto_correct: true | |
config.vm.network "private_network", ip: IP_ADDRESS | |
config.vm.provider "virtualbox" do |vb| | |
vb.customize ["modifyvm", :id, "--memory", "2048"] | |
end | |
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=775,fmode=775"] | |
config.vm.synced_folder "opencart/upload", "/var/www/opencart", create: true, group: "www-data", :mount_options => ["dmode=775,fmode=775"] | |
config.vm.synced_folder "logs/", "/var/log/apache2", create: true, owner: "root", group: "www-data", :mount_options => ["dmode=775,fmode=775"] | |
config.vm.provision "shell", path: "config.sh" | |
config.vm.provision "shell", path: "bootstrap.sh", args: IP_ADDRESS | |
config.vm.provision "shell", run: "always", inline: "sudo apache2ctl restart" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment