X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=functions%2Fmain;h=b8edf5f8321be078c363b178bb83132e7cc8b59e;hb=3faa2b5a452ac4d86604c31278ff87fbee00fd54;hp=720715753ca337327e367a56d8b06511b41be475;hpb=564ec1bbb321286571c30da20b81620c33b18e6f;p=hvlinux.git diff --git a/functions/main b/functions/main index 7207157..b8edf5f 100644 --- a/functions/main +++ b/functions/main @@ -30,14 +30,14 @@ source ../config/packages-list # Load default values source ../config/sysinfos.default +# Load user-defined configuration values if [ ! -f ../config/sysinfos ]; then echo "Missing config/sysinfos configuration file." return ${EXIT_FAILURE} +else + source ../config/sysinfos fi -# Load user-defined configuration values -source ../config/sysinfos - # We want hvtrap_setup called only with the first sourcing of this script. if [ -z "${HVTRAP_SETUP_DONE1}" ]; then hvtrap_setup @@ -73,9 +73,7 @@ BRACKET="\033[1;34m" TAR_OPTS="-b8" # List of default archive extensions to try -DEFAULT_ARCH_EXT_LIST="tar.bz2 tar.gz tgz tar.Z zip" - -HV_FONTS_PATH="/usr/share/fonts" +DEFAULT_ARCH_EXT_LIST="tar.bz2 tar.gz tgz tar.Z tar.xz zip" DEFAULT_IPKG_SCRIPT="ipkg.def" @@ -126,6 +124,14 @@ fi CLFS=${LFS} +test_presence_of_packages_directory() +{ + if [ ! -d "$(dirname $(pwd))/packages" ]; then + echo "Error, could not find packages directory \"$(dirname $(pwd))/packages\", aborting." + exit 1 + fi +} + # Create log directory and log file for current stage if necessary # This should be done automatically... init_log_file() @@ -133,6 +139,8 @@ init_log_file() # Scripts directory export SCRDIR=$(pwd) + test_presence_of_packages_directory + export LFS_PKG_DIR="$(dirname $(pwd))/packages/${LFS_STAGE}" export LFS_LOG_DIR=${LFS}/var/log/hvlinux-install/${LFS_STAGE} export LFS_LOG_FILE=${LFS_LOG_DIR}/install.log @@ -144,6 +152,15 @@ init_log_file() fi } +# Check that we are logged in as the root user, and exit if this is not the case. +check_for_root_user() +{ + if [ "x${USER}" != "xroot" ]; then + echo "You must be the superuser to install hvlinux." + exit 1 + fi +} + # Extracting the version number from a complete package name. # Arg. #1: Complete package name with version (ex: firefox-3.5.5.source will output 3.5.5) get_pkg_ver() @@ -157,9 +174,9 @@ get_pkg_ver() echo ${1} | sed "s!.*-\([0-9].*\)!\1!g" } -# Extracting the base version number from a complete package name. -# Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3.4) -get_pkg_ver_base() +# Extracting the first digit version number from a complete package name. +# Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3) +get_pkg_ver1() { # Checking for correct number of arguments if [ $# -ne 1 ]; then @@ -167,13 +184,12 @@ get_pkg_ver_base() return 1 fi - echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\).*!\1!g" + echo ${1} | sed "s!^.*-\([0-9]*\)\..*!\1!g" } -# Extracting the 3-digit version number from a complete package name. -# Arg. #1: Complete package name with version -# (ex: linux-2.6.37.1 will output 2.6.37) -get_pkg_ver3() +# Extracting the first 2 digits version number from a complete package name. +# Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3.4) +get_pkg_ver2() { # Checking for correct number of arguments if [ $# -ne 1 ]; then @@ -181,12 +197,13 @@ get_pkg_ver3() return 1 fi - echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\.[0-9]*\).*!\1!g" + echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\).*!\1!g" } -# Extracting the base version number from a complete package name. -# Arg. #1: Complete package name with version (ex: gcc-3.4.4 will output 3) -get_pkg_ver_major() +# Extracting the first 3 digit version number from a complete package name. +# Arg. #1: Complete package name with version +# (ex: linux-2.6.37.1 will output 2.6.37) +get_pkg_ver3() { # Checking for correct number of arguments if [ $# -ne 1 ]; then @@ -194,7 +211,7 @@ get_pkg_ver_major() return 1 fi - echo ${1} | sed "s!^.*-\([0-9]*\)\..*!\1!g" + echo ${1} | sed "s!^.*-\([0-9]*\.[0-9]*\.[0-9]*\).*!\1!g" } # Extracting the name from a complete package name. @@ -213,37 +230,6 @@ get_pkg_name() echo ${1} | sed "s!\([^-][^0-9]*\)-[0-9].*!\1!" } -# Saves the content of CFLAGS and CXXFLAGS environment variables. -save_flags() -{ - export OLDCFLAGS=${CFLAGS} - export OLDCXXFLAGS=${CXXFLAGS} - - return ${EXIT_SUCCESS} -} - -# Saves the content of CFLAGS and CXXFLAGS environment variables, and then -# set them to empty strings. -save_flags_no_optimizations() -{ - export OLDCFLAGS=${CFLAGS} - export OLDCXXFLAGS=${CXXFLAGS} - export CFLAGS="" - export CXXFLAGS="" - - return ${EXIT_SUCCESS} -} - -# Restores the previous values of CFLAGS and CXXFLAGS environment variables. These -# must have been saved first using save_flags(). -restore_flags() -{ - export CFLAGS=${OLDCFLAGS} - export CXXFLAGS=${OLDCXXFLAGS} - - return ${EXIT_SUCCESS} -} - # Create symbolic links for start/stop scripts in /etc/rc.d # # Arg #1: script name @@ -557,7 +543,7 @@ hv_groupadd() done if ! cat /etc/group | egrep -q "^${groupname}:"; then - groupadd ${arguments} + groupadd ${arguments} fi } @@ -650,23 +636,27 @@ static_decompressed_dirname() continue; fi + local DIRNAME="" + case ${arch_ext} in - tar.bz2|tar.gz|tgz|tar.Z) + tar.bz2|tar.gz|tgz|tar.Z|tar.xz) # Remove optional "./" leading component with sed # and extract base directory name with awk. # tar 1.23 reports an error when using pipes, so # remove error message with "2> /dev/null" - local DIRNAME=$(tar ${TAR_OPTS} -tf \ + DIRNAME=$(tar ${TAR_OPTS} -tf \ ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} 2> /dev/null | \ head -n1 | sed 's!^\./!!' | awk -F \/ '{print $1}') - echo ${DIRNAME} ;; zip) - # TODO - echo ${PACKAGE} + DIRNAME=$(unzip -l \ + ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} | head -n4 | \ + sed '$!d' | awk -F " " '{print $4}' | sed 's!/$!!') ;; esac + echo ${DIRNAME} + return $? done @@ -678,6 +668,7 @@ static_decompressed_dirname() # Decompression of a package # First argument: package name # Second argument: directory where decompressing (optional, defaults to LFS_TMP) +# Third argument: directory levels to strip (optional) decompress_package() { # Checking for correct number of arguments @@ -685,8 +676,11 @@ decompress_package() local TOPDIR=${LFS_TMP} elif [ $# -eq 2 ]; then local TOPDIR=${2} + elif [ $# -eq 3 ]; then + local TOPDIR=${2} + local STRIP_LEVEL="--strip-components=${3}" else - echo "${FUNCNAME}(): Incorrect number of arguments (must be 1 or 2)" > /dev/stderr + echo "${FUNCNAME}(): Incorrect number of arguments (must be 1, 2 or 3)" > /dev/stderr return ${EXIT_FAILURE} fi @@ -703,17 +697,15 @@ decompress_package() rm -rf ${TOPDIR}/${PACKAGE} fi + # Decompressing package case ${arch_ext} in - tar.bz2) - tar -C ${TOPDIR} ${TAR_OPTS} -jxf \ - ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} - ;; - tar.gz|tgz|tar.Z) - tar -C ${TOPDIR} ${TAR_OPTS} -zxf \ + tar.bz2|tar.gz|tgz|tar.Z|tar.xz) + tar -C ${TOPDIR} ${TAR_OPTS} ${STRIP_LEVEL} -xf \ ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} ;; zip) + # Support STRIP_LEVEL??? unzip -qq -d ${TOPDIR} ${LFS_PKG_DIR}/${PACKAGE}.${arch_ext} ;; esac @@ -761,7 +753,7 @@ ipkg_display_build_infos() echo " BUILD64: ${BUILD64}" echo " CFLAGS: ${CFLAGS}" echo " CPPFLAGS: ${CPPFLAGS}" - echo " CXXFLAGS: ${CFLAGS}" + echo " CXXFLAGS: ${CXXFLAGS}" echo " LDFLAGS: ${LDFLAGS}" echo " RANLIB: ${RANLIB}" echo " CC: ${CC}" @@ -776,6 +768,30 @@ ipkg_display_build_infos() echo " GCC CPU OPTIONS: ${GCCCPUOPT}" } +# Arg. #1: Package label +indicate_pkg_build_complete() +{ + # Checking for correct number of arguments + if [ $# -ne 1 ]; then + echo "${FUNCNAME}(): Missing argument(s)" + exit ${EXIT_FAILURE} + fi + + local HVLABEL=${1} + + # The following will be renamed to PACKAGE_DONE in one atomic operation. + local PACKAGE_STATUS=${LFS_LOG_DIR}/${HVLABEL}.status + local PACKAGE_DONE=${LFS_LOG_DIR}/${HVLABEL}.done + + ipkg_display_build_infos > ${PACKAGE_STATUS} + echo "Source size: " ${SOURCE_SIZE} >> ${PACKAGE_STATUS} + echo "Build size: " ${BUILD_SIZE} >> ${PACKAGE_STATUS} + echo -n "Build time: " >> ${PACKAGE_STATUS} + display_build_time >> ${PACKAGE_STATUS} + echo -e "\n" >> ${PACKAGE_STATUS} + mv ${PACKAGE_STATUS} ${PACKAGE_DONE} +} + # Installation of a package # Arg. #1: Package name and version (ex: gcc-4.5.1) # Remaining arguments: Additional configure options @@ -801,6 +817,9 @@ ipkg() local HVMAKE_ORIG=${HVMAKE} + # Make sure to get latest variables assignments (ex: pkg-config) + source /etc/profile + while getopts "jl:m:s:" flag ;do case ${flag} in j) @@ -858,12 +877,17 @@ ipkg() fi PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log + PACKAGE_DONE=${LFS_LOG_DIR}/${HVLABEL}.done + PACKAGE_STATUS=${LFS_LOG_DIR}/${HVLABEL}.status # Checking if package was previously successfully installed - if grep -q "^${HVLABEL} successfully installed" ${LFS_LOG_FILE}; then + if [ -f ${PACKAGE_DONE} ]; then return $EXIT_SUCCESS fi + # Create or empty status file + cp /dev/null ${PACKAGE_STATUS} + # Displaying label MSGSTRING="Installing ${HVLABEL}" display_checkbox_msg ${MSGSTRING} @@ -873,12 +897,6 @@ ipkg() echo "------------------------" 1>> ${LFS_LOG_FILE} echo "${MSGSTRING}" 1>> ${LFS_LOG_FILE} - exec 7>&1 # Save current "value" of stdout. - # All output from commands in this block sent to file $LFS_LOG_FILE. - exec >> ${LFS_LOG_FILE} 2>&1 - ipkg_display_build_infos - exec 1>&7 7>&- # Restore stdout and close file descriptor #7. - # All output from commands in this block sent to file $PACKAGE_LOG. exec > ${PACKAGE_LOG} 2>&1 @@ -895,14 +913,20 @@ ipkg() exec 1>&6 # Restore stdout. - # Writing success string to the end of the log file - echo "${HVLABEL} successfully installed" 1>> ${LFS_LOG_FILE} - - # Displaying build time after the package name + # Displaying build time after the package name. print_status success + # Indicate success in global log file. + echo "Completed" 1>> ${LFS_LOG_FILE} + + # Report successfull installation of the package. + indicate_pkg_build_complete ${HVLABEL} + ipkg_trap_end + # Make sure to update dynamic linker run-time bindings + ldconfig + return $EXIT_SUCCESS } @@ -953,12 +977,17 @@ rscr() fi PACKAGE_LOG=${LFS_LOG_DIR}/${HVLABEL}.log + PACKAGE_DONE=${LFS_LOG_DIR}/${HVLABEL}.done + PACKAGE_STATUS=${LFS_LOG_DIR}/${HVLABEL}.status if [ "x${SCRMODE}" = "xonce" ]; then # Checking if package was previously successfully installed - if grep -q "^${HVLABEL} successfully installed" ${LFS_LOG_FILE}; then + if [ -f ${PACKAGE_DONE} ]; then return $EXIT_SUCCESS fi + + # Create or empty status file + cp /dev/null ${PACKAGE_STATUS} fi display_checkbox_msg ${MSGSTRING} @@ -966,19 +995,22 @@ rscr() ipkg_trap_setup echo "------------------------" 1>> ${LFS_LOG_FILE} - echo ${HVLABEL} 1>> ${LFS_LOG_FILE} + echo "Running script ${HVLABEL}" 1>> ${LFS_LOG_FILE} # Executing script ${SCRDIR}/${SCRIPT} ${SCRIPT_ARGS} 1>> ${PACKAGE_LOG} 2>&1 + # Displaying build time after the package name. + print_status success + + # Indicate success in global log file. + echo "Completed" 1>> ${LFS_LOG_FILE} + if [ "x${SCRMODE}" = "xonce" ]; then - # Writing success string to the end of the log file - echo "${HVLABEL} successfully installed" 1>> ${LFS_LOG_FILE} + # Report successfull installation of the script. + indicate_pkg_build_complete ${HVLABEL} fi - # Displaying build time after the package name - print_status success - ipkg_trap_end return $EXIT_SUCCESS @@ -1065,7 +1097,7 @@ get_total_build_time() exit ${EXIT_FAILURE} fi - TIMES=$(cat ${INFILE} | grep "Build time:" | sed "s!Build time: \(.*\)h!\1!g") + TIMES=$(cat ${LFS_LOG_DIR}/*.done | grep "Build time:" | sed "s!Build time: \(.*\)h!\1!g") for time in ${TIMES}; do HOURS=$(( $HOURS + $(echo ${time} | sed "s!^\([0-9]*\)\..*!\1!g") )) @@ -1087,27 +1119,22 @@ display_build_time() END_TIME=$(echo `date +%s`) HOURS=$(( ( ${END_TIME} - ${START_TIME} ) / 3600 )) - echo -n " ("${HOURS}"." - echo -n " Build time: ${HOURS}." 1>> ${LFS_LOG_FILE} + echo -n ${HOURS}"." # Time is inferior to 1 hour... MINUTES=$(( ( ( ${END_TIME} - ${START_TIME} ) % 3600 ) / 36 )) if [ ${MINUTES} -lt 10 ]; then echo -n "0" - echo -n "0" 1>> ${LFS_LOG_FILE} fi if [ ${MINUTES} -eq 0 ]; then echo -n "1" - echo -n "1" 1>> ${LFS_LOG_FILE} else echo -n ${MINUTES} - echo -n ${MINUTES} 1>> ${LFS_LOG_FILE} fi - echo -n "h)" - echo "h" 1>> ${LFS_LOG_FILE} + echo -n "h" } # Global variable: MSGSTRING @@ -1155,7 +1182,9 @@ print_status() echo -en "${BRACKET}[${COLOR}X${BRACKET}]${NORMAL} ${MSGSTRING}" if [ "x${MSGSTRING}" != "x" ]; then + echo -n " (" display_build_time + echo -n ")" fi echo