TAR_OPTS="-b8"
# List of default archive extensions to try
-DEFAULT_ARCH_EXT_LIST="tar.bz2 tar.gz tgz tar.Z zip"
+DEFAULT_ARCH_EXT_LIST="tar.bz2 tar.gz tgz tar.Z tar.xz zip"
HV_FONTS_PATH="/usr/share/fonts"
# Scripts directory
export SCRDIR=$(pwd)
+ if [ ! -d "$(dirname $(pwd))/packages" ]; then
+ echo "Error, could not find packages directory \"$(dirname $(pwd))/packages\", aborting."
+ exit 1
+ fi
+
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
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()
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
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
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
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.
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
# 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
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
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