From 25d3fef4aa6f53b09249fae8001e4357f8215b70 Mon Sep 17 00:00:00 2001 From: myvesta <38690722+myvesta@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:27:39 +0200 Subject: [PATCH] Create v-fix-user-permissions --- bin/v-fix-user-permissions | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 bin/v-fix-user-permissions diff --git a/bin/v-fix-user-permissions b/bin/v-fix-user-permissions new file mode 100644 index 000000000..fa902ec32 --- /dev/null +++ b/bin/v-fix-user-permissions @@ -0,0 +1,55 @@ +#!/bin/bash + +# info: +# This script will fix files permissions for desired user (if ownership is lost or files have wrong chmod) + +# options: user + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +whoami=$(whoami) +if [ "$whoami" != "root" ] && [ "$whoami" != "admin" ] ; then + echo "You must be root or admin to execute this script"; + exit 1; +fi + +# Argument definition +user=$1 + +# Includes +source $VESTA/func/main.sh + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'USER' +is_format_valid 'user' +is_object_valid 'user' 'USER' "$user" + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +find /home/$user/conf/mail/ -type d -exec chown Debian-exim:mail {} \; +find /home/$user/conf/mail/*/ -type f -exec chown Debian-exim:mail {} \; +find /home/$user/conf/mail/*/ -name "passwd" -type f -exec chown dovecot:mail {} \; +find /home/$user/mail/ -type d -exec chown $user:mail {} \; +find /home/$user/mail/*/ -type d -exec chown $user:mail {} \; +find /home/$user/mail/*/ -type f -exec chown $user:mail {} \; + +find /home/$user/conf/dns/ -type f -exec chown root:bind {} \; +find /home/$user/conf/ -type d -exec chown root:root {} \; + +find /home/$user/web/*/public_html/ -type d -exec chmod 755 {} + +find /home/$user/web/*/public_html/ -type f -exec chmod 644 {} + +find /home/$user/web/*/public_html/ -exec chown $user:$user {} \; + +echo "Done, permissions fixed for user: $user" + +# Logging +log_event "$OK" "$ARGUMENTS" + +exit