#!/bin/bash
#
# $Id$
#
# PBA localbuild program
#
# (C) ITEG IT-Engineers GmbH 2010-2021
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# tries a local pba-build using /tmp/pba-spool and /tmp/pba-results,
# logging to /tmp/pba-release.log and /tmp/pba-build.log
#
# requires local pba chroot tarballs installed and sudo privileges
#
# supports $* like: -o 8

sudo rm -rf /tmp/pba-spool /tmp/pba-results /tmp/pba-release.log /tmp/pba-builder.log 

mkdir /tmp/pba-spool /tmp/pba-results

echo "Calling   pba-release -u -b /tmp/pba-spool/ $*" |tee /tmp/pba-release.log
pba-release -u -b /tmp/pba-spool/ $* 2>&1 |tee /tmp/pba-release.log
if [ ${PIPESTATUS[0]} != "0" ] ; then
  echo "FAILED to   pba-release -u -b /tmp/pba-spool/ $*"
  sudo chmod -R ugo+rx /tmp/pba-release.log 2>/dev/null
  ls -ld /tmp/pba-release.log 
  echo "Evtl. call   gvim /tmp/pba-release.log"
  exit 11
fi

#exit 99

echo "Calling   sudo pba-builder -B /tmp/pba-spool/ -b /tmp/pba-results/"
sudo pba-builder -B /tmp/pba-spool/ -b /tmp/pba-results/ $* 2>&1 |tee /tmp/pba-builder.log
if [ ${PIPESTATUS[0]} != "0" ] ; then
  echo "FAILED to   sudo pba-builder -B /tmp/pba-spool/ -b /tmp/pba-results/"
  #exit 12
fi

sudo chmod -R ugo+rx /tmp/pba-release.log /tmp/pba-builder.log /tmp/pba-results 2>/dev/null

ls -ld /tmp/pba-release.log /tmp/pba-builder.log /tmp/pba-results/* /tmp/pba-results/*/* 2>/dev/null

echo "Evtl. call   gvim /tmp/pba-builder.log"

