Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 211 - (hide 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 niro 32 #!/bin/bash
2    
3     # mage upgrade
4 niro 211 # $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 niro 32
6     # some default vars
7     : ${MLIBDIR=/usr/lib/mage}
8     : ${DEBUG=false}
9     : ${AUTOANSWER=false}
10 niro 80 : ${SRCINSTALL=false}
11 niro 187 : ${AUTOCLEAN=false}
12     : ${NO_CALC=false}
13 niro 32
14     source /etc/mage.rc
15     source ${MLIBDIR}/mage3.functions.sh
16 niro 80 source /etc/init.d/functions
17 niro 32
18     unset UPGRADE_LIST
19     unset PLEASE_VALIDATE
20    
21 niro 211 if [[ ${NOCOLORS} = true ]]
22     then
23     COLRED=""
24     COLGREEN=""
25     COLYELLOW=""
26     COLBLUE=""
27     COLMAGENTA=""
28     COLWHITE=""
29     COLDEFAULT=""
30     fi
31    
32 niro 187 usage()
33     {
34     echo
35     echo "Usage: $(basename $0) [command] ..."
36     echo
37     echo " --help shows this help"
38 niro 211 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 niro 187 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 niro 211 --calc)
58     ONLY_CALC_DEPS=true
59     ;;
60     --calc-bash)
61     ONLY_CALC_DEPS_SCRIPTABLE=true
62     ;;
63 niro 187 --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 niro 211 # 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 niro 80
88 niro 32 # get list
89     for directory in ${INSTALLDB}/*
90     do
91     # supress virtuals and fake packages or files
92     x=$(basename ${directory})
93 niro 166 if [ ${x} = virtual ] ||
94 niro 32 [ ${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 niro 166 # needed packages may have been renamed ??
112 niro 32 if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ]
113     then
114 niro 37 CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null
115 niro 32
116 niro 166 # compare them
117 niro 32 if [[ $(basename ${HIGHEST_MAGEFILE} .mage) > ${PNAME}-${PVER}-${PBUILD} ]]
118     then
119     UPGRADE_LIST="${UPGRADE_LIST} ${PNAME}"
120 niro 80 SHOW_LIST="${SHOW_LIST}:${PCAT}/${PNAME},[${PVER}-${PBUILD} -> $(basename ${HIGHEST_MAGEFILE#${HIGHEST_MAGEFILE%-*-*}-} .mage)]"
121 niro 211 SHOW_LIST_SCRIPTABLE="${SHOW_LIST_SCRIPTABLE}:${PCAT},${PNAME},${PVER}-${PBUILD},$(basename ${HIGHEST_MAGEFILE#${HIGHEST_MAGEFILE%-*-*}-} .mage)"
122 niro 32 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 niro 211 # 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 niro 32 PLEASE_VALIDATE="${PLEASE_VALIDATE} ${PNAME}-${PVER}-${PBUILD}"
130     fi
131     fi
132     fi
133    
134 niro 166 # unset some vars for sure
135 niro 32 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 niro 187 if [[ ${NO_CALC} = false ]] && [[ ${AUTOANSWER} = false ]]
149     then
150     # show the list
151 niro 211 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 niro 80
180 niro 187 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 niro 80
187 niro 32
188 niro 166 # now run the update
189 niro 32 for package in ${UPGRADE_LIST}
190     do
191 niro 80 if [[ ${SRCINSTALL} = false ]]
192     then
193     /sbin/mage install ${package} || exit 1
194     else
195     /sbin/mage srcinstall ${package} || exit 1
196     fi
197 niro 166
198 niro 32 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 niro 166
212 niro 187 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 niro 32 if [[ ${DEBUG} = true ]]
223     then
224     echo "Uninstallation of ${package} completed."
225     echo "Press any key to continue ..."
226     read
227     fi
228 niro 166
229     # resource /etc/profile
230 niro 32 source /etc/profile
231     done
232    
233     echo "The system upgrade is now complete."
234 niro 80
235 niro 187 if [ -n "${PLEASE_VALIDATE}" ] && [[ ${AUTOANSWER} = false ]]
236 niro 32 then
237 niro 80 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 niro 32 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