#!/bin/sh - # # make_package_stuff # # Copyright (C) 2000-2005 by # Oliver Fromme # All rights reserved. # Standard 2-clause BSD license and disclaimer applies. # # This script is useful for the creation of package sets # during production of FreeBSD release media. # Please refer to the usage message below for details. # ME=`basename $0` if [ $# -ne 1 -o ! -f "$1" -o ! -d All ]; then cat <<-tac >&2 Usage: $ME Example: $ME /usr/ports/INDEX The current directory must be the package base directory, e.g. /release/R/disc1/packages, and the packages that are to be included in the distribution must be placed in the "All" subdirectory. The list of the actual packages will be read from the "All" subdirectory, an INDEX with those packages will be created (as subset of the given master index), subdirectories for the categories will be created as necessary, and symlinks to the actual packages will be created in those category subdirectories. It also creates a "Latest" subdir and fills it appropriately with symlinks. WARNING! Everything (except the "All" subdirectory) will be removed from the current directory, before it gets re-created! Remember to create All/CHECKSUM.MD5, this script doesn't do that for you. It's simple: cd All; echo *.t[bg]z | xargs md5 > CHECKSUM.MD5 tac exit 1 fi TGZ_NUM=`ls All | grep -c '\.tgz$'` TBZ_NUM=`ls All | grep -c '\.tbz$'` if [ $TGZ_NUM -gt 0 ]; then if [ $TBZ_NUM -gt 0 ]; then echo "${ME}: ERROR (aborting):" >&2 echo "The \"All\" directory contains .tgz and .tbz packages!" >&2 echo "(You cannot have both at the same time.)" >&2 echo "Type \"$ME -h\" for help." >&2 exit 1 fi PKG_EXT=".tgz" elif [ $TBZ_NUM -gt 0 ]; then PKG_EXT=".tbz" else echo "${ME}: ERROR (aborting):" >&2 echo "No packages found in the \"All\" directory!" >&2 echo "Type \"$ME -h\" for help." >&2 exit 1 fi cat <<-tac >&2 WARNING -- Everything in the current directory will be removed, except for the "All" subdirectory and its contents. (Type "$ME -h" for more information.) Are you sure you want to continue? tac printf 'Please enter "yes" to continue: ' read ANSWER case "$ANSWER" in yes) ;; *) echo "Aborted." >&2 exit 1 ;; esac INDEX="$1" echo "" echo "====== Removing everything except \"All\" ... ======" ls | egrep -v '^(All|\..*)$' | xargs rm -rf echo "Done." echo "" echo "====== Creating INDEX ... ======" (ls All | grep '\.t[bg]z$' ; echo "xxx" ; cat "$INDEX" ) \ | awk -F '|' ' BEGIN{ mas = 0; all = 0; idx = 0; } { if (x) { if (have[$1]) { print > "INDEX"; have[$1]++; idx++; } mas++; } else if ($0 == "xxx") { x = 1; print "The \"All\" directory contains", all, "packages."; print "The package file extension is \"'$PKG_EXT'\"." } else { port = $0; sub(/\.t[bg]z$/, "", port); have[port] = 1; all++; } } END{ print "Transferred", idx, "of", mas, "entries from the master INDEX."; if (idx < all) { print "The following packages where missing in the master:"; for (i in have) if (have[i] == 1) printf "\t%s\n", i; } }' echo "Done." echo "" echo "====== Creating categories ... ======" awk -F '|' < INDEX '{print $7}' | tr ' ' '\n' | sort -u | xargs mkdir echo "Done." echo "" echo "====== Creating symlinks ... ======" awk -F '|' < INDEX ' BEGIN{ npkg = 0; nlnk = 0; } { pkg = "../All/" $1 "'$PKG_EXT'"; ncats = split($7, cats, / /); for (i = 1; i <= ncats; i++) { print pkg, cats[i]; nlnk++; } npkg++; } END{ print "Total number of packages:", npkg > "/dev/stderr"; print "Number of links:", nlnk > "/dev/stderr"; }' \ | while read PKG CAT; do if [ -e All/"$PKG" ]; then ln -s "$PKG" "$CAT" else printf "\t%s\tdoes not exist!\n" "$PKG" fi done echo "Done." echo "" echo "====== Peparing \"Latest\" directory ... ======" mkdir Latest cd Latest ls ../All \ | grep '\.t[bg]z$' \ | sed 's+^\(.*\)-\([^-]*\)\.t[bg]z$+../All/\1-\2'$PKG_EXT' \1'$PKG_EXT'+' \ | while read PKG LNK; do ln -sf "$PKG" "$LNK" done echo "Done." #--