blob: 98d27cf0ae11a6e4a1095644ea0c1762697a61b8 (
plain) (
tree)
|
|
#!/bin/bash
ROOT_DIR=$(dirname $(readlink -f $0))
SELF=$(readlink -f $0)
print_usage() {
echo "create tools for minilinux"
echo "Usage: $(basename $SELF) TOOL"
}
if [ "x$1" = "x" ]; then
print_usage
exit 0
elif [ "x$(whoami)" != "xroot" ]; then
echo "ERROR: You need to have root rights to install packages."
exit 1
fi
#Create tools directory if not exists
TOOL_DIR=$ROOT_DIR/tools
INIT_DIR=$ROOT_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/build.$TOOL
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
[ ! -d $INIT_DIR ] && mkdir $INIT_DIR
COPYFILES_LIST="copyfiles.list"
[ -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 $FILE >> $COPYFILES_LIST
# fetch dependencies
# quick fix to exclude libc*, else it copies unneeded libs...
for i in $(ldd $FILE |awk -F ">" '{print $2}'|awk '{print $1}'|grep ^/|grep -v libc.so*)
do
filename_base=$(basename $i | awk -F "." '{print $1}')
filename_path=$(dirname $i)
echo "$filename_path/$filename_base*" >> $COPYFILES_LIST
done
done
for FILENAME in $REQUIRED_FILES
do
for f in $(find . -name $FILENAME)
do
FILE=$f
echo $FILE >> $COPYFILES_LIST
done
#echo $FILE >> $COPYFILES_LIST
done
#copy to initramfsdir
tar -cpv $(cat $COPYFILES_LIST) | tar -xpv -C $INIT_DIR &>/dev/null
}
get_basic_libs () {
# 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."
}
main () {
get_basic_libs
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
cd $TOOL_DIR
else
echo "Tool directory not found."
fi
shift
done
}
main $@
|