Last active
August 22, 2018 18:43
-
-
Save birkin/5014164 to your computer and use it in GitHub Desktop.
shell script for easily updating django app code
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/sh | |
## shell script for easily updating django app code | |
## usage, `bash ./this.sh` | |
## setup | |
ACTIVATE_FILE="" | |
GROUP="" | |
LOG_DIR_PATH="" | |
PROJECT_DIR_PATH="" | |
PYTHON_PATH="" | |
STATIC_WEB_MEDIA_DIR_PATH="" | |
TOUCH_PATH="" | |
## update app | |
cd $PROJECT_DIR_PATH | |
git pull | |
## run collectstatic | |
source $ACTIVATE_FILE | |
$PYTHON_PATH ./manage.py collectstatic --noinput # add --clear if needed | |
## cleanup | |
array=( $LOG_DIR_PATH $PROJECT_DIR_PATH $STATIC_WEB_MEDIA_DIR_PATH ) | |
for i in "${array[@]}" | |
do | |
sudo /bin/chmod u=rwx,g=rwx,o=rx $i # properly sets the executable/searchable bit for this directory | |
find $i -type d | xargs sudo /bin/chmod u=rwx,g=rwx,o=rx # properly sets the executable/searchable bit for sub-directories | |
find $i -type f | xargs sudo /bin/chmod u=rw,g=rw,o=r # properly sets the executable/searchable bit for files | |
sudo /bin/chgrp -R $GROUP $i # recursively ensures all items are set to proper group -- solves problem of an item being root/root if sudo-updated after a forced deletion | |
done | |
## make it real | |
touch $TOUCH_PATH | |
## [END] |
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/sh | |
## Usage: `$ ./this_file.sh` or, if not executible, `$ bash ./this_file.sh` | |
## Useful when getting chmod args-too-long error, likely because of big git directory | |
## The dots don't take up much extra time, according to `$ time bash ./this_file.sh` | |
## setup | |
ACTIVATE_FILE="" | |
GROUP="" | |
LOG_DIR_PATH="" | |
PROJECT_DIR_PATH="" | |
PYTHON_PATH="" | |
STATIC_WEB_MEDIA_DIR_PATH="" | |
TOUCH_PATH="" | |
## update app | |
cd "$PROJECT_DIR_PATH" | |
git pull | |
## run collectstatic | |
source "$ACTIVATE_FILE" | |
"$PYTHON_PATH" ./manage.py collectstatic --noinput | |
## reset directory permissions | |
array=( "$LOG_DIR_PATH" "$PROJECT_DIR_PATH" "$STATIC_WEB_MEDIA_DIR_PATH" ) | |
echo ; echo | |
for i in "${array[@]}" | |
do | |
echo "chmod/chgrp-ing main directory:" | |
echo "$i" | |
echo "setting group for this directory" | |
sudo /usr/bin/chgrp -R "$GROUP" "$i" # recursively ensures all items are set to proper group -- solves problem of an item being root/root if sudo-updated after a forced deletion | |
folder_array=( `find "$i" -type d` ) | |
echo "processing subdirectories..." | |
for j in "${folder_array[@]}" | |
do | |
# echo "processing directory..." | |
# echo "$j" | |
echo -ne "." | |
sudo /bin/chmod u=rwx,g=rwx,o=rx "$j" # properly sets the executable/searchable bit for this subdir (includes initial main dir) | |
nice find "$j" -maxdepth 1 -type f -print0 | xargs -0 --no-run-if-empty sudo /usr/bin/chmod u=rw,g=rw,o=r | |
done | |
echo ; echo | |
done | |
## make it real | |
touch $TOUCH_PATH | |
# [END] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment