Par Mushroom.
Ce script crée des bases de données exploitables par mirza à partir de paquets Slackware ou de fichiers MANIFEST.bz2.
Donnez simplement le fichier source (un paquet, ou un des fichiers MANIFEST.bz2 qui peuvent être trouvés dans les dossiers slackware/ de chaque CD de la distribution éponyme) puis éventuellement le nom à attribuer à la base de données. Assurez-vous simplement auparavant que VAR, le répertoire où sont stockées les bases de données, est bien renseigné de manière identique dans mirza.
Pour connaître toutes les options de mirzadb, consultez mirzadb -h.
Vous voudrez sans doute que tous les utilisateurs puissent chercher dans toutes les bases, rendant la centralisation de celles-ci dans un répertoire sous l'autorité de l'administrateur nécessaire. La bonne place pour installer mirzadb sera alors logiquement /usr/local/sbin ou /usr/sbin, puisque seul l'administrateur aura à s'en servir.
Dans tous les cas, pensez-bien à initialiser les permissions et propriétés de manière adéquate :
chmod 755 /usr/local/sbin/mirzadb chown root:root /usr/local/sbin/mirzadb
spkdb.
#!/bin/sh # # MIRZADB - create a data base from a MANIFEST file for mirza. # # c. 2007-08-27 # r. 2007-08-30 2 # Copyright (c) 2007 Sébastien Boillod. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. growl () { # Print error message on stderr an exits with the given non-null code. # growl <CODE> <MESSAGE> local ERR=$1 shift 1 if [ "$1" ]; then # If there is a second argument, we print arguments with 'echo'. echo "$*" 1>&2 else # Otherwise we use 'cat' and print stdin. cat <&0 >&2 fi [ $ERR = 0 ] || exit $ERR } unset HLP VAR DB SRC APD OVW TGZ # Directory where the data bases will be stored. VAR=/usr/local/var/lib/mirza for ARG in "$@"; do case $ARG in '-h') HLP="cat" ;; '-a') APD=1 ;; '-p') TGZ=1 ;; '-f') OVW=1 ;; -*) growl 0 "*** Error: unknown '$ARG' option." HLP="growl 1" break ;; *) if [ -z "$SRC" ]; then SRC=$ARG elif [ -z "$DB" ]; then DB=$ARG.gz else growl 0 "*** Error: too much arguments." HLP="growl 1" break fi esac done if [ -z "$SRC$HLP" ]; then # No help request, no source, we have a problem. growl 0 "*** Error: at least a source file is expected." HLP="growl 1" fi if [ "$HLP" ]; then # If help is requested, we print it and exit. $HLP <<H3LP mirzadb creates a data basis for mirza from the given source file. This one must be unique and is expected to be a MANIFEST.bz2 file that can be found in the './slackware' directory of each Slackware CD/DVD. If you don't specify a name for your data basis, the used one will be 'default.gz' (note: don't add the '.gz' extension to the name you give). Usage: mirzadb <source file> [DB name] [-a|-f|-h|-p]. Options: -a --- append the new data basis to the previous existing one instead of replace it. -f --- don't ask anything before replacing an existing data basis. -h --- print this help on the standard output. -p --- the source file isn't a MANIFEST.bz2 file but directly a package (useful with '-a', if you want to create your own data basis). Bug reports, suggestions, feedbacks, questions, and so on are welcome here (the license is at the head of the script): <sbb at tuxfamily dot org>. H3LP exit 0 fi # If we haven't DB, we will use the default one. [ "$DB" ] || DB="default.gz" if [ ! -f $SRC ]; then # We exit if the source doesn't exist. growl 1 "*** Error: '$SRC' source file doesn't exist or is not a regular file." elif [ -z "$TGZ" ] && [ "$(file -b $SRC | cut -f 1 -d " ")" != 'bzip2' ]; then # We exit too if the file isn't bzip2/gzip compressed. growl 1 "*** Error: the expected MANIFEST source file must be compressed by 'bzip2'." elif [ "$TGZ" ] && [ "${SRC%%*.tgz}" ]; then # If we are in tgz mode, we ensure the archive is a little bit orthodox. growl 1 "*** Error: the expected source file should end with '.tgz'." fi if [ "$OVW" ]; then # We initialize the db rm -f $VAR/$DB elif [ -f $VAR/$DB ] && [ -z "$APD" ] ; then # If the db already exists and we are not in append mode, we warn. growl 0 "*** Warning: the '$DB' data base already exists, do you want to overwrite it ?" growl 0 "*** Press [Return] or [Ctrl]+[c]." read ARG # we use ARG because 'read' requires a variable with ash. rm -f $VAR/$DB fi # OK, we create the DB. if [ "$APD" ]; then echo "Appending to '$DB'..." else echo "Generating '$DB'..." fi if [ "$TGZ" ]; then echo @@@$SRC | gzip -9 >>$VAR/$DB ( tar ftz $SRC 2>/dev/null || growl 1 "*** Error: your 'tar' archive seems to be corrupted.") | \ sed "{1d; \#install/#d; s#^#/#}" | gzip -9 >>$VAR/$DB else bzcat $SRC | sed "{ s/^.*:[0-9][0-9] //; /[a-z]/!d; s/[\t ]//g; \#^install#d; s%^/*%/%; s/^.*Package:/@@@/}" | gzip -9 >>$VAR/$DB fi # EOF