|
|
|
Listing 7
#! /bin/bash -
# FILENAME: userunzip
# DESCRIPTION: Moves to user's home directory and unzips any zipfile
# to public_html directory. Useful for ftp-only users which are allowed
# to put their zipfile in their homedir and have them exploded without
# manual intervention.
#
# USAGE: userunzip [user]
#
# LABEN S.p.A. - 10-dec-1997
#
# HISTORY:
# 0.0 Luca Salvadori <salvadori.l@laben.it> 10-dec-1997
# - Basic functions and behaviour
#
#
######################### M A I N P R O G R A M #########################
# Initialization of local variables
UNZIP=/usr/bin/unzip # Set executable, just in case
USERNAME=${1:-$LOGNAME} # Assign default user if needed
#HOMEDIR=~$USERNAME # Assign home directory
HOMEDIR=`eval echo ~$USERNAME` # Assign home directory
TARGETDIR=$HOMEDIR/public_html # Target directory to explode zipfiles
ZIPFILE=*.zip # Default zipfile to search for
EXITCODE=1 # Set exitcode to 1 to prepare for errors
DISKSPACE=5000 # Minimum free space (KBytes) on disk to proceed
DISK=/dev/hdb1 # Disk to search space on
# Here begins the real stuff
# Move to home directory: "eval" it to allow expansion
eval cd $HOMEDIR 2>/dev/null || { echo "ERROR=1 - Directory $HOMEDIR does not exist" 1>&2 ; exit 1 }
cd $TARGETDIR 2>/dev/null || { echo "ERROR=1 - Directory $TARGETDIR does not exist" 1>&2 ; exit 1 }
#for zipfile in `eval ls $HOMEDIR/$ZIPFILE`
for zipfile in `find $HOMEDIR -maxdepth 1 -name "$ZIPFILE"`
do
echo "Processing $zipfile..."
if [ -f $zipfile ]
then
EXITCODE=0
# Rename zipfile
mv $zipfile $zipfile.$$
# Cleanup previous issue
find r_* -name \*.jpg -exec rm \{\} \;
# Loop until sufficient diskspace is available
FREEDISK=`df|grep "$DISK"|tr -s " " | cut -d" " -f4`
while [ $FREEDISK -lt $DISKSPACE ]
do
sleep 60
done
$UNZIP -u -o $zipfile.$$ && {
rm $zipfile.$$
# Linking index.htm to index.html, just in case
for dir in `find $TARGETDIR -type d`
do
cd $dir
[ -f index.html -a ! -L index.html ] && ln -v -s index.htm index.html
cd $TARGETDIR
done
echo "Done at `date`." }
[ $? -ne 0 ] && { echo "Failed. $zipfile is not a zip file or is corrupted." ; EXITCODE=1 }
else
echo "Failed. $zipfile does not exist."
EXITCODE=1
fi
done
[ -f $zipfile.$$ ] && mv $zipfile.$$ $zipfile
exit $EXITCODE
##################### E N D O F M A I N P R O G R A M ###################
|