#!/bin/bash
#===========================
# UMVIRT LINUX FROM SCRATCH 
#===========================
# Compilation script.
# Network mode. 
#===========================
# Release: 0.2.3
# Package: games-gnome
#===========================
# DB commit: be1eaeb9e1d7ba0146566f8c9226f3f3cf6c6aa8
# APP commit: 1ca4178aea919e4c9e869e3d650ff8af9678bd6f
#===========================

echo "ULFS Package installation start"
echo "==============================="
echo "Package: games-gnome" 
echo "Release: 0.2.3" 

echo "checking config file"
if [ -f $ULFS_CONFIG_FILE ]
then
echo "loading config file $ULFS_CONFIG_FILE..."
. $ULFS_CONFIG_FILE
fi
#Creating log directory
mkdir -p /var/log/ulfs-packages/games-gnome/
#Saving start timestamp
date +%s > /var/log/ulfs-packages/games-gnome/start.time
#Going to source directory...
cd /sources
#Checking dependances...
      #Checking gnome-chess...
      if [ ! -f /var/cache/ulfs-packages/gnome-chess ]; then
           echo "Dependance \"gnome-chess\" not found. Trying to install...";
           wget --no-check-certificate https://umvirt.com/linux/packages//0.2.3/gnome-chess/install -O - | bash
           if [ ! -f /var/cache/ulfs-packages/gnome-chess ]; then
	             echo "Dependance \"gnome-chess\" is not installed. Exiting..."
               exit
           fi
      fi
      #Checking gnome-mines...
      if [ ! -f /var/cache/ulfs-packages/gnome-mines ]; then
           echo "Dependance \"gnome-mines\" not found. Trying to install...";
           wget --no-check-certificate https://umvirt.com/linux/packages//0.2.3/gnome-mines/install -O - | bash
           if [ ! -f /var/cache/ulfs-packages/gnome-mines ]; then
	             echo "Dependance \"gnome-mines\" is not installed. Exiting..."
               exit
           fi
      fi
      #Checking gnome-sudoku...
      if [ ! -f /var/cache/ulfs-packages/gnome-sudoku ]; then
           echo "Dependance \"gnome-sudoku\" not found. Trying to install...";
           wget --no-check-certificate https://umvirt.com/linux/packages//0.2.3/gnome-sudoku/install -O - | bash
           if [ ! -f /var/cache/ulfs-packages/gnome-sudoku ]; then
	             echo "Dependance \"gnome-sudoku\" is not installed. Exiting..."
               exit
           fi
      fi
      #Checking quadrapassel...
      if [ ! -f /var/cache/ulfs-packages/quadrapassel ]; then
           echo "Dependance \"quadrapassel\" not found. Trying to install...";
           wget --no-check-certificate https://umvirt.com/linux/packages//0.2.3/quadrapassel/install -O - | bash
           if [ ! -f /var/cache/ulfs-packages/quadrapassel ]; then
	             echo "Dependance \"quadrapassel\" is not installed. Exiting..."
               exit
           fi
      fi
      #Checking gnome-nibbles...
      if [ ! -f /var/cache/ulfs-packages/gnome-nibbles ]; then
           echo "Dependance \"gnome-nibbles\" not found. Trying to install...";
           wget --no-check-certificate https://umvirt.com/linux/packages//0.2.3/gnome-nibbles/install -O - | bash
           if [ ! -f /var/cache/ulfs-packages/gnome-nibbles ]; then
	             echo "Dependance \"gnome-nibbles\" is not installed. Exiting..."
               exit
           fi
      fi
      #Checking five-or-more...
      if [ ! -f /var/cache/ulfs-packages/five-or-more ]; then
           echo "Dependance \"five-or-more\" not found. Trying to install...";
           wget --no-check-certificate https://umvirt.com/linux/packages//0.2.3/five-or-more/install -O - | bash
           if [ ! -f /var/cache/ulfs-packages/five-or-more ]; then
	             echo "Dependance \"five-or-more\" is not installed. Exiting..."
               exit
           fi
      fi
#Saving configuration timestamp
date +%s > /var/log/ulfs-packages/games-gnome/configure.time
#Saving build timestamp
date +%s > /var/log/ulfs-packages/games-gnome/build.time
#Saving install timestamp
date +%s > /var/log/ulfs-packages/games-gnome/install.time
#Running install script...
#
#Saving finish timestamp
date +%s > /var/log/ulfs-packages/games-gnome/finish.time
#Marking package as installed...
mkdir -p /var/cache/ulfs-packages
USER=`whoami`
if [ "$USER" == "root" ] ; then 
touch /var/cache/ulfs-packages/games-gnome
else
sudo touch /var/cache/ulfs-packages/games-gnome
fi
#Calculate prepare time
a=`cat /var/log/ulfs-packages/games-gnome/start.time`
b=`cat /var/log/ulfs-packages/games-gnome/configure.time`
dp=$(($b-$a))
#Calculate download time
a=`cat /var/log/ulfs-packages/games-gnome/download.time`
b=`cat /var/log/ulfs-packages/games-gnome/unpack.time`
dd=$(($b-$a))
#Calculate delta time
a=`cat /var/log/ulfs-packages/games-gnome/configure.time`
b=`cat /var/log/ulfs-packages/games-gnome/finish.time`
db=$(($b-$a))
echo $db > /var/log/ulfs-packages/games-gnome/delta.time 
#Report
echo ""
echo "ULFS Package installation report"
echo "================================"
echo "Package: games-gnome" 
echo "Release: 0.2.3" 
echo "Prepare time: $dp sec." 
echo "Download time: $dd sec." 
echo "Build time: $db sec." 

#End of script