f39beaa1ad6ac21c0f10e40d8076fba5aa24e755
[febootstrap.git] / febootstrap-minimize.sh
1 #!/bin/bash -
2 # febootstrap minimize
3 # (C) Copyright 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # Written by Richard W.M. Jones <rjones@redhat.com>
20
21 TEMP=`getopt \
22         -o '' \
23         --long help,all,none,keep-locales,drop-locales,keep-docs,drop-docs,keep-yum-cache,drop-yum-cache,keep-cracklib,drop-cracklib,keep-i18n,drop-i18n,keep-zoneinfo,drop-zoneinfo \
24         -n febootstrap-minimize -- "$@"`
25 if [ $? != 0 ]; then
26     echo "febootstrap-minimize: problem parsing the command line arguments"
27     exit 1
28 fi
29 eval set -- "$TEMP"
30
31 set_all ()
32 {
33   keep_locales=no
34      keep_docs=no
35 keep_yum_cache=no
36  keep_cracklib=no
37      keep_i18n=no
38  keep_zoneinfo=no
39 }
40
41 set_none ()
42 {
43   keep_locales=yes
44      keep_docs=yes
45 keep_yum_cache=yes
46  keep_cracklib=yes
47      keep_i18n=yes
48  keep_zoneinfo=yes
49 }
50
51 set_all
52
53 usage ()
54 {
55     echo "Usage: febootstrap-minimize [--options] DIR"
56     echo "Please read febootstrap-minimize(8) man page for more information."
57 }
58
59 while true; do
60     case "$1" in
61         --all)
62             set_all
63             shift;;
64         --none)
65             set_none
66             shift;;
67         --keep-locales)
68             keep_locales=yes
69             shift;;
70         --drop-locales)
71             keep_locales=no
72             shift;;
73         --keep-docs)
74             keep_docs=yes
75             shift;;
76         --drop-docs)
77             keep_docs=no
78             shift;;
79         --keep-yum-cache)
80             keep_yum_cache=yes
81             shift;;
82         --drop-yum-cache)
83             keep_yum_cache=no
84             shift;;
85         --keep-cracklib)
86             keep_cracklib=yes
87             shift;;
88         --drop-cracklib)
89             keep_cracklib=no
90             shift;;
91         --keep-i18n)
92             keep_i18n=yes
93             shift;;
94         --drop-i18n)
95             keep_i18n=no
96             shift;;
97         --keep-zoneinfo)
98             keep_zoneinfo=yes
99             shift;;
100         --drop-zoneinfo)
101             keep_zoneinfo=no
102             shift;;
103         --help)
104             usage
105             exit 0;;
106         --)
107             shift
108             break;;
109         *)
110             echo "Internal error!"
111             exit 1;;
112     esac
113 done
114
115 if [ $# -lt 1 ]; then
116     usage
117     exit 1
118 fi
119
120 target="$1"
121
122 #----------------------------------------------------------------------
123
124 if [ ! -d "$target" ]; then
125     echo "febootstrap-minimize: $target: target directory not found"
126     exit 1
127 fi
128
129 #du -sh "$target"
130
131 if [ "$keep_locales" != "yes" ]; then
132     rm -f "$target"/usr/lib/locale/*
133     rm -rf "$target"/usr/share/locale
134 fi
135
136 if [ "$keep_docs" != "yes" ]; then
137     rm -rf "$target"/usr/share/man
138     rm -rf "$target"/usr/share/doc
139 fi
140
141 if [ "$keep_yum_cache" != "yes" ]; then
142     rm -rf "$target"/var/cache/yum/*
143 fi
144
145 if [ "$keep_cracklib" != "yes" ]; then
146     rm -rf "$target"/usr/share/cracklib
147 fi
148
149 if [ "$keep_i18n" != "yes" ]; then
150     rm -rf "$target"/usr/share/i18n
151 fi
152
153 if [ "$keep_zoneinfo" != "yes" ]; then
154     mv "$target"/usr/share/zoneinfo/{UCT,UTC,Universal,Zulu,GMT*,*.tab} \
155       "$target"
156     rm -rf "$target"/usr/share/zoneinfo/*
157     mv "$target"/{UCT,UTC,Universal,Zulu,GMT*,*.tab} \
158       "$target"/usr/share/zoneinfo/
159 fi