X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions%2Ffpkg;h=eedc14dc18192ad43f067d1f63b7ca658d6476d2;hb=769abe2665103a85d34685c3e1fff5d04480c47a;hp=fed9089c6158fd68b327c58de93d542c893e24a1;hpb=05a63ae322941e807a917d83bed8348202e22807;p=hvlinux.git diff --git a/functions/fpkg b/functions/fpkg index fed9089..eedc14d 100644 --- a/functions/fpkg +++ b/functions/fpkg @@ -3,22 +3,29 @@ source ../config/urls source ../functions/gztobz2 -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" +# Ownership of downloaded files +FPKG_USER="root" +FPKG_GROUP="users" -WGETCMD="wget --directory-prefix=${LFS_PKG_DIR} --timeout=15 --tries=3 -nc --continue --no-check-certificate --no-verbose --output-file=${WGET_LOG_FILE}" +# Test if the given file extension correspond to a compressed archive +# Arg. #1: File extension +is_extension_archive() +{ + if [ ${#} -ne 1 ]; then + echo "${FUNCNAME}(), wrong number of arguments: ${*}" + return 1 + fi -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 + local EXT=${1} -FTYPE_ARCHIVE="0" -FTYPE_PATCH="1" -FTYPE_OTHER="2" + for k in "gz" "tgz" "Z" "zip" "xz" "bz2"; do + if [ "x${EXT}" = "x${k}" ]; then + return 0 + fi + done + + return 1 +} # Test if the given file extension correspond to a tar/gzip archive # Arg. #1: File extension @@ -68,25 +75,27 @@ remove_partial_file() # Download a file, and making sure it is valid (at least it's header!) # Arg. #1: Source URL. # Arg. #2: Source filename (on server) -# Arg. #3: File type: 0 : Archive -# 2 : Patch -# 1 : Other +# Arg. #3: Output directory (optional). Default = LFS_PKG_DIR # # Return: 0 : success # 1 : wget error -# 2 : File not found or not an archive +# 2 : File not found or not an archive (if file extension was archive type) wget_wrapper() { - if [ ${#} -lt 2 -a ${#} -gt 3 ]; then + if [ ${#} -lt 2 ]; then echo "${FUNCNAME}(), wrong number of arguments: ${*}" return 1 fi local URL=${1} local SOURCE=${2} - local FTYPE=${3} + local DESTDIR=${LFS_PKG_DIR} - remove_partial_file ${LFS_PKG_DIR}/${SOURCE} + if [ ${#} -eq 3 ]; then + DESTDIR=${3} + fi + + remove_partial_file ${DESTDIR}/${SOURCE} local STRING="Fetching ${SOURCE}" if [ "x${FTYPE}" = "x${FTYPE_PATCH}" ]; then @@ -94,9 +103,12 @@ wget_wrapper() fi rcmd "${STRING}" ${WGETCMD} ${URL}/${SOURCE} \ - --output-document=${LFS_PKG_DIR}/${SOURCE}.part + --output-document=${DESTDIR}/${SOURCE}.part wget_status=$? + chown ${FPKG_USER}:${FPKG_GROUP} ${DESTDIR}/${SOURCE}.part + chmod 664 ${DESTDIR}/${SOURCE}.part + # Append log to global log file cat ${WGET_LOG_FILE} >> ${LFS_LOG_FILE} @@ -108,26 +120,32 @@ wget_wrapper() # Partial failure if file was not found. if detect_file_not_found; then - remove_partial_file ${LFS_PKG_DIR}/${SOURCE} + remove_partial_file ${DESTDIR}/${SOURCE} return 2 fi if [ ${wget_status} -ne 0 ]; then - remove_partial_file ${LFS_PKG_DIR}/${SOURCE} + echo "Error: wget returned error status ${wget_status}" >> \ + ${LFS_LOG_FILE} + remove_partial_file ${DESTDIR}/${SOURCE} return 1 fi - if [ "x${FTYPE}" = "x${FTYPE_ARCHIVE}" ]; then + local FEXT=${SOURCE##*.} + if is_extension_archive "${FEXT}"; then # Just to be sure, test if downloaded file is really an archive: - if ! is_archive ${LFS_PKG_DIR}/${SOURCE}.part; then + if ! is_archive ${DESTDIR}/${SOURCE}.part; then # Partial failure if file is invalid. - remove_partial_file ${LFS_PKG_DIR}/${SOURCE} + echo "Error: failed archive test" >> ${LFS_LOG_FILE} + remove_partial_file ${DESTDIR}/${SOURCE} return 2 fi fi # Rename temporary file to final name - mv ${LFS_PKG_DIR}/${SOURCE}{.part,} + mv ${DESTDIR}/${SOURCE}{.part,} + chown ${FPKG_USER}:${FPKG_GROUP} ${DESTDIR}/${SOURCE} + chmod 664 ${DESTDIR}/${SOURCE} return 0 } @@ -136,16 +154,24 @@ wget_wrapper() # Arg. #2: Destination filename. static_fetch_patches_list() { + local wget_status + PATCHES_URL=${1} PATCHES_LIST_FILENAME=${2} - # Appending a slash (/) will download the directory content as a file named index.html - ${WGETCMD} "${PATCHES_URL}/" && + # Appending a slash (/) will download the directory content as a file named + # index.html + ${WGETCMD} "${PATCHES_URL}/" + wget_status=$? # Append log to global log file - cat ${WGET_LOG_FILE} >> ${LFS_LOG_FILE} && + cat ${WGET_LOG_FILE} >> ${LFS_LOG_FILE} - mv ${LFS_PKG_DIR}/index.html ${PATCHES_LIST_FILENAME} + if [ ${wget_status} -eq 0 ]; then + mv ${LFS_PKG_DIR}/index.html ${PATCHES_LIST_FILENAME} + else + return 1 + fi } # Arg. #1: If "test" is specified, set TEST_INTEGRITY to 1 @@ -159,16 +185,24 @@ update_packages_init() # downloading other packages export RCMD_NO_EXIT=1 - test_presence_of_packages_directory + init_log_file_update - # First create log directory if it does not exists. - if [ ! -d ${LFS_LOG_DIR} ]; then - install -m755 -d ${LFS_LOG_DIR} || exit 1 - fi + export LFS_PATCHES_LIST=${LFS_PKG_DIR}/patches/list-lfs.html + export BLFS_PATCHES_LIST=${LFS_PKG_DIR}/patches/list-blfs.html + export CLFS_PATCHES_LIST=${LFS_PKG_DIR}/patches/list-clfs.html + export WGET_LOG_FILE="${LFS_LOG_DIR}/pkg-wget.log" + export WGETCMD="wget --directory-prefix=${LFS_PKG_DIR} --timeout=15 --tries=3 -nc --continue --no-check-certificate --no-verbose --output-file=${WGET_LOG_FILE}" # 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 + install -v -m775 -o ${FPKG_USER} -g ${FPKG_GROUP} \ + -d ${LFS_PKG_DIR} 1> ${LFS_LOG_FILE} 2>&1 || exit 1 + fi + + # Create patches destination directory if it does not exists. + if [ ! -d ${LFS_PATCHES_DIR} ]; then + install -v -m775 -o ${FPKG_USER} -g ${FPKG_GROUP} \ + -d ${LFS_PATCHES_DIR} 1> ${LFS_LOG_FILE} 2>&1 || exit 1 fi if [ -n "${TEST_INTEGRITY}" ]; then @@ -183,26 +217,24 @@ update_packages_init() if [ -n "${USE_LFS_PATCHES}" ]; then # Getting list of all patches from LFS server. - rcmd "Fetching LFS patches list" static_fetch_patches_list ${LFS_PATCHES_URL} ${LFS_PATCHES_LIST} + rcmd "Fetching LFS patches list" static_fetch_patches_list \ + ${LFS_PATCHES_URL} ${LFS_PATCHES_LIST} fi if [ -n "${USE_BLFS_PATCHES}" ]; then # Getting list of all patches from BLFS server. - rcmd "Fetching BLFS patches list" static_fetch_patches_list ${BLFS_PATCHES_URL} ${BLFS_PATCHES_LIST} + rcmd "Fetching BLFS patches list" static_fetch_patches_list \ + ${BLFS_PATCHES_URL} ${BLFS_PATCHES_LIST} fi if [ -n "${USE_CLFS_PATCHES}" ]; then # Getting list of all patches from CLFS server. - rcmd "Fetching CLFS patches list" static_fetch_patches_list ${CLFS_PATCHES_URL} ${CLFS_PATCHES_LIST} - fi - - if [ -n "${USE_HV_PATCHES}" ]; then - # Getting list of all patches from hugovil.com server. - rcmd "Fetching hugovil.com patches list" static_fetch_patches_list ${HV_PATCHES_URL} ${HV_PATCHES_LIST} + rcmd "Fetching CLFS patches list" static_fetch_patches_list \ + ${CLFS_PATCHES_URL} ${CLFS_PATCHES_LIST} fi } -# Get patch package if it is not in the repository +# Get patch for package if it is not in the repository # Arg. #1: Package name and version # Arg. #2: Patches list file (HTML) # Arg. #3: Patches URL @@ -212,19 +244,33 @@ static_checkpatch() local PATCHES_LIST=${2} local PATCHES_URL=${3} + # Make sure patch list file exists + if [ ! -f ${PATCHES_LIST} ]; then + return + fi + # Remplace les "+" par "%2B" local PACK_URL=$(echo $PACK | sed s!\+!%2B!g) - local PATCHES_FOUND=$(cat ${PATCHES_LIST} | grep "${PACK_URL}-" | sed "s/.*\(${PACK_URL}-.*\.patch\).*/\1/") + # Patches list formats (patches-list-*.html): + # LFS: a href="name.patch" + # hugovil: a href="dir/subdir/subdir/name.patch" + # We must search for a patch beginning with either a slash or a " to avoid + # the possibility of having another package name within a patch name: + # if patch = Mesalib-8.0.4-llvm-3.1-fixes-1.patch + # then we could erroneously try to download patch "llvm-3.1-fixes-1.patch" + local PATCHES_FOUND=$(cat ${PATCHES_LIST} | \ + egrep "\"${PACK_URL}-|/${PACK_URL}-" | \ + egrep ".patch\"" | \ + sed "s/.*\(${PACK_URL}-.*\.patch\)\".*/\1/") + if [ -n "${PATCHES_FOUND}" ]; then for p in ${PATCHES_FOUND}; do # Remplace les "%2B" par "+" PATCH_NAME=$(echo ${p} | sed s!%2B!\+!g) - if [ ! -f ${LFS_PKG_DIR}/${PATCH_NAME} ]; then - # String uses $PATCH_NAME and not $p ??? - #####rcmd "Fetching ${PATCH_NAME} from ${PATCHES_URL}" wget_wrapper ${PATCHES_URL} ${p} ${FTYPE_OTHER} - wget_wrapper ${PATCHES_URL} ${p} ${FTYPE_PATCH} + if [ ! -f ${LFS_PATCHES_DIR}/${PATCH_NAME} ]; then + wget_wrapper ${PATCHES_URL} ${PATCH_NAME} ${LFS_PATCHES_DIR} fi done fi @@ -256,11 +302,6 @@ static_getpatch() # 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 } detect_file_not_found() @@ -303,7 +344,7 @@ static_getpkg() fi for arch_ext in ${PREFERRED_EXT}; do - wget_wrapper ${URL} ${PACK}.${arch_ext} ${FTYPE_ARCHIVE} + wget_wrapper ${URL} ${PACK}.${arch_ext} wget_wrapper_status=$? if [ ${wget_wrapper_status} -eq 1 ]; then @@ -463,7 +504,7 @@ fpkg() fi if [ -z "${FILE_EXT}" ]; then # Default file extension is tar.gz - FILE_EXT="tar.gz" + FILE_EXT="tar.xz" fi ;; gnome) @@ -473,6 +514,10 @@ fpkg() SRC_DIR=$(get_pkg_name ${PACK}) fi SRC_DIR="${SRC_DIR}/$(get_pkg_ver2 ${PACK})" + if [ -z "${FILE_EXT}" ]; then + # Default file extension is xz + FILE_EXT="tar.xz" + fi ;; sf) URL=${SOURCEFORGE_URL} @@ -492,10 +537,6 @@ fpkg() echo "${FUNCNAME}(), mode 'xorg' needs '-s' option" return 1 fi - if [ -z "${DEST_DIR}" ]; then - # Default fetch (write to) directory - DEST_DIR=${LFS_PKG_DIR}/${SRC_DIR} - fi ;; fd) # Most common layout: @@ -638,7 +679,7 @@ fpkg() # Rename any patch fetched (in fpkg call) and replace SOURCE by TARGET # in patch name. - local PATCHES_LIST="${LFS_PKG_DIR}/${SRC_FILENAME}-*.patch" + local PATCHES_LIST="${LFS_PATCHES_DIR}/${SRC_FILENAME}-*.patch" if ls ${PATCHES_LIST} 1> /dev/null 2>&1; then echo "CMD=${SRC_FILENAME} ${PACK} ${PATCHES_LIST}" rename ${SRC_FILENAME} ${PACK} ${PATCHES_LIST}