diff --git a/documents/references.md b/documents/references.md new file mode 100644 index 0000000000000000000000000000000000000000..8434b101fc9d2d84154e5d064fbc8bf5f9a5773e --- /dev/null +++ b/documents/references.md @@ -0,0 +1,17 @@ +# 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> diff --git a/general/update_permissions.sh b/general/update_permissions.sh new file mode 100755 index 0000000000000000000000000000000000000000..2c830aa2a5494b1efa29921824bd73a3152abf5f --- /dev/null +++ b/general/update_permissions.sh @@ -0,0 +1,92 @@ +#!/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 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..b0e141436aeb0feba27f5dc4e23c98af7480d3f9 --- /dev/null +++ b/readme.md @@ -0,0 +1,19 @@ +# 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.