Add protection in case patch list file does not exist
[hvlinux.git] / functions / fpkg
index 6c0c26e..eedc14d 100644 (file)
@@ -3,18 +3,9 @@
 source ../config/urls
 source ../functions/gztobz2
 
-LFS_PKG_BASE="$(dirname $(pwd))/packages"
-LFS_PKG_DIR="${LFS_PKG_BASE}/${LFS_STAGE}"
-LFS_PATCHES_DIR="${LFS_PKG_BASE}/${LFS_STAGE}/patches"
-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"
-
-WGETCMD="wget --directory-prefix=${LFS_PKG_DIR} --timeout=15 --tries=3 -nc --continue --no-check-certificate --no-verbose --output-file=${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
+# Ownership of downloaded files
+FPKG_USER="root"
+FPKG_GROUP="users"
 
 # Test if the given file extension correspond to a compressed archive
 # Arg. #1: File extension
@@ -115,6 +106,9 @@ wget_wrapper()
         --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}
 
@@ -150,6 +144,8 @@ wget_wrapper()
 
     # Rename temporary file to final name
     mv ${DESTDIR}/${SOURCE}{.part,}
+    chown ${FPKG_USER}:${FPKG_GROUP} ${DESTDIR}/${SOURCE}
+    chmod 664 ${DESTDIR}/${SOURCE}
 
     return 0
 }
@@ -158,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
@@ -181,21 +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 -m755 -d ${LFS_PATCHES_DIR} 1> ${LFS_LOG_FILE} 2>&1 || exit 1
+       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
@@ -210,17 +217,20 @@ 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}
+        rcmd "Fetching CLFS patches list" static_fetch_patches_list \
+            ${CLFS_PATCHES_URL} ${CLFS_PATCHES_LIST}
     fi
 }
 
@@ -234,6 +244,11 @@ 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)
 
@@ -522,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: