spina ha scritto:conraid ha scritto:...
se guardi gli autori di xz, producono anche pkgtool per Slackware che supporta però i file tlz (lzma prima di xz) e lo mette proprio in memoria. Da li ho preso spunto per quell'esempio che ho mostrato, ma non riesco a farlo funziona con xz...
Non ho capito che vuoi dire, io mi sto guardando i sorgenti di xz per vedere cosa si può fare. Il tuo script dovresti modificarlo per cercare tutti i t.z e non solo i tgz. Poi si dovrebbe parametrizzare il comando da eseguire per prelevare le info.
Fin li ci sono emanuale, per desso mi basta anche fare due sezioni distinte, tanto quelle parti creano i file .meta (che poi cancello) e da li poi nasce il packages.txt
Intendo questi script
http://tukaani.org/pkgtools/
esiste un makerepo che fa quel che chiedo, ma ancora senza txz, loro usano i tlz, che erano una delle opzioni di Pat quando ha scelto il metodo di compressione. Cioè utilizzano lzma utils, che sono le vecchie xz utils
La funziona è questa
Codice: Seleziona tutto
# PACKAGES.TXT
create_packagestxt() {
local I DIRNAME
echo
echo "Creating $1/PACKAGES.TXT"
DIRNAME=${1##*/}
# Cache file:
if [ "$NO_CACHE" = 1 ]; then
: > "$TMP/cache"
elif [ -f "$1/PACKAGES.TXT" ]; then
cat "$1/PACKAGES.TXT" > "$TMP/cache"
elif [ -f "$1/PACKAGES.TXT.gz" ]; then
gunzip -c "$1/PACKAGES.TXT.gz" > "$TMP/cache"
fi
# Create the list of valid package names:
create_safelist "$1"
# Create the new PACKAGES.TXT with requested fields:
for I in $(cat "$TMP/pkglist.$DIRNAME"); do
# A kind of progress indicator:
printf "%-60s" "$I:"
# Package may be already in PACKAGES.TXT. We save a lot of time
# by reusing that information:
unset P_NAME P_MIRROR P_LOCATION P_CSIZE P_USIZE P_MD5SUM P_SHA1SUM \
P_REQUIRED P_CONFLICTS P_SUGGESTS P_DESC
if [ -s "$TMP/cache" ]; then
packagestxt_parse "$TMP/cache" "$I"
else
examine_package_contents "$I"
fi
# Set the variables:
[ -z "$P_NAME" ] && P_NAME=${I##*/}
# Refresh P_LOCATION since the package may be moved:
P_LOCATION="./${I%/*}"
[ "$P_LOCATION" = "./$I" ] && P_LOCATION=.
P_CSIZE=${P_CSIZE:-"$(($(ls -lL "$I" | tr -s ' ' | cut -f 5 -d ' ') / 1024))"}
[ -z "$P_USIZE" ] && examine_package_contents "$I"
# Optional fields:
if [ $O_MD5SUM = 1 -a ${#P_MD5SUM} != 32 ];then
echo -n " MD5"
P_MD5SUM=$(md5sum < "$I" | cut -f 1 -d ' ')
fi
if [ $O_SHA1SUM = 1 -a ${#P_SHA1SUM} != 40 ]; then
echo -n " SHA1"
P_SHA1SUM=$(sha1sum < "$I" | cut -f 1 -d ' ')
fi
if [ $O_SLAPT = 1 -a \( -z "$P_REQUIRED" -o -z "$P_CONFLICTS" \
-o -z "$P_SUGGESTS" \) ]; then
examine_package_contents "$I"
fi
# Set mirror after all examine_pakcage_contents commands because we want
# this to be overridable by a command line option:
P_MIRROR=${MIRROR:-"$P_MIRROR"}
# Write the entry to a preliminary PACKAGES.TXT file:
{
echo "PACKAGE NAME: $P_NAME"
[ $O_MIRROR = 1 ] && echo "PACKAGE MIRROR: $P_MIRROR"
echo "PACKAGE LOCATION: $P_LOCATION"
printf "PACKAGE SIZE (compressed): %6d K\n" "$P_CSIZE"
printf "PACKAGE SIZE (uncompressed): %6d K\n" "$P_USIZE"
[ $O_MD5SUM = 1 ] && echo "PACKAGE MD5 SUM: $P_MD5SUM"
[ $O_SHA1SUM = 1 ] && echo "PACKAGE SHA1 SUM: $P_SHA1SUM"
if [ $O_SLAPT = 1 ]; then
echo "PACKAGE REQUIRED: $P_REQUIRED"
echo "PACKAGE CONFLICTS: $P_CONFLICTS"
echo "PACKAGE SUGGESTS: $P_SUGGESTS"
fi
echo "$P_DESC"
# Empty line works as a separator:
echo
} >> "$TMP/txt"
# Collect statistics:
TOTAL_CSIZE=$((TOTAL_CSIZE + P_CSIZE))
TOTAL_USIZE=$((TOTAL_USIZE + P_USIZE))
echo " OK"
done
# Convert from KiB to MiB:
TOTAL_CSIZE=$((TOTAL_CSIZE / 1024))
TOTAL_USIZE=$((TOTAL_USIZE / 1024))
# Add the header information:
cat << EOF > "$TMP/PACKAGES.TXT"
PACKAGES.TXT; $(date)
This file provides details on the packages found
in the $1/ directory.
EOF
printf "Total size of all packages (compressed) : %5d MB\n" "$TOTAL_CSIZE" >> "$TMP/PACKAGES.TXT"
printf "Total size of all packages (uncompressed) : %5d MB\n" "$TOTAL_USIZE" >> "$TMP/PACKAGES.TXT"
echo >> "$TMP/PACKAGES.TXT"
echo >> "$TMP/PACKAGES.TXT"
# Remove trailing spaces and append to the final PACKAGES.TXT:
sed 's/ *$//' "$TMP/txt" >> "$TMP/PACKAGES.TXT"
rm -f "$TMP/txt"
}
lasciando perdere create_safelist (crea la lista dei pacchetti, io uso find) le funzioni utili sono
Codice: Seleziona tutto
examine_package_contents() {
echo -n " uncompress"
mknod "$TMP/fifo" p
( uncompress_pkg "$1" | tee "$TMP/fifo" | $TAR xf - -C "$TMP" install \
> /dev/null 2> /dev/null ) &
P_USIZE=$(wc -c < "$TMP/fifo" | tr -d ' ')
P_USIZE=$((P_USIZE / 1024))
rm -f "$TMP/fifo"
wait # Wait for tar.
# Nice trick to avoid blank lines in P_DESC:
P_DESC=$(echo; grep "^$(package_basename "$1"):" "$TMP/install/slack-desc" 2> /dev/null)
P_DESC="PACKAGE DESCRIPTION:$P_DESC"
if [ $O_SLAPT = 1 ]; then
# See packagestxt_parse() for reasoning of the extra space.
P_REQUIRED="$(slapt_extract "$TMP/install/slack-required") "
P_CONFLICTS="$(slapt_extract "$TMP/install/slack-conflicts") "
P_SUGGESTS="$(slapt_extract "$TMP/install/slack-suggests") "
fi
rm -rf "$TMP/install"
}
Codice: Seleziona tutto
uncompress_pkg() {
case "$1" in
*.tlz|*.lzma)
# Reset PKGTOOLS_LZMA if we are installing/upgrading
# the lzma package:
case "$1" in (lzma-*) PKGTOOLS_LZMA= ;; esac
# Check which lzma command we are using:
[ -z "$PKGTOOLS_LZMA" ] && check_cmd_lzma
case "$PKGTOOLS_LZMA" in
# -d is only temporarily here
new) unlzma -dc "$1" 2> /dev/null ;;
old) lzma d -si -so < "$1" 2> /dev/null ;;
*) echo 'BUG in uncompress_pkg!' 1>&2 ;;
esac
;;
*.tbz|*.bz2)
# Use bunzip2 instead of bzip2 for BusyBox compatibility:
bunzip2 -c "$1" 2> /dev/null
;;
*.tar)
cat "$1" 2> /dev/null
;;
*)
# For explodepkg compatibility we default to tgz.
# Do no add -f as it does not work with busybox.
gunzip -c "$1" 2> /dev/null
;;
esac
}
In pratica per un tgz per esempio tutto diventerebbe
Codice: Seleziona tutto
mknod "$TMP/fifo" p
( gunzip -c "$1" | tee "$TMP/fifo" | $TAR xf - -C "$TMP" install \
> /dev/null 2> /dev/null ) &
P_USIZE=$(wc -c < "$TMP/fifo" | tr -d ' ')
P_USIZE=$((P_USIZE / 1024))
rm -f "$TMP/fifo"
siccome esiste xz -c pensavo di fare la stessa cosa, ma mi da errore
sicuramente sbaglio qualcosa io