From 1680f69b4cf2ea104037257ba1e0c18e8a967bb6 Mon Sep 17 00:00:00 2001 From: "Henrique F. Simoes" Date: Tue, 16 Apr 2024 08:41:20 -0300 Subject: [PATCH] ioc: prune module directories from non-static builds. Modules may contain several artifacts, including configuration files, graphical interface files and other repository artifacts that do not need to be in the IOC image. Remove them all except the ones containing EPICS database (`.db` and `.template`) or autosave requirement (`.req`) files, besides shared libraries. Binaries directory (`bin`) is also removed, as only $REPONAME and $RUNDIR should contain target executables, which are filtered out from the list. --- base/lnls-prune-artifacts.sh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/base/lnls-prune-artifacts.sh b/base/lnls-prune-artifacts.sh index 19d61f6..7652d88 100755 --- a/base/lnls-prune-artifacts.sh +++ b/base/lnls-prune-artifacts.sh @@ -77,7 +77,27 @@ get_used_epics_modules() { filter_out_paths "$all_modules" "$unused_modules" } -remove_unused_epics_modules() { +prune_module_dirs() { + module=$1 + + keep_paths=" + $(find_shared_libs $module) + $(find $module -type f -regex ".*\.\(db\|template\|req\)" -printf "%h\n" | sort -u) + " + + while read -r candidate; do + [ -d $candidate ] || continue + + if [[ ! $keep_paths =~ "$candidate".* ]]; then + size=$(du -hs $candidate | cut -f 1) + + printf "Removing directory '$candidate' ($size)...\n" + rm -rf $candidate + fi + done < <(find $module -type d) +} + +clean_up_epics_modules() { targets=$@ all_modules=$(get_all_epics_modules) @@ -97,6 +117,13 @@ remove_unused_epics_modules() { echo "Removing module '$module' ($size)..." rm -rf $module done + + prune_dirs=$(filter_out_paths "$used_modules" "$targets") + + for dir in $prune_dirs; do + echo "Pruning module '$dir'..." + prune_module_dirs $dir + done } remove_static_libs() { @@ -129,6 +156,6 @@ remove_unused_shared_libs() { done } -remove_unused_epics_modules $@ +clean_up_epics_modules $@ remove_static_libs /opt remove_unused_shared_libs $@