#!/bin/bash
# Simple script to update web files at hosting mashine.
# (c) Light Olli <olli@digger.org.ru>, License is current GNU GPL.

## variables.

# permissions for directories
dmode=755
# permissions for directories
fmode=644
pubhtml=public_html
newarch=public_html.tar
dir=$HOME
backup=$dir/$pubhtml.old

## script work start.
echo "This script assumes that your public_html directory is $dir/$pubhtml,"
echo "It also assumes that its new version is in  $dir/$newarch file."
echo "Backups are made only once, ovewriting existing directory ($backup)."
echo "Edit $0 to change this beheviour."
echo "press <Enter> to continue or ^C to quit"
read wait
cd $dir
echo "removing old backup.."
rm -Rf $backup
echo "Creating new backup.."
mv $pubhtml $backup
echo "Extracting files.."
tar xf $newarch
echo "Setting permissions to 644 & 755 for files & dirs.."
find $pubhtml -type f -exec chmod $fmode {} \; ; find $pubhtml -type d -exec chmod $dmode {} \;
