1

I have following package repository format

Package: enigma2-plugin-extensions-airplayer
Version: 0.3.9
Section: extra
Architecture: all
Maintainer: hellmaster1024 and DonDavici <hellmaster1024 and DonDavici@code.google.com/p/airplayer/>
MD5Sum: b0c862e749846521ea11eeae77ddf905
Size: 166268
Filename: enigma2-plugin-extensions-airplayer_0.3.9_mips32el.ipk
Source: ftp://code.google.com/p/airplayer//hellmaster1024 and DonDavici/airplayer-0.3.9.tar.gz
Description: Enigma2 Plugin AirPlayer by hellmaster1024 and DonDavici
OE: airplayer-0.3.9
HomePage: code.google.com/p/airplayer/
Priority: optional


Package: enigma2-plugin-extensions-atmolightd
Version: 0.7-pre22
Section: extra
Architecture: all
Maintainer: mamba0815 <mamba0815@gmx.li>
MD5Sum: af17593ec8ad4a00c1fa843ccb17be6f
Size: 851522
Filename: enigma2-plugin-extensions-atmolightd_0.7-pre22_all.ipk
Source: www.noip.com
Description: Sedulight/Atmolight/amBXlight/Karatelight for Enigma2
OE: 1.6
HomePage: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=136415
Priority: optional

Now I need a bash script which finds in a Loop the "Package Name" example "enigma2-plugin-extensions-atmolightd" and the "Filename" example enigma2-plugin-extensions-atmolightd_0.7-pre22_all.ipk

I started with following script

for i in `cat Packages.txt |grep Filename|cut -b 11-`; do
 wget "http://sources.dreamboxupdate.com/opendreambox/1.5/dm7025/feed/$i";
done

I can download all the packages - but I miss the Package Name. Want to create a folder with the Package Name and then store all versions of the packages into this folder.

For sure this can be solved with Regex? But I am not good at this,...

Greet`s erich

My final solution

#!/bin/bash
#
echo "Downloading all Packages from the feed"

rootPath="/tmp/Openwrt/Trunk"
#echo $rootPath
mkdir -p $rootPath

wget -O "$rootPath/Packages" http://enigma2.world-of-satellite.com/feeds/3.0/et9x00/3rdparty/Packages

while read -r p f; do
   mkdir -p "$rootPath/$p" 2>/dev/null
   wget -nc -P "$rootPath/$p" "http://enigma2.world-of-satellite.com/feeds/3.0/et9x00/3rdparty/$f"
done < <(awk -F ' *: *' '$1=="Package"{p=$2;next} $1=="Filename"{print p, $2}' "$rootPath/Packages")

2 Answers2

0

You can use awk:

while read -r p f; do
   mkdir -p "$p" 2>/dev/null
   wget "http://sources.dreamboxupdate.com/opendreambox/1.5/dm7025/feed/$f"
done < <(awk -F ' *: *' '$1=="Package"{p=$2;next} $1=="Filename"{print p, $2}' Packages.txt)

Explanation:

  • awk command used input field separator as : and searches input file for Package and Filename lines. If found both values are printed in same line with a space delimiter.

  • while read command reads both values in variable p and f. These variables are used for further processing.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks for you quick answer! I only had to edit the code a little bit, because the packages were not saved in the created fodlers. With a -P as parameter for the destination path and a -nc for skipping downloaded I am very happy! Amazing what a few lines of code can manage if you know what you are doing ;) – user3352603 Feb 26 '14 at 09:35
  • Nice would be if you could explain in words what the while loop with the awk command is doing exactly - I would like to understand it ;) – user3352603 Feb 26 '14 at 12:25
  • I will add explanation to my answer in few minutes. – anubhava Feb 26 '14 at 12:28
0

Another idea might be like below.

#!/bin/bash
#example_script.sh
package="";
filename="";
while read line
do
  echo "$line" | grep "Package"
  if [ $? -eq 0 ]; then
    package=`echo "$line" | grep "Package" | cut -f 2 -d ":"  | tr -d ' '`
    mkdir -p "$package"
  fi
  echo "$line" | grep "Filename"
  if [ $? -eq 0 ]; then
    filename=`echo "$line" | grep "Filename" | cut -f 2 -d ":" | tr -d ' '`
    cd "$package"
    wget "YOUR_BASE_URL_GOES_HERE/$filename"
    cd ..
  fi
done < $1

Then call it.

./example_script.sh filename.txt

*Read a file line by line assigning the value to a variable
*http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html
*How to trim whitespace from a Bash variable?
*http://unixhelp.ed.ac.uk/CGI/man-cgi?mkdir
*http://linux.die.net/man/1/tr

Community
  • 1
  • 1