Last active
March 29, 2024 13:09
-
-
Save fryfrog/ee4a2a3a43a2a644e7c42e7f729664ca to your computer and use it in GitHub Desktop.
An NZBGet post processing script that sets user, group and permissions of folders and files.
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 | |
################################################################################ | |
### NZBGET POST-PROCESSING SCRIPT ### | |
# Change user:group ownership and folder/file permission. | |
################################################################################ | |
### OPTIONS ### | |
# Set owner and group (yes, no). | |
setowner=no | |
# Put user here. | |
user=user | |
# Put group here. | |
group=group | |
# Set folder and file permissions (yes, no). | |
setmode=no | |
# Put file mode here. | |
mode=664 | |
# Put folder mode here. | |
dirmode=775 | |
### NZBGET POST-PROCESSING SCRIPT ### | |
################################################################################ | |
# Exit codes | |
#POSTPROCESS_PARCHECK=92 | |
#POSTPROCESS_SUCCESS=93 | |
POSTPROCESS_ERROR=94 | |
#POSTPROCESS_NONE=95 | |
POSTPROCESS=95 | |
# Check if the script is called from nzbget 11.0 or later | |
if [[ "${NZBOP_SCRIPTDIR}" = "" ]]; then | |
echo "*** NZBGet post-processing script ***" | |
echo "This script is supposed to be called from nzbget (11.0 or later)." | |
exit ${POSTPROCESS_ERROR} | |
fi | |
if [[ "${NZBPO_USER}" = "user" ]] || [[ "${NZBPO_GROUP}" = "group" ]]; then | |
echo "*** NZBGet post-processing script ***" | |
echo "[WARN] The user and group are set to defaults, check script settings." | |
exit ${POSTPROCESS_ERROR} | |
fi | |
# Check if directory exists | |
if [[ -d "${NZBPP_DIRECTORY}" ]]; then | |
# chown | |
if [[ "${NZBPO_SETOWNER}" = "yes" ]]; then | |
if chown "${NZBPO_USER}:${NZBPO_GROUP}" -R "${NZBPP_DIRECTORY}"; then | |
echo "[INFO] Ownership set to ${NZBPO_USER}:${NZBPO_GROUP}" | |
POSTPROCESS=93 | |
else | |
echo "[WARN] User and group NOT set" | |
exit ${POSTPROCESS_ERROR} | |
fi | |
fi | |
# chmod | |
if [[ "${NZBPO_SETMODE}" = "yes" ]]; then | |
# recursively set perms on files | |
if find "${NZBPP_DIRECTORY}" -type f -exec chmod "${NZBPO_MODE}" '{}' ';'; then | |
echo "[INFO] File permissions set to ${NZBPO_MODE}" | |
POSTPROCESS=93 | |
else | |
echo "[WARN] File permissions NOT set" | |
exit ${POSTPROCESS_ERROR} | |
fi | |
# recursively set perms on folders | |
if find "${NZBPP_DIRECTORY}" -type d -exec chmod "${NZBPO_DIRMODE}" '{}' ';'; then | |
echo "[INFO] Folder permissions set to ${NZBPO_DIRMODE}" | |
POSTPROCESS=93 | |
else | |
echo "[WARN] Folder permissions NOT set" | |
exit ${POSTPROCESS_ERROR} | |
fi | |
fi | |
else | |
echo "[WARN] Directory not found" | |
echo "[DETAIL] $NZBPP_DIRECTORY" | |
exit ${POSTPROCESS} | |
fi | |
exit ${POSTPROCESS} |
You can only change owner and permissions if the owner is trying to change it, so make sure your existing permissions and ownership are correct.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick question. Script is called for and user/group are setup correctly.
However she fails with an "Operation not permitted" thus not setting requested chmod?