46 lines
1.1 KiB
Bash
46 lines
1.1 KiB
Bash
#!/bin/bash
|
|
#
|
|
# vhost-stack
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
# load config
|
|
|
|
source /etc/vhost.conf || echo "ERROR: Either you do not have vhost user permissions or the config file is missing." && exit
|
|
|
|
if [ -n "$1" ]; then
|
|
if [ "$1" = '--verbose' ] || [ "$1" = '-v' ]; then
|
|
mode=verbose
|
|
elif [ "$1" = '--dry-run' ] || [ "$1" = '-n' ]; then
|
|
mode=dry-run
|
|
fi
|
|
fi
|
|
|
|
for VHOST in /srv/www/*/; {
|
|
|
|
# get username
|
|
USER=$(stat -c '%U' $VHOST)
|
|
# make sure all files & dirs are owned by user
|
|
if [ "$mode" = "verbose" ] || [ "$mode" = "dry-run" ]; then
|
|
/usr/bin/find $VHOST ! -user $USER
|
|
fi
|
|
if [ "$mode" != "dry-run" ]; then
|
|
/usr/bin/find $VHOST ! -user $USER -exec chown $USER {} +
|
|
fi
|
|
|
|
}
|
|
|
|
for HOME in /home/*/; {
|
|
|
|
# get username
|
|
USER=$(stat -c '%U' $HOME)
|
|
# make sure all files & dirs are owned by user
|
|
if [ "$mode" = "verbose" ] || [ "$mode" = "dry-run" ]; then
|
|
/usr/bin/find $HOME ! -user $USER
|
|
fi
|
|
if [ "$mode" != "dry-run" ]; then
|
|
/usr/bin/find $HOME ! -user $USER -exec chown $USER {} +
|
|
fi
|
|
|
|
}
|