Created
December 21, 2022 10:33
-
-
Save rawiriblundell/c272d2f9876ae964bcca8b18cfaedd9a to your computer and use it in GitHub Desktop.
One-off script to recursively capture ownership/perms on a Jenkins directory and to apply them to correct ownership/perms on a target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while read -r file; do | |
printf -- '%s;%s\n' "$(md5sum < "${file}" | awk '{print $1}')" "$(stat -c "%a;%U;%G;%n" "${file}")" | |
done < <(find . -type f -print) > data.manifest | |
51e7d30fab63ba29f86bcf6f807b88cf;674;jenkins;jenkins;./org.jenkinsci.plugins.gitclient.JGitApacheTool.xml | |
0a363d9165e56856e0f693152fc0fe88;644;jenkins;jenkins;./queue.xml.bak | |
d99c0a9f0563b0203c6ce7d778a14338;674;jenkins;jenkins;./hudson.plugins.disk_usage.DiskUsageProperty.xml | |
671c3c9ef67c47d75f73d4d9280e2b28;674;jenkins;jenkins;./org.jenkinsci.plugins.workflow.libs.GlobalLibraries.xml | |
71c550ce25d0c9095cf9493cb188f7c6;644;jenkins;jenkins;./nodeMonitors.xml | |
while IFS=';' read -r file_hash file_perms file_owner file_group file_path; do | |
{ | |
if [[ ! -f "${file_path}" ]]; then | |
printf -- '%s\n' "${file_path} (missing)" | |
continue | |
fi | |
cur_hash="$(md5sum "${file_path}" | awk '{print $1}')" | |
if [[ "${cur_hash}" != "${file_hash}" ]]; then | |
printf -- '%s\n' "${file_path} (different)" | |
continue | |
fi | |
chown "${file_owner}:${file_group}" "${file_path}" | |
chmod "${file_perms}" "${file_path}" | |
} >> data.parsed 2>&1 | |
done < data.manifest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment