-
Notifications
You must be signed in to change notification settings - Fork 9
/
quarantine_score
executable file
·106 lines (73 loc) · 2.11 KB
/
quarantine_score
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env zsh
# macos-scripts/quarantine_score
# quarantine_score
# For files with the com.apple.quarantine extended attribute
# Print the name of the file and the quarantine flag value
set -euo pipefail
# -e exit if any command returns non-zero status code
# -u prevent using undefined variables
# -o pipefail force pipelines to fail on first non-zero status code
IFS=$'\n\t'
# Set Internal Field Separator to newlines and tabs
# This makes bash consider newlines and tabs as separating words
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
### Define Colours ###
tput sgr0;
# reset colors
RED="$(tput setaf 1)"
readonly RED
RESET="$(tput sgr0)"
readonly RESET
### END Colours ###
### UTILITY FUNCTIONS ###
# ctrl_c
function ctrl_c {
echo -e "\\n[❌] ${USER} has chosen to quit!"
exit 1
}
### END UTILITY FUNCTIONS ###
function usage {
echo -e "\\nPrint gatekeeper score if file has the com.apple.quarantine extended attribute. Highlights scores other than '0083'"
echo " ./quarantine_score {directory_path}"
echo -e " {directory_path} defaults to $HOME/Downloads\\n"
exit 0
}
function get_files {
while IFS=$'\n' read -r file; do
files+=("${file}");
done < <(find "${arg}" -type f -maxdepth 1)
}
function procees_files {
for file in "${files[@]}"; do
if xattr "${file}" | grep -q 'quarantine'; then
flag=$(xattr -p "com.apple.quarantine" "${file}" | awk -F ';' '{print $1}')
if [ "${flag}" != "0083" ]; then
echo -e "File: ${file}\\nFlag: ${RED}${flag}${RESET}"
else
file_name=$(basename "${file}")
echo -e "File: ${file_name}\\nFlag: ${flag}"
fi
fi
done
}
function main {
trap ctrl_c SIGINT
# Detect and react to the user hitting CTRL + C
declare -a files
arg=${1:-"$HOME/Downloads"}
case "${arg}" in
usage|help|-h|--help|🤷♂️|🤷♀️|"¯\_(ツ)_/¯")
usage
;;
*)
if [[ -d "${arg}" ]]; then
get_files
procees_files
else
echo "[❌] ${arg} is not a directory"
exit 1
fi
;;
esac
}
main "$@"