Skip to content

Instantly share code, notes, and snippets.

@shapeshed
Created July 27, 2010 11:24
Show Gist options
  • Save shapeshed/492089 to your computer and use it in GitHub Desktop.
Save shapeshed/492089 to your computer and use it in GitHub Desktop.
Sets permissions on an ExpressionEngine 2 install
#!/bin/bash
# File: exp_permissions.sh
# Description: Sets permssions on a ExpressionEngine 2 install
#
# Copyright 2010 George Ornbo (Shape Shed)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Get the working directory
DIR=$(pwd)
# The default ExpressionEngine system folder
DEFAULT="system"
# The message shown if we can't find a file / folder
ERROR_MESSAGE="Not found so no action taken:"
# Has the user changed the system folder name?
printf "Enter your system folder name (default: system):\n"
read SYSTEM_FOLDER
# If no value is entered set default
if [ "$SYSTEM_FOLDER" == "" ]
then
SYSTEM_FOLDER=$DEFAULT
fi
# Declare files and folders as arrays
FILES_666[0]=$DIR/$SYSTEM_FOLDER/expressionengine/config/config.php
FILES_666[1]=$DIR/$SYSTEM_FOLDER/expressionengine/config/database.php
DIRS_777[0]=$DIR/images/avatars/uploads/
DIRS_777[1]=$DIR/images/captchas/
DIRS_777[2]=$DIR/images/member_photos/
DIRS_777[3]=$DIR/images/pm_attachments/
DIRS_777[4]=$DIR/images/signature_attachments/
DIRS_777[5]=$DIR/images/uploads/
DIRS_777[6]=$DIR/$SYSTEM_FOLDER/expressionengine/cache/
# Check files exist and change permissions
for FILE in ${FILES_666[@]}
do
if [ -e $FILE ]
then
chmod 666 $FILE
else
printf "$ERROR_MESSAGE $FILE\n"
fi
done
# Check directories exist and change permissions
for DIR in ${DIRS_777[@]}
do
if [ -d $DIR ]
then
chmod -R 777 $DIR
else
printf "$ERROR_MESSAGE $DIR\n"
fi
done
@wesbaker
Copy link

wesbaker commented Aug 2, 2010

This is a nice looking script and is conveniently expandable, but why not just create an alias to do the same thing?

alias eepermissions="sudo chmod 666 system/expressionengine/config/{config.php,database.php} && 
    sudo chmod -R 777 system/expressionengine/cache && 
    sudo chmod -R 777 system/expressionengine/templates"

@wesbaker
Copy link

wesbaker commented Aug 2, 2010

My alias doesn't have it, but you could easily add images.

@shapeshed
Copy link
Author

I thought about an alias but wanted to include some error handling and make it extensible. The nice thing about UNIX if that there is no right way of doing something so if you prefer an alias then great.

One thing I thought about was adding project specific folders. This works for both the alias and the script with &&:

ee2_permissions.sh && chmod 777 images/somefolder

eepermissions && chmod 777 images/somefolder

Eventually I'd like to be able to pass the script arguments so I'd get error handling if anything went wrong.

Accept your point it may be overkill for something so simple!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment