Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Štvrtok, 28. marec 2024

Súbor: [Platon] / scripts / shell / sign / sign-gen.sh (stiahnutie)

Revízia 1.6, Tue Feb 12 00:34:27 2002 UTC (22 years, 1 month ago) by jombik9

Zmeny od 1.5: +2 -2 [lines]

Sync.
New shell scripts.
CVS tags inprovements.
Extended pipelining merging and code stabilization.

#!/bin/bash

# sign_gen.sh 
#
# (c) 2001-2002 Ondrej Jombik <nepto@pobox.sk>
# - based on the characters created by Rider <rider@lonestar.sk>
#
# $Id: sign-gen.sh,v 1.6 2002/02/12 00:34:27 jombik9 Exp $
#
# Updates: [14/4/2001] [3/10/2001] [7/11/2001]

# Directory of sign scripts (this one and cooperates scripts)
SIGN_DIR="$HOME/prog/scripts/sign"

# Full path and file name of signature database file.
SIGN_DB_FILE="$SIGN_DIR/sign.db"

# 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
# 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=" "

#############################################################################

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

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

while [ `ps x | sed 's/^ *//' | cut -f1 -d" " | grep "^$PPID$"` ]; do

    # 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
    # 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 (\$count > $sign_id) { last; } \
            if (\$count    == $sign_id && \$ok == 1) { print; } \
        }" 2>/dev/null > ~/.tmp.s;

    # 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/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok