2013-07-12 01:55:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# automaint -- batch automatic maintainance tool of the autodist suite
|
2014-05-23 21:17:27 +02:00
|
|
|
# Copyright (C) 2013-2014 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
2013-07-12 01:55:29 +02:00
|
|
|
#
|
|
|
|
# Released under the terms of the GNU GPL release 3 license
|
|
|
|
#
|
|
|
|
VERSION=0.9.7
|
|
|
|
# First in vector is base arch
|
|
|
|
ARCHS=(i586 arm x86_64)
|
|
|
|
|
|
|
|
. /etc/autodist/config
|
|
|
|
|
|
|
|
me=(${0##*/} $VERSION "Sat Mar 20 2011")
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "\
|
|
|
|
${me[0]} ${me[1]}
|
|
|
|
"$"Copyright (C) 2013 Silvan Calarco <silvan.calarco@mambasoft.it>""
|
|
|
|
"$"Released under the terms of the GNU GPL v3 license"
|
|
|
|
echo "
|
|
|
|
"$"Batch automatic maintainance tool of the autodist suite.""
|
|
|
|
|
|
|
|
"$"Usage"":
|
2013-07-12 02:03:09 +02:00
|
|
|
$me [-s repository -d repository ] [-p repository] [-h] [-v]
|
2013-07-12 01:55:29 +02:00
|
|
|
|
|
|
|
-d repository "$"Main destination repository
|
|
|
|
-p repository "$"Port repository
|
2013-07-13 13:52:23 +02:00
|
|
|
-s repository "$"Automatic/Staging builds source repository
|
|
|
|
|
2013-07-12 01:55:29 +02:00
|
|
|
-h "$"Show this help and exit
|
2013-07-13 13:52:23 +02:00
|
|
|
-t "$"Test mode (no change will be made)
|
|
|
|
-v "$"Verbose output
|
2013-07-12 01:55:29 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# for webbuild message
|
|
|
|
function cgi_encodevar() {
|
|
|
|
local string="${1}"
|
|
|
|
local strlen=${#string}
|
|
|
|
local encoded=""
|
|
|
|
|
|
|
|
for (( pos=0 ; pos<strlen ; pos++ )); do
|
|
|
|
c=${string:$pos:1}
|
|
|
|
case "$c" in
|
|
|
|
[-_.~a-zA-Z0-9] ) o="${c}" ;;
|
|
|
|
* ) printf -v o '%%%02x' "'$c"
|
|
|
|
esac
|
|
|
|
encoded+="${o}"
|
|
|
|
done
|
|
|
|
echo "${encoded}" # You can either set a return variable (FASTER)
|
|
|
|
# REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
|
|
|
|
}
|
|
|
|
|
|
|
|
# get_pkg_buildinfo - uses distromatic generated build file for
|
|
|
|
# getting information on the repository
|
|
|
|
#
|
|
|
|
# $1: distromatic files base url for repository
|
|
|
|
# $2: architecture
|
|
|
|
# $3: pkg name
|
|
|
|
function get_pkg_buildinfo() {
|
|
|
|
|
|
|
|
local pkg i a local_arch local_distromatic
|
|
|
|
|
|
|
|
[ $1 ] && local_distromatic=$1 || exit 1
|
|
|
|
[ $2 ] && local_arch=$2 || exit 1
|
|
|
|
[ $3 ] && pkg=$3
|
|
|
|
|
|
|
|
if [ ! "$pkg" ]; then
|
|
|
|
[ -e $local_distromatic/builds-${local_arch}.sh ] && . $local_distromatic/builds-${local_arch}.sh
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
pkg_archs=();
|
|
|
|
for a in ${archs[*]}; do
|
|
|
|
[ "$a" = "${local_arch}" ] && continue
|
|
|
|
pkg_header=();
|
|
|
|
DISTROMATIC_BUILD_FILE=$local_distromatic/builds-$a.sh
|
|
|
|
[ -e $DISTROMATIC_BUILD_FILE ] && . $DISTROMATIC_BUILD_FILE
|
|
|
|
[ ${pkg_header[0]} ] && pkg_archs=(${pkg_archs[*]} $a)
|
|
|
|
done
|
|
|
|
|
|
|
|
pkg_header=();
|
|
|
|
pkg_builds=();
|
|
|
|
pkg_obsoletes=();
|
|
|
|
pkg_list=();
|
|
|
|
|
|
|
|
DISTROMATIC_BUILD_FILE=$local_distromatic/builds-${local_arch}.sh
|
|
|
|
[ -e $DISTROMATIC_BUILD_FILE ] && . $DISTROMATIC_BUILD_FILE
|
|
|
|
[ ${pkg_header[0]} ] && pkg_archs=(${pkg_archs[*]} ${local_arch})
|
|
|
|
|
|
|
|
# {
|
|
|
|
# echo "Error: missing distromatic generated file $DISTROMATIC_BUILD_FILE; aborting."
|
|
|
|
# return;
|
|
|
|
# }
|
|
|
|
# . $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=${local_arch}
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset pkg_name pkg_arch pkg_version pkg_release \
|
|
|
|
pkg_group pkg_license pkg_size pkg_buildtime pkg_altrep pkg_repository
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ $# -gt 0 ] || { usage ; exit 1; }
|
|
|
|
|
|
|
|
for ((i=1; i<=$#; i++)); do
|
|
|
|
case ${!i} in
|
|
|
|
-s) shift
|
|
|
|
SOURCE_REPOSITORY="${!i}"
|
|
|
|
;;
|
|
|
|
-d) shift
|
|
|
|
DEST_REPOSITORY="${!i}"
|
|
|
|
;;
|
|
|
|
-p) shift
|
|
|
|
PORT_REPOSITORY="${!i}"
|
|
|
|
;;
|
2013-07-13 13:52:23 +02:00
|
|
|
-t) TESTMODE=1
|
|
|
|
;;
|
2013-07-12 02:03:09 +02:00
|
|
|
-v) VERBOSE=1
|
|
|
|
;;
|
2013-07-12 01:55:29 +02:00
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$SOURCE_REPOSITORY" -a "$DEST_REPOSITORY" ] || { usage; exit 1; }
|
|
|
|
|
|
|
|
[ "$SOURCE_REPOSITORY" = "$DEST_REPOSITORY" ] && {
|
|
|
|
echo "ERROR: source and destination repository cannot be the same; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-07-13 13:52:23 +02:00
|
|
|
[ "$TESTMODE" ] && echo "** TEST MODE enabled: no changes will be made **"
|
|
|
|
|
2013-07-12 01:55:29 +02:00
|
|
|
for a in `seq 1 ${#ARCHS[*]}`; do
|
|
|
|
. $LOCAL_REPS_BASE_DIR/distromatic/$SOURCE_REPOSITORY/builds-${ARCHS[$a-1]}.sh
|
|
|
|
pkglist[$a-1]="${pkg_list[*]}"
|
|
|
|
warningslist[$a-1]="${warnings_list[*]}"
|
|
|
|
needportlist[$a-1]="${needport_list[*]}"
|
|
|
|
done
|
|
|
|
|
2014-05-24 20:17:44 +02:00
|
|
|
tmpfile=`mktemp -q -t $me.XXXXXXXX` || {
|
|
|
|
echo "ERROR: cannot create temporary files." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
for a in `seq 1 ${#ARCHS[*]}`; do
|
|
|
|
echo -n "${pkglist[$a-1]} " >> $tmpfile
|
|
|
|
done
|
|
|
|
allpkgs="`cat $tmpfile | xargs -n 1 | sort -u | xargs`"
|
|
|
|
rm -f $tmpfile
|
|
|
|
|
|
|
|
for p in ${allpkgs}; do
|
|
|
|
pkgcontinue=
|
|
|
|
needsport=
|
|
|
|
for a in `seq 1 ${#ARCHS[*]}`; do
|
2013-07-12 01:55:29 +02:00
|
|
|
for w in ${warningslist[*]}; do
|
|
|
|
[ "$p" = "$w" ] && { pkgcontinue=1; break; }
|
|
|
|
done
|
2014-05-24 20:17:44 +02:00
|
|
|
[ "$pkgcontinue" ] && break
|
2013-07-12 01:55:29 +02:00
|
|
|
|
2014-05-24 20:17:44 +02:00
|
|
|
get_pkg_buildinfo $LOCAL_REPS_BASE_DIR/distromatic/$SOURCE_REPOSITORY ${ARCHS[$a-1]} $p
|
|
|
|
|
|
|
|
[ "$pkg_name" ] || {
|
|
|
|
#echo "$p: looks like a new package; skipping."
|
|
|
|
continue
|
|
|
|
}
|
2013-07-12 01:55:29 +02:00
|
|
|
|
|
|
|
for o in ${needportlist[*]}; do
|
|
|
|
[ "$p" = "$o" ] && { needsport=1; break; }
|
|
|
|
done
|
2014-05-24 20:17:44 +02:00
|
|
|
[ "$needsport" -a ! "$PORT_REPOSITORY" ] && break
|
2013-07-12 01:55:29 +02:00
|
|
|
|
|
|
|
spkg_version=$pkg_version
|
|
|
|
spkg_release=$pkg_release
|
2014-05-24 20:17:44 +02:00
|
|
|
get_pkg_buildinfo $LOCAL_REPS_BASE_DIR/distromatic/$DEST_REPOSITORY ${ARCHS[$a-1]} $p
|
2013-07-12 02:03:09 +02:00
|
|
|
|
2013-07-12 01:55:29 +02:00
|
|
|
if [ "$pkg_version" = "$spkg_version" ]; then
|
2013-07-13 13:52:23 +02:00
|
|
|
if [ "$pkg_release" = "$spkg_release" ]; then
|
|
|
|
echo "$p: same release as upstream; skipping."
|
2014-05-24 20:17:44 +02:00
|
|
|
break
|
2013-07-13 13:52:23 +02:00
|
|
|
fi
|
2013-07-12 01:55:29 +02:00
|
|
|
update_type="release"
|
|
|
|
else
|
|
|
|
OIFS=$IFS
|
|
|
|
IFS='.'
|
|
|
|
read -ra SVER <<< "$spkg_version"
|
|
|
|
read -ra VER <<< "$pkg_version"
|
|
|
|
IFS=$OIFS
|
|
|
|
for i in `seq 1 ${#SVER[*]}`; do
|
|
|
|
[ "${SVER[i-1]}" != "${VER[i-1]}" ] && break
|
|
|
|
done
|
|
|
|
if [ "$i" = "${#SVER[*]}" ]; then
|
|
|
|
if [[ 64#${SVER[i-1]} -gt 64#89 && 64#${VER[i-1]} -lt 64#80 ]]; then
|
2013-07-12 02:03:09 +02:00
|
|
|
[ "$VERBOSE" ] && echo "$p: dubious beta upgrade from ${VER[i-1]} to ${SVER[i-1]}; skipping."
|
2014-05-24 20:17:44 +02:00
|
|
|
break
|
2013-07-12 01:55:29 +02:00
|
|
|
fi
|
|
|
|
update_type="minor"
|
|
|
|
else
|
2013-07-12 02:03:09 +02:00
|
|
|
[ "$VERBOSE" ] && echo "$p: dubious not-minor version update $i/${#SVER[*]}: ${SVER[i-1]} != ${VER[i-1]}; skipping."
|
2014-05-24 20:17:44 +02:00
|
|
|
break
|
2013-07-12 01:55:29 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ "$needsport" ]; then
|
|
|
|
echo "$p: importing from $SOURCE_REPOSITORY to $PORT_REPOSITORY ($spkg_version-$spkg_release -> $pkg_version-$pkg_release)"
|
2013-07-13 13:52:23 +02:00
|
|
|
if [ ! "$TESTMODE" ]; then
|
2014-05-23 21:17:27 +02:00
|
|
|
autodist-repository import $SOURCE_REPOSITORY $p -d $PORT_REPOSITORY -y >/dev/null
|
2013-07-13 13:52:23 +02:00
|
|
|
if [ $? -eq 0 -a "$WEBBUILD_URL" -a "$WEBBUILD_USER" ]; then
|
|
|
|
curl -s "$WEBBUILD_URL?REQUEST=message&USER=$WEBBUILD_USER&SECRET=${WEBBUILD_SECRET}&USER_EMAIL=$WEBBUILD_EMAIL&\
|
2013-07-12 01:55:29 +02:00
|
|
|
MESSAGE=`cgi_encodevar \"imported <b>$p</b> from <b>$SOURCE_REPOSITORY</b> to <b>$PORT_REPOSITORY</b> for porting\"`" >/dev/null
|
2013-07-13 13:52:23 +02:00
|
|
|
fi
|
2013-07-12 01:55:29 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$p: importing from $SOURCE_REPOSITORY to $DEST_REPOSITORY ($spkg_version-$spkg_release -> $pkg_version-$pkg_release; update type: $update_type)"
|
2013-07-13 13:52:23 +02:00
|
|
|
if [ ! "$TESTMODE" ]; then
|
2014-05-23 21:17:27 +02:00
|
|
|
autodist-repository import $SOURCE_REPOSITORY $p -d $DEST_REPOSITORY -y >/dev/null
|
2013-07-13 13:52:23 +02:00
|
|
|
if [ $? -eq 0 -a "$WEBBUILD_URL" -a "$WEBBUILD_USER" ]; then
|
|
|
|
curl -s "$WEBBUILD_URL?REQUEST=message&USER=$WEBBUILD_USER&SECRET=${WEBBUILD_SECRET}&USER_EMAIL=$WEBBUILD_EMAIL&\
|
2013-07-12 01:55:29 +02:00
|
|
|
MESSAGE=`cgi_encodevar \"imported <b>$p</b> from <b>$SOURCE_REPOSITORY</b> to <b>$DEST_REPOSITORY</b>\"`" >/dev/null
|
2013-07-13 13:52:23 +02:00
|
|
|
fi
|
2013-07-12 01:55:29 +02:00
|
|
|
fi
|
|
|
|
fi
|
2014-05-24 20:17:44 +02:00
|
|
|
break
|
|
|
|
done
|
2013-07-12 01:55:29 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|