#!/bin/sh
################################################################################
# Script name: zip_cleaner_v0.1beta.sh #
# Author: SoD- #
# Contact: SoD- @ EFNet #
# Releasedate: 2004-01-29 #
# #
# This script uses zip and unzip to remove garbage files and comments from zip #
# files. Just run it with the file to be cleaned as argument. #
# #
# Installation: -Add any files u want denied in the $REMOVE_LIST variable. #
# -For usage with Dark0n3's zipscript-c: #
# +Add "char *zip_cleaner_arg;" to the variable declarations in #
# zipscript-c.c's main(). #
# +Add these lines above the line "d_log("Integrity ok\n");" : #
# if((zip_cleaner_arg = malloc(strlen(argv[2]) + strlen(argv[1]) + 26)) == NULL) {
# d_log("zip_cleaner: couldn't allocate memory, aborting\n");#
# break; #
# } #
# sprintf(zip_cleaner_arg, "zip_cleaner_v0.1beta.sh %s/%s\n", argv[2], argv[1]);
# if(system(zip_cleaner_arg) != 0) #
# d_log("zip_cleaner: failed to execute\n"); #
# else #
# d_log("zip_cleaner: executed ok\n"); #
# #
# Requirements: awk, chown, echo, grep, ls, unzip, zip, zipinfo (symlink #
# pointing to unzip). #
# #
# Limitations: -Can only handle file names without spaces. #
# #
# NOTE: I normally wouldn't dream of using site names in a script but #
# since those listed in $REMOVE_LIST have been found in loads of #
# zip files i guess they want the publicity. #
################################################################################
# Add any file names you want removed from zip files here.
REMOVE_LIST="nf2k2.nfo twh.nfo pH.nfo bar.nfo ti.nfo usux.nfo paranoia.nfo
echobase.nfo nia.nfo trope.exe stb.nfo ghetto.txt tnl.nfo tnl.exe
pre.nfo hello.kitty rb.nfo pbox.nfo kane.ans kane.jpg kane.nfo
asylum.txt ghetto.nfo tqs.nfo topcn.nfo spy.nfo ts.nfo playboys.nfo
dl.nfo ptp.nfo wizard.nfo bkn.nfo wto.nfo me.nfo tdi.nfo dm.nfo
kane-xmas.nfo tct.nfo"
################################################################################
# No more specifications needed below,just some editing if the script won't work
################################################################################
if [ ! $1 ] || [ ! -f $1 ] || [ ! -w $1 ]; then
exit 1
fi
OWNER=`ls -l $1 | awk '{print $3}'`
GROUP=`ls -l $1 | awk '{print $4}'`
FILE_LIST=`unzip -l $1 | tail -n+4 | awk '{print $4}' | grep -iv "\.rar$\| \
\.r[[:digit:]][[:digit:]]$\|\.zip$\|\.ace\|\.c[[:digit:]][[:digit:]]$\|\.diz$"`
# This outer loop goes thru each file in the zip (except those excluded above).
for FILE in $FILE_LIST; do
# This inner loop removes files listed in $REMOVE_LIST from the zip.
for REMOVE_FILE in $REMOVE_LIST; do
if [ "$FILE" == "$REMOVE_FILE" ]; then
#echo "Removing $REMOVE_FILE from `basename $1`"
zip -dq "$1" "$REMOVE_FILE"
fi
done
done
#echo "Removing any multi-line comment from `basename $1`"
zip -qz "$1" < .
chown $OWNER:$GROUP "$1"
exit