Re: Re: rpmrepo sync bash script

From Bistre Iguana, 7 Years ago, written in Bash, viewed 405 times. This paste is a reply to Re: rpmrepo sync bash script from Ample Cheetah - view diff
URL https://paste.steamr.com/view/3f9dddda Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. function PrimaryXml {
  4.         wget -q -O - "$1/repodata/repomd.xml" \
  5.                 | grep primary.xml \
  6.                 | sed -n -e 's/.*"\(.*\)".*/\1/p'
  7. }
  8.  
  9. function GetPackages {
  10.         BaseUrl="$1"
  11.         # Packages end with - and start with /
  12.         Include=`echo $2 | sed 's/ /-|\//g'`
  13.         Exclude=`echo $3 | sed 's/ /-|\//g'`
  14.  
  15.         wget -q -O - "$BaseUrl`PrimaryXml $BaseUrl`" \
  16.                 | zcat \
  17.                 | sed -n -e 's/.*href="\([^"]*\)\".*/\1/p' \
  18.                 | grep -E "rpm$" \
  19.                 | ( [ -z "$Include" ] && cat || grep -E "($Include)" ) \
  20.                 | ( [ -z "$Exclude" ] && cat || grep -vE "($Exclude)" ) \
  21. }
  22.  
  23. function DownloadPackages {
  24.         BaseUrl="$1"
  25.  
  26.         Mode=0
  27.         Include=""
  28.         Exclude=""
  29.  
  30.         shift
  31.         while (($#)); do
  32.                 if [[ "$1" == "-v" ]] ; then
  33.                         Mode=1
  34.                 else
  35.                         if [ $Mode -eq 1 ] ; then
  36.                                 Exclude="$Exclude $1"
  37.                         else
  38.                                 Include="$Include $1"
  39.                         fi
  40.                 fi
  41.  
  42.                 shift
  43.         done
  44.  
  45.         Packages=0
  46.  
  47.         GetPackages "$BaseUrl" "$Include" "$Exclude" | {
  48.                 while read i ; do
  49.                         if [ ! -f `basename $i` ] ; then
  50.                                 test -d `dirname $i` || mkdir -p `dirname $i`
  51.  
  52.                                 echo "Downloading $BaseUrl$i..."
  53.                                 wget -q -O "`basename $i`" "$BaseUrl$i"
  54.                         fi
  55.                         Packages=$((Packages+1))
  56.                 done
  57.  
  58.                 echo "Download complete: $Packages from $BaseUrl"
  59.         }
  60. }
  61.  

Replies to Re: Re: rpmrepo sync bash script rss

Title Name Language When
Re: Re: Re: rpmrepo sync bash script Gracious Mockingjay bash 7 Years ago.

Reply to "Re: Re: rpmrepo sync bash script"

Here you can reply to the paste above