Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 187 - (hide annotations) (download) (as text)
Tue Aug 16 23:24:11 2005 UTC (18 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 4618 byte(s)
added command line parameters support

1 niro 32 #!/bin/bash
2    
3     # mage upgrade
4 niro 187 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mageupgrade.sh,v 1.10 2005-08-16 23:24:11 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 187 usage()
22     {
23     echo
24     echo "Usage: $(basename $0) [command] ..."
25     echo
26     echo " --help shows this help"
27     echo " --no-calc do not show deps, running straight forward"
28     echo " --autoclean clean all downloaded files automatically"
29     echo " --autoanswer answer all questions automatically"
30     echo " --src-install install from sources rather from binary packages"
31     echo " --debug show debug messages"
32     echo
33     exit 1
34     }
35    
36     # get options
37     for opt in $@
38     do
39     case ${opt} in
40     --no-calc)
41     NO_CALC=true
42     ;;
43     --autoclean)
44     AUTOCLEAN=true
45     ;;
46     --autoanswer)
47     AUTOANSWER=true
48     ;;
49     --src-install)
50     SRCINSTALL=true
51     ;;
52     --debug)
53     DEBUG=true
54     ;;
55     --help)
56     usage
57     ;;
58     *)
59     usage
60     ;;
61     esac
62     done
63    
64 niro 80 echo "Fetching list of all installed packages ..."
65    
66 niro 32 # get list
67     for directory in ${INSTALLDB}/*
68     do
69     # supress virtuals and fake packages or files
70     x=$(basename ${directory})
71 niro 166 if [ ${x} = virtual ] ||
72 niro 32 [ ${x} = virtuals ] ||
73     [ ${x} = virtuals.old ] ||
74     [ ! -d ${directory} ]
75     then
76     continue
77     fi
78    
79     for package in ${directory}/*
80     do
81     x=$(basename ${package})
82     PNAME=${x%-*-*}
83     PVER=$(echo ${x#${PNAME}-}| cut -d- -f1)
84     PBUILD=$(echo ${x#${PNAME}-}| cut -d- -f2)
85     PCAT=$(basename $(dirname ${package}))
86    
87     # check if there is any higher version in mage db
88    
89 niro 166 # needed packages may have been renamed ??
90 niro 32 if [ -d ${MAGEDIR}/${PCAT}/${PNAME} ]
91     then
92 niro 37 CATEGORIE=${PCAT} MAGENAME=${PNAME} get_highest_magefile &> /dev/null
93 niro 32
94 niro 166 # compare them
95 niro 32 if [[ $(basename ${HIGHEST_MAGEFILE} .mage) > ${PNAME}-${PVER}-${PBUILD} ]]
96     then
97     UPGRADE_LIST="${UPGRADE_LIST} ${PNAME}"
98 niro 80 SHOW_LIST="${SHOW_LIST}:${PCAT}/${PNAME},[${PVER}-${PBUILD} -> $(basename ${HIGHEST_MAGEFILE#${HIGHEST_MAGEFILE%-*-*}-} .mage)]"
99 niro 32 else
100     # put them only on PLEASE_VALIDATE if they are not the same package
101     if [[ $(basename ${HIGHEST_MAGEFILE} .mage) != ${PNAME}-${PVER}-${PBUILD} ]]
102     then
103     echo "Not added: ${PNAME}-${PVER}-${PBUILD} is newer than $(basename ${HIGHEST_MAGEFILE} .mage)."
104     PLEASE_VALIDATE="${PLEASE_VALIDATE} ${PNAME}-${PVER}-${PBUILD}"
105     fi
106     fi
107     fi
108    
109 niro 166 # unset some vars for sure
110 niro 32 unset x
111     unset PNAME
112     unset PVER
113     unset PBUILD
114     unset PCAT
115     unset CATEGORIE
116     unset MAGENAME
117     unset HIGHEST_MAGEFILE
118     done
119     done
120    
121     unset package directory
122    
123 niro 187 if [[ ${NO_CALC} = false ]] && [[ ${AUTOANSWER} = false ]]
124     then
125     # show the list
126     echo
127     echo "Packages selected for upgrade:"
128     OLDIFS="${IFS}"
129     IFS=:
130     for package in ${SHOW_LIST}
131     do
132     # nice output :)
133     echo -en \\033[10G
134     echo -en ${COLGREEN}"$(echo ${package} | cut -d',' -f1)"${COLDEFAULT}
135     echo -en \\033[40G
136     echo -e ${COLBLUE}"$(echo ${package} | cut -d',' -f2)"${COLDEFAULT}
137     done
138     IFS="${OLDIFS}"
139 niro 80
140 niro 187 echo
141     echo "I'm now ready to upgrade your system."
142     echo "Press any key to continue or [CTRL-C] to abort ..."
143     echo
144     read
145     fi
146 niro 80
147 niro 32
148 niro 166 # now run the update
149 niro 32 for package in ${UPGRADE_LIST}
150     do
151 niro 80 if [[ ${SRCINSTALL} = false ]]
152     then
153     /sbin/mage install ${package} || exit 1
154     else
155     /sbin/mage srcinstall ${package} || exit 1
156     fi
157 niro 166
158 niro 32 if [[ ${DEBUG} = true ]]
159     then
160     echo "Installation of ${package} completed."
161     echo "Press any key to continue ..."
162     read
163     fi
164    
165     if [[ ${AUTOANSWER} = true ]]
166     then
167     yes | MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1
168     else
169     MAGE_UNINSTALL_TIMEOUT=0 /sbin/mage uninstall ${package} || exit 1
170     fi
171 niro 166
172 niro 187 if [[ ${AUTOCLEAN} = true ]]
173     then
174     /sbin/mage clean || exit 1
175     if [[ ${SRCINSTALL} = true ]] && \
176     [ -d ${SOURCEDIR}/${package} ]
177     then
178     rm -f ${SOURCEDIR}/${package} || exit 1
179     fi
180     fi
181    
182 niro 32 if [[ ${DEBUG} = true ]]
183     then
184     echo "Uninstallation of ${package} completed."
185     echo "Press any key to continue ..."
186     read
187     fi
188 niro 166
189     # resource /etc/profile
190 niro 32 source /etc/profile
191     done
192    
193     echo "The system upgrade is now complete."
194 niro 80
195 niro 187 if [ -n "${PLEASE_VALIDATE}" ] && [[ ${AUTOANSWER} = false ]]
196 niro 32 then
197 niro 80 echo -n "Would you like to see the list of ignored packages ? [ y/n ] "
198     read answer
199     if [[ ${answer} = y ]]
200     then
201     echo
202     for i in ${PLEASE_VALIDATE}
203     do
204     echo "avoided: ${i}"
205     done
206     fi
207 niro 32 fi
208    
209     echo
210     echo "Please remember to run etc-update to update your config files."
211     echo "You should also source /etc/profile or re-login to your shell."
212     echo