#! /bin/bash

## change.log
#
# obi activates editing of change.log only when testing
# (not when running from /home/myself)

curdir=$(pwd)
if [ "$curdir" != "/home/myself" ] && [ "$curdir" != "/root" ]
 then
 lastf=$(ls -Ftr| grep -v -e '/$' -e selected \
    -e obilevel -e partitions -e '\.txt' -e '\.[gx]z'| tail -n1)

 if [ "$1" == "-v" ]
 then
  grep -i 'obi version' change.log|tail -n1|tr -s ' ' ' '| \
       cut -d ' ' -f 4-6
  exit
 elif [ "$lastf" != "change.log" ]
 then
  echo "Newer files than change.log: Describe the changes!"
  ls -Ftr| grep -v '/$'|grep -A10 change.log|grep -v -e selected \
    -e obilevel -e partitions -e '\.tar\.[gx]z' \
    -e change.log -e md5sums-phillw.txt | tee -a change.log
  read -sn1 -t1
  nano change.log
 fi
fi

# usage

if [ "$(whoami)" != "root" ]
then
 echo "Usage:"
 echo "Install operating system with the One Button Installer"
 echo "sudo $0"
 exit
fi


## functions are sourced from other files

source mkctrl
source labelfix
source functions

# select partitioning

mkctrl

echo "selected tarball: $tarball"

if $advanced
then
 echo "selecting mkpxpy (with swap)"
 source mkpxpy
elif [ "$tarball" == "${tarball/noswap}" ]
then
 echo "selecting mkp2p1 (with swap)"
 source mkp2p1
else
 echo "selecting mkp1 (no swap)"
 source mkp1
fi

## main program is sourced from another file

if $advanced
then
 source confirm-partition
else
 source select-device
fi
