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

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

Revízia 1.11, Sun Nov 9 18:54:22 2003 UTC (21 years, 1 month ago) by nepto


Zmeny od 1.10: +2 -2 [lines]

Added $Platon$ header.

#!/bin/sh

#
# sign - powerful signature handling
#
# sign-gen.sh - powerful signature generator
# (based on the characters created by Rider <rider@lonestar.sk>)
# ____________________________________________________________
#
# Developed by Ondrej Jombik <nepto@pobox.sk>
# Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/
# All rights reserved.
#
# See README file for more information about this software.
# See COPYING file for license information.
#
# Download the latest version from
# http://www.platon.sk/projects/sign/
#
# $Platon: sign-gen.sh,v 1.10 2002/06/21 14:15:15 jombik9 Exp $
#
# Updates: 14/4/2001, 3/10/2001, 7/11/2001
#   12/4/2002 - execution code signature support
#             - multi user support via hashfile
#   21/6/2002 - header & copyright update
#             - 'cat' command optimalizations
#

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

#
# 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 1;
    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;
    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 < $SIGN_DB_FILE;

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