jw-pkg/scripts/purge-stale-projects.sh
Jan Lindemann 3eb2904958
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m22s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m28s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m0s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m20s
CI / Packaging test (push) Successful in 0s
purge-stale-projects.sh: Fix getopt regression

The last commit passes "$*" to getopt in purge-stale-projects.sh, which is nonsense. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-30 07:36:15 +02:00

132 lines
3.1 KiB
Bash

#!/bin/bash
log()
{
printf '%s\n' "$*"
}
fatal()
{
log "$*"
exit 1
}
goodbye()
{
rm -f $scm_status
}
check_scm()
{
local p=$1
if [ -d $p/.git ]; then
log + checking git
#git -C $p pull --no-edit || fatal "git pull failed, giving up"
if git -C $p status --porcelain --untracked-files=no | grep -v '^??' | grep -q . ; then
git -C $p status
fatal "git in project \"$p\" has locally modified files, giving up"
fi
else
log + checking cvs
#cvs update -dP $p
cvs status $p > $scm_status 2>&1
if [ $? != 0 ]; then
cat $scm_status
fatal "\n======== cvs status failed in project \"$p\", giving up."
fi
grep -qi "locally modified" $scm_status && \
fatal "cvs copy in project \"$p\" has locally modified files, giving up"
grep -qi "needs" $scm_status && \
fatal "+ cvs copy in project \"$p\" is out-of-date, giving up"
fi
}
set -e
date=`date +'%Y%m%d'`
myname=`basename $0`
vcss="git"
opts=$(getopt -o C --long "vcs:" -n $myname -- "$@") || fatal "Failed to parse options $*"
eval set -- "$opts"
while [ "$1" != -- ]; do
case "$1" in
--vcs)
vcss="$2"
shift
;;
*)
fatal "Unknown option $1"
;;
esac
shift
done
vcss=$(echo -e $vcss | sed 's/[, ]\+/\n/g' | sort -u)
ssh=ssh
[ "$CVS_RSH" ] && ssh="$CVS_RSH"
[ "$GIT_SSH" ] && ssh="$GIT_SSH"
ssh=`which $ssh`
[ -x "$ssh" ] || fatal "SSH executable \"$ssh\" not found"
[ "$JANWARE_USER" ] || JANWARE_USER=`whoami`
ssh="$ssh -l $JANWARE_USER"
for vcs in $vcss; do
case "$vcs" in
cvs|CVS) host=cvs.janware.com;;
git|Git) host=devgit.janware.com;;
esac
$ssh $host echo hallo >/dev/null 2>&1 || fatal "Can't ssh into host $host"
done
trap goodbye EXIT INT QUIT
scm_status=`mktemp /tmp/$myname""_XXXXXX`
for vcs in $vcss; do
case $vcs in
cvs|CVS)
local_cvs_proj=`ls -d */CVS 2>/dev/null | sed 's%/[^/]*%%'`
remote_cvs_proj=`$ssh cvs.janware.com find /srv/cvs/proj -maxdepth 1 -mindepth 1 -type d -executable -readable | sed 's%.*/%%'`
for p in $local_cvs_proj; do
[ -L $p ] && continue
[ -d $p ] || continue
echo $remote_cvs_proj | grep -q "\(^\| \)$p\($\| \)" && continue
n=purged/cvs/$date/$p
mkdir -p `dirname $n`
echo "--------------- moving stale cvs project $p to $n"
if ! make -C $p distclean; then echo "distclean failed, ignoring"; fi
if ! make -C $p clean; then echo "clean failed, ignoring"; fi
mv $p $n
sed -i "/\/$p\// d" CVS/Entries
purged="$purged $p"
done
[ "$purged" ] && {
cp -p CVS/Entries CVS/Entries-$date-`date +'%H%M%S'`
for p in $purged; do
sed -i "/D\/$p\/\/\/\// d" CVS/Entries
done
}
;;
git|Git)
local_git_proj=`ls -d */.git 2>/dev/null | sed 's%/[^/]*%%'`
remote_git_proj=`$ssh devgit.janware.com /opt/jw-pkg/bin/git-srv-admin.sh -j list-personal-projects`
for p in $local_git_proj; do
[ -L $p ] && continue
[ -d $p ] || continue
echo $remote_git_proj | grep -q "\(^\| \)$p\($\| \)" && continue
check_scm $p
echo done checking scm
n=purged/git/$date/$p
mkdir -p `dirname $n`
mv $p $n
log "moving stale project \"$p\" to \"$n\""
done
;;
*)
log "Unsupported version-control system >$vcs<, ignoring"
;;
esac
done