Súbor: [Platon] / scripts / shell / sign / sign-gen.sh (stiahnutie)
Revízia 1.9, Sun Jun 16 10:17:25 2002 UTC (21 years, 9 months ago) by jombik9
Zmeny od 1.8: +2 -2
[lines]
Updated $SIGN_DIR constant according to new position in directory tree.
|
#!/bin/sh
#
# sign_gen.sh - powerful signature generator
#
# (c) 2001-2002 Ondrej Jombik <nepto@pobox.sk>
# - based on the characters created by Rider <rider@lonestar.sk>
#
# $Id: sign-gen.sh,v 1.9 2002/06/16 10:17:25 jombik9 Exp $
#
# Updates: [14/4/2001] [3/10/2001] [7/11/2001]
# 12/4/2002 - execution code signature support
# - multi user support via hashfile
#
#
# Directory of sign scripts (this one and cooperates scripts)
#
SIGN_DIR="$HOME/prog/scripts/shell/sign"
#
# Hash file
#
SIGN_HASH_FILE="$SIGN_DIR/hash.cfg"
#
# Full path and file name of signature database file.
#
SIGN_DB_FILE="$SIGN_DIR/data/default.sign"
#
# Signature file separator. This string separate various signatures. It
# must be alone on the line without any characters before or after string.
#
SIGN_DB_SEPARATOR="~~"
#
# Not used signature file separator. The same as parameter above, but this
# signature will be never used. This allows you to specify deprecated
# signatures without removing them from DB file.
#
SIGN_DB_SEPARATOR_NOTUSED="~~!!"
#
# Signature update delay time in seconds.
#
SIGN_DELAY=55
#
# Number of characters to indent header.
#
SIGN_INDENT_HEADER_NO_CHARS=40
#
# Character to indent header.
#
SIGN_INDENT_HEADER_CHAR=" "
#############################################################################
#
# Locating DB file
#
if [ -f "$SIGN_HASH_FILE" ]; then
function extract_hash_file() {
local filename="`cat $SIGN_HASH_FILE \
| sed -e 's/^[[:space:]]*//g' \
| sed -e 's/[[:space:]]*$//g' \
| grep -v '^#' \
| grep -i \"^$1:$2:\" \
| cut -d: -f3 \
| head -n1`";
eval echo "$filename";
}
tmp_sign_db_file="`extract_hash_file \"\`id -un\`\" \"\`uname -n\`\"`";
# If not found, try empty hostname
if [ "x" = "x$tmp_sign_db_file" -o ! -f "$tmp_sign_db_file" ]; then
tmp_sign_db_file="`extract_hash_file \"\`id -un\`\" \"\"`";
fi
# If still not found, try empty username
if [ "x" = "x$tmp_sign_db_file" -o ! -f "$tmp_sign_db_file" ]; then
tmp_sign_db_file="`extract_hash_file \"\" \"\`uname -n\`\"`";
fi
# If still not found, try empty hostname and username
if [ "x" = "x$tmp_sign_db_file" -o ! -f "$tmp_sign_db_file" ]; then
tmp_sign_db_file="`extract_hash_file \"\" \"\"`";
fi
if [ "x" != "x$tmp_sign_db_file" -a -f "$tmp_sign_db_file" ]; then
SIGN_DB_FILE="$tmp_sign_db_file";
fi
fi
#
# Testing if DB file exists
#
if [ -f "$SIGN_DB_FILE" ]; then
echo "sign_gen.sh: using signature DB file '$SIGN_DB_FILE'";
else
echo "sign_gen.sh: signature DB file '$SIGN_DB_FILE' not exists";
exit;
fi
#
# Creating indent header string
#
SIGN_INDENT_HEADER_STR="";
while [ $SIGN_INDENT_HEADER_NO_CHARS -gt 0 ]; do
SIGN_INDENT_HEADER_STR="$SIGN_INDENT_HEADER_STR$SIGN_INDENT_HEADER_CHAR";
SIGN_INDENT_HEADER_NO_CHARS=$(($SIGN_INDENT_HEADER_NO_CHARS-1));
done
#
# Creating server name (with uppercasing first character)
#
SIGN_SERVER_NAME=`uname -n \
| perl -pe 's/^([^\.]*)\..*/$1/; s/^(.)/uc $1/e if not /[[:upper:]]/;'`;
#
# This is the same job as command above.
# (c) Rajo
#
if [ 0 -eq 1 ]; then
uname -n | awk ' \
function capitalize(str) { \
if (str !~ tolower(str)) { \
printf("%s",str) \
} \
else { \
printf("%.1s%s", toupper(str), substr(str,2,length(str))) \
} \
} \
BEGIN { FS = "." } \
{ capitalize($1) } ' > /dev/null;
fi
#
# Main loop
#
while [ `ps x | sed 's/^ *//' | cut -f1 -d" " | grep "^$PPID$"` ]; do
#
# Fast check if signature file is still present; if not exit immidiately
#
if [ ! -f "$SIGN_DB_FILE" ]; then
exit;
fi
#
# Preparing some variabiles for date file
#
case `date +%m` in
01) month="januar";;
02) month="februar";;
03) month="marec";;
04) month="april";;
05) month="maj";;
06) month="jun";;
07) month="jul";;
08) month="august";;
09) month="september";;
10) month="oktober";;
11) month="november";;
12) month="december";;
esac
case `date +%w` in
1) day="pondelok";;
2) day="utorok";;
3) day="streda";;
4) day="stvrtok";;
5) day="piatok";;
6) day="sobota";;
0) day="nedela";;
esac
#
# Compose the date file
#
echo -e "$SIGN_INDENT_HEADER_STR$SIGN_SERVER_NAME, `date +%T`" \
> ~/.tmp.d;
echo -e "$SIGN_INDENT_HEADER_STR`date +%d`. $month `date +%Y` ($day)" \
>> ~/.tmp.d;
#
# Preparing some variabiles for date file
#
sign_count=`cat $SIGN_DB_FILE | egrep "^$SIGN_DB_SEPARATOR$" \
| wc -l | perl -pe 's/^\D*(\d)*$/$1/g;' 2>/dev/null`;
sign_id=$RANDOM;
sign_id=$(($sign_id%$(($sign_count+1))));
#
# Compose
# - the down signature file on stderr
# - the whole database file on stdout
#
# echo -e "----\nid - $sign_id\ncount - $sign_count" >> ~/.tmp.s;
cat $SIGN_DB_FILE | perl -e " \
my \$count; \$count = 0; \
my \$ok; \$ok = 1; \
while(<>) { \
if (\$_ =~ /^$SIGN_DB_SEPARATOR_NOTUSED\$/) { \$ok = 0; next; } \
if (\$_ =~ /^$SIGN_DB_SEPARATOR\$/) { \$ok = 1; \$count++; next; } \
if (\$ok == 1) { \
\$_ = eval(\$_) if (\$_ =~ '^\`'); \
print stderr if (\$count == $sign_id); \
print stdout; \
} \
}" 2> ~/.tmp.s > ~/.tmp.s.db;
#
# Compose whole database file (without separating tags)
# TODO: only valid signatures should be witten into file
#
#cat $SIGN_DB_FILE \
# | egrep -v "^($SIGN_DB_SEPARATOR|$SIGN_DB_SEPARATOR_NOTUSED)$" \
# > ~/.tmp.s.db
#
# Compose whole signature
#
cat ~/.tmp.d > ~/.tmp.signature;
echo "" >> ~/.tmp.signature;
cat ~/.tmp.s >> ~/.tmp.signature;
#
# And now make some real job
#
mv -f ~/.tmp.d ~/.d;
mv -f ~/.tmp.s ~/.s;
mv -f ~/.tmp.s.db ~/.s.db;
mv -f ~/.tmp.signature ~/.signature;
#
# Sleeping for a while
# TODO: check child process in loop and abort when it terminates
#
sleep $SIGN_DELAY;
done
Platon Group <platon@platon.sk> http://platon.sk/
|