Last active
January 27, 2021 09:36
-
-
Save iegik/1202742750ed8e916d80 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| # Checks the files and directories permissions of the web application | |
| Options=$@ | |
| Optnum=$# | |
| httpd_group="www" | |
| app_owner="wwwrun" | |
| app_group="wwwdata" | |
| app_path="." | |
| _version(){ | |
| cat <<EOF | |
| $0 v0.1 | |
| 2014 (cc) Arturs Jansons a.jansons@gmail.com | |
| Checks the files and directories permissions of the web application | |
| EOF | |
| } | |
| _usage() { | |
| _version | |
| cat <<EOF | |
| Usage: $0 [-sogp] <[file1 directory1 ...]> | |
| Options: | |
| -s --httpd-group=... Set an web-server\`s deamon group name ($httpd_group) | |
| -o --app-owner=... Set an application owner name ($app_owner) | |
| -g --app-group=... Set an application group name ($app_group) | |
| -p --app-path=... Set an application path ($app_path) | |
| EOF | |
| } | |
| while getopts ':v-s:-o:-g:-p:' OPTION ; do | |
| case "$OPTION" in | |
| (s) httpd_group="$OPTARG";shift ;; | |
| (o) app_owner="$OPTARG" ;shift ;; | |
| (g) app_group="$OPTARG" ;shift ;; | |
| (p) app_path="$OPTARG" ;shift ;; | |
| (-) [ $OPTIND -ge 1 ] && optind=$(expr $OPTIND - 1 ) || optind=$OPTIND | |
| eval OPTION="\$$optind" | |
| OPTARG=$(echo $OPTION | cut -d'=' -f2) | |
| OPTION=$(echo $OPTION | cut -d'=' -f1) | |
| case $OPTION in | |
| --httpd-group ) httpd_group="$OPTARG" ;shift;; | |
| --app-owner ) app_owner="$OPTARG" ;shift;; | |
| --app-group ) app_group="$OPTARG" ;shift;; | |
| --app-path ) app_path="$OPTARG" ;shift;; | |
| --version ) _version; exit ;; | |
| --test ) test=true; ;; | |
| * ) _usage; exit ;; | |
| esac | |
| OPTIND=1 | |
| ;; | |
| v) _version; exit ;; | |
| *) _usage ;; | |
| esac | |
| shift | |
| done | |
| if [ $test ]; then | |
| _version | |
| echo "-s or --httpd-group: "$httpd_group | |
| echo "-o or --app-owner: "$app_owner | |
| echo "-g or --app-group: "$app_group | |
| echo "-p or --app-path: "$app_path | |
| echo "test: "$test | |
| echo "Script name: "$0 | |
| echo "1/$#: "$1 | |
| echo "Other arguments: "$@ | |
| exit; | |
| fi | |
| #echo "-s "$httpd_group" -o "$app_owner" -g "$app_group" -p "$app_path" ("$test") ["$@"]" | |
| #exit 0; | |
| # reset to safe defaults | |
| find ${app_path} -exec chown ${app_owner}:${app_group} {} \; | |
| find ${app_path} -type d -exec chmod 755 {} \; | |
| find ${app_path} -type f -exec chmod 644 {} \; | |
| # allow application to manage files and folders | |
| for item in $@ | |
| do | |
| find ${app_path}/${item} -exec chgrp ${httpd_group} {} \; | |
| find ${app_path}/${item} -type d -exec chmod 775 {} \; | |
| find ${app_path}/${item} -type f -exec chmod 664 {} \; | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment