1
0
CISS.2024.vps.bookworm.hard.../lib/mod/do_set_permissions.lib
2024-08-05 21:15:19 +01:00

50 lines
2.3 KiB
Bash

#!/bin/bash
###########################################################################################
# Debian Tools V5.0.256.2024.08.05 #
###########################################################################################
# Copyright (c) 2019 - 2024, Marc Weidner, Centurion Intelligence Consulting Agency #
# https://coresecret.eu/ #
# Licensed under the EUROPEAN UNION PUBLIC LICENCE v. 1.2 https://eupl.eu/1.2/en/ #
###########################################################################################
# https://keys.openpgp.org/vks/v1/by-fingerprint/A6D46A56AE17A185AB0F6DB77095A8A13CBE0FA3 #
# Fingerprint A6D4 6A56 AE17 A185 AB0F 6DB7 7095 A8A1 3CBE 0FA3 ## valid till: 01.01.2031 #
###########################################################################################
# Module: exdo_set_permissions #
###########################################################################################
# shellcheck disable=SC2129 disable=SC2162
set -o errexit # Exit if a command fails.
set -o nounset # Exit if an unset variable is used.
set -o pipefail # Exit if a pipeline fails.
set -o noclobber # Prevent output redirection ">", ">&", "<>" from overwriting existing files.
set +o history # Temporarily turn off history, to avoid sensitive information leakage.
do_set_permissions() {
local FILE="$1"
PERMISSIONS_OLD=$(stat -c "%a" "$FILE")
if [[ "$PERMISSIONS_OLD" -eq 400 ]]; then
echo "Nothing changed: $FILE" >> "$DIR_LOG"permissions.log
else
if [[ -x "$FILE" ]]; then
chmod u=rwx,g=,o= "$FILE"
echo "Changed to 0700: $FILE" >> "$DIR_LOG"permissions.log
else
chmod u=rw,g=,o= "$FILE"
echo "Changed to 0600: $FILE" >> "$DIR_LOG"permissions.log
fi
fi
}
exdo_set_permissions() {
clear
date >>"$LOG_INS"
echo -e "\033[33m++++ ++++ ++++ ++++ ++++ ++++ ++ Set Permissions $1 - ...\033[0m" | tee -a "$LOG_INS"
find "$1" -type f | while read -r FILE; do
do_set_permissions "$FILE"
done
find "$1" -type d -exec chmod u=rwx,g=rx,o= {} +
date >>"$LOG_INS"
echo -e "\033[32m++++ ++++ ++++ ++++ ++++ ++++ ++ Set Permissions $1 - done\033[0m" | tee -a "$LOG_INS"
sleep "$SLEEPTIMER"
clear
}