User:Lunaryn
CLFS user for x86_64 multilib and formerly x86_64 pure64 (pure64 system was migrated back to LFS 6.5), also using CBLFS for LFS 6.5 systems.
Here are a small collection of scripts that have proven useful with [C][B]LFS. They are intended primarily for users who have their browsers on a different system/console than their software builds, and thus cannot download source packages by clicking links, nor copy/paste commands into the build shell.
stub-header-gen:
#!/bin/bash # This script generates a stub header which is consistent with those described by # the CLFS book and CBLFS wiki pages. Usage: stub-header-gen <name> <id> HDR_NAME="$1" HDR_ID="$2" HDR_BASE="$(basename "${HDR_NAME}")" [ "${HDR_NAME:0:1}" = / ] || [ "${HDR_NAME:0:1}" = . ] || HDR_NAME="/usr/include/${HDR_NAME}" if [ -f "${HDR_NAME}-32.h" -a -f "${HDR_NAME}-64.h" ] then EXT=.h elif [ -f "${HDR_NAME}-32.hh" -a -f "${HDR_NAME}-64.hh" ] then EXT=.hh elif [ -f "${HDR_NAME}-32.hpp" -a -f "${HDR_NAME}-64.hpp" ] then EXT=.hpp else echo "Unable to find headers." exit 1 fi if [ -f "${HDR_NAME}${EXT}" ] then echo "Stub header appears to already exist." exit 1 fi echo "/* ${HDR_BASE}${EXT} - Stub Header */" >"${HDR_NAME}${EXT}" echo "#ifndef __STUB__${HDR_ID}__" >>"${HDR_NAME}${EXT}" echo -e "#define __STUB__${HDR_ID}__\n" >>"${HDR_NAME}${EXT}" cat >> "${HDR_NAME}${EXT}" << EOF #if defined(__x86_64__) || \\ defined(__sparc64__) || \\ defined(__arch64__) || \\ defined(__powerpc64__) || \\ defined (__s390x__) EOF echo -e "# include \"${HDR_BASE}-64${EXT}\"\n#else\n# include \"${HDR_BASE}-32${EXT}\"\n#endif\n\n#endif /* __STUB__${HDR_ID}__ */" >>"${HDR_NAME}${EXT}"
Note that the use of basename is to allow for headers that are in subdirectories of /usr/include without breaking the generated #include directives. For instance, stub-header-gen python2.6/pyconfig PYCONFIG_H will produce a stub header /usr/include/python2.6/pyconfig.h which includes either "pyconfig-32.h" or "pyconfig-64.h"
docdir-inst:
#!/bin/bash # This script assists in the manual install of documentation. # The primary purpose is to avoid needing to type out the package name and version. DIRNAME="$PWD" while [ -z "$PACKAGE" ]; do TMPDN="$(basename "$DIRNAME")" DIRNAME="$(dirname "$DIRNAME")" if [[ "$TMPDN" =~ .*-.*\..* ]]; then PACKAGE="$TMPDN" elif [ "$DIRNAME" = "/" ]; then echo "Unable to discern package name. Try invoking as:" echo "PACKAGE=<package name> $0 [<files>]" exit 1 fi done [ -n "$SUBDIR" ] && PACKAGE="$(PACKAGE}/${SUBDIR}" install -v -m755 -d "/usr/share/doc/$PACKAGE" until [ -z "$1" ]; do install -v -m644 "$1" "/usr/share/doc/$PACKAGE" shift done
Invoke without parameters to create an empty directory for the package under /usr/share/doc, for the sake of shell completion in typing a later command. Specifying files as parameters causes those files to be installed in the directory as well. Setting the SUBDIR variable when invoking allows you to install into a subdirectory of the package doc directory, e.g. /usr/share/doc/package-#.#.#/html (SUBDIR=html docdir-inst doc/html/*)
getcpan:
#!/bin/bash # Downloads packages from CPAN. Usage: getcpan <packer> <filename> PACKER="$1" FILENAME="$2" cd /sources wget "http://search.cpan.org/CPAN/authors/id/${PACKER:0:1}/${PACKER:0:2}/${PACKER}/${FILENAME}"
getgnome: (Segmented syntax only)
#!/bin/bash # Downloads packages from ftp.gnome.org. Usage: getgnome <package> <version> PACKAGE="$1" VERSION="$2" if [ -z "$EXT" ]; then EXT="tar.bz2" fi VER="$(echo ${VERSION} | awk -F. '{ print $1 "." $2 }')" cd /sources wget "http://ftp.gnome.org/pub/gnome/sources/${PACKAGE}/${VER}/${PACKAGE}-${VERSION}.${EXT}"
getgnu: (Filename syntax -- NOTE: Does not work for gcc without a workaround)
#!/bin/bash # Downloads packages from ftp.gnu.org. Usage: getgnu <filename> [<package>] PACKAGE="$2" FILENAME="$1" if [ -z "$PACKAGE" ]; then PACKAGE="$(echo ${FILENAME} | sed 's/-[0-9].*$//')" fi cd /sources wget "http://ftp.gnu.org/gnu/${PACKAGE}/${FILENAME}"
I recommend using the segmented syntax instead, but this option is provided since I did happen to make one. For gcc, specify the version subdir as part of the "package" name, e.g. getgnu gcc-4.4.1.tar.gz gcc/gcc-4.4.1
getgnu: (Segmented syntax)
#!/bin/bash # Downloads packages from ftp.gnu.org. Usage: getgnu <package> <version> [<extension>] PACKAGE="$1" VERSION="$2" EXT="$3" [ -z "$3" ] && EXT="tar.bz2" cd /sources if [ "$PACKAGE" = "gcc" ]; then wget "http://ftp.gnu.org/gnu/gcc/gcc-${VERSION}/gcc-${VERSION}.${EXT}" else wget "http://ftp.gnu.org/gnu/${PACKAGE}/${PACKAGE}-${VERSION}.${EXT}" fi md5sum "${PACKAGE}-${VERSION}.${EXT}"
You may wish to change the default extension to tar.gz since most ftp.gnu.org packages are packaged as tar.gz, but I preferred to keep it as tar.bz2 for the sake of [C]LFS package verification when preparing for a new system build; any package that can be downloaded as tar.bz2 generally is there, so there's less chance of a mistake.
getsf: (Filename syntax only)
#!/bin/bash # Downloads packages from sourceforge. Usage: getsf <filename> [<project>] PACKAGE="$2" FILENAME="$1" if [ -z "$PACKAGE" ]; then PACKAGE="$(echo ${FILENAME} | sed 's/-[0-9].*$//')" fi if [ -z "$MIRROR" ]; then MIRROR="easynews" fi cd /sources wget "http://downloads.sourceforge.net/${PACKAGE}/${FILENAME}?use_mirror=${MIRROR}"
You may wish to change the default mirror based on your location (I think easynews may not be valid anymore anyway). Note that you will need to specify the "package" name (project) more often here than with most other scripted sites, but the majority of packages still 'guess' correctly.
getsrc: (Only bother with this if you build sources in a different directory than you keep the tarballs)
#!/bin/bash # Generic wrapper script for wget. This is used to make sure source packages # end up in a central location. cd /sources wget "$1"
getpatch: (C[B]LFS version)
#!/bin/bash # Downloads C[B]LFS patches. Usage: getpatch <package> <version> <patchname> <patchver> PACKAGE="$1" VERSION="$2" PATCHNAME="$3" PATCHVER="$4" if [ -z "$PATCHVER" ]; then PATCHVER="1" fi [ -z "$BOOKVER" ] && BOOKVER=cblfs cd /sources if [ "$BOOKVER" = cblfs ]; then wget "http://svn.cross-lfs.org/svn/repos/patches/${PACKAGE}/${PACKAGE}-${VERSION}-${PATCHNAME}-${PATCHVER}.patch" else wget "http://patches.cross-lfs.org/${BOOKVER}/${PACKAGE}-${VERSION}-${PATCHNAME}-${PATCHVER}.patch" fi md5sum "${PACKAGE}-${VERSION}-${PATCHNAME}-${PATCHVER}.patch"
getpatch: ([B]LFS version)
#!/bin/bash [ -z "$BOOKVER" ] && BOOKVER=blfs FILE="$1" cd /sources if [ "$BOOKVER" = blfs ]; then wget "http://www.linuxfromscratch.org/patches/blfs/svn/$FILE" else wget "http://www.linuxfromscratch.org/patches/lfs/$BOOKVER/$FILE" fi md5sum "$FILE"
BLFS usage presumes using the dev trunk, which is probably the case for many users given how much the stable books lag behind LFS. If you do use this you may want to tweak it further. If you prefer segmented syntax, it should be trivial to modify the C[B]LFS version above to that end.