lilypond-user-fr
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: vérification intégrité des binaires


From: Philippe Neyrat
Subject: Re: vérification intégrité des binaires
Date: Sat, 20 Nov 2010 15:27:30 +0100
User-agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100330)

Désolé, j'ai encore envoyé en privé...
Voici donc pour la liste :

Bonjour,

J'ai pondu un petit script qui fait (chez moi en tous cas) ce que
demandait Michel Villeneuve dans son mail.

Je suis sous Linux (debian (i386 et ppc) et Ubuntu, ça dépend des
machines...), je l'ai donc naturellement écrit en bash.

Il s'appelle mkrcmd5f (Make recursive md5 file). Vous pouvez lui ajouter
un ".sh" si ça vous chante.
Le script parcourt une arborescence à partir de sa racine et pour chaque
fichier "normal", calcule la somme md5, et la met dans un fichier
temporaire. S'il trouve un répertoire, il fait de même sur celui-ci.
Il ne tient pas compte des liens, des fichiers spéciaux, etc., et à la
fin du traitement, crée un fichier dans le répertoire concerné avec
dedans toutes les sommes. Si un fichier contenant déjà des sommes et
portant le même nom existe, il le remplace.
Il ne fait rien si le répertoire est vide.
Les fichiers sont bien sûr lisibles par les utilisateurs normaux, même
s'il doit être lancé par "root" ou avec sudo.
Il est très largement modifiable (nom des fichiers générés, choix de la
méthode de cryptage, etc.

Ça marche chez moi. J'espère qu'il conviendra.

Mais je suis loin d'être un pro en la matière (j'ai bien galéré deux
jours !), aussi, je serais reconnaissant à ceux qui savent de me donner
leur avis, et me corriger si possible.

Si on pouvait faire passer ce script à ceux qui gèrent les dépôts, ça
serait encore mieux...

J'espère que les dépôts n'utilisent pas winchose...

Cordialement,

Philippe


PS : vérifiez que les droits /lecture écriture exécution/ sont bien
conservés pour "root", le téléchargement les modifie...


#!/bin/bash
# mkrcfmd5 :
# Make md5sums of files, recursively in a directory tree, from the root of it,
# and for each files which is not a directory.
# Philippe Neyrat 2011 [philippe DOT neyrat AT sfr DOT fr]
# Execute this scrip as root, as it writes in the directory tree.
# You MUST run it at the root of the directories you want to proceed in.
# If there is already a "md5sums.txt" file in the directory, it is replaced by 
the new one.
# The md5sums.txt files which are created are only readable by normal user...

# Change these according to your needs, for example if you prefer SHA1 
encryption,
# or if you prefer your files called like "SHA256sums_of_all_that_stuff.txt"...

ROOT_UID=0                  # Only users with $UID 0 have root privileges.
E_NOTROOT=87                # Non-root exit error.
E_WRONGARGS=89              # Invalid arguments error.
TMP_FILE_NAME=/tmp/md5sum   # Temporary file name part to collect md5sums.
CYPHER=/usr/bin/md5sum      # Commant to be executed on each file.
MD5FILENAME="md5sums.txt"   # Name of the created md5sums file in each 
directory.

# function treat () : accepts only one argument : a path to a directory.
# If it's a non-empty directory, executes the function on the directory.
# If it finds a "normal" file, executes CYPHER on it and saves the result in a 
new file,
# but if it's a link, a pipe, a block, an already existing "md5sum.txt" file,
# or some other special file or socket, don't do anything...
treat ()
{
   WRITE_IN=`basename $1`
   cd $1

   # Creates a new unique temporary file.
   TMP_FILE=${TMP_FILE_NAME}${WRITE_IN}
   touch "$TMP_FILE"

   for file in *
   do
      if [[ -d "$file" && -s "$file" ]]
      then 
      {
         ( treat $file )
      }
      elif [[ -f "$file" && -s "$file" && ! -h "$file" && ! -p "$file" && ! -b 
"$file" && ! -S "$file" && ! -c "$file" ]]
      then
      {
         if [[ ! "$file" == "$MD5FILENAME" ]]
         then
         {
            $CYPHER "$file" >> $TMP_FILE
         }
         fi
      }
      fi
   done
   # When it's done, copies the tmp file, if not empty, in the current 
directory,
   # and erases it from the tmp directory. If empty, erases it.
   if [[ -s "$TMP_FILE" ]]
   then
   {
       cp "$TMP_FILE" "$MD5FILENAME" && rm -f "$TMP_FILE" && chmod go-wx 
"$MD5FILENAME" && chmod go+r "$MD5FILENAME"
   }
   else
   {
      rm -f "$TMP_FILE"
   }
   fi
cd ..
} # end of function treat.

# Run as root, of course.
if [ "$UID" -ne "$ROOT_UID" ]
then
  echo -e "You must be root to run this script.\nYou better use \"sudo\" at 
least\nExiting...\n"
  exit $E_NOTROOT
fi

# If argument are missing or invalid, exit.
if [[ -z "$1" || "$#" -ne 1 || ! -d "$1" ]]
   then echo -e "USAGE : `basename $0` <Directory>\nUse a complete path, or 
launch it at the root of the directory you want to proceed in.\nExiting...\n" 
>&2 && exit $E_WRONGARGS
   else ( treat $1 )
fi

# Tell me where I can write this script better, if you know how. I'm an 
absolute begginer.
# Sorry for my english. ;-)
# Hope this helps... Bye you all ! 

exit 0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]