#! /bin/sh
caninstall=1
failmsg="gviewzip will not work on your machine"
successmsg="gviewzip will work on your machine"

# Check if /tmp exists
if [ -d /tmp/ ]
then
	echo "/tmp/ directory found..."
else
	echo "/tmp/ directory not found..."
	caninstall=0
fi

# Check if /tmp/gviewzip_files exists
if [ -d /tmp/gviewzip_files  ]
then
	echo "Error: /tmp/gviewzip_files already exists"
	echo "Exit gviewzip, delete the directory and rerun this script"
	exit 0
fi

# Check if /tmp/ directory is writeable
mkdir /tmp/gviewzip_files
if [ -d /tmp/gviewzip_files ]
then
	echo "/tmp/ directory is writeable..."
fi

# Remove the /tmp/gviewzip_files directory which was created
rmdir /tmp/gviewzip_files
if [ -d /tmp/gviewzip_files ] 
then
	echo "Error: Could not remove /tmp/gviewzip_files directory"
	exit 0
fi

# Check if /usr/bin/unzip is present
if [ -f /usr/bin/unzip ]
then
	echo "/usr/bin/unzip found..."
else
	echo "Error: /usr/bin/unzip not found..."
	echo "gviewzip will not work on your machine"
	exit 0
fi

# Check if the temporary file is present
if [ -f gviewziptest ]
then
	echo "Error: The file gviewziptest already exists."
	echo "Delete the file and rerun this script"
	exit 0
fi

# Check if unzip supports the -o flag
/usr/bin/unzip | grep "\-o" > gviewziptest
if [ -s gviewziptest ]
then
	echo "unzip supports the -o flag..."
else
	echo "unzip does not support the -o flag..."
	caninstall=0
fi

# Check if unzip supports the -qq flag
/usr/bin/unzip | grep "\-qq" > gviewziptest
if [ -s gviewziptest ]
then
	echo "unzip supports the -qq flag..."
else
	echo "unzip does not support the -qq flag..."
	caninstall=0
fi

# Check if unzip supports the -d flag
/usr/bin/unzip | grep "\-d" > gviewziptest
if [ -s gviewziptest ]
then
	echo "unzip supports the -d flag..."
else
	echo "unzip does not support the -d flag..."
	caninstall=0
fi

# Remove the temporary file
rm -f gviewziptest
if [ -f gviewziptest ]
then
	echo "Error: Could not remove the file gviewziptest"
	exit 0
fi

if [ "$caninstall" -eq 0  ]
then
	echo "gviewzip will not work on your machine"
else
	echo  "You can proceed with the installation"
fi

