You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
5.2 KiB
189 lines
5.2 KiB
8 years ago
|
#!/bin/sh
|
||
|
set -e
|
||
8 years ago
|
|
||
|
gpgkey=''
|
||
|
timestamp="$(LC_ALL=C date -u)"
|
||
|
cachedir='.cache'
|
||
|
|
||
|
# Cleanup
|
||
|
if [ "$1" = 'clean' ]; then
|
||
|
rm -rf "$cachedir" ChangeLog.txt PACKAGES.TXT MANIFEST.bz2 FILELIST.TXT CHECKSUMS.md5 CHECKSUMS.md5.asc GPG-KEY
|
||
|
find . -regex '.*\.t[bglx]z$' | while read -r package; do
|
||
|
pkgbase="$(echo "$package" | sed 's?.*/??;s/\.t[bglx]z$//')"
|
||
|
rm -f "$(dirname "$package")/$pkgbase.txt"
|
||
|
rm -f "$package.asc"
|
||
|
done
|
||
|
|
||
|
exit
|
||
|
fi
|
||
|
|
||
|
mkdir -p "$cachedir"
|
||
|
|
||
|
# Process all packages
|
||
|
find . -regex '.*\.t[bglx]z$' | while read -r package; do
|
||
|
case "$package" in
|
||
|
*.tgz)
|
||
|
tool=gzip
|
||
|
;;
|
||
|
*.tbz)
|
||
|
tool=bzip2
|
||
|
;;
|
||
|
*.tlz)
|
||
|
tool=lzma
|
||
|
;;
|
||
|
*.txz)
|
||
|
tool=xz
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
# See the pkgbase and package_name functions in /sbin/installpkg
|
||
|
pkgbase="$(echo "$package" | sed 's?.*/??;s/\.t[bglx]z$//')"
|
||
|
pkgdir="$(dirname "$package")"
|
||
|
pkgname="$(echo "$pkgbase" | sed 's?-[^-]*-[^-]*-[^-]*$??')"
|
||
|
|
||
|
pkgtxt="$pkgdir/$pkgbase.txt"
|
||
|
pkgmeta="$cachedir/$pkgdir/$pkgbase.meta"
|
||
|
pkgmanifest="$cachedir/$pkgdir/$pkgbase.manifest"
|
||
|
pkgsize="$cachedir/$pkgdir/$pkgbase.size"
|
||
|
pkgusize="$cachedir/$pkgdir/$pkgbase.usize"
|
||
|
|
||
8 years ago
|
pkgsum="$cachedir/$pkgdir/$pkgbase.checksum"
|
||
|
|
||
|
if [ -f "$pkgtxt" -a \
|
||
|
-f "$pkgmeta" -a \
|
||
|
-f "$pkgmanifest" -a \
|
||
|
-f "$pkgsize" -a \
|
||
|
-f "$pkgusize" -a \
|
||
|
-f "$pkgsum" ]; then
|
||
|
if [ "$gpgkey" ]; then
|
||
|
if [ -f "$package.asc" ]; then
|
||
|
md5sum --status -c "$pkgsum" && continue
|
||
|
fi
|
||
|
else
|
||
|
md5sum --status -c "$pkgsum" && continue
|
||
|
fi
|
||
|
fi
|
||
8 years ago
|
|
||
|
echo "Adding $package..."
|
||
|
mkdir -p "$cachedir/$pkgdir"
|
||
|
|
||
|
# Decompress the package
|
||
|
tmppkg="$(mktemp)"
|
||
|
$tool -cd "$package" > "$tmppkg"
|
||
|
|
||
|
# Get package size
|
||
|
du -k "$package" | cut -f 1 > "$pkgsize"
|
||
|
du -k "$tmppkg" | cut -f 1 > "$pkgusize"
|
||
|
|
||
|
# Generate .txt file (see /usr/bin/slackdtxt)
|
||
|
(tar xOf "$tmppkg" install/slack-desc 2> /dev/null || echo "$pkgname:") | egrep -v '^($|#| *\|)' > "$pkgtxt"
|
||
|
|
||
|
# Create manifest for this package
|
||
|
cat > "$pkgmanifest" << EOF
|
||
|
++========================================
|
||
|
||
|
||
|
|| Package: $package
|
||
|
||
|
||
|
++========================================
|
||
7 years ago
|
$(TZ=EST tar tvvf "$tmppkg")
|
||
8 years ago
|
|
||
|
|
||
|
EOF
|
||
|
|
||
|
# Create metadata for this package
|
||
|
# Source for the sed line: https://stackoverflow.com/questions/1444406/how-can-i-delete-duplicate-lines-in-a-file-in-unix#1444433
|
||
|
cat > "$pkgmeta" << EOF
|
||
|
PACKAGE NAME: $(basename "$package")
|
||
|
PACKAGE LOCATION: $pkgdir
|
||
|
PACKAGE SIZE (compressed): $(cat "$pkgsize" | xargs) K
|
||
|
PACKAGE SIZE (uncompressed): $(cat "$pkgusize" | xargs) K
|
||
|
PACKAGE DESCRIPTION:
|
||
|
$(cat "$pkgtxt" | sed -e '$!N; /^\(.*\)\n\1$/!P; D')
|
||
|
|
||
|
EOF
|
||
|
|
||
|
# Sign the package
|
||
|
rm -f "$package.asc"
|
||
|
[ "$gpgkey" ] && gpg -bas --use-agent --batch -u "$gpgkey" "$package"
|
||
|
|
||
|
# Remove decompressed package
|
||
|
rm -f "$tmppkg"
|
||
8 years ago
|
|
||
|
# Save checksum
|
||
|
md5sum "$package" > "$pkgsum"
|
||
8 years ago
|
done
|
||
|
|
||
|
# Generate shitty ChangeLog.txt
|
||
|
echo "$timestamp" > ChangeLog.txt
|
||
|
|
||
|
# Create GPG-KEY
|
||
|
if [ "$gpgkey" ]; then
|
||
|
gpg --list-keys "$gpgkey" > GPG-KEY
|
||
|
gpg -a --export "$gpgkey" >> GPG-KEY
|
||
|
fi
|
||
|
|
||
|
# Generate PACKAGES.TXT
|
||
|
echo "Generating PACKAGES.TXT..."
|
||
|
|
||
|
cat > PACKAGES.TXT << EOF
|
||
|
|
||
|
PACKAGES.TXT; $timestamp
|
||
|
|
||
|
This file provides details on the Slackware packages found
|
||
|
in this directory.
|
||
|
|
||
|
Total size of all packages (compressed): $(expr \( 0$(find "$cachedir" -type f -name '*.size' | xargs cat | xargs printf ' + %s') \) / 1024 || true) MB
|
||
|
Total size of all packages (uncompressed): $(expr \( 0$(find "$cachedir" -type f -name '*.usize' | xargs cat | xargs printf ' + %s') \) / 1024 || true) MB
|
||
|
|
||
|
|
||
|
EOF
|
||
|
|
||
|
# https://stackoverflow.com/questions/4255603/sort-files-by-basename#4256095
|
||
|
find "$cachedir" -type f -name '*.meta' | perl -e 'print sort{($p=$a)=~s!.*/!!;($q=$b)=~s!.*/!!;$p cmp$q}<>' | xargs cat >> PACKAGES.TXT
|
||
|
|
||
|
echo >> PACKAGES.TXT
|
||
|
|
||
|
# Generate MANIFEST.bz2
|
||
|
echo "Generating MANIFEST.bz2..."
|
||
|
find "$cachedir" -type f -name '*.manifest' | sort | xargs cat | bzip2 -9 -z > MANIFEST.bz2
|
||
|
|
||
|
# Generate FILELIST.TXT
|
||
|
echo "Generating FILELIST.TXT..."
|
||
|
|
||
|
cat > FILELIST.TXT << EOF
|
||
|
$timestamp
|
||
|
|
||
|
Here is the file list for this directory. If you are using a
|
||
|
mirror site and find missing or extra files in the disk
|
||
|
subdirectories, please have the archive administrator refresh
|
||
|
the mirror.
|
||
|
|
||
|
EOF
|
||
|
find . ! -path "./$cachedir/*" -a ! -name "$cachedir" | sort | xargs fakeroot ls -ld --time-style=long-iso > FILELIST.TXT
|
||
|
|
||
|
# Generate CHECKSUMS.md5
|
||
|
echo "Generating CHECKSUMS.md5..."
|
||
|
|
||
|
cat > CHECKSUMS.md5 << EOF
|
||
|
These are the MD5 message digests for the files in this directory.
|
||
|
If you want to test your files, use 'md5sum' and compare the values to
|
||
|
the ones listed here.
|
||
|
|
||
|
To test all these files, use this command:
|
||
|
|
||
|
tail +13 CHECKSUMS.md5 | md5sum -c --quiet - | less
|
||
|
|
||
|
'md5sum' can be found in the GNU coreutils package on ftp.gnu.org in
|
||
|
/pub/gnu, or at any GNU mirror site.
|
||
|
|
||
|
MD5 message digest Filename
|
||
|
EOF
|
||
|
find . -type f -a ! -path "./$cachedir/*" | sort | xargs md5sum >> CHECKSUMS.md5
|
||
|
|
||
|
# Sign CHECKSUMS.md5
|
||
|
rm -f CHECKSUMS.md5.asc
|
||
|
[ "$gpgkey" ] && gpg -bas --use-agent --batch -u "$gpgkey" CHECKSUMS.md5
|
||
|
|
||
|
# Remove tmpdir
|
||
|
rm -rf "$tmpdir"
|