Last active
November 27, 2015 20:26
-
-
Save aamnah/12eb2e44ae2a1352f28e to your computer and use it in GitHub Desktop.
Bash script for OC install
This file contains 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
#!/bin/bash | |
### | |
# Author: Aamnah | |
# Link: http://aamnah.com | |
# Description: Install script for Opencart 2.x on a Linux (Ubuntu/Debian) server | |
### | |
# Color Reset | |
Color_Off='\033[0m' # Text Reset | |
# Regular Colors | |
Red='\033[0;31m' # Red | |
Green='\033[0;32m' # Green | |
Cyan='\033[0;36m' # Cyan | |
get() { | |
# Get latest source files from git repo | |
git clone https://github.com/opencart/opencart.git | |
# clean up | |
mv opencart/upload/* . | |
} | |
config() { | |
# add config files | |
cp config-dist.php config.php | |
cp admin/config-dist.php admin/config.php | |
} | |
htaccess() { | |
htaccess='.htaccess.txt' | |
# if .htaccess.txt exists then rename it | |
if [ -s ${htaccess} ]; then | |
cp .htaccess.txt .htaccess | |
#otherwise, create a new file | |
else | |
touch .htaccess | |
echo "# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. | |
# 2. In your opencart directory rename htaccess.txt to .htaccess. | |
# For any support issues please visit: http://www.opencart.com | |
Options +FollowSymlinks | |
# Prevent Directoy listing | |
Options -Indexes | |
# Prevent Direct Access to files | |
<FilesMatch \"(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))\"> | |
Order deny,allow | |
Deny from all | |
</FilesMatch> | |
# SEO URL Settings | |
RewriteEngine On | |
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ | |
RewriteBase / | |
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] | |
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] | |
RewriteRule ^system/download/(.*) /index.php?route=error/not_found [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) | |
RewriteRule ^([^?]*) index.php?_route_=\$1 [L,QSA] | |
### Additional Settings that may need to be enabled for some servers | |
### Uncomment the commands by removing the # sign in front of it. | |
### If you get an \"Internal Server Error 500\" after enabling any of the following settings, restore the # as this means your host doesn't allow that. | |
# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it: | |
# php_flag register_globals off | |
# 2. If your cart has magic quotes enabled, This may work to disable it: | |
# php_flag magic_quotes_gpc Off | |
# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try | |
# php_value upload_max_filesize 999M | |
# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields | |
# php_value post_max_size 999M | |
# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields | |
# php_value max_execution_time 200 | |
# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields | |
# php_value max_input_time 200 | |
# 7. disable open_basedir limitations | |
# php_admin_value open_basedir none" > .htaccess | |
fi | |
} | |
installPerms() { | |
# set permissions for install | |
chmod 777 config.php | |
chmod 777 admin/config.php | |
chmod 777 image/ | |
chmod 777 image/cache/ | |
chmod 777 image/catalog/ | |
chmod 777 system/storage/cache/ | |
chmod 777 system/storage/logs/ | |
chmod 777 system/storage/download/ | |
chmod 777 system/storage/upload/ | |
chmod 777 system/storage/modification/ | |
} | |
installMessage() { | |
echo -e "\n ${Red} Please finish the installation by going to http://yourdomain.com/install \n | |
When you are done with installing, come back here and secure the installation. ${Color_Off}" | |
} | |
secure() { | |
# delete install folder | |
if [ -d "install/" ]; then | |
rm -rf install | |
fi | |
# To change all the directories to 755 (-rwxr-xr-x) | |
find . -type d -exec chmod 755 {} \; | |
# To change all the files to 644 (-rw-r--r--): | |
find . -type f -exec chmod 644 {} \; | |
# set 444 for admin files | |
chmod 444 config.php | |
chmod 444 admin/config.php | |
chmod 444 index.php | |
chmod 444 admin/index.php | |
chmod 444 system/startup.php | |
# set 777 for cache | |
chmod 777 image/cache/ | |
chmod 777 system/storage/cache/ | |
} | |
# RUN | |
echo -e "\n ${Cyan} Cloning latest files from Github repo.. ${Color_Off}" | |
get | |
echo -e " ${Cyan} Creating config files.. ${Color_Off}" | |
config | |
echo -e " ${Cyan} Creating .htaccess ${Color_Off}" | |
htaccess | |
echo -e " ${Cyan} Settings install permissions.. ${Color_Off}" | |
installPerms | |
installMessage | |
# Secure install - this needs to be done AFTER the INSTALL as this step will delete the install folder | |
read -e -p "Should i secure the install now? (y / n)" -i "y" DOSECURE | |
if [ DOSECURE == 'y' ]; then | |
secure | |
echo -e " ${Cyan} Securing.. ${Color_Off}" | |
else | |
echo -e " ${Red} Your install is INSECURE! ${Color_Off}" | |
fi | |
echo -e " ${Green} OpenCart has been successfully installed! ${Color_Off}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment