Skip to content
Snippets Groups Projects
Commit 1233f7b4 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Create permissions script

parent 0168589d
Branches
No related merge requests found
# Bash Utils - Documents > References
## Description
Various references used in project.
## Outside References
See <https://git.brandon-rodriguez.com/scripts/bash/utils/-/blob/master/documents/references.md> for a variety of
bash-related references.
## References
### Properly Setting Permissions of Files and Subdirectories
<https://stackoverflow.com/a/11512211>
<https://stackoverflow.com/a/54462381>
#!/usr/bin/env bash
###
# Updates permissions such that "user" and "group" owners are able to access, and "other" uses cannot access.
##
# Import utils script.
. $(dirname ${0})/../utils.sh
# Stop on error.
set -e
###
# Script entry point.
##
function main () {
# Check if user is root.
check_is_user "root"
# Check number of passed function args.
if [[ ${#args[@]} == 1 ]]
then
# Location passed. Use as directory.
get_absolute_path ${args[0]}
set_permissions ${return_value}
elif [[ ${#args[@]} == 0 ]]
then
# Zero args passed.
echo -e "${text_red}Too few args passed. Expected 1 args.${text_reset}"
echo -e "${text_red}Please specify a single directory or file to adjust permissions on.${text_reset}"
exit 1
else
# Two or more args passed.
echo -e "${text_red}Too many args passed. Expected 1 args.${text_reset}"
echo -e "${text_red}Please specify a single directory or file to adjust permissions on.${text_reset}"
exit 1
fi
}
###
# Sets permissions for provided location.
##
function set_permissions() {
input_location=${1}
get_user_confirmation "Set permissions for \"${text_purple}${input_location}${text_reset}\"?"
# Proceed if confirmed.
if [[ ${return_value} == true ]]
then
# Change to appropriate directory.
get_directory_path ${input_location}
cd ${return_value}
# Check location type.
if [[ -d ${input_location} ]]
then
# Handle for directory.
echo -e "${text_blue}Setting file/folder permissions for \"user\" & \"group\" access.${text_reset}"
find . -type d -exec chmod u+rwx {} \;
find . -type d -exec chmod g+rwx {} \;
find . -type f -exec chmod u+rw {} \;
find . -type f -exec chmod g+rw {} \;
echo -e "${text_blue}Removing file/folder permissions for \"other\" access.${text_reset}"
find . -exec chmod o-rwx {} \;
else
# Handle for file.
echo -e "${text_blue}Setting file permissions for \"user\" & \"group\" access.${text_reset}"
chmod u+rw ${input_location}
chmod g+rw ${input_location}
echo -e "${text_blue}Removing file permissions for \"other\" access.${text_reset}"
chmod o-rwx ${input_location}
fi
echo ""
echo -e "${text_green}Permissions updated for ${text_purple}${input_location}${text_green}.${text_reset}"
echo -e "${text_green}Make sure both \"user\" & \"group\" ownership is set properly!${text_reset}"
else
echo -e "${text_orange}Cancelling permission change.${text_reset}"
fi
}
main
# Bash - Server Management Scripts
## Description
Various scripts to help with management of servers. Most centered around data backups and related maintenance.
## Provided Scripts
### General
Various general scripts.
#### Update Permissions
Updates permissions such that "user" and "group" owners are able to access, and "other" uses cannot access.
Takes in exactly one arg, consisting of the path to either a file or directory to adjust permissions of.
### Backups
Various scripts related to backing up + maintenance of databases or files.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment