-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from tegonal/improve/remove-unused-signatures
remove unused signatures during cleanup
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2059 | ||
# | ||
# __ __ | ||
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts | ||
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <[email protected]> | ||
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 | ||
# /___/ Please report bugs and contribute back your improvements | ||
# | ||
# Version: v3.2.0 | ||
####### Description ############# | ||
# | ||
# Functions which help in doing cleanup in e.g. scripts/cleanup-on-push-to-main.sh | ||
# | ||
####### Usage ################### | ||
# | ||
# #!/usr/bin/env bash | ||
# set -euo pipefail | ||
# shopt -s inherit_errexit | ||
# | ||
# projectDir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.." | ||
# | ||
# # Assumes tegonal's scripts were fetched with gt - adjust location accordingly | ||
# dir_of_tegonal_scripts="$projectDir/lib/tegonal-scripts/src" | ||
# source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts" | ||
# | ||
# sourceOnce "$dir_of_tegonal_scripts/utility/cleanups.sh" | ||
# | ||
# # e.g. in scripts/cleanup-on-push-to-main.sh | ||
# function cleanupOnPushToMain() { | ||
# removeUnusedSignatures "$projectDir" | ||
# logSuccess "cleanup done" | ||
# } | ||
# | ||
################################### | ||
set -euo pipefail | ||
shopt -s inherit_errexit | ||
unset CDPATH | ||
|
||
if ! [[ -v dir_of_tegonal_scripts ]]; then | ||
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.." | ||
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts" | ||
fi | ||
sourceOnce "$dir_of_tegonal_scripts/utility/log.sh" | ||
|
||
function removeUnusedSignatures() { | ||
if ! (($# == 1)); then | ||
logError "One argument needs to be passed to removeUnusedSignatures, given \033[0;36m%s\033[0m\n" "$#" | ||
echo >&2 '1: projectDir the path to the root directory of the project' | ||
printStackTrace | ||
exit 9 | ||
fi | ||
local projectRootDir=$1 | ||
shift 1 || die "could not shift by 1" | ||
|
||
find "$projectRootDir" \ | ||
-type f \ | ||
-name "*.sig" \ | ||
-not -path "$projectRootDir/.gt/signing-key.public.asc.sig" \ | ||
-not -path "$projectRootDir/.gt/remotes/*/public-keys/*.sig" \ | ||
-print0 | | ||
while read -r -d $'\0' sigFile; do | ||
if ! [[ -f ${sigFile::${#sigFile}-4} ]]; then | ||
logInfo "remove unused signature \033[0;36m%s\033[0m as the corresponding file does no longer exist" "$sigFile" | ||
rm "$sigFile" | ||
fi | ||
done | ||
} |
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