From 4672138b009f25c1c2d546ca700e0c8f5730f809 Mon Sep 17 00:00:00 2001 From: clsty Date: Wed, 29 Oct 2025 08:15:47 +0800 Subject: [PATCH] Add auto_get_git_submodule() --- sdata/lib/functions.sh | 22 ++++++++++++++++++++++ sdata/subcmd-install/3.files.sh | 2 ++ 2 files changed, 24 insertions(+) diff --git a/sdata/lib/functions.sh b/sdata/lib/functions.sh index 496397f83..3282637bb 100644 --- a/sdata/lib/functions.sh +++ b/sdata/lib/functions.sh @@ -287,3 +287,25 @@ function check_disk_space() { return 0 } + +function auto_get_git_submodule(){ + local git_submodules_list=() + + while IFS= read -r path; do + [ -z "$path" ] && continue + git_submodules_list+=("$path") + done < <(git submodule status --recursive 2>/dev/null | awk '{print $2}') + + local missing=0 + + for p in "${git_submodules_list[@]}"; do + if [ ! -d "$p" ] || [ -z "$(ls -A "$p" 2>/dev/null)" ]; then + missing=1 + break + fi + done + + if [ "$missing" -eq 1 ]; then + x git submodule update --init --recursive + fi +} diff --git a/sdata/subcmd-install/3.files.sh b/sdata/subcmd-install/3.files.sh index cb294ce29..5b2ca8020 100644 --- a/sdata/subcmd-install/3.files.sh +++ b/sdata/subcmd-install/3.files.sh @@ -81,6 +81,8 @@ function auto_backup_configs(){ } ##################################################################################### +showfun auto_get_git_submodule +v auto_get_git_submodule # In case some dirs does not exists v mkdir -p $XDG_BIN_HOME $XDG_CACHE_HOME $XDG_CONFIG_HOME $XDG_DATA_HOME