72 lines
1.6 KiB
Bash
Executable File
72 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# vhost-stack
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
# load include file
|
|
source $(dirname $0)/vhost.sh
|
|
|
|
help()
|
|
{
|
|
thisfilename=$(basename -- "$0")
|
|
echo "Make sure all home (/home/...) and virtualhost (/srv/www/...) files are owned by correct users."
|
|
echo ""
|
|
echo "usage: $thisfilename [OPTIONS]"
|
|
echo ""
|
|
echo " -h Print this help."
|
|
echo " -n dry-run - List all files that need modification, but don't actually do anything."
|
|
echo " -v verbose - List all files that are being modified."
|
|
exit
|
|
}
|
|
|
|
while getopts "hvn" opt; do
|
|
case "${opt}" in
|
|
h )
|
|
help
|
|
;;
|
|
v )
|
|
mode=verbose
|
|
;;
|
|
n )
|
|
mode=dry-run
|
|
;;
|
|
\? )
|
|
echo "Invalid option: $OPTARG"
|
|
exit 1
|
|
;;
|
|
: )
|
|
echo "Invalid option: $OPTARG requires an argument"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
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
|
|
|
|
}
|