Procházet zdrojové kódy

Merge branch 'master' of git.galthub.com:gmj/home.public.bin

George Jones před 6 měsíci
rodič
revize
ff0211337f
2 změnil soubory, kde provedl 110 přidání a 0 odebrání
  1. 72 0
      bin/artificial-ignorance.sh
  2. 38 0
      bin/cryptdir.sh

+ 72 - 0
bin/artificial-ignorance.sh

@@ -0,0 +1,72 @@
+#! /bin/bash
+# Extract a stream of keywords from a file
+#
+# This is an applicaton of Marcus Ranum's principal of "Artificial Ignorance"
+# http://www.ranum.com/security/computer_security/papers/ai/
+#
+# Usage: ai input-file term1 [term2 ...]
+#
+#   Input:
+#      - input-file on the command line
+#      - terms - one or more on the command line.
+#
+#                terms can have "|" to match more than one term.
+#
+#                If there is a "|", the first term will be used
+#                as the output file name.
+#
+#                Note if you want the
+#                output to have a particualr name, use it as
+#                the first term, it may not actually match in grep.
+#
+#   Output:
+#      - ai-TERM1.txt
+#      - ai-TERM2.txt
+#      - ...
+#      - ai-TERMn.txt
+#      - ai-leftovers.txt
+#
+# Example
+#
+# I wrapped this in a shell script as follows to write a report.
+#
+#    ! /bin/bash
+#    artificial-ignorance.sh completd-only.org \
+#    'research-projects|clustering|heatmaps' \
+#    'external|USENIX' \
+#    'products|firewall' \
+#    'development|lint|make|python' \
+#
+# set -e
+set -u
+
+PREFIX=ai-
+LEFTOVERS=ai-leftovers.txt
+LEFTOVERS_TMP=/dev/null
+
+INPUT=${1:-""}
+OUTOUT=""
+
+if [ "$INPUT" == "" ]; then
+    echo Need file on command line
+    exit 1
+else
+    shift
+fi
+
+for var in "$@"
+do
+    PATTERN="${var}"
+    # allow patterns of A|B|C, use first element as name
+    FIRST_ELEMENT=`echo $PATTERN | sed -e 's/|.*//'`
+    OUTPUT="${PREFIX}${FIRST_ELEMENT}.txt"
+    LEFTOVERS_TMP="ai-leftovers-${FIRST_ELEMENT}.tmp"
+
+    cat $INPUT | tee >(egrep -i "$PATTERN" > $OUTPUT) | (egrep -vi "$PATTERN" > $LEFTOVERS_TMP)
+
+
+    INPUT=$LEFTOVERS_TMP
+done
+
+cp $LEFTOVERS_TMP $LEFTOVERS
+rm -f ai-*.tmp || echo no leftovers

+ 38 - 0
bin/cryptdir.sh

@@ -0,0 +1,38 @@
+#!/bin/bash
+# Use zip to encrypt all single files CRYPTDIR with PASSWORD
+
+# this is bash; be safe
+set -e
+set -u
+
+# Set up logging functions (die, warn, info ...)
+source $HOME/lib/bash/bashutils.sh
+
+# Get the encryption password from the CRYPTDIR_PASS environment variable
+password=${CRYPTDIR_PASS:-"NONE"}
+
+# Check if password is defined
+if [ $password == "NONE" ]; then
+  die "ERROR: CRYPTDIR_PASS environment variable not defined"
+fi
+
+cryptdir=${CRYPTDIR:-"NONE"}
+
+# Check if password is defined
+if [ $cryptdir == "NONE" ]; then
+  die "ERROR: CRYPTDIR environment variable not defined"
+fi
+
+cd $cryptdir || die "Can't cd to $cryptdir"
+info "encrypting files in $cryptdir"
+
+# Loop through all files in the current directory
+for file in *; do
+  # Check if the file is not a directory and is not already a zip file
+  if [ ! -d "$file" ] && [[ "$file" != *.zip ]]; then
+      # Create a zip file with the same name as the original file with .zip extension
+      info "Encrypting $file ..."
+      zip --encrypt --password "$password" "$file.zip" "$file"
+  fi
+done
+info done