blob: f9867048e2d669a061d1e3259cac0b3be63f5d3f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#!/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 -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
done
# fast hack
LDLINUX=$(ldd $FILE | grep ld-linux | awk '{print $1}' |cut -c2-)
echo "/$LDLINUX" >> $COPYFILES_LIST
tar -cpv $(readlink "/$LDLINUX") | tar -xpv -C $INIT_DIR
case $LDLINUX in
*lib/*)
#cp -a /lib/ld-* $INIT_DIR/lib/ ;;
#tar -cpv $(readlink "/$LDLINUX") | tar -xpv -C $INIT_DIR
;;
*lib64/*)
#cp -a /lib64/ld-* $INIT_DIR/lib64/ ;;
#tar -cpv "/lib64/ld-*" | tar -xpv -C $INIT_DIR
;;
esac
for FILENAME in $REQUIRED_FILES
do
for f in $(find . -name $FILENAME)
do
[ $(file $f |grep -c ELF) -eq 0 ] && 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
}
main () {
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
else
echo "Tool directory not found."
fi
shift
done
}
main $@
|