#!/bin/sh
#
# upgrade
#
# Installs files from tar file. 
# First extracts `advice', `comment' and `index' and then 
# asks user for confirmation. 
#

USAGE="Usage: $0 file
	Where file is absolute path of Xdenu upgrade archive."

if [ $# != 1 ]; then
  echo "$USAGE" >&2 
  exit 1
fi

TAR="$1"
cd /
tar -x -z -f $TAR ./tmp/comment ./tmp/index ./tmp/advice
# Exit if extracting failed
if [ ! -f ./tmp/comment -o ! -f ./tmp/index ]; then
  dialog --title "Installation error" --msgbox \
"This file doesn't look like Xdenu upgrade archive.\n\n\
Check parameters or use tar command to extract.\n" 8 70
  exit 1
else 
  dialog --title "Install package" --yesno "`cat ./tmp/comment` \n\
\n\
Files: \n\
`cat ./tmp/index`\n\
\n\
Install this package?\n" 15 70
  if [ $? = 0 ]; then
    cd /
    tar -x -z -f $TAR
  else
    rm -f ./tmp/comment ./tmp/index ./tmp/advice
    exit 1
  fi
fi

sleep 2
if [ -f ./tmp/advice ]; then
dialog --title "Installation done" --msgbox \
"\nInstalled `cat ./tmp/comment`.\n\
\n\
`cat ./tmp/advice`" 8 70
else
dialog --title "Installation done" --msgbox \
"\nInstalled `cat ./tmp/comment`.\n" 5 70
fi

rm -f ./tmp/comment ./tmp/index ./tmp/advice
exit 0
