forked from ProfileManifests/ProfileManifests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateIndexIcons
executable file
·83 lines (66 loc) · 2.94 KB
/
updateIndexIcons
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
#!/bin/bash
if (($( sw_vers -productVersion | awk -F. '{ print $2 }' ) < 14)); then
printf "%s\n" "This script requires macOS 10.14 or higher to create correct hashes for the icons..."
exit 1
fi
shopt -s nullglob
# Verify the script is running inside the ProfileManifests repository and get the repository root path
repository_path=$( git rev-parse --show-toplevel 2> /dev/null )
if !( [[ $? -eq 0 ]] && [[ $(git remote -v) == *"ProfileManifests.git"* ]] ); then
printf "%s\n" "This script must be run inside the ProfileManifests repository."
exit 1
fi
cd $repository_path
# Set the path to the index file
index_path="${repository_path}/Icons/index"
# Set the path to the temporary index file
index_path_tmp="/private/tmp/index.$( cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 8 )"
# List all directories to index
manifest_directories=( 'ManagedPreferencesApple' 'ManifestsApple' 'ManagedPreferencesApplications' 'ManagedPreferencesDeveloper' )
# Loop through all directories
for directory_name in ${manifest_directories[@]}; do
directory_path="${repository_path}/Icons/${directory_name}"
if ! [[ -d ${directory_path} ]]; then
printf "%s\n" "${directory_path}: No such file or directory"
continue
fi
# Create the directory dictionary
if ! /usr/libexec/PlistBuddy -c "Add :${directory_name} dict" "${index_path_tmp}" &>/dev/null; then
printf "%s\n" "${file_name}: Failed to add dictionary with key: ${directory_name}"
exit 1
fi
# Loop through all files in the directory
for file in "${directory_path}"/*.png; do
# Get the file name
file_name=$( basename "${file}" )
# Get the file domain
file_domain="${file_name%.*}"
# Get the file hash
file_hash=$( md5 -q "${file}" )
# Create the file dictionary
if ! /usr/libexec/PlistBuddy -c "Add :${directory_name}:${file_domain} dict" "${index_path_tmp}"; then
printf "%s\n" "${file_name}: Failed to add dictionary with key: ${directory_name}:${file_domain}"
exit 1
fi
# Add the file hash
if ! /usr/libexec/PlistBuddy -c "Add :${directory_name}:${file_domain}:hash string ${file_hash}" "${index_path_tmp}"; then
printf "%s\n" "${file_name}: Failed to add value: ${file_hash} for key: ${directory_name}:${file_domain}:hash"
exit 1
fi
# Add the file path
if ! /usr/libexec/PlistBuddy -c "Add :${directory_name}:${file_domain}:path string Icons/${directory_name}/${file_name}" "${index_path_tmp}"; then
printf "%s\n" "${file_name}: Failed to add value: ${directory_name}/${file_name} for key: ${directory_name}:${file_domain}:path"
exit 1
fi
done
done
# Set the date the file was generated
if ! /usr/libexec/PlistBuddy -c "Add :date date $( LANG=C /bin/date +%a" "%b" "%d" "%T" "%Z" "%Y )" "${index_path_tmp}"; then
printf "%s\n" "Failed to add value for key: date"
exit 1
fi
# Move the temporary file in place
if ! mv "${index_path_tmp}" "${index_path}"; then
printf "%s\n" "Failed to move the temporary index file to the repository"
exit 1
fi