Magellan Linux

Contents of /trunk/mage/usr/lib/mage/mageupgrade.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 211 - (show annotations) (download) (as text)
Sun Aug 28 19:19:25 2005 UTC (18 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 5807 byte(s)
- added --calc and --calc-bash
- added NOCOLOR option

1 #!/bin/bash
2
3 # mage upgrade
4 # $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
7 : ${MLIBDIR=/usr/lib/mage}
8 : ${DEBUG=false}
9 : ${AUTOANSWER=false}
10 : ${SRCINSTALL=false}
11 : ${AUTOCLEAN=false}
12 : ${NO_CALC=false}
13
14 source /etc/mage.rc
15 source ${MLIBDIR}/mage3.functions.sh
16 source /etc/init.d/functions
17
18 unset UPGRADE_LIST
19 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
89 for directory in ${INSTALLDB}/*
90 do
91 # supress virtuals and fake packages or files
92 x=$(basename ${directory})
93 if [ ${x} = virtual ] ||
94 [ ${x} = virtuals ] ||
95 [ ${x} = virtuals.old ] ||
96 [ ! -d ${directory} ]
97 then
98 continue
99 fi
100
101 for package in ${directory}/*
102 do
103 x=$(basename ${package})
104 PNAME=${x%-*-*}
105 PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)
106 PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)
107 PCAT=$(basename $(dirname ${package}))
108
109 # check if there is any higher version in mage db
110
111 # needed packages may have been renamed ??
112 if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ]
113 then
114 CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null
115
116 # compare them
117 if [[ $(basename ${HIGHEST_MAGEFILE} .mage) > ${PNAME}-${PVER}-${PBUILD} ]]
118 then
119 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
123 # put them only on PLEASE_VALIDATE if they are not the same package
124 if [[ $(basename ${HIGHEST_MAGEFILE} .mage) != ${PNAME}-${PVER}-${PBUILD} ]]
125 then
126 # 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}"
130 fi
131 fi
132 fi
133
134 # unset some vars for sure
135 unset x
136 unset PNAME
137 unset PVER
138 unset PBUILD
139 unset PCAT
140 unset CATEGORIE
141 unset MAGENAME
142 unset HIGHEST_MAGEFILE
143 done
144 done
145
146 unset package directory
147
148 if [[ ${NO_CALC} = false ]] && [[ ${AUTOANSWER} = false ]]
149 then
150 # show the list
151 if [[ ${ONLY_CALC_DEPS_SCRIPTABLE} = true ]]
152 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 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}
190 do
191 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 ]]
199 then
200 echo "Installation of ${package} completed."
201 echo "Press any key to continue ..."
202 read
203 fi
204
205 if [[ ${AUTOANSWER} = true ]]
206 then
207 yes | MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1
208 else
209 MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1
210 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 ]]
223 then
224 echo "Uninstallation of ${package} completed."
225 echo "Press any key to continue ..."
226 read
227 fi
228
229 # resource /etc/profile
230 source /etc/profile
231 done
232
233 echo "The system upgrade is now complete."
234
235 if [ -n "${PLEASE_VALIDATE}" ] && [[ ${AUTOANSWER} = false ]]
236 then
237 echo -n "Would you like to see the list of ignored packages ? [ y/n ] "
238 read answer
239 if [[ ${answer} = y ]]
240 then
241 echo
242 for i in ${PLEASE_VALIDATE}
243 do
244 echo "avoided: ${i}"
245 done
246 fi
247 fi
248
249 echo
250 echo "Please remember to run etc-update to update your config files."
251 echo "You should also source /etc/profile or re-login to your shell."
252 echo