summaryrefslogtreecommitdiffstats
path: root/remote/setup_tools
diff options
context:
space:
mode:
authorJonathan Bauer2012-12-20 15:33:34 +0100
committerJonathan Bauer2012-12-20 15:33:34 +0100
commitf6dad6269ab3228ead055291b846d2a9edb04564 (patch)
tree30096a5fbd037fe4f9f0a0ef2b68d04317883c8e /remote/setup_tools
parentstatic unit files for dbus, cleanup (diff)
downloadtm-scripts-f6dad6269ab3228ead055291b846d2a9edb04564.tar.gz
tm-scripts-f6dad6269ab3228ead055291b846d2a9edb04564.tar.xz
tm-scripts-f6dad6269ab3228ead055291b846d2a9edb04564.zip
mltk basic script :)
Diffstat (limited to 'remote/setup_tools')
-rwxr-xr-xremote/setup_tools188
1 files changed, 188 insertions, 0 deletions
diff --git a/remote/setup_tools b/remote/setup_tools
new file mode 100755
index 00000000..cf96df7b
--- /dev/null
+++ b/remote/setup_tools
@@ -0,0 +1,188 @@
+#!/bin/bash
+
+MODULE_DIR=${ROOT_DIR}/remote
+
+#Create tools directory if not exists
+TOOL_DIR=${MODULE_DIR}/tools
+INIT_DIR=${MODULE_DIR}/stage3.2
+
+setup_git ()
+{
+ if [ ! -z "${GIT}" ]; then
+ GIT_BIN=$(which git)
+ [ -z "${GIT_BIN}" ] && echo "Installing git..." && apt-get install git
+ fi
+}
+
+read_config ()
+{
+ TOOL_CONFIG=${TOOL_DIR}/${TOOL}/${TOOL}.conf
+
+ if [ ! -e ${TOOL_CONFIG} ]; then
+ echo "ERROR: Config for specified tool not found."
+ exit 1
+ fi
+
+ . ${TOOL_CONFIG}
+}
+
+read_build ()
+{
+ BUILD_SCRIPT=${TOOL_DIR}/${TOOL}/${TOOL}.build
+
+ if [ ! -e ${BUILD_SCRIPT} ]; then
+ echo "ERROR: Build script for specified tool not found."
+ exit 1
+ fi
+
+ . ${BUILD_SCRIPT}
+}
+
+copyfileswithdependencies ()
+{
+ [ ! -d build ] && echo "No build directory for ${TOOL} found." && return
+ cd build
+
+
+ COPYFILES_LIST="list_wanted_stage3.2"
+ [ -e ${COPYFILES_LIST} ] && rm ${COPYFILES_LIST}
+
+ for FILENAME in ${REQUIRED_BINARIES}
+ do
+ for f in $(find . -name ${FILENAME} -type f -executable)
+ do
+ [ $(file $f |grep -c ELF) -eq 1 ] && FILE=$f
+ done
+ echo "Found ${FILENAME} at ${FILE}. Searching libraries..."
+ echo ${FILE} >> ${COPYFILES_LIST}
+ # fetch dependencies
+ # quick fix to exclude libc*, else it copies unneeded libs...
+ for i in $(ldd ${FILE} |awk '{print $1 $2 $3}'|grep -v ld-linux|grep -v libc.so*|grep -v linux-gate)
+ do
+ arrIN=(${i//=>/ })
+ echo "--------------------------------------------------------"
+ echo "Searching ${arrIN[0]} under $(pwd)..."
+ LOCAL_MATCHES=$(find . -name $(echo ${arrIN[0]}|awk -F "." '{print $1}').*)
+ if [ "x${LOCAL_MATCHES}" != "x" ];
+ then
+ for llib in ${LOCAL_MATCHES};
+ do
+ echo "Copying ${llib}"
+ echo ${llib} >> ${COPYFILES_LIST}
+ done
+ else
+ echo "Did not found ${arrIN[0]} in $(pwd)"
+ if [ -e ${arrIN[1]} ];
+ then
+ echo -n "Trying ${arrIN[1]} ..."
+ echo " found! Copying."
+ echo ${arrIN[1]} >> ${COPYFILES_LIST}
+ [ -L ${arrIN[1]} ] && echo $(readlink -f ${arrIN[1]}) >> ${COPYFILES_LIST}
+ fi
+ fi
+ done
+ echo "Copied ${FILENAME}."
+ echo "-----------------------------------------------------------------"
+ done
+
+ for LIB in ${REQUIRED_LIBRARIES}
+ do
+ for LOCATION in $(find . -name ${LIB}*)
+ do
+ echo ${LOCATION} >> ${COPYFILES_LIST}
+ done
+ done
+
+ echo "Copying required directories and files from config file..."
+ for ENTRY in ${REQUIRED_DIRECTORIES} ${REQUIRED_FILES}
+ do
+ echo ".${ENTRY}" >> ${COPYFILES_LIST}
+ done
+
+ #copy to initramfsdir
+ tar -cpv $(cat ${COPYFILES_LIST}|sort -u) | tar -xpv -C ${INIT_DIR} &>/dev/null
+ unset REQUIRED_BINARIES
+ unset REQUIRED_LIBRARIES
+ unset REQUIRED_DIRECTORIES
+ unset REQUIRED_FILES
+}
+
+get_basic_libs () {
+
+ [ ! -d ${INIT_DIR} ] && mkdir ${INIT_DIR}
+
+ # copy libc and ld-linux separatly
+ echo "Looking for libc and ld-linux used for ${SHELL}..."
+ 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 "Found basic lib at: $i"
+ BASICLIBS="${BASICLIBS} $i $(readlink -f "$i")"
+ fi
+ done
+ tar -cpv ${BASICLIBS} | tar -xpv -C ${INIT_DIR} &>/dev/null
+ echo "Basic libs copied."
+}
+
+generate_stage32 () {
+
+ # if no arguments assume all.
+ if [ "x$1" = "x" -o "x$1" = "xall" ]; then
+ tools=$(ls ${TOOL_DIR})
+ set -- $tools
+ fi
+
+ # first copy libc and ld-linux
+ get_basic_libs
+
+ # now iterate over given tools and copy them
+ cd ${TOOL_DIR}
+ while (( "$#" )); do
+ TOOL=$1
+ if [ -d ${TOOL} ];
+ then
+ cd ${TOOL}
+ read_config
+ read_build
+ setup_git
+ install_dependencies
+ fetch_source
+ build
+ copyfileswithdependencies
+ post_copy
+ cd ${TOOL_DIR}
+ else
+ echo "Tool directory not found."
+ fi
+ shift
+ done
+
+}
+
+clean_sys() {
+ if [ "x$1" = "x" -o "x$1" = "xall" ]; then
+ #clean all
+ [ -d ${INIT_DIR} ] && rm -rf ${INIT_DIR}
+ for TOOL in $(ls ${TOOL_DIR}); do
+ clean_tool $TOOL
+ done
+ else
+ while (( "$#" )); do
+ clean_tool $1
+ shift
+ done
+ fi
+}
+clean_tool() {
+ TOOLDIR=${TOOL_DIR}/$1
+ echo "Cleaning ${TOOLDIR}"
+ [ -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
+}
+
+#generate_stage32 $@