#!/bin/sh LFS_PKG_BASE="$(dirname $(pwd))/packages" LFS_PKG_DIR="${LFS_PKG_BASE}/${LFS_STAGE}" LFS_LOG_DIR="${LFS}/var/log/hvlinux-install/${LFS_STAGE}" LFS_LOG_FILE="${LFS_LOG_DIR}/pkg-update.log" WGET_LOG_FILE="${LFS_LOG_DIR}/pkg-wget.log" # URL LFS_BASE_URL="http://www.linuxfromscratch.org" CLFS_BASE_URL="http://svn.cross-lfs.org/svn/repos/cross-lfs/trunk" HV_BASE_URL="http://www.hugovil.com/hvlinux-repository" LFS_PATCHES_URL="${LFS_BASE_URL}/patches/lfs/development" BLFS_PATCHES_URL="${LFS_BASE_URL}/patches/blfs/svn" CLFS_PATCHES_URL="http://patches.cross-lfs.org/dev" HV_PATCHES_URL="${HV_BASE_URL}/patches" LFS_PACKAGES_URL="ftp://ftp.osuosl.org/pub/lfs/lfs-packages/conglomeration" HV_PACKAGES_URL="${HV_BASE_URL}/packages" SOURCEFORGE_URL="http://internap.dl.sourceforge.net/sourceforge" GNOME_URL="http://ftp.gnome.org/pub/gnome/sources" GNU_URL="http://ftp.gnu.org/pub/gnu" TETEX_URL="http://www.tug.org/ftp/tex-archive/systems/unix/teTeX" WGETCMD="wget --directory-prefix=${LFS_PKG_DIR} --timeout=5 --tries=3 -nc -c -o ${WGET_LOG_FILE}" LFS_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-lfs.html BLFS_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-blfs.html CLFS_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-clfs.html HV_PATCHES_LIST=${LFS_PKG_DIR}/patches-list-hv.html # Arg. #1: URL for patches repository. # Arg. #2: Destination filename. static_fetch_patches_list() { PATCHES_URL=${1} PATCHES_LIST_FILENAME=${2} ${WGETCMD} "${PATCHES_URL}/" && mv ${LFS_PKG_DIR}/index.html ${PATCHES_LIST_FILENAME} } # Arg. #1: URL for patches repository. The trailing # slash is absolutely necessary for this to work. update_packages_init() { # First create log directory if it does not exists. if [ ! -d ${LFS_LOG_DIR} ]; then install -m755 -d ${LFS_LOG_DIR} || exit 1 fi # Then create destination directory if it does not exists. if [ ! -d ${LFS_PKG_DIR} ]; then install -v -m755 -d ${LFS_PKG_DIR} 1> ${LFS_LOG_FILE} 2>&1 || exit 1 fi # Getting list of all patches from LFS server. action_checkbox "Fetching LFS patches list" static_fetch_patches_list ${LFS_PATCHES_URL} ${LFS_PATCHES_LIST} # Getting list of all patches from BLFS server. action_checkbox "Fetching BLFS patches list" static_fetch_patches_list ${BLFS_PATCHES_URL} ${BLFS_PATCHES_LIST} # Getting list of all patches from CLFS server. action_checkbox "Fetching CLFS patches list" static_fetch_patches_list ${CLFS_PATCHES_URL} ${CLFS_PATCHES_LIST} # Getting list of all patches from hugovil.com server. action_checkbox "Fetching hugovil.com patches list" static_fetch_patches_list ${HV_PATCHES_URL} ${HV_PATCHES_LIST} } # Get patch package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: Patches list file (HTML) # Arg. #3: Patches URL static_checkpatch() { local PACK=${1} local PATCHES_LIST=${2} local PATCHES_URL=${3} local PATCHES_FOUND=$(cat ${PATCHES_LIST} | grep "${PACK}-" | sed "s/.*\(${PACK}-.*\.patch\).*/\1/") if [ -n "${PATCHES_FOUND}" ]; then for p in ${PATCHES_FOUND}; do if [ ! -f ${LFS_PKG_DIR}/${p} ]; then action_checkbox_time "Fetching ${p} from ${PATCHES_URL}" ${WGETCMD} ${PATCHES_URL}/${p} fi done fi } # Get patch package if it is not in the repository # Arg. #1: Package name and version static_getpatch() { PACK=${1} # Checking for correct number of arguments if [ $# -ne 1 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi if [ -n "${USE_LFS_PATCHES}" ]; then # Checking if patch is available from LFS. static_checkpatch ${PACK} ${LFS_PATCHES_LIST} ${LFS_PATCHES_URL} fi if [ -n "${USE_BLFS_PATCHES}" ]; then # Checking if patch is available from BLFS. static_checkpatch ${PACK} ${BLFS_PATCHES_LIST} ${BLFS_PATCHES_URL} fi if [ -n "${USE_CLFS_PATCHES}" ]; then # Checking if patch is available from CLFS. static_checkpatch ${PACK} ${CLFS_PATCHES_LIST} ${CLFS_PATCHES_URL} fi if [ -n "${USE_HV_PATCHES}" ]; then # Checking if patch is available from hugovil.com. static_checkpatch ${PACK} ${HV_PATCHES_LIST} ${HV_PATCHES_URL} fi } # Convert multiple compressed gzip files to bzip2. # Usage: gztobz2 [FILES] gztobz2() { if [ $# = 0 ]; then echo "$0: -- Convert multiple compressed gzip files to bzip2." echo "Usage: $0: [FILES]" return 1 fi while [ $# -ne 0 ]; do local ORIG_GZIPPED_FILENAME=${1} # Checking if input file exist. if [ ! -f $1 ]; then echo "$0: File ${ORIG_GZIPPED_FILENAME} not found." return 1 fi # Checking if input file is a valid gzipped file. gzip -t ${ORIG_GZIPPED_FILENAME} if [ $? -ne 0 ] ; then echo "$0: File ${ORIG_GZIPPED_FILENAME} is not a valid gzip file." return 1 fi # Obtaining uncompressed name of file local FILENAME=$(gunzip -l ${ORIG_GZIPPED_FILENAME} | sed '1d' | sed 's/\(.*\)% \(.*\)/\2/') # Decompressing file to standard output and piping result to bzip2 gunzip ${ORIG_GZIPPED_FILENAME} --stdout | bzip2 --best > ${FILENAME}.bz2 if [ $? -ne 0 ] ; then echo "$0: Error converting file ${ORIG_GZIPPED_FILENAME} to bzip2." return 1 fi # Keeping the original file's timestamp touch --reference=${ORIG_GZIPPED_FILENAME} ${FILENAME}.bz2 # Deleting original gzipped file if [ -f ${FILENAME}.bz2 ]; then rm ${ORIG_GZIPPED_FILENAME} fi shift done } detect_file_not_found() { # HTTP: will return error code 404. # FTP: will say "File not found" if grep "404" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then return 0 elif grep "No such file" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then return 0 else return 1 fi } # Get package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: URL static_getpkg() { PACK=${1} URL=${2} # Checking for correct number of arguments if [ $# -ne 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi ${WGETCMD} ${URL}/${PACK}.tar.bz2 && return 0 # Failure: if it was a connection timeout, don't try for other file extensions. if grep "failed: Connection timed out" ${WGET_LOG_FILE} 1> /dev/null 2>&1; then echo "Error, wget reported: Connection timed out" return 1 fi if detect_file_not_found; then # If file was not found, maybe a .tar.gz file exist... ${WGETCMD} ${URL}/${PACK}.tar.gz if [ ${?} -eq 0 ]; then gztobz2 ${LFS_PKG_DIR}/${PACK}.tar.gz || return 1 return 0 else if detect_file_not_found; then # If file was not found, maybe a .tgz file exist... ${WGETCMD} ${URL}/${PACK}.tgz if [ ${?} -eq 0 ]; then gztobz2 ${LFS_PKG_DIR}/${PACK}.tgz || return 1 return 0 else if detect_file_not_found; then # If file was not found, maybe a .tar.Z file exist... (uw-imap...) ${WGETCMD} ${URL}/${PACK}.tar.Z if [ ${?} -eq 0 ]; then gztobz2 ${LFS_PKG_DIR}/${PACK}.tar.Z || return 1 return 0 fi fi fi fi fi fi # Failure... return 1 } # Get package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: URL fpkg() { PACK=${1} URL=${2} # Checking for correct number of arguments if [ $# -ne 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi if [ ! -f ${LFS_PKG_DIR}/${PACK}.tar.bz2 ]; then action_checkbox_time "Fetching ${PACK}" static_getpkg ${PACK} ${URL} fi # Check if a patch is available. static_getpatch ${PACK} } # Get package if it is not in the repository. # This function is used if the source and target names for the # package are different (name mismatch). # Arg. #1: Target package name and version (on disk) # Arg. #2: Source package name and version (on internet) # Arg. #3: URL fpkg_mis() { TARGET=${1} SOURCE=${2} URL=${3} # Checking for correct number of arguments if [ $# -ne 3 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi if [ ! -f ${LFS_PKG_DIR}/${TARGET}.tar.bz2 ]; then fpkg ${SOURCE} ${URL} if [ -f ${LFS_PKG_DIR}/${SOURCE}.tar.bz2 ]; then mv ${LFS_PKG_DIR}/${SOURCE}.tar.bz2 ${LFS_PKG_DIR}/${TARGET}.tar.bz2 fi fi # Check for available patches with TARGET name. static_getpatch ${TARGET} # Check for available patches with SOURCE name. static_getpatch ${SOURCE} # Rename any patch fetched (in fpkg call) and replace SOURCE by TARGET in # patch name. if ls ${LFS_PKG_DIR}/${SOURCE}-*.patch 1> /dev/null 2>&1; then rename ${SOURCE} ${TARGET} ${LFS_PKG_DIR}/${SOURCE}-*.patch fi } # Get package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: Directory name (optional) fpkg_gnu() { PACK=${1} if [ $# -eq 2 ]; then NAME=${2} else NAME=$(get_pkg_name ${PACK}) fi # Checking for correct number of arguments if [ $# -lt 1 -o $# -gt 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi fpkg ${PACK} "${GNU_URL}/${NAME}" } # Fetch Gnome package (if it is not in the repository). # Arg. #1: Package name and version # Arg. #2: Directory name (optional) fpkg_gnome() { PACK=${1} if [ $# -eq 2 ]; then NAME=${2} else NAME=$(get_pkg_name ${PACK}) fi # Checking for correct number of arguments if [ $# -lt 1 -o $# -gt 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi fpkg ${PACK} "${GNOME_URL}/${NAME}/$(get_pkg_ver_base ${PACK})" } # Get package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: Directory name (optional) fpkg_sf() { PACK=${1} if [ $# -eq 2 ]; then NAME=${2} else NAME=$(get_pkg_name ${PACK}) fi # Checking for correct number of arguments if [ $# -lt 1 -o $# -gt 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi fpkg ${PACK} ${SOURCEFORGE_URL}/${NAME} } # Get package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: Directory name (optional) fpkg_hv() { PACK=${1} # Checking for correct number of arguments if [ $# -lt 1 -o $# -gt 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi if [ $# -eq 2 ]; then fpkg ${PACK} "${HV_PACKAGES_URL}/${2}" else fpkg ${PACK} ${HV_PACKAGES_URL} fi } # Get package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: Directory name (optional) fpkg_lfs() { PACK=${1} # Checking for correct number of arguments if [ $# -lt 1 -o $# -gt 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi if [ $# -eq 2 ]; then fpkg ${PACK} "${LFS_PACKAGES_URL}/${2}" else fpkg ${PACK} ${LFS_PACKAGES_URL} fi } # Create a symbolic link to a package that is located in another stage # repository (to not have the same file twice). # Arg. #1: Source stage number (1, 2, 3, etc) # Arg. #2: Package name lpkg() { SRCSTAGE="stage${1}" FILE="${2}.tar.bz2" PACKAGE_NAME="${2}" # Checking for correct number of arguments if [ $# -ne 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi if [ ! -h ${LFS_PKG_DIR}/${FILE} ]; then # Issue a warning if source file doesn't exist. if [ ! -f ${LFS_PKG_BASE}/${SRCSTAGE}/${FILE} ]; then source_link_status=" (missing source file)" else source_link_status="" fi # Create link if it doesn't exist action_checkbox_time "Linking ${PACKAGE_NAME}${source_link_status}" ln -s ../${SRCSTAGE}/${FILE} ${LFS_PKG_DIR}/${FILE} fi # Create link for patches corresponding to that package: if ls ${LFS_PKG_BASE}/${SRCSTAGE}/${PACKAGE_NAME}-*.patch 1> /dev/null 2>&1; then for patch in ${LFS_PKG_BASE}/${SRCSTAGE}/${PACKAGE_NAME}-*.patch; do PATCHFILE=$(basename ${patch}) if [ ! -h ${LFS_PKG_DIR}/${PATCHFILE} ]; then # Create link if it doesn't exist action_checkbox_time "Linking ${PATCHFILE}" ln -s ../${SRCSTAGE}/${PATCHFILE} ${LFS_PKG_DIR}/${PATCHFILE} fi done fi }