-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibcheck
More file actions
executable file
·137 lines (129 loc) · 3.64 KB
/
libcheck
File metadata and controls
executable file
·137 lines (129 loc) · 3.64 KB
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
#!/bin/bash
#Script to check dependencies and the corresponding package.
#Only root can run equery
if [ $(whoami) != 'root' ]; then
echo "Must be root to run $0"
exit 1;
fi
filename="/tmp/out"
temp="/tmp/temp"
tmp_pack="/tmp/tmp_pack"
declare -a LibrariesArray=()
declare -a PackagesArray=()
declare -a TempArray=()
toolchoice="$1"
tool=""
NULL=""
Version="0.1"
MsgVer="depcheck $Version \n
Dependency/Package finder for portage/gentoo.\n
Written by Petross404 (petross404@gmail.com) \n
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
"
Warning="Warning! This tool is based on ldd. Don't use depcheck or
ldd to figure out the dependencies of a binary you don't trust!
Use objdump -p /path/file or sudo pldd <PID> instead in that case."
#check which tool the user prefers.
if [[ -z "$toolchoice" ]]
then
echo -e "Please re-run and append output file or tool"
echo -e ""
echo -e "Usage: $0 [options] output file..."
echo -e "options:"
echo -e ""
echo -e "--e-file Use e-file (PFL) to search online"
echo -e "--equery Use equery (gentoolkit) to search locally (slow)"
echo -e "--fquery Use fquery (fquery) to search locally (faster)"
echo -e "--version $MsgVer
"
echo -e "$Warning"
exit
fi
if [[ "$1" = "--equery" ]]; then
option=" b -e"
tool="equery$option"
elif [[ "$1" = "--fquery" ]]; then
option=" b"
tool="fquery$option"
elif [[ "$1" = "--e-file" ]]; then
tool="e-file"
elif [[ "$1" = "--version" ]]; then
echo -e $MsgVer
exit
elif [[ "$1" = "--warning" ]]; then
echo -e $Warning
echo -e "For more info follow this link \n
http://ask.xmodulo.com/check-library-dependency-program-process-linux.html"
exit;
else
echo "Typing error";
exit;
fi
if [[ "$3" != "--quiet" || "$3" != "-q" ]]; then
echo -e "$Warning"
echo -e ""
fi
if [[ -x "$2" ]]; then
echo "File found."
else
echo "File not found, not executable or typing error."
exit 1;
fi
#Keep only the libName.so and not the whole output
ldd "$2" | grep '=' | cut -d'=' -f2 | cut -d'(' -f1 | cut -d'>' -f2-256 > "$filename"
echo -e "\n$2 uses these libraries: "
echo "$(<"$filename")"
value=`$tool $2`
echo -e "and the binary belongs to \c"
echo "$value" | [ -z "$value" ] && echo 'UKNOWN package' || echo "$value"
echo -e "\nIt will take time to process the libraries..."
#spinner will keep a busy cursor
spinner()
{
local pid=$1
local delay=0.1
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
spin(){
pid=$! # Process Id of the previous running command
spin='-\|/'
i=0
while kill -0 $pid 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "[%c]" "${spin:$i:1}"
sleep .2
printf "\b\b\b"
done
}
#Go on and process the entries in the filename
counter=0
echo -e "" > "$temp"
while read -r line
do
echo "$counter"
lib="$line"
LibrariesArray[$counter]="$lib" && printf "\n $lib belongs to :"
PackagesArray[$counter]=( `$tool ${LibrariesArray[$counter]} | nl -s = | cut -c7- ` & )
spin $!
#PackagesArray["$counter"]=$(</dev/stdout)
#PackagesArray["$counter"]=$(echo -e"$package")
sleep .5
#The [] will now be replaced by space chars
printf ' %0.s' {0..4}
echo ${PackagesArray[$counter"]}
echo "${PackagesArray[@]}"
let counter="$(( $counter + 1 ))"
done < "$filename"
echo "Outside loop"
#echo "${PackagesArray[@]}" | awk '{for(i=1;i<=NF;i++)a[$i]++}END{for(o in a) printf "%s %s \n",o,a[o]}'
#echo "${PackagesArray[@]}"
rm "$filename"