autodist-repository: new "install" option to install packages with rpm directly from local repositories

This commit is contained in:
Silvan Calarco 2014-09-05 19:08:34 +02:00
parent bf3085f435
commit 491357aebb

View File

@ -15,21 +15,22 @@ function usage() {
echo "Copyright (c) 2007-2014 by Silvan Calarco"
echo
echo "Usage:"
echo "$me list"
echo "$me import REPOSITORY [PKGS ...] [-d REPOSITORY] [-s] [-y]"
echo "$me release REPOSITORY [PKGS ...] [-d REPOSITORY] [-s] [-y]"
echo "$me archive REPOSITORY PKGS ..."
echo "$me restore REPOSITORY PKGS ..."
echo "$me query REPOSITORY PKGS ..."
echo "$me search [-i] [-r regexp] STRING"
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 "$me install REPOSITORY [PKGS ...] [-f]"
echo "$me import REPOSITORY [PKGS ...] [-d REPOSITORY] [-s] [-y]"
echo "$me inspect REPOSITORY {PKGS ...} [-d REPOSITORY]"
echo "$me list"
echo "$me query REPOSITORY PKGS ..."
echo "$me release REPOSITORY [PKGS ...] [-d REPOSITORY] [-s] [-y]"
echo "$me restore REPOSITORY PKGS ..."
echo "$me search [-i] [-r regexp] STRING"
echo "$me setwarning REPOSITORY {PKG ...} -t \"TEXT\""
echo "$me verify REPOSITORY [PKGS ...]"
echo
echo " -d use given repository as destination (default: devel)"
echo " -f force import to destination repository"
echo " -f force operation"
echo " -r match repositories with given regexp"
echo " -s simulate operations to see if it would work"
echo " -t warning text"
@ -152,6 +153,38 @@ function get_pkg_buildinfo() {
return 0
}
# get_pkg_info - uses distromatic generated build file to get packages information from the repository
#
# $1: repository name
# $2: architecture
# $3: pkg name
function get_pkg_info() {
local pkg buildarch rep line
[ $1 ] && rep=$1 || exit 200
[ $2 ] && buildarch=$2 || exit 200
[ $3 ] && pkg=$3 || exit 200
[ -e ${PKGLIST}.$buildarch ] || {
echo "ERROR: get_pkg_info: file ${PKGLIST}.$buildarch missing; aborting."
exit 1
}
line=`grep "^$pkg " ${PKGLIST}.$buildarch 2>/dev/null | tail -n1`
set -- $line
pkg_name=$1
pkg_version=$2
pkg_size=$3
pkg_unknown=$4
pkg_repository=$5
pkg_unknown2=$6
pkg_release=$7
pkg_arch=$buildarch
return 0
}
function import_file() {
[ $1 ] || exit 200
@ -638,7 +671,7 @@ while [ "$1" ]; do
*)
if [ "$command" ]; then
case "$command" in
"import"|"release"|"query"|"verify"|"archive"|"restore"|"diff"|"inspect"|"setwarning"|"distromatic")
"import"|"release"|"query"|"verify"|"archive"|"restore"|"diff"|"inspect"|"install"|"setwarning"|"distromatic")
[ "$origrepository" ] &&
packages="$packages $1" ||
origrepository=$1
@ -657,7 +690,7 @@ while [ "$1" ]; do
esac
else
case "$1" in
"import"|"release"|"query"|"verify"|"archive"|"restore"|"list"|"diff"|"inspect"|"setwarning"|"distromatic"|"search") command=$1 ;;
"import"|"release"|"query"|"verify"|"archive"|"restore"|"list"|"diff"|"inspect"|"install"|"setwarning"|"distromatic"|"search") command=$1 ;;
*)
usage
echo "Errror: $1 is not a valid command; aborting."
@ -711,6 +744,7 @@ done
[ "$origrepository" ] || { usage; exit 200; }
SRCPKGLIST="${LOCAL_REPS_BASE_DIR}/$origrepository/srcpkglist"
PKGLIST="${LOCAL_REPS_BASE_DIR}/$origrepository/pkglist"
[ "$DEST_MODE" ] || { echo "ERROR: $destrepository is not a valid repository; aborting." >&2; exit 200; }
[ "$ORIG_MODE" ] || { echo "ERROR: $origrepository is not a valid repository; aborting." >&2; exit 200; }
@ -896,6 +930,60 @@ SRCPKGLIST="${LOCAL_REPS_BASE_DIR}/$origrepository/srcpkglist"
exit 0;
}
[ "$command" = "install" ] && {
[ "$packages" ] || { usage; exit 1; }
myarch=`uname -p`
if [ "$myarch" = "*686" -o "$myarch" = "athlon" -o "$myarch" = "pentium*" ]; then
myarch="i586"
fi
for i in $packages; do
pkg=$i
pkgarch=
if [ "${i/.*}" != "${i}" ]; then
pkg=${i/.*}
pkgarch=${i/*.}
fi
if [ "$pkgarch" -a "$pkgarch" != "$myarch" ]; then
get_pkg_info $origrepository $pkgarch $pkg
[ "$pkg_name" ] || {
echo "WARNING: $pkg not found in $origrepository for arch $pkgarch; skipping."
continue
}
else
get_pkg_info $origrepository $myarch $pkg
[ "$pkg_name" ] || {
echo "WARNING: $pkg not found in $origrepository for arch $myarch; skipping."
continue
}
fi
pkg_file=${pkg_name}-${pkg_version}-${pkg_release}.$pkg_arch.rpm
pkg_path=${LOCAL_REPS_BASE_DIR}/$pkg_repository/RPMS.$pkg_arch/${pkg_file}
[ -r $pkg_path ] || {
echo "WARNING: file $pkg_path should exist but doesn't; skipping."
continue
}
echo "Installing $pkg_file..."
if [ "$force" = "1" ]; then
rpm -i $pkg_path --force
rpmret=$?
[ $rpmret -gt 0 ] && echo "WARNING: rpm returned $rpmret"
if [ "$pkg_arch" != "$myarch" ]; then
pkg_file=${pkg_name}-${pkg_version}-${pkg_release}.$myarch.rpm
pkg_path=${LOCAL_REPS_BASE_DIR}/$pkg_repository/RPMS.$myarch/${pkg_file}
echo "Other arch installation forced; reinstalling native arch package after..."
rpm -i $pkg_path --force
rpmret=$?
[ $rpmret -gt 0 ] && echo "WARNING: rpm returned $rpmret"
fi
else
rpm -i $pkg_path
rpmret=$?
[ $rpmret -gt 0 ] && echo "WARNING: rpm returned $rpmret"
fi
done
exit 0;
}
[ "$command" = "distromatic" ] && {
[ -r $SRCPKGLIST ] || {
echo "ERROR: srcpkglist file missing for $origrepository repository; aborting." >&2