-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions
145 lines (124 loc) · 2.58 KB
/
functions
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
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh
scan_deps(){
# This is really hacky but it might just work for most things
ldd "$1" | tr -d "\t=" | cut -d "(" -f 1 | while read line; do
case "$line" in
"not a dynamic executable"*)
printf "Can't properly read dependencies, this may not work\n"
break
;;
"statically"*)
# Statically linked, we're done
break
;;
"linux-vdso"*)
# Skip, provided by kernel
;;
*" > "*)
want_lib "$(printf "%s" "$line" | tr -d "[:space:]" | cut -d ">" -f 1)" "$(printf "%s" "$line" | tr -d "[:space:]" | cut -d ">" -f 2)"
;;
*)
want_lib "$line"
;;
esac
done
}
want_bin(){
binpath=$(which "$1")
if [ -z "$binpath" ]; then
printf "Failed to find binary %s\n" "$1"
exit 1
fi
if [ -x "./$binpath" ]; then
return 0
fi
printf "\tPulling in binary %s\n" "$1"
mkdir -p "./$(dirname $binpath)"
cp "$binpath" "./$binpath"
scan_deps "$binpath"
return 0
}
want_file(){
if [ ! -f "$1" ]; then
printf "No such file %s\n" "$1"
return 0
fi
printf "\tPulling in file %s\n" "$1"
mkdir -p "./$(dirname $1)"
cp "$1" "./$1"
return 0
}
want_lib(){
case "$1" in
/*)
# Direct-copy library
libpath="$1"
libname="$(basename "$1")"
;;
*)
# Test-find library
if [ -n "$2" ]; then
libpath="$2"
libname="$1"
else
# Need to find library path
printf "Functionality not yet implemented\n"
exit 1
fi
esac
if [ -f "./$libpath" ]; then
return 0
fi
printf "\tPulling in library %s\n" "$libname"
mkdir -p "./$(dirname $libpath)"
cp "$libpath" "./$libpath"
scan_deps "$libpath"
return 0
}
want_module_internal(){
modinfo=$(grep "$1" "/lib/modules/$(uname -r)/modules.dep" | head -n 1)
if [ -z "$modinfo" ]; then
printf "Module %s not found\n" "$1"
return 1
fi
modpath="/lib/modules/$(uname -r)/$(printf "%s" "$modinfo" | cut -d ":" -f 1)"
moddeps="$(printf "%s" "$modinfo" | cut -d ":" -f 2 | tr " " "\n")"
if [ -f ".$modpath" ]; then
return 0
fi
printf "\tPulling in module %s\n" "$(basename "$modpath")"
mkdir -p ".$(dirname $modpath)"
cp "$modpath" ".$modpath"
if [ -n "$moddeps" ]; then
for dep in $moddeps; do
want_module_internal "$dep:"
done
fi
return 0
}
want_module(){
printf "$1\n" >> modules
if [ -n "$2" ]; then
want_module_internal $2
else
want_module_internal $1
fi
}
want_module_dir(){
printf "Not yet implemented\n"
return 1
}
want_dir(){
case "$1" in
"/"*)
break;
;;
*)
printf "Cannot pull in directory %s based on relative paths\n" "$1"
return 1
;;
esac
printf "\tPulling in directory %s\n" "$1"
mkdir -p "./$1"
cp -dr "$1/." "./$1"
}