summaryrefslogblamecommitdiffstats
path: root/remote/setup-tools.sh
blob: da42ad0bc68f2381b7892ed087039a87e3883ad6 (plain) (tree)


















                                                                  

                            
 
               
 
                                              








                                                                   
            






                                                                                    
























                                                                                                                                                  
                       












                                         
#!/bin/bash

ROOT_DIR=$(readlink -f $(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/initramfs

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
}

setup_git ()
{
	if [ ! -z "$GIT" ]; then
		GIT_BIN=$(which git)
		[ -z "$GIT_BIN" ] && echo "Installing git..." && apt-get install git
	fi
}

copyfileswithdependencies () {
	cd $VERSION/tmp
	COPYFILES_LIST="copyfiles.list"

  for FILENAME in $REQUIRED_BINARIES
  do
		for f in $(find . -name $FILENAME -type f -executable); do [ $(file $f |grep -i Executable |grep -c ELF) -eq 1 ] && FILE=$f ; done
		echo $FILE >> $COPYFILES_LIST
		#fetch dependencies
		for i in $(ldd $FILE |awk -F ">" '{print $2}'|awk '{print $1}'|grep ^/)
		do
			filename_base=$(basename $i | awk -F "." '{print $1}') 
			filename_path=$(dirname $i)
			echo "$filename_path/$filename_base*" >> $COPYFILES_LIST
		done
		#copy to initramfsdir
		tar -cpv $(cat $COPYFILES_LIST) | tar -xpv -C $INSTALL_DIR
	done 
}

main () {

	setup_git

	while (( "$#" )); do
		TOOL=$1
		read_config
		install_dependencies
		fetch_source
		build
		copyfileswithdependencies
		shift
	done

}


main $@