#!/bin/bash
# /usr/local/bin/executable
# http://crystalfaeries.net/posix/bin/executable
# celeste:crystalfaery 2016-05-03 22:13:03+00:00
# echo "Shall I normalize file ownership and permissions"
# echo "in the script executable directories"
# echo -n "/usr/local/bin and /usr/lib/cgi-bin ? (NO/yes):"
# read answer
# if [ "X$answer" != "Xyes" ]
# then exit 0 # unless user answers "yes" we just quit
# fi
cd /usr/local/bin || exit 1
user=root
group=root # default in case following line fails
group=staff
dirs=0775
files=775
sudo find . \! -iname '*.txt' \! -iname '*.htm*' -type d \! -perm $dirs -print -exec chmod $dirs {} \;
sudo find . \! -iname '*.txt' \! -iname '*.htm*' -type f \! -perm $files -print -exec chmod $files {} \;
sudo find . \! -iname '*.txt' \! -iname '*.htm*' \! -user $user -print -exec chown $user:$group {} \;
sudo find . \! -iname '*.txt' \! -iname '*.htm*' \! -group $group -print -exec chgrp $group {} \;
sudo chmod $files readme.txt # unique local hack
files=664
sudo find . \( -iname '*.txt' -o -iname '*.htm*' \) \! -user $user -print -exec chown $user:$group {} \;
sudo find . \( -iname '*.txt' -o -iname '*.htm*' \) \! -group $group -print -exec chgrp $group {} \;
sudo find . \( -iname '*.txt' -o -iname '*.htm*' \) -type f \! -perm $files -print -exec chmod $files {} \;
cd /usr/lib/cgi-bin
user=www-data
group=www-data
dirs=0775
files=555
sudo find . \! -iname '*.txt' \! -iname '*.htm*' \! -user $user -print -exec chown $user:$group {} \;
sudo find . \! -iname '*.txt' \! -iname '*.htm*' \! -group $group -print -exec chgrp $group {} \;
sudo find . \! -iname '*.txt' \! -iname '*.htm*' -type d \! -perm $dirs -print -exec chmod $dirs {} \;
sudo find . \! -iname '*.txt' \! -iname '*.htm*' -type f \! -perm $files -print -exec chmod $files {} \;
rsync -auvzH $(file * | grep -v directory | grep -v ELF | sed 's/:.*$//') /usr/local/bin # update cgi scripts to /usr/local/bin
exit $?
syntax highlighted by Code2HTML, v. 0.9.1