1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
|
3 |
# mage upgrade |
# mage upgrade |
4 |
# version: 0.3.6-r10 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mageupgrade.sh,v 1.11 2005-08-28 19:19:25 niro Exp $ |
5 |
|
|
6 |
# some default vars |
# some default vars |
7 |
: ${MLIBDIR=/usr/lib/mage} |
: ${MLIBDIR=/usr/lib/mage} |
8 |
: ${DEBUG=false} |
: ${DEBUG=false} |
9 |
: ${AUTOANSWER=false} |
: ${AUTOANSWER=false} |
10 |
|
: ${SRCINSTALL=false} |
11 |
|
: ${AUTOCLEAN=false} |
12 |
|
: ${NO_CALC=false} |
13 |
|
|
14 |
source /etc/mage.rc |
source /etc/mage.rc |
15 |
source ${MLIBDIR}/mage3.functions.sh |
source ${MLIBDIR}/mage3.functions.sh |
16 |
|
source /etc/init.d/functions |
17 |
|
|
18 |
unset UPGRADE_LIST |
unset UPGRADE_LIST |
19 |
unset PLEASE_VALIDATE |
unset PLEASE_VALIDATE |
20 |
|
|
21 |
|
if [[ ${NOCOLORS} = true ]] |
22 |
|
then |
23 |
|
COLRED="" |
24 |
|
COLGREEN="" |
25 |
|
COLYELLOW="" |
26 |
|
COLBLUE="" |
27 |
|
COLMAGENTA="" |
28 |
|
COLWHITE="" |
29 |
|
COLDEFAULT="" |
30 |
|
fi |
31 |
|
|
32 |
|
usage() |
33 |
|
{ |
34 |
|
echo |
35 |
|
echo "Usage: $(basename $0) [command] ..." |
36 |
|
echo |
37 |
|
echo " --help shows this help" |
38 |
|
echo " --calc only calculates the dependencies" |
39 |
|
echo " --calc-bash only calculates the deps but with scriptable output" |
40 |
|
echo " output: categorie,pname,oldpver,newpver" |
41 |
|
echo " --no-calc do not show deps, running straight forward" |
42 |
|
echo " --autoclean clean all downloaded files automatically" |
43 |
|
echo " --autoanswer answer all questions automatically" |
44 |
|
echo " --src-install install from sources rather from binary packages" |
45 |
|
echo " --debug show debug messages" |
46 |
|
echo |
47 |
|
exit 1 |
48 |
|
} |
49 |
|
|
50 |
|
# get options |
51 |
|
for opt in $@ |
52 |
|
do |
53 |
|
case ${opt} in |
54 |
|
--no-calc) |
55 |
|
NO_CALC=true |
56 |
|
;; |
57 |
|
--calc) |
58 |
|
ONLY_CALC_DEPS=true |
59 |
|
;; |
60 |
|
--calc-bash) |
61 |
|
ONLY_CALC_DEPS_SCRIPTABLE=true |
62 |
|
;; |
63 |
|
--autoclean) |
64 |
|
AUTOCLEAN=true |
65 |
|
;; |
66 |
|
--autoanswer) |
67 |
|
AUTOANSWER=true |
68 |
|
;; |
69 |
|
--src-install) |
70 |
|
SRCINSTALL=true |
71 |
|
;; |
72 |
|
--debug) |
73 |
|
DEBUG=true |
74 |
|
;; |
75 |
|
--help) |
76 |
|
usage |
77 |
|
;; |
78 |
|
*) |
79 |
|
usage |
80 |
|
;; |
81 |
|
esac |
82 |
|
done |
83 |
|
|
84 |
|
# show this only if ONLY_CALC_DEPS_SCRIPTABLE is not set |
85 |
|
[[ ${ONLY_CALC_DEPS_SCRIPTABLE} != true ]] && \ |
86 |
|
echo "Fetching list of all installed packages ..." |
87 |
|
|
88 |
# get list |
# get list |
89 |
for directory in ${INSTALLDB}/* |
for directory in ${INSTALLDB}/* |
90 |
do |
do |
91 |
# supress virtuals and fake packages or files |
# supress virtuals and fake packages or files |
92 |
x=$(basename ${directory}) |
x=$(basename ${directory}) |
93 |
if [ ${x} = fake ] || |
if [ ${x} = virtual ] || |
|
[ ${x} = virtual ] || |
|
94 |
[ ${x} = virtuals ] || |
[ ${x} = virtuals ] || |
95 |
[ ${x} = virtuals.old ] || |
[ ${x} = virtuals.old ] || |
96 |
[ ! -d ${directory} ] |
[ ! -d ${directory} ] |
108 |
|
|
109 |
# check if there is any higher version in mage db |
# check if there is any higher version in mage db |
110 |
|
|
111 |
#needed packages may have ben renamed ?? |
# needed packages may have been renamed ?? |
112 |
if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ] |
if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ] |
113 |
then |
then |
114 |
CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null |
CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null |
115 |
|
|
116 |
#compare them |
# compare them |
117 |
if [[ $(basename ${HIGHEST_MAGEFILE} .mage) > ${PNAME}-${PVER}-${PBUILD} ]] |
if [[ $(basename ${HIGHEST_MAGEFILE} .mage) > ${PNAME}-${PVER}-${PBUILD} ]] |
118 |
then |
then |
119 |
UPGRADE_LIST="${UPGRADE_LIST} ${PNAME}" |
UPGRADE_LIST="${UPGRADE_LIST} ${PNAME}" |
120 |
|
SHOW_LIST="${SHOW_LIST}:${PCAT}/${PNAME},[${PVER}-${PBUILD} -> $(basename ${HIGHEST_MAGEFILE#${HIGHEST_MAGEFILE%-*-*}-} .mage)]" |
121 |
|
SHOW_LIST_SCRIPTABLE="${SHOW_LIST_SCRIPTABLE}:${PCAT},${PNAME},${PVER}-${PBUILD},$(basename ${HIGHEST_MAGEFILE#${HIGHEST_MAGEFILE%-*-*}-} .mage)" |
122 |
else |
else |
123 |
# put them only on PLEASE_VALIDATE if they are not the same package |
# put them only on PLEASE_VALIDATE if they are not the same package |
124 |
if [[ $(basename ${HIGHEST_MAGEFILE} .mage) != ${PNAME}-${PVER}-${PBUILD} ]] |
if [[ $(basename ${HIGHEST_MAGEFILE} .mage) != ${PNAME}-${PVER}-${PBUILD} ]] |
125 |
then |
then |
126 |
echo "Not added: ${PNAME}-${PVER}-${PBUILD} is newer than $(basename ${HIGHEST_MAGEFILE} .mage)." |
# show this only if ONLY_CALC_DEPS_SCRIPTABLE is not set |
127 |
|
[[ ${ONLY_CALC_DEPS_SCRIPTABLE} != true ]] && \ |
128 |
|
echo "Not added: ${PNAME}-${PVER}-${PBUILD} is newer than $(basename ${HIGHEST_MAGEFILE} .mage)." |
129 |
PLEASE_VALIDATE="${PLEASE_VALIDATE} ${PNAME}-${PVER}-${PBUILD}" |
PLEASE_VALIDATE="${PLEASE_VALIDATE} ${PNAME}-${PVER}-${PBUILD}" |
130 |
fi |
fi |
131 |
fi |
fi |
132 |
fi |
fi |
133 |
|
|
134 |
#unset some vars for shure |
# unset some vars for sure |
135 |
unset x |
unset x |
136 |
unset PNAME |
unset PNAME |
137 |
unset PVER |
unset PVER |
145 |
|
|
146 |
unset package directory |
unset package directory |
147 |
|
|
148 |
echo |
if [[ ${NO_CALC} = false ]] && [[ ${AUTOANSWER} = false ]] |
149 |
echo "I'm now ready to upgrade your system." |
then |
150 |
echo "Press any key to continue or [CTRL-C] to abort ..." |
# show the list |
151 |
echo |
if [[ ${ONLY_CALC_DEPS_SCRIPTABLE} = true ]] |
152 |
read |
then |
153 |
|
OLDIFS="${IFS}" |
154 |
|
IFS=: |
155 |
|
for package in ${SHOW_LIST_SCRIPTABLE} |
156 |
|
do |
157 |
|
# only if not empty # scriptable output |
158 |
|
[ -n "${package}" ] && echo "${package}" |
159 |
|
done |
160 |
|
IFS="${OLDIFS}" |
161 |
|
else |
162 |
|
echo |
163 |
|
echo "Packages selected for upgrade:" |
164 |
|
OLDIFS="${IFS}" |
165 |
|
IFS=: |
166 |
|
for package in ${SHOW_LIST} |
167 |
|
do |
168 |
|
# nice output :) |
169 |
|
echo -en \\033[10G |
170 |
|
echo -en ${COLGREEN}"$(echo ${package} | cut -d',' -f1)"${COLDEFAULT} |
171 |
|
echo -en \\033[40G |
172 |
|
echo -e ${COLBLUE}"$(echo ${package} | cut -d',' -f2)"${COLDEFAULT} |
173 |
|
done |
174 |
|
IFS="${OLDIFS}" |
175 |
|
fi |
176 |
|
# exit now if only_calc_deps is set |
177 |
|
[[ ${ONLY_CALC_DEPS} = true ]] || \ |
178 |
|
[[ ${ONLY_CALC_DEPS_SCRIPTABLE} = true ]] && exit 0 |
179 |
|
|
180 |
#now run the update |
echo |
181 |
|
echo "I'm now ready to upgrade your system." |
182 |
|
echo "Press any key to continue or [CTRL-C] to abort ..." |
183 |
|
echo |
184 |
|
read |
185 |
|
fi |
186 |
|
|
187 |
|
|
188 |
|
# now run the update |
189 |
for package in ${UPGRADE_LIST} |
for package in ${UPGRADE_LIST} |
190 |
do |
do |
191 |
/sbin/mage install ${package} || exit 1 |
if [[ ${SRCINSTALL} = false ]] |
192 |
|
then |
193 |
|
/sbin/mage install ${package} || exit 1 |
194 |
|
else |
195 |
|
/sbin/mage srcinstall ${package} || exit 1 |
196 |
|
fi |
197 |
|
|
198 |
if [[ ${DEBUG} = true ]] |
if [[ ${DEBUG} = true ]] |
199 |
then |
then |
200 |
echo "Installation of ${package} completed." |
echo "Installation of ${package} completed." |
208 |
else |
else |
209 |
MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1 |
MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1 |
210 |
fi |
fi |
211 |
|
|
212 |
|
if [[ ${AUTOCLEAN} = true ]] |
213 |
|
then |
214 |
|
/sbin/mage clean || exit 1 |
215 |
|
if [[ ${SRCINSTALL} = true ]] && \ |
216 |
|
[ -d ${SOURCEDIR}/${package} ] |
217 |
|
then |
218 |
|
rm -f ${SOURCEDIR}/${package} || exit 1 |
219 |
|
fi |
220 |
|
fi |
221 |
|
|
222 |
if [[ ${DEBUG} = true ]] |
if [[ ${DEBUG} = true ]] |
223 |
then |
then |
224 |
echo "Uninstallation of ${package} completed." |
echo "Uninstallation of ${package} completed." |
225 |
echo "Press any key to continue ..." |
echo "Press any key to continue ..." |
226 |
read |
read |
227 |
fi |
fi |
228 |
|
|
229 |
#resource /etc/profile |
# resource /etc/profile |
230 |
source /etc/profile |
source /etc/profile |
231 |
done |
done |
232 |
|
|
233 |
echo "The system upgrade is now complete." |
echo "The system upgrade is now complete." |
234 |
echo -n "Would you like to see the list of ignored packages ? [ y/n ] " |
|
235 |
read answer |
if [ -n "${PLEASE_VALIDATE}" ] && [[ ${AUTOANSWER} = false ]] |
|
if [[ ${answer} = y ]] |
|
236 |
then |
then |
237 |
echo |
echo -n "Would you like to see the list of ignored packages ? [ y/n ] " |
238 |
for i in ${PLEASE_VALIDATE} |
read answer |
239 |
do |
if [[ ${answer} = y ]] |
240 |
echo "avoided: ${i}" |
then |
241 |
done |
echo |
242 |
|
for i in ${PLEASE_VALIDATE} |
243 |
|
do |
244 |
|
echo "avoided: ${i}" |
245 |
|
done |
246 |
|
fi |
247 |
fi |
fi |
248 |
|
|
249 |
echo |
echo |