#!/bin/bash # # ipkg-push: push .ipk files to a packet repository site # # We assume that all packages follow this naming scheme: # # packetname_1.2.3-2_arch.ipk # ^^^^^^^^^^ ^^^^^ ^ ^^^^------ architecture # \ \ \----------- ipkg packet revision # \ \-------------- upstream packet revision # \---------------------- packet name # # And we assume that, if a packet is named after this scheme it is # versioned internally using the same one :-) # . `dirname $0`/libptxdist.sh PREFIX=`basename $0` usage() { echo [ -n "$1" ] && echo -e "${PREFIX} error: $1\n" echo "usage: $0 " echo echo " Arguments:" echo echo " --ipkgdir use this directory as an ipkg packet source" echo " --repodir path to ipkg packet repository to be updated" echo " --revision dist revision name to be updated" echo " --project project name" echo " --dist use this to make a dist release (optional)" echo exit 0 } IPKGDIR= REPODIR= DISTREVISION= PROJECT= DIST= # # Option parser # while [ $# -gt 0 ]; do case "$1" in --help) usage ;; --ipkgdir) IPKGDIR=`ptxd_abspath $2`; shift 2 ;; --repodir) REPODIR=`ptxd_abspath $2`; shift 2 ;; --revision) DISTREVISION=`ptxd_abspath $2`; shift 2 ;; --project) PROJECT=$2; shift 2 ;; --dist) DIST=$2; shift 2 ;; *) usage "unknown option $1" ;; esac done # # Sanity checks # [ -z "$IPKGDIR" ] && usage "${PREFIX} error: specify ipkg packet dir with --ipkgdir" [ -z "$REPODIR" ] && usage "${PREFIX} error: specify repository dir with --repodir" [ -z "$DISTREVISION" ] && usage "${PREFIX} error: specify dist revision with --revision" [ -d "$IPKGDIR" ] || usage "${PREFIX} error: ipkg directory does not exist" [ -d "$REPODIR" ] || usage "${PREFIX} error: repository dir does not exist" [ -z "$PROJECT" ] && usage "${PREFIX} error: specify a project name with --project" if [ "`find $IPKGDIR -name "*.ipk"`" = "" ]; then echo "no ipkg packets found in --ipkgdir $IPKGDIR" exit 0 fi IPKG_PACKETS=`find $IPKGDIR -name "*.ipk" -exec basename \{} \;` SCRIPTDIR=`dirname $0` POOL=$REPODIR/$PROJECT/pool if [ ! -d "$POOL" ]; then echo "IPKG pool directory ($POOL) does not exist, creating" mkdir -p $POOL [ "$?" = "0" ] || bailout "couldn't create pool directory $POOL" fi if [ -n "$DIST" ]; then if [ -d "$REPODIR/$PROJECT/dists/$DIST" ]; then echo "${PREFIX} error: $REPODIR/$PROJECT/dists/$DIST already exists!" echo "${PREFIX} error: please remove this directory first if this is intended" exit 1 fi echo "checking dist dir..: $REPODIR/$PROJECT/dists/$DIST" mkdir -p $REPODIR/$PROJECT/dists/$DIST fi echo "dist directory.....: $DIST" # # For all ipkg packets we have built: check if already in pool # for packet in $IPKG_PACKETS; do echo "checking pool for..: $packet" packet_split=`ptxd_ipkg_split $packet` IPKG_NAME=`ptxd_ipkg_name $packet_split` IPKG_REV_UPSTREAM=`ptxd_ipkg_rev_upstream $packet_split` IPKG_REV_PACKET=`ptxd_ipkg_rev_packet $packet_split` IPKG_REV="${IPKG_REV_UPSTREAM}${IPKG_REV_PACKET}" IPKG_ARCH=`ptxd_ipkg_arch $packet_split` PACKETS_IN_POOL=`find $POOL -name ${IPKG_NAME}_${IPKG_REV}-*_${IPKG_ARCH}.ipk -exec basename \{} \;` cp -f $IPKGDIR/$packet $POOL/$packet if [ "$PACKETS_IN_POOL" = "" ]; then # this packet wasn't there before, re-revision to -1 newpacket=`$SCRIPTDIR/ipkg-revision $POOL/$packet - 1` if [ -n "$DIST" ]; then echo " linking.source...: ../../pool/$newpacket" echo " linking.to.......: $REPODIR/$PROJECT/dists/$DIST/$newpacket" ln -sf ../../pool/$newpacket $REPODIR/$PROJECT/dists/$DIST/$newpacket fi else # find out latest revision latest_pkg="" for pkg in $PACKETS_IN_POOL; do echo " candidate........: $pkg" if [ "$latest_pkg" = "" ]; then latest_pkg=$pkg continue fi ptxd_ipkg_rev_smaller $pkg $latest_pkg && continue latest_pkg=$pkg done echo " latest version...: $latest_pkg" echo " comparing........: $packet with $latest_pkg" $SCRIPTDIR/ipkg-check-equal $POOL/$packet $POOL/$latest_pkg if [ "$?" = "0" ]; then echo " equal, new packet droped" rm -f $POOL/$packet if [ -n "$DIST" ]; then echo " linking.source...: ../../pool/$latest_pkg" echo " linking.to.......: $REPODIR/$PROJECT/dists/$DIST/$latest_pkg" ln -sf ../../pool/$latest_pkg $REPODIR/$PROJECT/dists/$DIST/$latest_pkg fi continue fi packet_split=`ptxd_ipkg_split $latest_pkg` IPKG_REV_PACKET=`ptxd_ipkg_rev_packet $packet_split` newpacket=`$SCRIPTDIR/ipkg-revision $POOL/$packet - $(($IPKG_REV_PACKET+1))` echo "RSC2: newpacket=$newpacket" if [ -n "$DIST" ]; then echo " linking.source...: ../../pool/$newpacket" echo " linking.to.......: $REPODIR/$PROJECT/dists/$DIST/$newpacket" ln -sf ../../pool/$newpacket $REPODIR/$PROJECT/dists/$DIST/$newpacket fi fi rm -f $POOL/$packet done # Everything finished, create the packet index echo "creating index.....: " (cd $REPODIR/$PROJECT/dists/$DIST && ipkg-make-index . > Packages) exit