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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
#!/bin/bash -
# febootstrap minimize
# (C) Copyright 2009 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Written by Richard W.M. Jones <rjones@redhat.com>
unset CDPATH
TEMP=`getopt \
-o '' \
--long help,all,none,keep-locales,drop-locales,keep-docs,drop-docs,keep-cracklib,drop-cracklib,keep-i18n,drop-i18n,keep-zoneinfo,drop-zoneinfo,keep-rpmdb,drop-rpmdb,keep-yum-cache,drop-yum-cache,keep-services,drop-services,keep-sln,drop-sln,keep-ldconfig,drop-ldconfig,no-pack-executables,pack-executables \
-n febootstrap-minimize -- "$@"`
if [ $? != 0 ]; then
echo "febootstrap-minimize: problem parsing the command line arguments"
exit 1
fi
eval set -- "$TEMP"
set_all ()
{
keep_locales=no
keep_docs=no
keep_cracklib=no
keep_i18n=no
keep_zoneinfo=no
keep_rpmdb=no
keep_yum_cache=no
keep_services=no
keep_sln=no
keep_ldconfig=no
}
set_none ()
{
keep_locales=yes
keep_docs=yes
keep_cracklib=yes
keep_i18n=yes
keep_zoneinfo=yes
keep_rpmdb=yes
keep_yum_cache=yes
keep_services=yes
keep_sln=yes
keep_ldconfig=yes
}
set_all
pack_executables=no
usage ()
{
echo "Usage: febootstrap-minimize [--options] DIR"
echo "Please read febootstrap-minimize(8) man page for more information."
}
while true; do
case "$1" in
--all)
set_all
shift;;
--none)
set_none
shift;;
--keep-locales)
keep_locales=yes
shift;;
--drop-locales)
keep_locales=no
shift;;
--keep-docs)
keep_docs=yes
shift;;
--drop-docs)
keep_docs=no
shift;;
--keep-cracklib)
keep_cracklib=yes
shift;;
--drop-cracklib)
keep_cracklib=no
shift;;
--keep-i18n)
keep_i18n=yes
shift;;
--drop-i18n)
keep_i18n=no
shift;;
--keep-zoneinfo)
keep_zoneinfo=yes
shift;;
--drop-zoneinfo)
keep_zoneinfo=no
shift;;
--keep-rpmdb)
keep_rpmdb=yes
shift;;
--drop-rpmdb)
keep_rpmdb=no
shift;;
--keep-yum-cache)
keep_yum_cache=yes
shift;;
--drop-yum-cache)
keep_yum_cache=no
shift;;
--keep-services)
keep_services=yes
shift;;
--drop-services)
keep_services=no
shift;;
--keep-sln)
keep_sln=yes
shift;;
--drop-sln)
keep_sln=no
shift;;
--keep-ldconfig)
keep_ldconfig=yes
shift;;
--drop-ldconfig)
keep_ldconfig=no
shift;;
--no-pack-executables)
pack_executables=no
shift;;
--pack-executables)
pack_executables=yes
shift;;
--help)
usage
exit 0;;
--)
shift
break;;
*)
echo "Internal error!"
exit 1;;
esac
done
if [ $# -lt 1 ]; then
usage
exit 1
fi
target="$1"
if [ ! -d "$target" ]; then
echo "febootstrap-minimize: $target: target directory not found"
exit 1
fi
# Create a temporary directory, make sure it gets cleaned up at the end.
tmpdir=$(mktemp -d)
remove_tmpdir ()
{
status=$?
rm -rf "$tmpdir" && exit $status
}
trap remove_tmpdir EXIT
#----------------------------------------------------------------------
if [ "$keep_locales" != "yes" ]; then
rm -f "$target"/usr/lib/locale/*
rm -rf "$target"/usr/share/locale
rm -rf "$target"/usr/lib*/gconv
rm -f "$target"/usr/bin/localedef
rm -f "$target"/usr/sbin/build-locale-archive
fi
if [ "$keep_docs" != "yes" ]; then
rm -rf "$target"/usr/share/man
rm -rf "$target"/usr/share/doc
rm -rf "$target"/usr/share/info
rm -rf "$target"/usr/share/gnome/help
fi
if [ "$keep_cracklib" != "yes" ]; then
rm -rf "$target"/usr/share/cracklib
fi
if [ "$keep_i18n" != "yes" ]; then
rm -rf "$target"/usr/share/i18n
fi
if [ "$keep_zoneinfo" != "yes" ]; then
mv "$target"/usr/share/zoneinfo/{UCT,UTC,Universal,Zulu,GMT*,*.tab} \
"$target"
rm -rf "$target"/usr/share/zoneinfo/*
mv "$target"/{UCT,UTC,Universal,Zulu,GMT*,*.tab} \
"$target"/usr/share/zoneinfo/
fi
if [ "$keep_rpmdb" != "yes" ]; then
rm -rf "$target"/var/lib/rpm/*
fi
if [ "$keep_yum_cache" != "yes" ]; then
rm -rf "$target"/var/cache/yum/*
fi
if [ "$keep_services" != "yes" ]; then
# NB: Overwrite the same file so that we have the same inode,
# since fakeroot tracks files by inode number.
cat > "$target"/etc/services <<'__EOF__'
tcpmux 1/tcp
tcpmux 1/udp
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
ftp 21/tcp
ftp 21/udp fsp fspd
ssh 22/tcp
ssh 22/udp
telnet 23/tcp
telnet 23/udp
smtp 25/tcp mail
smtp 25/udp mail
time 37/tcp timserver
time 37/udp timserver
nameserver 42/tcp name
nameserver 42/udp name
domain 53/tcp
domain 53/udp
bootps 67/tcp
bootps 67/udp
bootpc 68/tcp dhcpc
bootpc 68/udp dhcpc
tftp 69/tcp
tftp 69/udp
finger 79/tcp
finger 79/udp
http 80/tcp www www-http
http 80/udp www www-http
http 80/sctp
kerberos 88/tcp kerberos5 krb5
kerberos 88/udp kerberos5 krb5
pop3 110/tcp pop-3
pop3 110/udp pop-3
sunrpc 111/tcp portmapper rpcbind
sunrpc 111/udp portmapper rpcbind
auth 113/tcp authentication tap ident
auth 113/udp authentication tap ident
ntp 123/tcp
ntp 123/udp
imap 143/tcp imap2
imap 143/udp imap2
snmp 161/tcp
snmp 161/udp
snmptrap 162/tcp
snmptrap 162/udp snmp-trap
__EOF__
fi
if [ "$keep_sln" != "yes" ]; then
rm -f "$target"/sbin/sln
fi
if [ "$keep_ldconfig" != "yes" ]; then
rm -f "$target"/sbin/ldconfig
rm -f "$target"/etc/ld.so.cache
rm -rf "$target"/var/cache/ldconfig/*
fi
if [ "$pack_executables" = "yes" ]; then
# NB. Be careful to keep the same inode number, since fakeroot
# tracks files by inode number.
for path in $(find "$target" -type f -perm /111 |
xargs file |
grep executable |
awk -F: '{print $1}'); do
base=$(basename "$path")
cp "$path" "$tmpdir"
(cd "$tmpdir" && upx -q -q --best "$base")
cat "$tmpdir"/"$base" > "$path"
rm "$tmpdir"/"$base"
done
fi
|