I have been using a barely modified copy of Slackware's package management, so these should work for anyone who also uses Slack's tools. With some modification it should work fine with a custom-made tarball package management, which I plan to create, but not yet. I fall short in many areas when it comes to Linux, but I enjoy making scripts.
First is my "buildit" script. It is intended for use with package creation. It is very buggy if you redirect the output to a file. I decided to write this one when I realized somewhere during BLFS that my /lib64 directory wasn't a symlink to /lib like it was supposed to be. I'd like to rework a few parts, include more error checking, and clean it up a bit, but I haven't worked out the correct syntaxes yet.
Usage is:
buildit.sh <appname> <optional version number>
This moves the contents of the lib64 directories into lib, strips debugging symbols, then executes makepkg, incorporating the <appname> <version> arguments into the file name for that is automatically saved into the local repository directory. The REPO variable prepends $LFS so that it should work both during the tools build, and the chroot build.
Code:
#!/bin/bash
# J. Huffman -- 29January2016
# buildit.sh to automate the things I usually forget
# should have already done configure, make, make DESTDIR install
# and cd into the $DESTDIR
# Define some variables for ease of editing
APP=$1
VER=$2
if [ ! $REPO ] ; then REPO=$LFS/repo ; fi
# Make sure an argument has been passed, or else exit.
if [ ! $APP ] ; then
printf "\n\nUsage: buildit.sh <appname> <optional.version.num>\n\n"
exit
fi
# Move "lib64's" into "lib's", due to the way Slack's makepkg handles
# symlinks. This should prevent accidentally obliterating the root
# file system structure during install, since lib64's are just symlinks.
# Make sure any hidden files are included in the upcoming move.
shopt -s dotglob
# move/copy the lib64 files/folders
if [ -d lib64 ] ; then
if [ ! -d lib ] ; then
mv lib64 lib
else cp -R lib64/* lib && rm -fr lib64
fi
fi
if [ -d usr/lib64 ] ; then
if [ ! -d usr/lib ] ; then
mv usr/lib64 usr/lib
else cp -R usr/lib64/* usr/lib && rm -fr usr/lib64
fi
fi
if [ -d usr/local/lib64 ] ; then
if [ ! -d usr/local/lib ] ; then
mv usr/local/lib64 usr/local/lib
else cp -R usr/local/lib64/* usr/local/lib \
&& rm -fr usr/local/lib64
fi
fi
shopt -u dotglob
# Now that the directories are (hopefully) good, create the slack-desc
# file. My system currently has a slack-desc template file that I sed
# substitute the package name then edit with vim. Remove or alter the
# following lines as you deem appropriate.
if [ ! -d install ] ; then mkdir install ; fi
cp ~/Documents/slack-desc.template install/slack-desc
sed -i "s/appname/$APP/g" install/slack-desc
vim install/slack-desc
# strip debugging symbols
# This is the same command as LFS ch 6.72 - Stripping Again
find {,usr/}{bin,lib,sbin} -type f -exec strip --strip-debug '{}' ';'
# Now build the package and save it to the repository
# Alter the lines below to suit your system's method of package creation.
if [ ! -d $REPO ] ; then mkdir $REPO ; fi
makepkg -l y -c n $REPO/"$APP"-"$VER"-x86_64-1jh.tgz
# Prompt for cleanup.
printf "\nDelete the contents of the build directory? (y/n)"
read SMASH
if [ "$SMASH" = "y" ] ; then
rm -fr *
else
printf "\nKeeping build tree.\n\n"
fi
And the second one searches the local tarball repository for a given file or directory name (passed as a command line argument). I plan to add more error checking into it, but it works as advertised. For now, it complains if there are non-tarballs in the repo directory. It is more resource intensive than, for example, a search through the files in (Slackware's) /var/log/packages, but it yields an accurate display of the current contents of a package.
Code:
#!/bin/bash
# pkgprobe - created on: 25January2016 by J. Huffman
# Script for searching through the package repository and probing each
# tarball package for a string given as the command line argument.
# Define vars
if [ "$REPO" = "" ] ; then REPO="$LFS/repo" ; fi
FILE=$(mktemp)
# If no argument has been passed, echo usage statement.
if [ ! $1 ] ; then
echo -e "\npkgprobe USAGE:"
echo -e "[REPO=/repo_dir] [TMP=/temp_dir] pkgprobe <filename>\n"
echo -e "where <filename> is the file or directory to be found."
echo -e "Variables (if any) should precede the command.\n"
else
# The main loop
for PKG in $REPO/* # Searches every file in the repo directory
do
cat /dev/null > $FILE # Reset $FILE to empty for each iteration.
for ARCHIVE in $(tar -tf $PKG)
do
if [ $(basename $ARCHIVE) = $1 ]
then
echo $ARCHIVE >> $FILE
fi
done
if [ $(stat -c s $FILE) != 0 ]
then
echo
echo "==================================================="
echo "$PKG contains:"
echo "==================================================="
cat $FILE
fi
done
fi
rm $FILE
Sample output from the "pkgprobe" script:
# pkgprobe lynx
===================================================
/repo/lynx-2.8.9dev8-x86_64-1jh.tgz contains:
===================================================
./usr/bin/lynx
./etc/lynx/
Hopefully someone finds these tools useful. What I like most about these two scripts is that they can be used during every stage of B/LFS, even as early as creating the temporary toolchain, if one so desires.