AspireSync/svn/bin/update-plugin-trunk
Chuck Adams 33a7d0e19a
svn theme archive script, shorten log messages (#49)
* wip: themes version of update script

* tweak: add up-wp-cart to blacklist

* tweak: terser log format, not trying at json anymore

* cleanup: rm unused vars from .env
2025-02-22 13:19:28 -07:00

100 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
# Must be run from within the svn checkout. Will create or update the archive directory using the same name as the current
. $(dirname $0)/prelude.bash
cd $ORIG_PWD
enforce_svn_root
repo=$(basename $(pwd))
mkdir -p $ARCHIVE_DIR/$repo/trunks/
# These have so many redundant files (usually from recursively nested tags) that they're effectively zip bombs
bombs='all-in-one-contact-buttons-wpshare247|biblesupersearch'
# These produce errors when svn attempts to update them
corrupt='a2-optimized-wp|better-links|countdown-timer|facebook-album-sync|font-awesome-the-easy-way|up-wp-cart'
# combined blacklist
BLACKLIST="^($bombs|$corrupt)\$"
####
function main() {
for dir in $*
do
process $dir
done
}
function process() {
local dir=$1
echo -e "\nPROCESSING: $dir [trunk]"
if ! [[ $dir =~ ^[-A-Za-z0-9]+$ ]]; then
finalize $dir "malformed dir ignored"
return
fi
if [[ $dir =~ $BLACKLIST ]]; then
finalize $dir "blacklisted dir skipped"
return
fi
[[ -d $dir ]] || svn update --ignore-externals --set-depth=empty $dir
# Note: using a new /trunks base directory, but still using .trunk suffix so archive files can co-mingle
local rev=$(get_revision $dir)
local tar=$ARCHIVE_DIR/$repo/trunks/$rev/$rev.$dir.trunk.tar
local ztar=$tar.zst
if [[ -f $ztar ]]; then
finalize $dir "archive exists at revision $rev"
return
fi
mkdir -p $(dirname $tar)
update $dir
archive $dir $ztar
ls -lh $ztar
finalize $dir "archived at revision $rev"
}
function update() {
local dir=$1
svn update --set-depth=immediates --force $dir/tags # the list of versions is lightweight and useful metadata
svn update --ignore-externals --set-depth=infinity --force $dir/trunk
}
function archive() {
local dir=$1
local ztar=$2
tar cf - ./$dir | zstd --progress > $ztar.tmp
mv $ztar.tmp $ztar
rm -f $tar
}
function finalize() {
local dir=$1
local message=$2
warn "$dir: $message"
[[ -n $UPDATE_KEEP_DIRS ]] || rm -rf "$dir"
}
function get_revision() {
local dir=$1
local rev=$(svn info -r HEAD --show-item last-changed-revision $dir)
if [[ -z $rev ]]; then
die "fatal could not retrieve revision for $dir"
fi
echo $rev
}
################
main $*