openmamba-headserver-tools/bin/openmamba-repository

934 lines
29 KiB
Plaintext
Raw Normal View History

2012-03-12 15:18:41 +01:00
#!/bin/bash
#
# openmamba inter-repository import script from remote ftp to local
# Copyright (c) 2007-2012 by Silvan Calarco
2012-03-12 15:18:41 +01:00
#
. /etc/sysconfig/openmamba-central
basearch=i586
2012-03-12 15:18:41 +01:00
me=${0##*/}
function usage() {
echo "openmamba inter-repository import script"
echo "Copyright (c) 2007-2012 by Silvan Calarco"
2012-03-12 15:18:41 +01:00
echo
echo "Usage:"
echo "$me list"
echo "$me import REPOSITORY [PKGS ...] [-d REPOSITORY] [-s] [-y]"
echo "$me release REPOSITORY [PKGS ...] [-d REPOSITORY] [-s] [-y]"
2012-03-12 15:18:41 +01:00
echo "$me archive REPOSITORY PKGS ..."
echo "$me restore REPOSITORY PKGS ..."
2012-03-12 15:18:41 +01:00
echo "$me query REPOSITORY PKGS ..."
echo "$me search [-i] [-r regexp] STRING"
2012-03-12 15:18:41 +01:00
echo "$me verify REPOSITORY [PKGS ...]"
echo "$me inspect REPOSITORY {PKGS ...} [-d REPOSITORY]"
echo "$me setwarning REPOSITORY {PKG ...} -t \"TEXT\""
echo "$me diff REPOSITORY [PKGS ...] [-d REPOSITORY]"
echo "$me distromatic REPOSITORY"
echo
echo " -d use given repository as destination (default: devel)"
echo " -r match repositories with given regexp"
2012-03-12 15:18:41 +01:00
echo " -s simulate operations to see if it would work"
echo " -t warning text"
echo " -y assume yes to all questions (be careful!)"
2012-03-12 15:18:41 +01:00
}
# get_pkg_buildinfo - uses distromatic generated build file for
# getting information on the repository
#
# $1: repositoy name
# $2: architecture
# $3: pkg name
2012-03-12 15:18:41 +01:00
function get_pkg_buildinfo() {
local pkg i a
2012-03-12 15:18:41 +01:00
[ $1 ] && rep=$1 || exit 1
[ $2 ] && buildarch=$2 || exit 1
[ $3 ] && pkg=$3
pkg_archs=();
for a in ${archs[*]}; do
pkg_header=();
DISTROMATIC_BUILD_FILE=$local_distromatic/$rep/builds-$a.sh
[ -e $DISTROMATIC_BUILD_FILE ] && . $DISTROMATIC_BUILD_FILE
[ ${pkg_header[0]} ] && pkg_archs=(${pkg_archs[*]} $a)
done
2012-03-12 15:18:41 +01:00
pkg_header=();
pkg_builds=();
pkg_obsoletes=();
pkg_list=();
[ "$buildarch" = "any" ] && buildarch=${pkg_archs[0]}
DISTROMATIC_BUILD_FILE=$local_distromatic/$rep/builds-${buildarch}.sh
if [ ! -e $DISTROMATIC_BUILD_FILE ]; then
echo "Error: missing distromatic generated file $DISTROMATIC_BUILD_FILE; aborting."
return;
fi
2012-03-12 15:18:41 +01:00
. $DISTROMATIC_BUILD_FILE
for i in ${pkg_list[*]}; do
if [ "$i" == "${pkg_header[0]}" ]; then
pkg_name=${pkg_header[0]};
# Note: pkg_arch reported in builds file is just last arch source was
# built for, so we use repository arch instead
pkg_arch=${pkg_header[1]};
[ "$pkg_arch" = "noarch" ] || pkg_arch=$buildarch
2012-03-12 15:18:41 +01:00
pkg_version=${pkg_header[2]};
pkg_release=${pkg_header[3]};
pkg_group=${pkg_header[4]};
pkg_license=${pkg_header[5]};
pkg_size=${pkg_header[6]};
pkg_buildtime=${pkg_header[7]};
pkg_altrep=${pkg_header[8]};
pkg_repository=${pkg_header[9]};
return 0
2012-03-12 15:18:41 +01:00
fi
done
unset pkg_name pkg_arch pkg_version pkg_release \
pkg_group pkg_license pkg_size pkg_buildtime pkg_altrep pkg_repository
2012-03-12 15:18:41 +01:00
return 0
}
function import_file() {
[ $1 ] || exit 1
2012-03-12 15:18:41 +01:00
local f import_mode
f=$1
import_mode=$2
if [ "$import_mode" = "backup" ]; then
curl_delete_add="-Q '-DELE $f'"
else
curl_delete_add=""
fi
[ "$simulate" != "1" ] &&
if [ "$ORIG_MODE" = "remote" ]; then
if [ $ORIG_URL_LOCAL_ARCH -a ! -f $ORIG_URL_LOCAL_ARCH/$f ]; then
echo "Warning: package missing in local mirror; setting copy from remote repository."
fi
if [ "$DEST_MODE" = "local" ]; then
# remote -> local
if [ $ORIG_URL_LOCAL_ARCH -a -f $ORIG_URL_LOCAL_ARCH/$f ]; then
echo -n "(L) "
# if file exists in a local mirror use it by preference
cp $ORIG_URL_LOCAL_ARCH/$f $DEST_URL_ARCH/ || {
echo "Error: cannot move file $ORIG_URL_LOCAL_ARCH/$f to $DEST_URL_ARCH/$f; aborting."
exit 1
}
chown ftp$DEST_REPOSITORY:users $DEST_URL_ARCH/$f
2012-03-12 15:18:41 +01:00
eval curl -s -u$ftpuser:$ftppass $ORIG_URL_ARCH $curl_delete_add >/dev/null && {
rm -f $ORIG_URL_LOCAL_ARCH/$f
} || {
echo
2012-03-12 15:18:41 +01:00
echo "Warning: cannot delete remote file $ORIG_URL_ARCH/$f; you'll have to delete it."
}
else
echo -n "(R) "
curl -s -u$ftpuser:$ftppass \
--get $ORIG_URL_ARCH/$f \
-o $DEST_URL_ARCH/$f $curl_delete_add || {
echo
2012-03-12 15:18:41 +01:00
echo "Error: cannot get file $ORIG_URL_ARCH/$f; aborting."
exit 1
}
fi
else
# remote -> remote
echo "Error: remote to remote file import is not implemented yet; aborting."
exit 1
2012-03-12 15:18:41 +01:00
fi
else
if [ "$DEST_MODE" = "local" ]; then
# local -> local
cp $ORIG_URL_ARCH/$f $DEST_URL_ARCH/ || {
echo "Error: cannot copy file $ORIG_URL_ARCH/$f to $DEST_URL_ARCH/$f; aborting."
exit 1
}
chown ftp$DEST_REPOSITORY:users $DEST_URL_ARCH/$f
2012-03-12 15:18:41 +01:00
if [ "$import_mode" = "backup" ]; then
rm -f $ORIG_URL_ARCH/$f || {
echo "Error: cannot remove file $ORIG_URL_ARCH/$f; aborting."
exit 1
}
fi
else
# local -> remote
echo -n "(R) "
curl -s -u$ftpuser:$ftppass \
-T $ORIG_URL_ARCH/$f \
$DEST_URL_ARCH/ || {
echo
echo "Error: cannot send file $ORIG_URL_ARCH/$f; aborting."
exit 1
}
rm -f $ORIG_URL_ARCH/$f || {
echo
echo "Warning: cannot delete local file $ORIG_URL_ARCH/$f; you'll have to delete it."
}
2012-03-12 15:18:41 +01:00
fi
fi
}
function backup_local_file() {
[ $1 ] || return
2012-03-12 15:18:41 +01:00
[ -e $LOCAL_BACKUP ] || mkdir -p $LOCAL_BACKUP
movefiles=$1
#`find $DEST_URL_ARCH -maxdepth 1 -regex ".*/${pkgname}-[^-]*-[^-]*"`
for m in $movefiles; do
echo "backing up $m"
if [ "$simulate" != "1" ]; then
mv $m $LOCAL_BACKUP/ || {
echo "Error: can't move $m to $LOCAL_BACKUP; aborting."
exit 1
}
fi
done
}
function backup_package() {
local rep reg i
2012-03-12 15:18:41 +01:00
[ "$1" ] || return
[ "$2" ] && rep=$2 || rep=$destrepository
[ "$3" ] && reg=$3 || reg=$DESTREGFILE
archive_pkg=$1
get_pkg_buildinfo $rep any $archive_pkg
2012-03-12 15:18:41 +01:00
LOCAL_BACKUP=$DEST_URL_LOCAL/old/${pkg_name}_${BACKUP_DATE}
2012-03-12 15:18:41 +01:00
if [ "$pkg_name" ]; then
PKG_FILENAME="$pkg_name-$pkg_version-$pkg_release.src.rpm"
2012-03-12 15:18:41 +01:00
if [ -f $DEST_URL_LOCAL/SRPMS.base/$PKG_FILENAME ]; then
backup_local_file $DEST_URL_LOCAL/SRPMS.base/$PKG_FILENAME
else
echo "Warning: package $PKG_FILENAME does not exist in local repository"
fi
if [ "$simulate" != "1" -a "$DEST_MODE" = "remote" ]; then
curl -s -u$ftpuser:$ftppass $DEST_URL/SRPMS.base/ -Q "-DELE $PKG_FILENAME" >/dev/null || {
echo "Warning: cannot delete remote file $DEST_URL/SRPMS.base/$PKG_FILENAME; you'll have to delete it."
}
fi
for a in ${pkg_archs[*]}; do
get_pkg_buildinfo $rep $a $archive_pkg
for i in ${pkg_builds[*]}; do
2012-03-12 15:18:41 +01:00
PKG_FILENAME="$i-$pkg_version-$pkg_release.$pkg_arch.rpm"
if [ -f $DEST_URL_LOCAL/RPMS.$a/$PKG_FILENAME ]; then
backup_local_file $DEST_URL_LOCAL/RPMS.$a/$PKG_FILENAME
else
echo "Warning: package $PKG_FILENAME does not exist in local repository"
fi
2012-03-12 15:18:41 +01:00
if [ "$simulate" != "1" -a "$DEST_MODE" = "remote" ]; then
curl -s -u$ftpuser:$ftppass $DEST_URL/RPMS.$a/ -Q "-DELE $PKG_FILENAME" >/dev/null || {
echo "Warning: cannot delete remote file $DEST_URL/RPMS.$pkg_arch/$PKG_FILENAME; you'll have to delete it."
2012-03-12 15:18:41 +01:00
}
fi
done
done
2012-03-12 15:18:41 +01:00
# write register
[ "$simulate" != "1" ] && {
echo "`date +%Y%m%d%H%M` Package <a href=\"/distribution/distromatic.html?tag=$rep&pkg=$pkg_name.source\">$pkg_name</a> ($pkg_version-$pkg_release) archived" >> $reg
2012-03-12 15:18:41 +01:00
# | \
# tee -a $ORIGREGFILE $DESTREGFILE >/dev/null
# echo "`date +%Y%m%d%H%M` \"\" \"package $pkg_name ($pkg_version-$pkg_release) archived from $rep\"" >> $reg
}
else
echo "Warning: package $archive_pkg does not exists in $rep; skipping."
fi
}
function restore_local_file() {
[ $1 ] || return
[ $2 ] || return
restorefiles=$1
backupprefix=$2
ARCH=$3
#`find $DEST_URL_ARCH -maxdepth 1 -regex ".*/${pkgname}-[^-]*-[^-]*"`
for r in $restorefiles; do
[ "$ARCH" ] && restoredest=$DEST_URL_LOCAL/RPMS.$ARCH/ || restoredest=$DEST_URL_LOCAL/SRPMS.base/
echo "restoring $r"
if [ "$simulate" != "1" ]; then
cp ${backupprefix}/$r $restoredest || {
echo "Error: can't copy $p to $restoredest; aborting."
exit 1
2012-03-12 15:18:41 +01:00
}
fi
done
}
function restore_package() {
local rep reg i
[ "$1" ] || return
[ "$2" ] && rep=$2 || rep=$destrepository
[ "$3" ] && reg=$3 || reg=$DESTREGFILE
restore_pkg=$1
get_pkg_buildinfo $rep any $restore_pkg
if [ ! "$pkg_name" ]; then
echo "Info: package $restore_pkg does not exists in $rep"
fi
LOCAL_RESTORE_PREFIX=$DEST_URL_LOCAL/old/${restore_pkg}_
local cnt=0
local RESTORE_NAMES=()
ls ${LOCAL_RESTORE_PREFIX}* &>/dev/null && \
for f in ${LOCAL_RESTORE_PREFIX}*; do
[ "$cnt" = 0 ] && echo "Available backups: "
cnt=`expr $cnt + 1`
RESTORE_NAMES=(${RESTORE_NAMES[*]} `echo ${f/*_/}`)
echo "($cnt) ${RESTORE_NAMES[$cnt-1]}"
done
[ "$cnt" == "0" ] && {
echo "Sorry, no backups availables for ${restore_pkg} in $rep"
return
}
local ans=0
while [ $ans -le 0 2>/dev/null -o $ans -gt $cnt 2>/dev/null ]; do
echo
echo -n "Please select the entry to restore or press ENTER to skip (1-$cnt): "
read ans
[ "$ans" ] || return
[ $ans -eq $ans 2>/dev/null ] || ans=0
done
echo "Restoring: "
for f in `ls ${LOCAL_RESTORE_PREFIX}${RESTORE_NAMES[$ans-1]}`; do
echo -n "${f/*\/} "
done
echo
echo -n "Ok to restore [y/N]? "
read ans1
[ "$ans1" != "y" -a "$ans1" != "Y" ] && return
for a in ${archs[*]}; do
for f in `ls ${LOCAL_RESTORE_PREFIX}${RESTORE_NAMES[$ans-1]}/*.${a}.rpm 2>/dev/null`; do
restore_local_file ${f/*\/} ${LOCAL_RESTORE_PREFIX}${RESTORE_NAMES[$ans-1]}/ $a
done
done
for f in `ls ${LOCAL_RESTORE_PREFIX}${RESTORE_NAMES[$ans-1]}/*.src.rpm 2>/dev/null`; do
restore_local_file ${f/*\/} ${LOCAL_RESTORE_PREFIX}${RESTORE_NAMES[$ans-1]}/
done
# write register
[ "$simulate" != "1" ] && {
echo "`date +%Y%m%d%H%M` Package <a href=\"/distribution/distromatic.html?tag=$rep&pkg=$restore_pkg.source\">$restore_pkg</a> restored" >> $reg
}
2012-03-12 15:18:41 +01:00
}
function import_package() {
[ $1 ] || exit 1
local import_pkg import_mode
2012-03-12 15:18:41 +01:00
import_pkg=$1
import_mode=$2
get_pkg_buildinfo $destrepository any $import_pkg
# check for all architectures
for a in ${pkg_archs[*]}; do
# check release in dest repository
get_pkg_buildinfo $destrepository $a $import_pkg
[ "$pkg_name" ] && {
# IMPORT_ORIG_ARCHS=(${IMPORT_ORIG_ARCHS[*]} $a)
get_pkg_buildinfo $origrepository $a $import_pkg
[ "$pkg_name" ] || {
[ "$a" == "$basearch" ] && {
echo "Error: package $import_pkg does not exist in $origrepository($a); skipping."
return
}
if [ "$force" = "1" ]; then
echo "Warning: package $import_pkg is missing in $origrepository($a) but present in $destrepository($a)."
echo "Import forced. You will need to port package to the missing arch."
else
echo "Error: package $import_pkg is missing in $origrepository($a). This would break package in $destrepository($a) repository. Skipping."
return
fi
}
}
done
2012-03-12 15:18:41 +01:00
# check release in dest repository
get_pkg_buildinfo $destrepository any $import_pkg
2012-03-12 15:18:41 +01:00
[ "$pkg_version" ] && {
destpkgname="$pkg_name"
destpkgversion="$pkg_version-$pkg_release"
# destpkgarch="$pkg_arch"
2012-03-12 15:18:41 +01:00
} || destpkgversion="none"
get_pkg_buildinfo $origrepository any $import_pkg
2012-03-12 15:18:41 +01:00
[ "$pkg_version" ] && {
origpkgname="$pkg_name"
origpkgversion="$pkg_version-$pkg_release"
# origpkgarch="$pkg_arch"
2012-03-12 15:18:41 +01:00
} || origpkgversion="none"
2012-03-12 15:18:41 +01:00
[ $origpkgname ] || {
echo "Error: package $import_pkg does not exist in $origrepository; aborting."
2012-03-12 15:18:41 +01:00
exit 1
}
DEST_URL_ARCH=$DEST_URL/SRPMS.base/
ORIG_URL_ARCH=$ORIG_URL/SRPMS.base/
ORIG_URL_LOCAL_ARCH=$ORIG_URL_LOCAL/SRPMS.base/
2012-03-12 15:18:41 +01:00
PKG_FILENAME="$origpkgname-$origpkgversion.src.rpm"
[ "$ORIG_MODE" = "remote" ] &&
ORIG_FILELIST=`curl -s -l -u$ftpuser:$ftppass --url $ORIG_URL_ARCH/` ||
ORIG_FILELIST=`ls $ORIG_URL_ARCH`
2012-03-12 15:18:41 +01:00
check_existence=0;
for i in $ORIG_FILELIST; do
[ "$i" = "$PKG_FILENAME" ] && check_existence=1;
done
if [ $check_existence = 1 ]; then
[ "$destpkgversion" = "$origpkgversion" ] && {
echo "Warning: same version of $origpkgname exists in destination"
}
if [ "$assume_yes" != "1" ]; then
echo -n "Import $PKG_FILENAME ($origpkgversion -> $destpkgversion) [y/N]?"
read ans
fi
2012-03-12 15:18:41 +01:00
[ "$assume_yes" = "1" -o "$ans" = "y" -o "$ans" = "Y" ] && {
2012-03-12 15:18:41 +01:00
echo -n "Importing $PKG_FILENAME "
import_file $PKG_FILENAME $import_mode
get_pkg_buildinfo $origrepository any $import_pkg
for a in ${pkg_archs[*]}; do
get_pkg_buildinfo $origrepository $a $import_pkg
for i in ${pkg_builds[*]}; do
PKG_FILENAME="$i-$origpkgversion.$pkg_arch.rpm"
DEST_URL_ARCH=$DEST_URL/RPMS.$a/
ORIG_URL_ARCH=$ORIG_URL/RPMS.$a/
ORIG_URL_LOCAL_ARCH=$ORIG_URL_LOCAL/RPMS.$a/
echo -n "$PKG_FILENAME "
import_file $PKG_FILENAME $import_mode
done
2012-03-12 15:18:41 +01:00
done
echo
# write register
[ "$simulate" != "1" ] && {
echo "`date +%Y%m%d%H%M` Package <a href=\"/distribution/distromatic.html?tag=$destrepository&pkg=$import_pkg\">$import_pkg</a> ($origpkgversion -> $destpkgversion) imported from $origrepository to $destrepository" | \
tee -a $ORIGREGFILE $DESTREGFILE >/dev/null
}
# if [ "$import_mode" = "backup" ]; then
# backup old stuff in destination repository
2012-03-12 15:18:41 +01:00
[ "$destpkgversion" != "none" -a \
"$destpkgversion" != "$origpkgversion" ] && {
backup_package $import_pkg $destrepository $DESTREGFILE
}
2012-03-12 15:18:41 +01:00
# remove distromatic extra files associated with this package
[ -e $local_distromatic/$rep/warnings/$import_pkg.in ] && {
rm -f $local_distromatic/$rep/warnings/$import_pkg.in ||
echo "Warning: cannot remove file $local_distromatic/$rep/warnings/$import_pkg.in"
}
# fi
2012-03-12 15:18:41 +01:00
#for i in ${pkg_obsoletes}; do
# PKG_FILENAME="$i-$pkg_version-$pkg_release.$namearch.rpm"
# DEST_URL_ARCH=$DEST_URL/RPMS.$namearch/$PKG_FILENAME
2012-03-12 15:18:41 +01:00
# [ -e $DEST_URL_ARCH ] && echo "Warning: obsoleted package $i exists"
# backup_package $i $destrepository $DESTREGFILE
# #echo rm $DEST_URL_ARCH
#done
} # ans = y
2012-03-12 15:18:41 +01:00
else # check_existence != 1
echo "Warning: $import_pkg reported by distromatic does no longer exist"
fi
}
# FIXME: only works with basearch
2012-03-12 15:18:41 +01:00
function extract_diffinfo() {
PKG=$1
REP=$2
TMP=$3
local i
get_pkg_buildinfo $REP $basearch $PKG
2012-03-12 15:18:41 +01:00
if [ "$pkg_name" ]; then
PKG_FILENAME="$local_ftp/$REP/SRPMS.base/$pkg_name-$pkg_version-$pkg_release.src.rpm"
[ -e "$PKG_FILENAME" ] || {
echo "Error: package $PKG_FILENAME missing in $origrepository; skipping"
return 1
}
rpm -qp $PKG_FILENAME --requires > $TMP/buildrequires
autospec -q -x $PKG_FILENAME -F \*.spec --destdir $TMP >/dev/null || {
echo "Error: could not extract specfile from $PKG_FILENAME; skipping package"
return 1
}
[ -e "$TMP_SPEC_DIR/$pkg_name.spec" ] || {
SPEC_FOUND="`ls $TMP_SPEC_DIR/*.spec`"
mv $SPEC_FOUND $TMP_SPEC_DIR/$pkg_name.spec
echo "Warning: specfile name should be $pkg_name.spec instead of ${SPEC_FOUND/*\//} in $REP repository"
}
> $TMP/requires
> $TMP/provides
for i in ${pkg_builds[*]}; do
PKG_FILENAME="$local_ftp/$REP/RPMS.$basearch/$i-$pkg_version-$pkg_release.$pkg_arch.rpm"
2012-03-12 15:18:41 +01:00
[ -e "$PKG_FILENAME" ] || {
echo "Error: package $PKG_FILENAME missing in $origrepository; skipping"
return 1
}
rpm -qp $PKG_FILENAME --requires >> $TMP/requires
rpm -qp $PKG_FILENAME --provides >> $TMP/provides
rpm -qlp $PKG_FILENAME >> $TMP/files
done
else
#echo "Warning: can't find package $PKG in $REP repository"
return 1
fi
return 0
}
[ $1 ] || { usage; exit 1; }
origrepository=
destrepository=devel
packages=
command=
simulate=0
while [ "$1" ]; do
case $1 in
-d)
destrepository=$2; shift ;;
-r)
searchrep=$2; shift ;;
2012-03-12 15:18:41 +01:00
-s)
simulate=1 ;;
-t)
shift
warningtext="$@"
break ;;
-f)
force=1 ;;
-i)
ignorecase=1 ;;
-y)
assume_yes=1 ;;
2012-03-12 15:18:41 +01:00
*)
if [ "$command" ]; then
case "$command" in
"import"|"release"|"query"|"verify"|"archive"|"restore"|"diff"|"inspect"|"setwarning"|"distromatic")
[ "$origrepository" ] &&
2012-03-12 15:18:41 +01:00
packages="$packages $1" ||
origrepository=$1
;;
"search")
[ "$searchstring" ] && {
echo "Error: invalid option $1; aborting."
exit 1
}
searchstring="$1"
;;
2012-03-12 15:18:41 +01:00
*) usage
echo "Error: invalid option $1; aborting."
exit 1
;;
esac
else
case "$1" in
"import"|"release"|"query"|"verify"|"archive"|"restore"|"list"|"diff"|"inspect"|"setwarning"|"distromatic"|"search") command=$1 ;;
*)
2012-03-12 15:18:41 +01:00
usage
echo "Errror: $1 is not a valid command; aborting."
exit 1
;;
esac
fi
;;
esac
shift
done
[ "$command" = "" ] && { usage; exit 1; }
[ "$command" = "list" ] && echo "Local repositories:"
for a in ${local_reps[*]}; do
[ "$a" = "$destrepository" ] && DEST_MODE=local;
[ "$a" = "$origrepository" ] && ORIG_MODE=local;
[ "$command" = "list" ] && echo "$a"
done
[ "$do_list" ] && echo "Remote repositories:"
for a in ${remote_reps[*]}; do
[ "$a" = "$destrepository" ] && DEST_MODE=remote;
[ "$a" = "$origrepository" ] && ORIG_MODE=remote;
[ "$command" = "list" ] && echo "$a"
done
[ "$command" = "list" ] && exit 0;
[ "$command" = "search" ] && {
[ "$ignorecase" ] && GREP_OPTS="-i"
for rep in ${local_reps[*]} ${remote_reps[*]}; do
[[ "$rep" =~ "$searchrep" ]] || continue
[ -r $local_ftp/$rep/SRPMS.base ] || continue
ls $local_ftp/$rep/SRPMS.base | grep $GREP_OPTS "$searchstring" 2>/dev/null | \
while read PKGLINE; do
[ "$PKGLINE" ] && {
echo "$rep(source): ${PKGLINE/ *}"
}
done
for a in ${archs[*]}; do
[ -r $local_ftp/$rep/RPMS.$a ] || continue
ls $local_ftp/$rep/RPMS.$a | grep $GREP_OPTS "$searchstring" 2>/dev/null | \
while read PKGLINE; do
[ "$PKGLINE" ] && {
echo "$rep($a): ${PKGLINE/ *}"
}
done
done
done
exit 0
}
2012-03-12 15:18:41 +01:00
[ "$origrepository" ] || { usage; exit 1; }
[ "$DEST_MODE" ] || { echo "Error: $destrepository is not a valid repository; aborting."; exit 1; }
[ "$ORIG_MODE" ] || { echo "Error: $origrepository is not a valid repository; aborting."; exit 1; }
[ "$DEST_MODE" = "remote" ] && { echo "Waring: destination is a remote repository; this is an EXPERIMENTAL feature."; }
[ "$command" = "query" ] && {
[ "$packages" ] || { usage; exit 1; }
for i in $packages; do
get_pkg_buildinfo $origrepository any $i
2012-03-12 15:18:41 +01:00
if [ ! "$pkg_name" ]; then
echo "$i: package not found in $origrepository repository"
else
for a in ${pkg_archs[*]}; do
get_pkg_buildinfo $origrepository $a $i
if [ "$pkg_name" ]; then
echo "Repository:$origrepository($a)"
echo "Name: $pkg_name"
echo "BuildArch: $pkg_arch"
echo "Version: $pkg_version"
echo "Release: $pkg_release"
echo "Group: $pkg_group"
echo "License: $pkg_license"
echo "Size: $pkg_size"
echo "Builds: ${pkg_builds[*]}"
echo "Obsoletes: ${pkg_obsoletes[*]}"
echo
fi
done
2012-03-12 15:18:41 +01:00
fi
done
exit 0;
}
[ "$command" = "verify" ] && {
[ "$packages" ] || {
get_pkg_buildinfo $origrepository any
2012-03-12 15:18:41 +01:00
packages=${pkg_list[*]}
}
for i in $packages; do
get_pkg_buildinfo $origrepository any $i
2012-03-12 15:18:41 +01:00
if [ ! "$pkg_name" ]; then
echo "$i: package not found in $origrepository repository"
else
PKG_FILENAME="$i-$pkg_version-$pkg_release.src.rpm"
rpm2cpio $local_ftp/${origrepository}/SRPMS.base/$PKG_FILENAME &>/dev/null || {
echo "Warning: source package $PKG_FILENAME is empty or corrupted."
2012-03-12 15:18:41 +01:00
}
for a in ${archs[*]}; do
get_pkg_buildinfo $origrepository $a $i
if [ "$pkg_name" ]; then
for l in ${pkg_builds[*]}; do
PKG_FILENAME="$l-$pkg_version-$pkg_release.$pkg_arch.rpm"
rpm2cpio $local_ftp${origrepository}/RPMS.$a/$PKG_FILENAME &>/dev/null || {
echo "Warning: package $PKG_FILENAME($a) is empty or corrupted."
}
done
fi
2012-03-12 15:18:41 +01:00
done
fi
done
exit 0;
}
[ "$command" = "diff" ] && {
[ "$packages" ] || {
get_pkg_buildinfo $origrepository any
2012-03-12 15:18:41 +01:00
packages=${pkg_list[*]}
}
TMP_SPEC_DIR=`mktemp -d --tmpdir=/dev/shm`
2012-03-12 15:18:41 +01:00
for i in $packages; do
echo
echo "*******************************************************************"
echo "$i package check:"
echo "*******************************************************************"
extract_diffinfo $i $origrepository $TMP_SPEC_DIR || continue
[ -e $TMP_SPEC_DIR/$i.spec ] || {
echo "Error: could not extract specfile for $i in $origrepository repository; skipping"
continue
}
mv $TMP_SPEC_DIR/$i.spec $TMP_SPEC_DIR/$i.spec.origrep
mv $TMP_SPEC_DIR/files $TMP_SPEC_DIR/files.origrep
sort -u $TMP_SPEC_DIR/buildrequires > $TMP_SPEC_DIR/buildrequires.origrep
sort -u $TMP_SPEC_DIR/requires > $TMP_SPEC_DIR/requires.origrep
sort -u $TMP_SPEC_DIR/provides > $TMP_SPEC_DIR/provides.origrep
extract_diffinfo $i $destrepository $TMP_SPEC_DIR || {
echo "Looks like a new package; inspecting data:"
echo ""
echo "SPECFILE:"
echo "========="
cat $TMP_SPEC_DIR/$i.spec.origrep
echo ""
echo "REQUIRES:"
echo "========="
cat $TMP_SPEC_DIR/requires.origrep
echo ""
echo "PROVIDES:"
echo "========="
cat $TMP_SPEC_DIR/provides.origrep
echo ""
echo "FILES:"
echo "======"
cat $TMP_SPEC_DIR/files.origrep
continue
}
[ -e $TMP_SPEC_DIR/$i.spec ] || {
echo "Error: could not extract specfile for $i in $destrepository repository; skipping"
}
mv $TMP_SPEC_DIR/$i.spec $TMP_SPEC_DIR/$i.spec.destrep
mv $TMP_SPEC_DIR/files $TMP_SPEC_DIR/files.destrep
sort -u $TMP_SPEC_DIR/buildrequires > $TMP_SPEC_DIR/buildrequires.destrep
sort -u $TMP_SPEC_DIR/requires > $TMP_SPEC_DIR/requires.destrep
sort -u $TMP_SPEC_DIR/provides > $TMP_SPEC_DIR/provides.destrep
echo "Showing differences between package version in $origrepository and $destrepository:"
echo ""
echo "SPECFILE:"
echo "========="
diff -u $TMP_SPEC_DIR/$i.spec.destrep $TMP_SPEC_DIR/$i.spec.origrep
echo ""
echo "BUILDREQUIRES:"
echo "=============="
diff -u $TMP_SPEC_DIR/buildrequires.destrep $TMP_SPEC_DIR/buildrequires.origrep
echo ""
echo "REQUIRES:"
echo "========="
diff -u $TMP_SPEC_DIR/requires.destrep $TMP_SPEC_DIR/requires.origrep
echo ""
echo "PROVIDES:"
echo "========="
diff -u $TMP_SPEC_DIR/provides.destrep $TMP_SPEC_DIR/provides.origrep
echo ""
echo "FILES:"
echo "======"
diff -u $TMP_SPEC_DIR/files.destrep $TMP_SPEC_DIR/files.origrep
echo
done
rm -rf $TMP_SPEC_DIR
exit 0;
}
[ "$command" = "setwarning" ] && {
[ "$packages" ] || { usage; exit 1; }
TMP_SPEC_DIR=`mktemp -d`
for i in $packages; do
extract_diffinfo $i $origrepository $TMP_SPEC_DIR
[ -e $TMP_SPEC_DIR/$i.spec ] || {
echo "Error: could not extract specfile for $i in $origrepository repository; aborting."
exit 1
}
echo "$warningtext" > $local_ftp/distromatic/$origrepository/warnings/$i.in
done
[ "$TMP_SPEC_DIR" != "/" ] && rm -rf $TMP_SPEC_DIR
exit 0
}
[ "$command" = "inspect" ] && {
[ "$packages" ] || { usage; exit 1; }
TMP_SPEC_DIR=`mktemp -d`
for i in $packages; do
extract_diffinfo $i $origrepository $TMP_SPEC_DIR
[ -e $TMP_SPEC_DIR/$i.spec ] || {
echo "Error: could not extract specfile for $i in $origrepository repository; aborting."
exit 1
}
echo "$i: details of package in $origrepository repository"
echo ""
echo "SPECFILE:"
echo "========="
cat $TMP_SPEC_DIR/$i.spec
echo ""
echo "REQUIRES:"
echo "========="
cat $TMP_SPEC_DIR/requires
echo ""
echo "PROVIDES:"
echo "========="
cat $TMP_SPEC_DIR/provides
done
[ "$TMP_SPEC_DIR" != "/" ] && rm -rf $TMP_SPEC_DIR
exit 0;
}
[ "$command" = "distromatic" ] && {
SRCPKGLIST="$local_ftp/$origrepository/srcpkglist"
[ -r $SRCPKGLIST ] || {
echo "Error: srcpkglist file missing for $origrepository repository; aborting."
exit 1
}
[ -d $local_ftp/$origrepository/specs ] || mkdir $local_ftp/$origrepository/specs
[ -d $local_ftp/$origrepository/patches ] || mkdir $local_ftp/$origrepository/patches
while read line; do
set -- $line
[ -e $local_ftp/$origrepository/SRPMS.base/$1-$2-$6.src.rpm ] && {
[ $local_ftp/$origrepository/SRPMS.base/$1-$2-$6.src.rpm -nt \
$local_ftp/$origrepository/specs/$1.spec ] && {
# echo $local_ftp/$origrepository/SRPMS.base/$1-$2-$6.src.rpm
autospec -x $local_ftp/$origrepository/SRPMS.base/$1-$2-$6.src.rpm -F '*.spec' \
--destdir $local_ftp/$origrepository/specs/ -q >/dev/null
touch $local_ftp/$origrepository/specs/$1.spec
grep -i "^Patch[0-9]*:" $local_ftp/$origrepository/specs/$1.spec &>/dev/null && {
autospec -x $local_ftp/$origrepository/SRPMS.base/$1-$2-$6.src.rpm -F '*.patch' \
--destdir $local_ftp/$origrepository/patches/ -q >/dev/null
}
}
}
done < $SRCPKGLIST
exit 0
}
[ "$simulate" = "1" ] && echo "Simulation mode enabled."
#
# import and other active commands
2012-03-12 15:18:41 +01:00
#
if [ "$DEST_MODE" = "remote" ]; then
DEST_URL=$dest_ftp/pub/openmamba/$destrepository
else
DEST_URL=$local_ftp/$destrepository
fi
2012-03-12 15:18:41 +01:00
DEST_URL_LOCAL=$local_ftp/$destrepository
# ORIG_URL_LOCAL is set if a local copy of the repository exists
# and will be preferred for file transfer optimizations
if [ "$ORIG_MODE" = "remote" ]; then
ORIG_URL=$dest_ftp/pub/openmamba/$origrepository
else
ORIG_URL=$local_ftp/$origrepository
fi
ORIG_URL_LOCAL=$local_ftp/$origrepository
BACKUP_DATE=`date +%y%m%d.%H%M%S`
LOCAL_BACKUP=$DEST_URL/old
# operation files are always in the local copy of the repository
ORIGREGFILE=$local_ftp/$origrepository/operations.log.html
DESTREGFILE=$local_ftp/$destrepository/operations.log.html
2012-03-12 15:18:41 +01:00
[ "$command" = "archive" ] && {
DEST_URL=$ORIG_URL
DEST_URL_LOCAL=$ORIG_URL_LOCAL
DEST_MODE=$ORIG_MODE
[ "$packages" ] || { usage; exit 1; }
for i in $packages; do
backup_package $i $origrepository $ORIGREGFILE
done
exit 0
}
[ "$command" = "restore" ] && {
DEST_URL=$ORIG_URL
DEST_URL_LOCAL=$ORIG_URL_LOCAL
DEST_MODE=$ORIG_MODE
[ "$ORIG_MODE" = "remote" ] && {
echo "Error: restore is only implemented in local repository; exiting."
exit 1
}
[ "$packages" ] || { usage; exit 1; }
for i in $packages; do
restore_package $i $origrepository $ORIGREGFILE
done
exit 0
}
2012-03-12 15:18:41 +01:00
[ "$command" = "import" -o "$command" = "release" ] && {
[ "$origrepository" = "$destrepository" ] && {
2012-03-12 15:18:41 +01:00
echo "Error: source and destination repository cannot be the same; aborting."; exit 1; }
if [ "$command" = "import" ]; then
echo "Importing $1: $origrepository ($ORIG_MODE) => $destrepository ($DEST_MODE)"
backup_mode=backup
else
echo "Releasing $1: $origrepository ($ORIG_MODE) => $destrepository ($DEST_MODE)"
backup_mode=release
fi
if [ ! "$packages" ]; then
get_pkg_buildinfo $origrepository any
2012-03-12 15:18:41 +01:00
for i in ${pkg_list[*]}; do
import_package $i $backup_mode
done
else
for i in ${packages[*]}; do
import_package $i $backup_mode
done
fi
openmamba-repository-fix-permissions
2012-03-12 15:18:41 +01:00
exit 0
}
usage
echo "Error: $command is not a valid command; aborting."
exit 1