jw-pkg/scripts/collect-installed-pkg-changes.sh
2025-02-19 16:49:36 +00:00

111 lines
1.5 KiB
Bash

#!/bin/bash
log()
{
echo "=== $@"
}
err()
{
log $@
}
fatal()
{
err $@
exit 1
}
lp()
{
scm.sh ls-files | grep "/$1$"
}
usage()
{
echo "$myname [-h] [-t target-dir ] [ package-name ]"
[ "$1" ] && exit $1
}
collect_changes()
{
local projs="$*"
local proj changed_path project_path p b lp
[ "$projs" ] || {
if [ -f .git ]; then
projs=`pwd | xargs basename`
projs="$proj-run $proj-devel"
else
projs="$(jw-pkg list | sed 's/-[0-9].*//')"
fi
}
for proj in $projs; do
(
changed_paths=`rpm -qV $proj | sed '
/^..5.*/ !d
s%^..5...... . /%/%
'`
[ "$changed_paths" ] || exit
project_path=$(echo $proj | sed 's/-run$\|-devel$//')
cd $project_path || {
err "Failed to change to $project_path"
exit
}
log "Handling project $proj"
for p in $changed_paths; do
[ -r $p ] || {
err "can't read $p"
continue
}
b=`basename $p`
lp=`lp "$b"`
[ "$lp" ] || {
err "$p is not in repository"
continue
}
nl=`lp "$b" | wc -l`
[ $nl -gt 1 ] && {
log $p is more than once in repository:
lp $b
continue
}
diff -q $lp $p >/dev/null 2>&1 && {
continue
}
log copying $p $lp
cp $p $lp
done
)
done
}
# -- here we go
set -- `getopt 'ht:' $*`
while [ "$1" != -- ]; do
case "$1" in
-h)
usage 0
;;
-t)
target="$2"
shift
;;
*)
usage 1
;;
esac
shift
done
shift
[ "$target" ] && {
cd $target || fatal "failed to change to target dir \"$target\""
}
collect_changes