| verzia 1.7, 2002/04/05 03:24:27 |
verzia 1.8, 2002/04/12 17:33:02 |
|
|
| #!/bin/sh |
#!/bin/sh |
| |
|
| # sign_gen.sh |
# |
| |
# sign_gen.sh - powerful signature generator |
| # |
# |
| # (c) 2001-2002 Ondrej Jombik <nepto@pobox.sk> |
# (c) 2001-2002 Ondrej Jombik <nepto@pobox.sk> |
| # - based on the characters created by Rider <rider@lonestar.sk> |
# - based on the characters created by Rider <rider@lonestar.sk> |
|
|
| # $Id$ |
# $Id$ |
| # |
# |
| # Updates: [14/4/2001] [3/10/2001] [7/11/2001] |
# 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) |
# Directory of sign scripts (this one and cooperates scripts) |
| |
# |
| SIGN_DIR="$HOME/prog/scripts/sign" |
SIGN_DIR="$HOME/prog/scripts/sign" |
| |
|
| |
# |
| |
# Hash file |
| |
# |
| |
SIGN_HASH_FILE="$SIGN_DIR/hash.cfg" |
| |
|
| |
# |
| # Full path and file name of signature database file. |
# Full path and file name of signature database file. |
| SIGN_DB_FILE="$SIGN_DIR/sign.db" |
# |
| |
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. |
# 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="~~" |
SIGN_DB_SEPARATOR="~~" |
| |
|
| |
# |
| # Not used signature file separator. The same as parameter above, but this |
# Not used signature file separator. The same as parameter above, but this |
| # signature will be never used. This allows you to specify deprecated |
# signature will be never used. This allows you to specify deprecated |
| # without removing them from DB file. |
# signatures without removing them from DB file. |
| |
# |
| SIGN_DB_SEPARATOR_NOTUSED="~~!!" |
SIGN_DB_SEPARATOR_NOTUSED="~~!!" |
| |
|
| |
# |
| # Signature update delay time in seconds. |
# Signature update delay time in seconds. |
| |
# |
| SIGN_DELAY=55 |
SIGN_DELAY=55 |
| |
|
| |
# |
| # Number of characters to indent header. |
# Number of characters to indent header. |
| |
# |
| SIGN_INDENT_HEADER_NO_CHARS=40 |
SIGN_INDENT_HEADER_NO_CHARS=40 |
| |
|
| |
# |
| # Character to indent header. |
# Character to indent header. |
| |
# |
| SIGN_INDENT_HEADER_CHAR=" " |
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=""; |
SIGN_INDENT_HEADER_STR=""; |
| while [ $SIGN_INDENT_HEADER_NO_CHARS -gt 0 ]; do |
while [ $SIGN_INDENT_HEADER_NO_CHARS -gt 0 ]; do |
| SIGN_INDENT_HEADER_STR="$SIGN_INDENT_HEADER_STR$SIGN_INDENT_HEADER_CHAR"; |
SIGN_INDENT_HEADER_STR="$SIGN_INDENT_HEADER_STR$SIGN_INDENT_HEADER_CHAR"; |
| SIGN_INDENT_HEADER_NO_CHARS=$(($SIGN_INDENT_HEADER_NO_CHARS-1)); |
SIGN_INDENT_HEADER_NO_CHARS=$(($SIGN_INDENT_HEADER_NO_CHARS-1)); |
| done |
done |
| |
|
| |
# |
| |
# Creating server name (with uppercasing first character) |
| |
# |
| SIGN_SERVER_NAME=`uname -n \ |
SIGN_SERVER_NAME=`uname -n \ |
| | perl -pe 's/^([^\.]*)\..*/$1/; s/^(.)/uc $1/e if not /[[:upper:]]/;'`; |
| perl -pe 's/^([^\.]*)\..*/$1/; s/^(.)/uc $1/e if not /[[:upper:]]/;'`; |
| |
|
| # This is the same job as command above. (c) Rajo |
# |
| |
# This is the same job as command above. |
| |
# (c) Rajo |
| |
# |
| if [ 0 -eq 1 ]; then |
if [ 0 -eq 1 ]; then |
| uname -n | awk ' \ |
uname -n | awk ' \ |
| function capitalize(str) { \ |
function capitalize(str) { \ |
| Riadok 59 if [ 0 -eq 1 ]; then |
|
| Riadok 141 if [ 0 -eq 1 ]; then |
|
| { capitalize($1) } ' > /dev/null; |
{ capitalize($1) } ' > /dev/null; |
| fi |
fi |
| |
|
| |
# |
| |
# Main loop |
| |
# |
| while [ `ps x | sed 's/^ *//' | cut -f1 -d" " | grep "^$PPID$"` ]; do |
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 |
# Preparing some variabiles for date file |
| |
# |
| case `date +%m` in |
case `date +%m` in |
| 01) |
01) month="januar";; |
| month="januar" |
02) month="februar";; |
| ;; |
03) month="marec";; |
| 02) |
04) month="april";; |
| month="februar" |
05) month="maj";; |
| ;; |
06) month="jun";; |
| 03) |
07) month="jul";; |
| month="marec" |
08) month="august";; |
| ;; |
09) month="september";; |
| 04) |
10) month="oktober";; |
| month="april" |
11) month="november";; |
| ;; |
12) month="december";; |
| 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 |
esac |
| |
|
| case `date +%w` in |
case `date +%w` in |
| 1) |
1) day="pondelok";; |
| day="pondelok" |
2) day="utorok";; |
| ;; |
3) day="streda";; |
| 2) |
4) day="stvrtok";; |
| day="utorok" |
5) day="piatok";; |
| ;; |
6) day="sobota";; |
| 3) |
0) day="nedela";; |
| day="streda" |
|
| ;; |
|
| 4) |
|
| day="stvrtok" |
|
| ;; |
|
| 5) |
|
| day="piatok" |
|
| ;; |
|
| 6) |
|
| day="sobota" |
|
| ;; |
|
| 0) |
|
| day="nedela" |
|
| ;; |
|
| esac |
esac |
| |
|
| |
# |
| # Compose the date file |
# Compose the date file |
| |
# |
| echo -e "$SIGN_INDENT_HEADER_STR$SIGN_SERVER_NAME, `date +%T`" \ |
echo -e "$SIGN_INDENT_HEADER_STR$SIGN_SERVER_NAME, `date +%T`" \ |
| > ~/.tmp.d; |
> ~/.tmp.d; |
| echo -e "$SIGN_INDENT_HEADER_STR`date +%d`. $month `date +%Y` ($day)" \ |
echo -e "$SIGN_INDENT_HEADER_STR`date +%d`. $month `date +%Y` ($day)" \ |
| >> ~/.tmp.d; |
>> ~/.tmp.d; |
| |
|
| |
# |
| # Preparing some variabiles for date file |
# Preparing some variabiles for date file |
| |
# |
| sign_count=`cat $SIGN_DB_FILE | egrep "^$SIGN_DB_SEPARATOR$" \ |
sign_count=`cat $SIGN_DB_FILE | egrep "^$SIGN_DB_SEPARATOR$" \ |
| | wc -l | perl -pe 's/^\D*(\d)*$/$1/g;' 2>/dev/null`; |
| wc -l | perl -pe 's/^\D*(\d)*$/$1/g;' 2>/dev/null`; |
| sign_id=$RANDOM; |
sign_id=$RANDOM; |
| sign_id=$(($sign_id%$(($sign_count+1)))); |
sign_id=$(($sign_id%$(($sign_count+1)))); |
| |
|
| # Compose the down signature file |
# |
| |
# Compose |
| |
# - the down signature file on stderr |
| |
# - the whole database file on stdout |
| |
# |
| # echo -e "----\nid - $sign_id\ncount - $sign_count" >> ~/.tmp.s; |
# echo -e "----\nid - $sign_id\ncount - $sign_count" >> ~/.tmp.s; |
| cat $SIGN_DB_FILE | perl -e " \ |
cat $SIGN_DB_FILE | perl -e " \ |
| my \$count; \$count = 0; \ |
my \$count; \$count = 0; \ |
| Riadok 145 while [ `ps x | sed 's/^ *//' | cut -f1 |
|
| Riadok 209 while [ `ps x | sed 's/^ *//' | cut -f1 |
|
| while(<>) { \ |
while(<>) { \ |
| if (\$_ =~ /^$SIGN_DB_SEPARATOR_NOTUSED\$/) { \$ok = 0; next; } \ |
if (\$_ =~ /^$SIGN_DB_SEPARATOR_NOTUSED\$/) { \$ok = 0; next; } \ |
| if (\$_ =~ /^$SIGN_DB_SEPARATOR\$/) { \$ok = 1; \$count++; next; } \ |
if (\$_ =~ /^$SIGN_DB_SEPARATOR\$/) { \$ok = 1; \$count++; next; } \ |
| if (\$count > $sign_id) { last; } \ |
if (\$ok == 1) { \ |
| if (\$count == $sign_id && \$ok == 1) { print; } \ |
\$_ = eval(\$_) if (\$_ =~ '^\`'); \ |
| }" 2>/dev/null > ~/.tmp.s; |
print stderr if (\$count == $sign_id); \ |
| |
print stdout; \ |
| |
} \ |
| |
}" 2> ~/.tmp.s > ~/.tmp.s.db; |
| |
|
| |
# |
| # Compose whole database file (without separating tags) |
# Compose whole database file (without separating tags) |
| # TODO: only valid signatures should be witten into file |
# TODO: only valid signatures should be witten into file |
| cat $SIGN_DB_FILE \ |
# |
| | egrep -v "^($SIGN_DB_SEPARATOR|$SIGN_DB_SEPARATOR_NOTUSED)$" \ |
#cat $SIGN_DB_FILE \ |
| > ~/.tmp.s.db |
# | egrep -v "^($SIGN_DB_SEPARATOR|$SIGN_DB_SEPARATOR_NOTUSED)$" \ |
| |
# > ~/.tmp.s.db |
| |
|
| |
# |
| # Compose whole signature |
# Compose whole signature |
| |
# |
| cat ~/.tmp.d > ~/.tmp.signature; |
cat ~/.tmp.d > ~/.tmp.signature; |
| echo "" >> ~/.tmp.signature; |
echo "" >> ~/.tmp.signature; |
| cat ~/.tmp.s >> ~/.tmp.signature; |
cat ~/.tmp.s >> ~/.tmp.signature; |
| |
|
| |
# |
| # And now make some real job |
# And now make some real job |
| |
# |
| mv -f ~/.tmp.d ~/.d; |
mv -f ~/.tmp.d ~/.d; |
| mv -f ~/.tmp.s ~/.s; |
mv -f ~/.tmp.s ~/.s; |
| mv -f ~/.tmp.s.db ~/.s.db; |
mv -f ~/.tmp.s.db ~/.s.db; |
| mv -f ~/.tmp.signature ~/.signature; |
mv -f ~/.tmp.signature ~/.signature; |
| |
|
| |
# |
| # Sleeping for a while |
# Sleeping for a while |
| # TODO: check child process in loop and abort when it terminates |
# TODO: check child process in loop and abort when it terminates |
| |
# |
| sleep $SIGN_DELAY; |
sleep $SIGN_DELAY; |
| |
|
| done |
done |
| |
|