Select Git revision
check_ceph_io
-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
preinstall_cleanup.sh 4.21 KiB
#!/bin/bash
# ======================================================================
#
# CLEANUP BEFORE DEPLOYING A TGZ ON A SERVER
#
# ----------------------------------------------------------------------
#
# This script compares the content of a tgz with the data in
# the webroot. Additional files will be deleted
#
# SYNTAX:
# with 2 parameters it show infos only
# preinstall_cleanup.sh /var/www/preview.mmmu.iml.unibe.ch/ /var/puppet-tgz/mmmu.tgz
#
# with (any) 3rd parameter deletion will be activated
# preinstall_cleanup.sh /var/www/preview.mmmu.iml.unibe.ch/ /var/puppet-tgz/mmmu.tgz forcedelete
#
# ----------------------------------------------------------------------
# 2013-11-06 axel.hahn@iml.unibe.ch
# 2022-11-25 axel.hahn@unibe.ch do not check json in target dir; shellfixes
# ======================================================================
# ----------------------------------------------------------------------
# CONFIG
# ----------------------------------------------------------------------
prjdir=$1
tgz=$2
bForceDelete=$3
filelist=/tmp/keepdirslist_$$
filetgz=/tmp/list_in_tgz_$$
fileprj=/tmp/list_in_webroot_$$
keepfile=".htkeep"
# ----------------------------------------------------------------------
# HEADER
# ----------------------------------------------------------------------
echo
echo ===== CLEANUP BEFORE DEPLOYING A TGZ =====
echo
if [ $# -lt 2 ]; then
echo "Syntax is"
echo "$( basename $0 ) [webroot] [tgz-archive] [[deleteflag]]"
exit 1
fi
# ----------------------------------------------------------------------
# CHECKS
# ----------------------------------------------------------------------
# check $prjdir to prevent deletetion of a complete server
# the directory must exist, must have a subdir "public_html" or
# "public" and a part must be "/www/" (i.e. /var/www/)
cd $prjdir || exit 2
# see #2235 - for nodejs apps the target dir is different
# ls -ld $prjdir/public_html/ || ls -ld $prjdir/public/ || exit 2
# echo $prjdir | fgrep "/www/" || exit 2
# skip this - aum spider has no json
# ls -l $prjdir/*.json || exit 2
# check tgz
file $tgz | grep -F "gzip compressed" || exit 3
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
echo --- scanning for $keepfile in $prjdir ...
cd $prjdir
find . -type f -name $keepfile | sort | sed "s#/$keepfile##g" >$filelist
ls -l $filelist
cat $filelist
echo
echo --- scanning archive $tgz
# tar -tzf $tgz | sed 's#/$##g' | sort >$filetgz
tar -tzf $tgz | sed 's#/$##g' | sed "s#^#./#g" | sed "s#^\./\./#./#g" | sort >$filetgz
ls -l $filetgz
wc -l $filetgz
head $filetgz
echo
echo --- scanning web $prjdir
cd $prjdir
find . -print | sort >$fileprj
ls -l $fileprj
wc -l $fileprj
head $fileprj
echo
echo --- compare ...
# diff $filetgz $fileprj | grep "^>" | cut -f 2 -d " " | while read delfile
diff $filetgz $fileprj | grep "^>" | cut -f 2 -d " " | grep -vf $filelist | while read delfile
do
bDelete=1
testfile=$delfile
if [ ! -d $delfile ]; then
testfile=$( dirname $delfile )
fi
echo $testfile | grep -F -f $filelist >/dev/null
if [ $? -eq 0 ]; then
echo KEEP: $delfile
else
if [ -z $bForceDelete ]; then
echo WILL-BE-DELETED: $delfile
else
echo DELETE: $delfile
rm -rf $delfile
fi
fi
done
# ----------------------------------------------------------------------
# CLEANUP
# ----------------------------------------------------------------------
rm -f $filelist $filetgz $fileprj
echo done.