<?xml version='1.1' encoding='UTF-8'?>
<matrix-project plugin="matrix-project@1.13">
  <actions/>
  <description>Publish Services or Tools release to archive/. Optionally update symlink. Run only manually.&#xd;
This multi-config job runs on backend or download server, determined by args;&#xd;
It skips running on another server.&#xd;
</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin@1.7.3">
      <useBuildBlocker>false</useBuildBlocker>
      <blockLevel>UNDEFINED</blockLevel>
      <scanQueueFor>DISABLED</scanQueueFor>
      <blockingJobs></blockingJobs>
    </hudson.plugins.buildblocker.BuildBlockerProperty>
    <com.sonyericsson.rebuild.RebuildSettings plugin="rebuild@1.28">
      <autoRebuild>false</autoRebuild>
      <rebuildDisabled>false</rebuildDisabled>
    </com.sonyericsson.rebuild.RebuildSettings>
    <jenkins.model.BuildDiscarderProperty>
      <strategy class="hudson.tasks.LogRotator">
        <daysToKeep>-1</daysToKeep>
        <numToKeep>50</numToKeep>
        <artifactDaysToKeep>-1</artifactDaysToKeep>
        <artifactNumToKeep>-1</artifactNumToKeep>
      </strategy>
    </jenkins.model.BuildDiscarderProperty>
    <hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.ChoiceParameterDefinition>
          <name>project</name>
          <description></description>
          <choices class="java.util.Arrays$ArrayList">
            <a class="string-array">
              <string>tools</string>
              <string>services</string>
            </a>
          </choices>
        </hudson.model.ChoiceParameterDefinition>
      </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
  </properties>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>true</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <axes>
    <hudson.matrix.LabelAxis>
      <name>label</name>
      <values>
        <string>backend</string>
      </values>
    </hudson.matrix.LabelAxis>
  </axes>
  <builders>
    <hudson.tasks.Shell>
      <command>#!/bin/sh
set -x
RSYNC_OPT=&apos;-avz --exclude=micbootstrap --exclude=tizen-downloader --exclude=lthor-tool --exclude=*/repocache --delete-delay&apos;

modify_repo() {
  OBS_PATH=$1
  #echo &quot;modify_repo: OBS_PATH=$OBS_PATH&quot;
  TEMPARCHIVEDIR=$(mktemp -d)
  rsync $RSYNC_OPT $OBS_PATH/* $TEMPARCHIVEDIR/
  # Update the repo file to public URL
  update_repo_file $TEMPARCHIVEDIR/
  # Extrace release notes
  extract_release_notes $TEMPARCHIVEDIR/
}

update_repo_file() {
  repo_path=$1
  #echo &quot;update_repo_file: repo_path=$repo_path&quot;
  old_working_dir=$(pwd)
  for dir in $(ls $repo_path)
  do
      cd $repo_path/$dir
      # skip if no repo file found
      [ -f *.repo ] || continue

      # rename the repo file
      if [ -n &quot;$REPONAME&quot; ]; then
          # if there&apos;re more than one repo file, only keep the last one
          for repofile in $(ls *.repo)
          do
              mv -f $repofile $REPONAME.repo
          done
          sed -i &quot;s#^\[.*\]#\[$REPONAME\]#g&quot; $REPONAME.repo
          sed -i &quot;s#^name=.*#name=$REPONAME#g&quot; $REPONAME.repo
          # Disable gpgcheck
          sed -i &quot;/^gpg/ d&quot; $REPONAME.repo
          sed -i &apos;/enable/ a gpgcheck=0&apos; $REPONAME.repo
      fi
      # update baseurl
      public_url=$BASEURL/$dir
      sed -i &quot;s#^baseurl.*#baseurl=$public_url#g&quot; *.repo
  done
  cd $old_working_dir
}

extract_release_notes() {
  repo_dir=$1
  #echo &quot;extract_release_notes: repo_dir=$repo_dir&quot;
  dist=($(ls $repo_dir))
  cwd=$(pwd)
  rpm_list=$(find $repo_dir -name &apos;*.rpm&apos;)
  temp_list=$(mktemp)

  for rpm in $rpm_list
  do
      release_notes_file=$(rpm -qpl $rpm|grep &quot;/RELEASE_NOTES$&quot;)
      release_notes_name=$(echo $release_notes_file|sed &apos;s#/usr/share/doc/packages/\([a-z0-9-]*\)/RELEASE_NOTES#RELEASE_NOTES_\U\1#&apos;|| echo &apos;&apos;)
      [ -n &quot;$release_notes_name&quot; ] || continue
      grep $release_notes_file $temp_list &amp;&amp; continue

      # keep in temp list
      echo $release_notes_file &gt;&gt; $temp_list

      tempdir=$(mktemp -d)
      cwd=$(pwd)
      cd $tempdir
      rpm2cpio &lt; $rpm |cpio -idmv
      cd $cwd

      cp $tempdir/$release_notes_file $repo_dir/$release_notes_name.txt
      rm -r $tempdir
  done
  rm $temp_list
}

######### start of script ########
# OBS project
if [ $project = &quot;tools&quot; ]; then
  obs_project=Tools:
elif [ $project = &quot;services&quot; ]; then
  obs_project=Services:
else
  echo &quot;Error: Unexpected project value: $project&quot;
  exit 1
fi

SRC_PATH=/srv/obs/repos/$obs_project/Pre-release
DEST_PATH=&quot;${IMG_SYNC_DEST_BASE}/$project/pre-release&quot;

if [ ! -d $SRC_PATH ] ; then
    echo &quot;Error: Source directory $SRC_PATH does not exist&quot;
    exit 1
fi

BASEURL=${URL_PUBLIC_REPO_BASE}/$project/pre-release
REPONAME=$project
TEMPARCHIVEDIR=&quot;&quot;

modify_repo $SRC_PATH
rsync $RSYNC_OPT $TEMPARCHIVEDIR/* $DEST_PATH/

[ -d $TEMPARCHIVEDIR ] &amp;&amp; rm -rf $TEMPARCHIVEDIR</command>
    </hudson.tasks.Shell>
  </builders>
  <publishers/>
  <buildWrappers/>
  <executionStrategy class="hudson.matrix.DefaultMatrixExecutionStrategyImpl">
    <runSequentially>false</runSequentially>
  </executionStrategy>
</matrix-project>