This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
fake-aaa_elflibs.sh
executable file
·232 lines (217 loc) · 6.26 KB
/
fake-aaa_elflibs.sh
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/sh
#
#-- fake-aaa_elflibs 0.4 --
# Generate a fake aaa_elflibs file list to use in /var/log/packages to fool
# pkgtools to not remove essential libraries.
#--
# Script by Phantom X <megaphantomx at bol.com.br>
#
# Copyright 2011-2015 Phantom X, Goiania, Brazil.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Set arch - x86_64 sets lib64
ARCH=${ARCH:-x86_64}
if [ "${ARCH}" = "x86_64" ] ;then
LIBDIRSUFFIX=64
else
LIBDIRSUFFIX=""
fi
unset C32
txt() {
cat <<EOF
Usage :
$0 [-c] -f <file>
$0 -t <file>
-c|--compat32 Set creation of compat32 file (must be set before -f|--file)
-f|--file Create /var/log/packages file from a compliant list (see template option).
-t|--template Create a template for use with create option.
-h|--help Show this message.
EOF
}
header(){
cat <<EOF
PACKAGE NAME: $1
PACKAGE DESCRIPTION:
aaa_elflibs${C32}: aaa_elflibs${C32} (shared libraries needed by many programs)
aaa_elflibs${C32}:
aaa_elflibs${C32}: This is a collection of shared libraries needed to run Linux programs.
aaa_elflibs${C32}: ELF (Executable and Linking Format) is the standard Linux binary
aaa_elflibs${C32}: format. These libraries are gathered from other Slackware packages
aaa_elflibs${C32}: and are intended to give a fairly complete initial set of libraries.
aaa_elflibs${C32}: This package should be not upgraded or reinstalled (it could copy
aaa_elflibs${C32}: over newer library versions).
aaa_elflibs${C32}:
aaa_elflibs${C32}:
aaa_elflibs${C32}:
FILE LIST:
EOF
}
# Search .so first
testso(){
libso=$1
if [ -f /lib${LIBDIRSUFFIX}/${libso}.so ] ;then
testsoname /lib${LIBDIRSUFFIX}/${libso}.so
elif [ -f /usr/lib${LIBDIRSUFFIX}/${libso}.so ] ;then
testsoname /usr/lib${LIBDIRSUFFIX}/${libso}.so
fi
}
# Search for .so.*
testso2(){
libso=$1
if [ -f /lib${LIBDIRSUFFIX}/${libso} ] ;then
testfullname /lib${LIBDIRSUFFIX}/${libso}
echo lib${LIBDIRSUFFIX}/${libso}
elif [ -f /usr/lib${LIBDIRSUFFIX}/${libso} ] ;then
testfullname /usr/lib${LIBDIRSUFFIX}/${libso}
echo usr/lib${LIBDIRSUFFIX}/${libso}
fi
}
# Now soname
testsoname(){
libsoname="$(objdump -p $1 | grep SONAME | awk '{print $2}' 2>/dev/null)"
if [ -f /lib${LIBDIRSUFFIX}/${libsoname} ] ;then
testfullname /lib${LIBDIRSUFFIX}/${libsoname}
echo lib${LIBDIRSUFFIX}/${libsoname}
elif [ -f /usr/lib${LIBDIRSUFFIX}/${libsoname} ] ;then
testfullname /usr/lib${LIBDIRSUFFIX}/${libsoname}
echo usr/lib${LIBDIRSUFFIX}/${libsoname}
fi
}
# Now full file name
testfullname(){
libfullname=$(basename $(readlink $1) 2>/dev/null)
if [ -f /lib${LIBDIRSUFFIX}/${libfullname} ] ;then
echo lib${LIBDIRSUFFIX}/${libfullname}
elif [ -f /usr/lib${LIBDIRSUFFIX}/${libfullname} ] ;then
echo usr/lib${LIBDIRSUFFIX}/${libfullname}
fi
}
filetest(){
if [ $1 -eq 0 ] ;then
echo "${2} created"
else
echo "${2} not created"
return 5
fi
}
main(){
tmp=$(mktemp -d)
trap cleanup EXIT
cleanup() {
set +e
[ -z "${tmp}" -o ! -d "${tmp}" ] || rm -rf "${tmp}"
}
libsfile=$1
if [ -z "${libsfile}" ] || ! [ -r "${libsfile}" ] ;then
echo 'No file entered or file not readable!'
return 1
else
if head -n1 "${libsfile}" | grep -q -v '### fake-aaa_elflibs file ###' 2>/dev/null ;then
echo "No header in ${libsfile}"
return 2
fi
VERSION=$(grep ^VERSION= "${libsfile}" | cut -d= -f2)
if [ -z "${VERSION}" ] ;then
echo "No VERSION set in ${libsfile}"
return 2
fi
BUILD=$(grep ^BUILD= "${libsfile}" | cut -d= -f2)
if [ -z "${BUILD}" ] ;then
echo "No BUILD set in ${libsfile}"
return 2
fi
filename=aaa_elflibs${C32}-${VERSION}-"${ARCH}"-${BUILD}
if [ -r "${tmp}/${filename}" ] ;then
echo "A file ${tmp}/${filename} already exists"
return 2
else
echo "${ARCH} - lib${LIBDIRSUFFIX}"
echo -n "Searching libraries "
for lib in $(sed -n '9,$p' "${libsfile}" | sed '/^#/d;/^$/d' ) ;do
case ${lib} in
*.so.*)
testso2 ${lib} >> ${tmp}/${filename}.tmp
;;
*)
testso ${lib} >> ${tmp}/${filename}.tmp
;;
esac
echo -n .
done
echo
echo
header ${filename} > ${tmp}/${filename}
sort ${tmp}/${filename}.tmp >> ${tmp}/${filename}
filetest $? "./${filename}"
cp -f ${tmp}/${filename} .
echo
echo "Now, put ${filename} in /var/log/packages and profit"
fi
fi
}
ctemplate(){
tempfile=$1
if [ -r "${tempfile}" ] ;then
echo "A file ${tempfile} already exists"
return 2
elif [ -z "${tempfile}" ] ;then
echo "No file entered"
txt
return 3
else
cat > "${tempfile}" <<'EOF'
### fake-aaa_elflibs file ###
# put version of resulted file
VERSION=
# put build of resulted file
BUILD=
#
#### Insert library names after this line. Lines starting with # or blank are ignored.
################################################################################
libacl
EOF
filetest $? "${tempfile}"
fi
}
case "$1" in
-h|--help|-c|--compat32|-f|--file|-t|--template)
;;
*)
txt
exit 0
;;
esac
while [ -n "$1" ] ;do
case "$1" in
-h|--help)
txt
exit 0
;;
-c|--compat32)
export C32='-compat32'
export LIBDIRSUFFIX=""
;;
-f|--file)
main $2
;;
-t|--template)
ctemplate $2
;;
esac
shift
done