1 contributor
#!/bin/bash
hangar[path]=$HOME/.fgfs/flightgear-fgaddon/Aircraft
hangar[name]=FGADDON
hangar[source]=sourceforge
hangar[type]=svn
hangar[url]=https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft
hangar[active]=1
function getfromrepo () {
svn cat ${hangar[url]}/$1
}
function on_exit () {
rm -f $aircrafts $aircraft
}
function parse_repo_history () {
function getaircraftinfo () { # $1 = aircraft
svn list --xml --depth files ${hangar[url]}/$1 > $aircraft
unset xmlgetnext_empty_tag
while xmlgetnext; do
if test "$TAG" = 'name' && test "${VALUE/%-set.xml}" != "$VALUE"; then
add_setxml_for_aircraft $1 ${VALUE/%-set.xml}
fi
done < $aircraft
}
aircrafts=$temppath/Aircraft-$tempid
aircraft=$temppath/aircraft-$tempid
if test $latest_revision -eq 1; then
echo getting repository list
if ! svn list --xml --depth immediates ${hangar[url]} > $aircrafts; then
echo "error while retrieving list"
exit
fi
total=$(grep -c '<entry' $aircrafts)
is_ac=0
else
if test ${latest_revision:-0} -gt $(svn info --show-item revision ${hangar[url]}); then
echo "already latest revisison"
return
fi
echo "downloading history from revision ${latest_revision:-0}"
if ! svn log --revision ${latest_revision:-0}:HEAD --xml --verbose ${hangar[url]} > $aircrafts; then
echo "error while retrieving history"
exit
fi
total=$(grep -c '<logentry' $aircrafts)
fi
progress=0
echo parsing repository
unset xmlgetnext_empty_tag
while xmlgetnext; do
if test $latest_revision -eq 1; then
if test "$TAG" = 'entry kind="dir"'; then
is_ac=1
continue
elif test $is_ac -eq 0 -a "$TAG" != '/list'; then
continue
fi
else
if test "${TAG%% *}" = 'logentry'; then
is_ac=1
elif test ${is_ac:-0} -eq 0 -a "$TAG" != '/log'; then
continue
fi
fi
case "$TAG" in
'name')
add_record name $VALUE
;;
'logentry revision='*|'commit revision='*)
add_record revision ${TAG#*=}
;;
'author')
add_record author ${VALUE//\'/\'\'}
;;
'date')
add_record date $(date +%s -d "$VALUE")
;;
'path '*)
TAG=${TAG#* }
TAG=${TAG// /;}
TAG=${TAG//-/_}
eval $(echo ${TAG// /;})
path=(${VALUE//\// })
if test $kind = 'dir' -a ${#path[@]} -eq 3 -a $action = 'D'; then
sqlite_request "delete from setxml
where variantof in (
select id from aircrafts
where name = '${path[2]}'
and hangar = ${hangar[id]}
)"
sqlite_request "delete from aircrafts
where name = '${path[2]}'
and hangar = ${hangar[id]}"
is_ac=0
continue
fi
is_ac=1
add_record name ${path[2]}
;;
'/logentry'|'/entry')
getaircraftinfo $(get_record name)
add_aircraft
newprogress=$((++entry * 100 / $total))
if test $(( $newprogress - $progress )) -ge ${progress_granularity:-1}; then
progress=$newprogress
printf "\r%d%% (%d)" $progress $(sqlite_request 'select count(name) from recover_aircrafts')
fi
is_ac=0
;;
'/list'|'/log')
printf "\r\033[K"
apply_revision
break
;;
esac
done < $aircrafts
}