Last active
April 25, 2023 08:40
-
-
Save bartoszek/41a3bfb707f1b258de061f75b109042b to your computer and use it in GitHub Desktop.
PKGBUILD: generate git submodule configuration.
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 | |
# shellcheck disable=SC2164,SC2154 # mask unsafe cd and uninitialized variables warings | |
shopt -s globstar | |
# How to use: | |
# * run in PKGBUILD dir or pass path to PKGBUILD as argument | |
# this will generate volatile source tree in $TMP (default: /tmp) and | |
# generate source array and prepare_submodule() function to init them | |
# * add local=1 env var to use src/ dir in PKGBUILD path instead of $TMP | |
# * add remote=1 env var to update module past the pined commit hash | |
# * redirect stdout `>> PKGBUILD` to append generated script | |
# to do: | |
# * handle $srcdir | |
# * auto update PKGBUILD | |
# * handle source[] | |
# * handle checksums | |
# ✓ find all .gitmodules | |
# ✓ make sure noting goes to the stdout beside output script | |
[[ -f "${1:-$PWD}/PKGBUILD" ]] || { | |
echo -e "usage: $(basename "$0") run inside directory containing PKGBUILD or pass path as argument" >&2 | |
exit 1 | |
} | |
[[ -v 1 ]] && cd "$1" | |
if (( local )); then | |
cd src || { echo -e "usage: $(basename "$0") in local mode first run \`makepkg -Cod\`" >&2; exit 2; } | |
else | |
export BUILDDIR=${TMP:-/tmp}/aur_git_submodule_$$ | |
trap 'rm -rf "$BUILDDIR"' exit | |
makepkg -Cod --noprepare >&2 | |
cd "$BUILDDIR"/*/src | |
fi | |
while read -r gitmodule; do | |
while read -r submodule; do | |
prepare+=(" git -C \"\$srcdir/${gitmodule%/.gitmodules}\" -c protocol.file.allow=always config ${submodule% *} \"\$srcdir/${submodule##*/}\"") | |
source+=(" \"${submodule##*/}::git+${submodule#* }\"") | |
done < <(git config --file "$gitmodule" --get-regex url|sed 's/\.git$//') | |
prepare+=(" git -C \"\$srcdir/${gitmodule%/.gitmodules}\" submodule update --init${remote:+ --remote}") | |
done < <(ls -- **/.gitmodules ) | |
{ | |
IFS=$'\n' | |
echo -e "\n# Generated with git_submodule_PKGBUILD_conf.sh ( https://gist.github.com/bartoszek/41a3bfb707f1b258de061f75b109042b )" | |
echo -e "# Call prepare_submodule in prepare() function\n" | |
echo -e "prepare_submodule() {\n${prepare[*]}\n}" | |
echo -e "source+=(\n${source[*]}\n)" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment