1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#/bin/bash
VERSION=`date +%s`
SOURCE_DST=`pwd`
if [ "x$CARDPEEK_DST"="x" ]
then
DOT_CARDPEEK_SRC=~/.cardpeek
else
DOT_CARDPEEK_SRC=$CARDPEEK_DST
fi
DOT_CARDPEEK_DST="$SOURCE_DST/dot_cardpeek_dir"
MODIFIED='no'
case "$1"
in
dryrun)
TODO=dryrun
;;
update)
TODO=update
;;
*)
echo "Usage: $0 [dryrun|update]"
echo " 'dryrun' just prints what the script would do, without actually doing it."
echo " 'update' actually does the work."
exit
;;
esac
if [ -d "$DOT_CARDPEEK_SRC" ]; then
cd $DOT_CARDPEEK_SRC
echo "## Retrieving new files:"
IFS=$'\t\n'
for i in `find * \! -path replay/\* \! -path scripts.old\* \! -name \\.\*`;
do
if [ -d "$i" ]; then
if [ ! -e "$DOT_CARDPEEK_DST/$i" ]; then
echo "!! creating dir $DOT_CARDPEEK_DST/$i"
if [ $TODO = "update" ]; then
mkdir -p "$DOT_CARDPEEK_DST/$i"
MODIFIED='yes'
fi
fi
elif test ! -e "$DOT_CARDPEEK_DST/$i" || (diff -q "$i" "$DOT_CARDPEEK_DST/$i" | grep differ) &> /dev/null; then
if [ "$i" -nt "$DOT_CARDPEEK_DST/$i" ]; then
echo ">> $DOT_CARDPEEK_SRC/$i will be copied to $DOT_CARDPEEK_DST/$i"
if [ $TODO = "update" ]; then
cp -pRv "$i" "$DOT_CARDPEEK_DST/$i"
MODIFIED='yes'
fi
elif [ "$i" -ot "$DOT_CARDPEEK_DST/$i" ]; then
echo "<< $DOT_CARDPEEK_SRC/$i will be replaced by $DOT_CARDPEEK_DST/$i"
if [ $TODO = "update" ]; then
cp -pRv "$DOT_CARDPEEK_DST/$i" "$i"
MODIFIED='yes'
fi
fi
fi
done
if [ "$TODO" = "update" ]; then
if [ "$MODIFIED" = 'yes' ]; then
echo "## Removing unecessary files and updating directory modfication time:"
rm -vf $DOT_CARDPEEK_DST/replay/*
touch $DOT_CARDPEEK_DST
echo "## Creating default config.lua"
cat > "$DOT_CARDPEEK_DST/config.lua" << __EOF
--
-- This file is automatically generated by Cardpeek.
-- It holds cardpeek configuration parameters, which are stored in the
-- lua 'cardpeek' table.
--
-- See cardpeekrc.lua for adding your own functions and variables to
-- cardpeek.
--
cardpeek = {
}
dofile('scripts/lib/apdu.lua')
-- end --
__EOF
echo "## Set version info:"
echo " Version ID is now $VERSION"
echo $VERSION > $DOT_CARDPEEK_DST/version
echo $VERSION > $DOT_CARDPEEK_SRC/version
cat > "$SOURCE_DST/script_version.h" << __EOF
#ifndef SCRIPT_VERSION_H
#define SCRIPT_VERSION_H
#define SCRIPT_VERSION $VERSION
#endif
__EOF
if (echo "$OSTYPE"| grep -q "darwin"); then
echo "## Removing OS X annoying extended attributes."
find $DOT_CARDPEEK_DST -xattr -exec xattr -c {} \;
fi
else
echo "## No updates performed."
fi
fi
echo "## Done"
else
echo "Error: ~/.cardpeek does not exist. Doing nothing"
fi
|