summaryrefslogtreecommitdiffstats
path: root/remote/setup_tools
diff options
context:
space:
mode:
authorSimon Rettberg2013-02-21 22:24:35 +0100
committerSimon Rettberg2013-02-21 22:24:35 +0100
commit9804c991491e7f2ea9da3b4c9210595a3d336dfd (patch)
treea060a1f8bc2b7bb953b4182181caceb1f928f0c7 /remote/setup_tools
parentMerge branch 'master' of ssh://openslx/openslx-ng/tm-scripts (diff)
downloadtm-scripts-9804c991491e7f2ea9da3b4c9210595a3d336dfd.tar.gz
tm-scripts-9804c991491e7f2ea9da3b4c9210595a3d336dfd.tar.xz
tm-scripts-9804c991491e7f2ea9da3b4c9210595a3d336dfd.zip
1. New logging/output system - use functions provided by helper/logging.inc
2. Update modules to use new logging system - already updated policykit and systemd as an example 3. Stop all processing if a critical error occurs (use perror to notify user) 4. Some minor tweaks and fixes to setup_tools (added more error checking, but still incomplete)
Diffstat (limited to 'remote/setup_tools')
-rwxr-xr-xremote/setup_tools193
1 files changed, 101 insertions, 92 deletions
diff --git a/remote/setup_tools b/remote/setup_tools
index aaa7a23b..76f163f5 100755
--- a/remote/setup_tools
+++ b/remote/setup_tools
@@ -8,40 +8,35 @@ INIT_DIR=${MODULE_DIR}/stage3.2
initial_checks ()
{
- for BIN in $(which git) $(which locate)
+ for BIN in git locate
do
- [ -z $BIN ] && echo "Installing $BIN..." && apt-get install $BIN
+ local TEST=$(which ${BIN})
+ [ -z "$TEST" ] && pinfo "Installing $BIN..." && apt-get install $BIN
done
}
read_config ()
{
- TOOL_CONFIG=${TOOL_DIR}/${TOOL}/${TOOL}.conf
+ local TOOL_CONFIG=${TOOL_DIR}/${TOOL}/${TOOL}.conf
- if [ ! -e ${TOOL_CONFIG} ]; then
- echo "ERROR: Config for specified tool not found."
- exit 1
- fi
+ [ ! -e ${TOOL_CONFIG} ] && perror "Config for '$TOOL' not found."
. ${TOOL_CONFIG}
}
read_build ()
{
- BUILD_SCRIPT=${TOOL_DIR}/${TOOL}/${TOOL}.build
+ local BUILD_SCRIPT=${TOOL_DIR}/${TOOL}/${TOOL}.build
- if [ ! -e ${BUILD_SCRIPT} ]; then
- echo "ERROR: Build script for specified tool not found."
- exit 1
- fi
+ [ ! -e ${BUILD_SCRIPT} ] && perror "Build script for specified tool not found."
. ${BUILD_SCRIPT}
}
copyfileswithdependencies ()
{
- [ ! -d build ] && echo "No build directory for ${TOOL} found." && return
+ [ ! -d build ] && pinfo "No build directory found, skipping dependency copying" && return 0
cd build
@@ -49,21 +44,16 @@ copyfileswithdependencies ()
[ -e ${COPYFILES_LIST} ] && rm ${COPYFILES_LIST}
- echo -e "\n\n*********************************************************"
- echo "*"
- echo "* Copying required binaries from config file..."
- echo "*"
- echo -e "*********************************************************\n\n"
+ [ ! -z "${REQUIRED_BINARIES}" ] && pinfo "Gathering required binaries from config file..."
for FILENAME in ${REQUIRED_BINARIES}
do
- FILE=$(find . -name ${FILENAME} -type f -executable | xargs grep -l ELF)
+ FILE=$(find . -name ${FILENAME} -type f -executable | xargs grep -l '^.ELF') # FIXME: What happens on multiple matches? Maybe add " | head -1"
if [ -z "$FILE" ]; then
- echo -e "\tNo Binary found for ${FILENAME}. Skipping."
- echo "-----------------------------------------------------------------"
+ pwarning "\tNo Binary found for ${FILENAME}. Skipping."
continue
fi
- echo -e "\tFound ${FILENAME} at ${FILE}"
- echo ${FILE} >> ${COPYFILES_LIST}
+ pdebug "\tFound ${FILENAME} at ${FILE}"
+ echo "${FILE}" >> "${COPYFILES_LIST}"
# fetch dependencies
# quick fix to exclude libc*, else it copies unneeded libs...
# workaround for
@@ -71,104 +61,100 @@ copyfileswithdependencies ()
ldd_exit_code=$?
if [ "x$ldd_exit_code" != "x0" ];
then
- echo -e "\tldd $FILE failed."
+ pdebug "\tldd $FILE failed."
continue
fi
- for i in $(ldd ${FILE} |awk '{print $1 $2 $3}'|grep -v ld-linux|grep -v libc.so*|grep -v linux-gate|grep -v linux-vdso)
+ for i in $(ldd "${FILE}" | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso)
do
arrIN=(${i//=>/ })
- echo -en "\t\t${arrIN[0]}"
- LOCAL_MATCHES=$(find . -name $(echo ${arrIN[0]}|awk -F "." '{print $1}').so*)
+ pdebug "* ${arrIN[0]}"
+ LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*)
if [ "x${LOCAL_MATCHES}" != "x" ];
then
for llib in ${LOCAL_MATCHES};
do
- echo -ne " ->${llib}"
- echo ${llib} >> ${COPYFILES_LIST}
+ pdebug " at ${llib}"
+ echo ${llib} >> "${COPYFILES_LIST}"
done
- echo ""
else
if [ -e ${arrIN[1]} ];
then
- echo ${arrIN[1]} >> ${COPYFILES_LIST}
+ echo ${arrIN[1]} >> "${COPYFILES_LIST}"
if [ ! -L ${arrIN[1]} ];
then
- echo -e " -> ${arrIN[1]}"
+ pdebug " at ${arrIN[1]}"
else
- echo -e " -> ${arrIN[1]} -> $(readlink -f ${arrIN[1]})"
+ pdebug " at ${arrIN[1]} -> $(readlink -f ${arrIN[1]})"
echo $(readlink -f ${arrIN[1]}) >> ${COPYFILES_LIST}
fi
fi
fi
done
- echo -e "\t-------------------------------------------------------------------------------------------------------------"
done
+ [ ! -z "${REQUIRED_LIBRARIES}" ] && pinfo "Gathering required libraries from config file..."
for LIB in ${REQUIRED_LIBRARIES}
do
for LOCATION in $(find . -name ${LIB}*)
do
+ pdebug "* $LOCATION"
echo ${LOCATION} >> ${COPYFILES_LIST}
done
done
- echo -e "\n\n*********************************************************"
- echo "*"
- echo "* Copying required directories from config file..."
- echo "*"
- echo -e "*********************************************************\n\n"
+ [ ! -z "${REQUIRED_DIRECTORIES}" ] && pinfo "Gathering required directories from config file..."
+ local CURRENT_PWD=$(pwd) # Prevent calling pwd 50000 times inside the loop below
for ENTRY in ${REQUIRED_DIRECTORIES}
do
- echo ".${ENTRY}" >> ${COPYFILES_LIST}
- for BIN in $(find .${ENTRY} -type f -not -name "*.a" | xargs grep -l ELF)
- do
- echo -e "\tSearching libs for ${BIN}..."
- for i in $(ldd ${BIN} |awk '{print $1 $2 $3}'|grep -v ld-linux|grep -v libc.so*|grep -v linux-gate|grep -v linux-vdso)
+ pdebug "* ./$ENTRY"
+ echo "./${ENTRY}" >> "${COPYFILES_LIST}"
+ for BIN in $(find "./${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF')
+ do
+ pdebug " Searching libs for ${BIN}..."
+ for i in $(ldd ${BIN} | awk '{print $1 $2 $3}' | grep -v ld-linux | grep -v libc.so | grep -v linux-gate | grep -v linux-vdso)
do
arrIN=(${i//=>/ })
- echo -e "\t\t---------------------------------------------------------"
- echo -ne "\t\tSearching ${arrIN[0]} under $(pwd)..."
- LOCAL_MATCHES=$(find . -name $(echo ${arrIN[0]}|awk -F "." '{print $1}').so*)
+ pdebug " Searching for ${arrIN[0]}...($i)"
+ local LOCAL_MATCHES=$(find . -name "$(echo ${arrIN[0]} | awk -F '.' '{print $1}')".so\*)
if [ "x${LOCAL_MATCHES}" != "x" ];
then
for llib in ${LOCAL_MATCHES};
do
- echo -en "\n\t\tCopying ${llib}"
- echo ${llib} >> ${COPYFILES_LIST}
+ pdebug " Found locally, copying ${llib}"
+ echo ${llib} >> "${COPYFILES_LIST}"
done
- echo ""
else
- echo " not found."
- if [ ! -z ${arrIN[1]} ];
+ if [ ! -z ${arrIN[1]} ] && [ "x${arrIN[1]}" != "xnot" ];
then
- echo -e "\t\tCopying from system ${arrIN[1]} ..."
- echo ${arrIN[1]} >> ${COPYFILES_LIST}
- [ -L ${arrIN[1]} ] && echo $(readlink -f ${arrIN[1]}) >> ${COPYFILES_LIST}
+ pdebug " Not found locally but in system, copying ${arrIN[1]}"
+ echo ${arrIN[1]} >> "${COPYFILES_LIST}"
+ [ -L ${arrIN[1]} ] && echo $(readlink -f "${arrIN[1]}") >> "${COPYFILES_LIST}"
+ else
+ pwarning "Lib '${arrIN[0]}' from required dir '$ENTRY' neither found in build directory nor on this system."
+ pwarning "If this lib is not supplied by another module, this module will probably fail in your final system"
fi
fi
done
- echo -e "\tCopied $BIN"
- echo -e "\t-------------------------------------------------------------------------------------------------------------"
done
- echo -e "\t Copied directory $ENTRY"
done
- echo "*********************************************************"
- echo "*"
- echo "* Copying required files from config file..."
- echo "*"
- echo "*********************************************************"
+ [ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..."
for ENTRY in ${REQUIRED_FILES}
do
- echo ".${ENTRY}" >> ${COPYFILES_LIST}
- echo -e "\t Copied file $ENTRY"
+ echo "./${ENTRY}" >> "${COPYFILES_LIST}"
done
#copy to initramfsdir
- echo "[stage32] Completed file list generation at ${TOOL_DIR}/${TOOL}/build/${COPYFILES_LIST}."
- (tar -cpv $(cat ${COPYFILES_LIST}|sort -u) | tar -xpv -C ${INIT_DIR}) &>/dev/null
+ pdebug "[stage32] Completed file list generation at ${TOOL_DIR}/${TOOL}/build/${COPYFILES_LIST}."
+ if [ -s "$COPYFILES_LIST" ]; then
+ local CLISTCOUNT=$(cat "$COPYFILES_LIST" | wc -l)
+ pinfo "Copying $CLISTCOUNT files to stage 3.2 target directory."
+ tar -cp $(cat ${COPYFILES_LIST}|sort -u) | tar -xp -C "${INIT_DIR}"
+ local RET=$?
+ [ "x$RET" != "x0" ] && perror "Could not tar-copy to $INIT_DIR"
+ fi
unset REQUIRED_BINARIES
unset REQUIRED_LIBRARIES
unset REQUIRED_DIRECTORIES
@@ -180,17 +166,19 @@ get_basic_libs () {
[ ! -d ${INIT_DIR} ] && mkdir ${INIT_DIR}
# copy libc and ld-linux separatly
- echo "----------------------------------------------------"
+ pinfo "Adding basic libs"
BASICLIBS=""
for i in $(ldd ${SHELL})
do
if [ $(echo $i | grep '^/' | grep -c ld) -eq 1 -o $(echo $i | grep '^/' | grep -c libc.so) -eq 1 ];
then
- echo "Copied $i"
+ pdebug "Adding $i"
BASICLIBS="${BASICLIBS} $i $(readlink -f "$i")"
fi
done
- (tar -cpv ${BASICLIBS} | tar -xpv -C ${INIT_DIR}) &>/dev/null
+ tar -cp ${BASICLIBS} | tar -xp -C ${INIT_DIR}
+ local RET=$?
+ [ "x$RET" != "x0" ] && perror "Could not tar-copy to $INIT_DIR"
}
generate_stage32 () {
@@ -211,32 +199,40 @@ generate_stage32 () {
TOOL=$1
if [ -d ${TOOL} ];
then
- echo "###################################################################################"
- echo "# BUILDING $TOOL"
- echo "#"
+ TOOL_STR="[${TOOL}]"
+ pinfo "## ## Processing module ## ##"
- [ "x$DEBUG" != "x1" ] \
- && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \
- && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log
- cd ${TOOL}
+ #[ "x$DEBUG" != "x1" ] \
+ # && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \
+ # && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log
+ # TODO: Make above work with the new logging system (add function to logging.inc to switch logfile)
+ cd "${TOOL}"
+ pinfo "## Reading config"
read_config
- read_build
+ pinfo "## Reading build"
+ read_build
+ pinfo "## Installing dependencies"
install_dependencies
+ pinfo "## Fetching source"
fetch_source
+ pinfo "## Building"
build
# remove *.la files as they might confuse libtool/linker of other tool packages
find "${TOOL_DIR}/${TOOL}/build" -name '*.la' -exec rm -f {} \;
+ pinfo "## Copying files with dependencies"
copyfileswithdependencies
+ pinfo "## Post copy"
post_copy
cd ${TOOL_DIR}
# reset pipes
- [ "x$DEBUG" != "x1" ] && exec 1>&6 6>&-
- echo "#"
- echo "# DONE"
- echo "###################################################################################"
+ #[ "x$DEBUG" != "x1" ] && exec 1>&6 6>&-
+ # TODO
+ pinfo "## ## Module completed ## ##"
+ TOOL_STR=""
else
- echo "Tool directory not found."
+ perror "Tool directory for '$TOOL' not found."
+ # maybe make this a warning instead of error?
fi
shift
done
@@ -245,8 +241,11 @@ generate_stage32 () {
clean_tools() {
if [ "x$1" = "x" -o "x$1" = "xall" ]; then
#clean all
- [ -d ${INIT_DIR} ] && echo -n "Cleaning ${INIT_DIR}..." \
- && rm -rf ${INIT_DIR} && echo " done."
+ if [ -d ${INIT_DIR} ]; then
+ pinfo "Cleaning ${INIT_DIR}..."
+ rm -rf "${INIT_DIR}" || perror "Error deleting $INIT_DIR"
+ pinfo "done."
+ fi
for TOOL in $(ls ${TOOL_DIR}); do
clean_tool $TOOL
done
@@ -260,17 +259,27 @@ clean_tools() {
clean_tool() {
TOOLDIR=${TOOL_DIR}/$1
- echo -n "Cleaning ${TOOLDIR}..."
+ pinfo "Cleaning ${TOOLDIR}..."
#[ -e ${TOOLDIR}/build/list_wanted_stage3.2 ] && cd ${INIT_DIR} \
# && xargs rm < ${TOOLDIR}/build/list_wanted_stage3.2
#[ -d ${TOOLDIR}/data ] && cd ${INIT_DIR} \
# && xargs rm < $(find ${TOOLDIR}/data -type f)
- [ -e ${TOOLDIR}/.built ] && rm ${TOOLDIR}/.built
- [ -e ${TOOLDIR}/.fetched_source ] && rm ${TOOLDIR}/.fetched_source
- [ -d ${TOOLDIR}/build ] && rm -rf ${TOOLDIR}/build
- [ -d ${TOOLDIR}/src ] && rm -rf ${TOOLDIR}/src
- [ -e ${TOOLDIR}/list_binaries_and_files ] && rm ${TOOLDIR}/list_binaries_and_files
- echo " done."
+ if [ -e ${TOOLDIR}/.built ]; then
+ rm "${TOOLDIR}/.built" || perror "Could not clear built flag"
+ fi
+ if [ -e ${TOOLDIR}/.fetched_source ]; then
+ rm "${TOOLDIR}/.fetched_source" || perror "Could not clear fetched_source flag"
+ fi
+ if [ -d ${TOOLDIR}/build ]; then
+ rm -rf "${TOOLDIR}/build" || perror "Could not delete build path"
+ fi
+ if [ -d ${TOOLDIR}/src ]; then
+ rm -rf "${TOOLDIR}/src" || perror "Could not delete src path"
+ fi
+ if [ -e ${TOOLDIR}/list_binaries_and_files ]; then
+ rm "${TOOLDIR}/list_binaries_and_files" || perror "Could not delete list_binaries_and_files"
+ fi
+ pinfo "done."
}
#generate_stage32 $@