#!/bin/sh
#
# SYNTAX: import-meego-release.sh <RELEASE NUMBER> <DOWNLOAD LOCATION> <PRJCONF>
# Example: import-meego-release.sh 1.0.99.0.20101005.1 rsync://mirrors.kernel.org/meego/builds/1.0.99/ Trunk
# This will set up a OBS project MeeGo:RELEASE NUMBER:Core
# You might have to use login for OBS, that is, login Admin password opensuse
ORIGINALDIR=$PWD
# Download the RPMs
mkdir -p /obs/imports/MeeGo_$1/core/
for x in ia32 armv7l
do
    mkdir -p /obs/imports/MeeGo_$1/core/$x/
    cd /obs/imports/MeeGo_$1/core/$x/
    rsync -a --progress $2/$1/core/repos/$x/packages/* .
done

# Set up symlinks to packages

mkdir -p /obs/build/MeeGo:$1:Core/standard/i586/:full
cd /obs/build/MeeGo:$1:Core/standard/i586/:full
find /obs/imports/MeeGo_$1/core/ia32/ -name \*.rpm | xargs -I@ ln @ .

mkdir -p /obs/build/MeeGo:$1:Core/standard/armv7el/:full
cd /obs/build/MeeGo:$1:Core/standard/armv7el/:full
find /obs/imports/MeeGo_$1/core/armv7l/ -name \*.rpm | xargs -I@ ln @ .

chown -R obsrun:obsrun /obs/build/
chown -R obsrun:obsrun /obs/imports/

# Set up prj information in OBS 
osc -A http://localhost:81 meta prj -F - MeeGo:$1:Core << OTHEREOF
<project name="MeeGo:$1:Core">

  <title></title> <!-- Short title of NewProject -->
  <description>
    <!-- This is for a longer description of the purpose of the project -->
  </description>

  <person role="maintainer" userid="Admin" />
  <person role="bugowner" userid="Admin" />
<!-- remove this block to publish your packages on the mirrors -->
  <publish>
    <disable />
  </publish>
  <build>
    <enable />
  </build>
  <debuginfo>
    <disable />
  </debuginfo>

  <repository name="standard">
    <arch>armv7el</arch>
    <arch>i586</arch>
  </repository>
</project>

OTHEREOF
cd $ORIGINALDIR
# Set up prjconf in OBS
osc -A http://localhost:81 meta prjconf -F $3 MeeGo:$1:Core 

# And then finally, rescan

for x in i586 armv7el
do 
  /usr/lib/obs/server/bs_admin --rescan-repository MeeGo:$1:Core standard $x
done

echo "MeeGo:$1:Core imported into OBS, after rescan is done."

