Skip to content

Instantly share code, notes, and snippets.

@libcrack
Created February 25, 2017 07:55
Show Gist options
  • Save libcrack/90bd790f7f9482c2e17a36dca31ec0e7 to your computer and use it in GitHub Desktop.
Save libcrack/90bd790f7f9482c2e17a36dca31ec0e7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# [email protected]
# 18/08/2016 05:54:35
#
#
# From man(1) find:
#
# -P Never follow symbolic links. This is the default behaviour. When find
# examines or prints information a file, and the file is a symbolic link,
# the information used shall be taken from the properties of the symbolic
# link itself.
#
# -L Follow symbolic links. When find examines or prints information about
# files, the information used shall be taken from the properties of the
# file to which the link points, not from the link itself [...]
#
# When the -L option is in effect, the -type predicate will always match
# against the type of the file that a symbolic link points to rather than
# the link itself (unless the symbolic link is broken). [...]
#
# -H Do not follow symbolic links, except while processing the command line
# arguments.
finddir="$(realpath "$PWD")"
tmpfile="$("$(which mktemp)" /tmp/XXXXXXXXXXX)"
ret=0
trap _catch_ctrl_c INT
function _catch_ctrl_c() {
printf " \e[31mCtrl+C\e[0m: exiting\n"
rm "$tmpfile"
exit $?
}
_fix_dir_perms(){
find -L "${finddir}/" -type d -exec chmod +x {} \; && {
ret=$?
printf "\e[32m[+]\e[0m Done. All directory are now accesible (chmod -R +x $finddir)\n"
} || {
ret=$?
printf "\e[31m[x]\e[0m Error when chmod -R +x $finddir\n"
}
return $ret
}
_compile_file_list(){
# -name "*.[0-9]" -or \
find -L "${finddir}/" -type f \
-name "vimrc" -or \
-name "CHANGELOG" -or \
-name "LICENSE" -or \
-name "Makefile" -or \
-name ".gitconfig" -or \
-name ".gitignore" -or \
-name "*.ac" -or \
-name "*.am" -or \
-name "*.asm" -or \
-name "*.asc" -or \
-name "*.c" -or \
-name "*.conf" -or \
-name "*.cmake" -or \
-name "*.crt" -or \
-name "*.cy" -or \
-name "*.db" -or \
-name "*.deb" -or \
-name "*.diff" -or \
-name "*.docx" -or \
-name "*.gif" -or \
-name "*.gz" -or \
-name "*.img" -or \
-name "*.ico" -or \
-name "*.in" -or \
-name "*.ini" -or \
-name "*.jpg" -or \
-name "*.json" -or \
-name "*.kdbx" -or \
-name "*.log" -or \
-name "*.manifest" -or \
-name "*.mbox" -or \
-name "*.md" -or \
-name "*.mk" -or \
-name "*.ml" -or \
-name "*.mll" -or \
-name "*.mly" -or \
-name "*.nmap" -or \
-name "*.gnmap" -or \
-name "*.nse" -or \
-name "*.odf" -or \
-name "*.pdf" -or \
-name "*.png" -or \
-name "*.plist" -or \
-name "*.pptx" -or \
-name "*.rc" -or \
-name "*.svg" -or \
-name "*.tar" -or \
-name "*.tar.gz" -or \
-name "*.tgz" -or \
-name "*.txt" -or \
-name "*.txt" -or \
-name "*.vbs" -or \
-name "*.xls" -or \
-name "*.xm" -or \
-name "*.xml" -or \
-name "*.yacc" -or \
-name "*.zip" \
1>"$tmpfile" 2>/dev/null
ret=$?
return $ret
}
_fix_file_perms(){
if [ -f "$tmpfile" ]; then
while read line; do
chmod -x "$line" && ret=0 || {
ret=$?
printf "\e[31m[x]\e[0m $_\n"
}
done < "$tmpfile"
rm "$tmpfile"
return $ret
else
return 1
fi
}
printf "\e[0;93m[i]\e[0m Fixing directory permissions in \"\e[1;33m${finddir}\e[0m\"\n"
_fix_dir_perms "${finddir}/"
printf "\e[0;93m[i]\e[0m Compiling file list in \"\e[0;33m${tmpfile}\e[0m\"\n"
_compile_file_list "${finddir}/"
printf "\e[0;93m[i]\e[0m Fixing file permissions in \"\e[0;33m${finddir}/\e[0m\"\n"
_fix_file_perms "${finddir}/"
printf "\e[0;93m[i]\e[0m Finished\n"
exit $ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment