Magellan Linux

Annotation of /trunk/mlivecdbuild/files/mage3.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations) (download) (as text)
Wed Jan 5 05:36:10 2005 UTC (19 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 7778 byte(s)
mlivecdbuild-0.3.6-r7 import

1 niro 27 #!/bin/sh
2     # Magellan Linux Installer (mage.sh)
3     # version: 0.3.1
4    
5     ##configuration -> mage.rc
6     #PKGDIR="/usr/src/packages"
7     PKGSUFFIX="mpk"
8     #BUILDDIR="/usr/src"
9     #INSTALLDB="/var/ALXInstDB"
10     #MAGEDIR="/usr/src/mage-0.2"
11     MAGENAME="$2"
12     #PKGNAME="`basename $2 .mage`"
13     MLIBDIR=/usr/lib/mage
14    
15     ## nur für tests -> normalerweise in /etc/rc.d/init.d/functions
16     COLRED="\033[1;6m\033[31m"
17     COLGREEN="\033[1;6m\033[32m"
18     COLBLUE="\033[1;6m\033[34m"
19     COLDEFAULT="\033[0m"
20    
21    
22     ##functions
23     if [ -f /etc/mage.rc ]
24     then
25     source /etc/mage.rc
26     else
27     echo "Your /etc/mage.rc is missing. Aborting."
28     exit 1
29     fi
30    
31     #loads functions
32     source ${MLIBDIR}/mage3.functions.sh
33    
34     #############DIALOGE##############
35     print_usage(){
36     echo -e "\nUsage: $0 [option] pkgname ..."
37     echo "Options:"
38     echo -e "\tpretend - pretend package's depencies"
39     echo -e "\tinstall - installs package"
40     echo -e "\tuninstall - removes package"
41     echo -e "\tupdate - updates pkg database"
42     echo -e "\tclean - removes downloaded packages"
43     echo -e "\tunpack - unpacks package"
44     echo -e "\tdownload - downloads package"
45     echo -e "\tkeepfiles - prevents files from uninstalling"
46     echo -e "\tinject - inject a package to fake depencies"
47     echo -e "\treminjected - removes *all* fake packages"
48     echo
49     }
50    
51     xtitle() {
52     if [ ${TERM} == "xterm" ]
53     then
54     echo -ne "\033]0;Mage: $1\007"
55     fi
56     return 0
57     }
58    
59     xtitleclean() {
60     if [ ${TERM} == "xterm" ]
61     then
62     echo -ne "\033]0;\007"
63     fi
64     return 0
65     }
66    
67     spin_processbar() {
68     echo -en "Processing: "
69     while [ -f /var/tmp/proz ]
70     do
71     echo -en "-\b"
72     sleep 0.01
73     echo -en "\\ \b\b"
74     sleep 0.01
75     echo -en "|\b"
76     sleep 0.01
77     echo -en "/\b"
78     sleep 0.01
79     done
80     echo "done"
81     return 0
82     }
83    
84     #cuts full pathnames or versioniezed names down to basename
85     choppkgname(){
86     #we want this only if full name was used
87     if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
88     then
89     #cuts ARCH and PBUILD
90     #ARCH comes from /etc/mage.rc
91     MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
92    
93     #cuts version number
94     MAGENAME=$(basename ${MAGENAME%-*} .mage)
95     fi
96     }
97    
98     # get_categorie $PKGNAME, returns CATEGORIE
99     # ret 0=ok, 1=not_found
100     getcategorie(){
101    
102     for CAT in ${MAGEDIR}/*
103     do
104     if [ -d ${CAT}/${MAGENAME} ]
105     then
106     #debug only
107     if [ "$MAGEDEBUG" == "on" ]
108     then
109     echo "$MAGENAME found -> $CAT/$MAGENAME"
110     echo "categorie = $(basename ${CAT})"
111     fi
112     CATEGORIE=$(basename ${CAT})
113     fi
114     done
115    
116     #package does not exists
117     if [ -z "$CATEGORIE" ]
118     then
119     echo -e "Package "${COLRED}"\"${MAGENAME}\""${COLDEFAULT}" does not exists."
120     exit 1
121     fi
122     }
123    
124    
125     #check_stable_package /path/to/foo.mage
126     # returns 0=stable 1=unstable
127     check_stable_package(){
128     #be sure no previous $STATES exists
129     unset STATE
130    
131     source $1
132     if [ "${STATE}" != "stable" ]
133     then
134     return 1
135     fi
136    
137     #unset the sourced varibales;
138     #we'll got bad problems later on if we don't do this
139     unset PKGNAME
140     unset STATE
141     unset DESCRIPTION
142     unset HOMEPAGE
143     unset DEPEND
144     unset preinstall
145     unset postinstall
146    
147     return 0
148     }
149    
150     #get_highest_magefile ${CATEGORIE} ${PKGNAME}
151     #fake at moment returns only stable pkgs (must set to be one)
152     # return $HIGHEST_MAGEFILE
153     get_highest_magefile(){
154     unset HIGHEST_MAGEFILE
155     #CATEGORIE=$1
156     #PKGNAME=$2
157    
158     for i in ${MAGEDIR}/${CATEGORIE}/${MAGENAME}/*
159     do
160     #we exclude subdirs (for stuff like a md5sum dir)
161     if [ ! -d ${i} ]
162     then
163     check_stable_package ${i}
164     if [ "$?" == "0" ]
165     then
166     HIGHEST_MAGEFILE=${i}
167     #for debug only
168     if [ "$MAGEDEBUG" == "on" ]
169     then
170     echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
171     fi
172     fi
173     fi
174     done
175    
176     MAGEFILE=${HIGHEST_MAGEFILE}
177     return 0
178     }
179    
180     mage_install_virtual(){
181     echo -e "\nInstallation of Package: ${COLGREEN}$PKGNAME${COLDEFAULT}\n"
182    
183     export -f preinstall 2> /dev/null
184     if [ "$?" == "0" ]
185     then
186     echo -e "\nRunning Preinstall ... \n"
187     preinstall
188     unset preinstall
189     fi
190    
191     #creates fake db entry
192     install -d ${INSTALLDB}/${PKGNAME}
193     touch ${INSTALLDB}/${PKGNAME}/.virtual
194    
195     #fake file-descriptors
196     touch ${INSTALLDB}/${PKGNAME}/.dirs
197     touch ${INSTALLDB}/${PKGNAME}/.symlinks
198     touch ${INSTALLDB}/${PKGNAME}/.files
199     touch ${INSTALLDB}/${PKGNAME}/.pipes
200     touch ${INSTALLDB}/${PKGNAME}/.char
201    
202     #installs mage file to database
203     #install -m 0644 -o root -g root \
204     # ${MAGEDIR}/${MAGENAME} \
205     # ${INSTALLDB}/${PKGNAME}
206    
207     install -m 0644 -o root -g root \
208     ${MAGEFILE} \
209     ${INSTALLDB}/${PKGNAME}
210    
211     export -f postinstall 2> /dev/null
212     if [ "$?" == "0" ]
213     then
214     echo -e "\nRunning Postinstall ... \n"
215     postinstall
216     unset postinstall
217     fi
218    
219     ${MLIBDIR}/env-rebuild.sh
220     echo -e "\nPackage \"$PKGNAME\" sucessfully installed.\n"
221    
222     #unsets virtual state of packages
223     unset PKGTYPE
224     exit 0
225     }
226    
227    
228     mage_install() {
229     local MAGEFILE
230     MAGEFILE=$1
231    
232     source ${MAGEFILE}
233    
234     #abbruch wenn schon installiert
235     if [ -e ${INSTALLDB}/${PKGNAME} ]
236     then
237     echo -e "\n${COLRED}Package \"$PKGNAME\" already installed. Installation Aborted.${COLDEFAULT}\n"
238     exit 3
239     fi
240    
241     xtitle "[ Installing ${PKGNAME} ]"
242    
243     if [ "${PKGTYPE}" == "virtual" ]
244     then
245     mage_install_virtual
246     fi
247    
248    
249     if [ ! -e ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} ]
250     then
251     echo -e "\nPrefetching needed Packages for ${COLGREEN}${PKGNAME}${COLDEFAULT}...\n"
252     getpackages
253     fi
254    
255     echo -e "\nInstallation of Package: ${COLGREEN}$PKGNAME${COLDEFAULT}\n"
256     ( build_unpackpkg ) | echo -e "Unpacking Package ...\n"
257    
258     ##preinstall scripte
259     export -f preinstall 2> /dev/null
260     if [ "$?" == "0" ]
261     then
262     echo -e "\nRunning Preinstall ... \n"
263     preinstall
264     unset preinstall
265     fi
266    
267     #install of package
268     if [ "$VERBOSE" == "off" ]
269     then
270     touch /var/tmp/proz
271     build_doinstall|spin_processbar
272     fi
273    
274     if [ "$VERBOSE" == "on" ]
275     then
276     build_doinstall
277     fi
278    
279     #postinstall scripte
280     export -f postinstall 2> /dev/null
281     if [ "$?" == "0" ]
282     then
283     echo -e "\nRunning Postinstall ... \n"
284     postinstall
285     unset postinstall
286     fi
287    
288     #cleanup
289     if [ -d ${BUILDDIR}/${PKGNAME} ]
290     then
291     rm -rf ${BUILDDIR}/${PKGNAME}
292     fi
293    
294     #rebuilds the enviroment with the content of /etc/env.d
295     ${MLIBDIR}/env-rebuild.sh
296    
297     xtitleclean
298    
299     echo -e "\nPackage \"$PKGNAME\" sucessfully installed.\n"
300    
301     }
302    
303     mage_uninstall() {
304     # #installdbhome #packagedir #magefile
305     source ${INSTALLDB}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME})
306    
307     if [ ! -e ${INSTALLDB}/${PKGNAME} ]
308     then
309     echo -e "\nPackage \"$PKGNAME\" is not installed. Uninstallation Aborted.\n"
310     exit 3
311     fi
312    
313     echo -e "\nUninstall of Package:\t${COLRED}$PKGNAME${COLDEFAULT}\n"
314    
315     if [ -z "${MAGE_UNINSTALL_TIMEOUT}" ]
316     then
317     MAGE_UNINSTALL_TIMEOUT=5
318     fi
319    
320     for ((i=0; i < MAGE_UNINSTALL_TIMEOUT; i++))
321     do
322     timeout=$(expr ${MAGE_UNINSTALL_TIMEOUT} - ${i})
323     echo -e "Starting in ${COLRED} ${timeout}" \
324     "${COLDEFAULT} seconds ... ( [CTRL+C] to abort )"
325     sleep 1
326     #moves the cursor up
327     echo -en \\033[A
328     done
329    
330     #moves the cursor up
331     echo -en \\033[A
332     #min. 30 spaces needed for clearing up the rest of the line
333     echo -e "\nUninstall ${COLRED}started${COLDEFAULT} ..." \
334     " \n"
335     sleep 1
336    
337     build_douninstall
338    
339     #rebuilds the enviroment with the content of /etc/env.d
340     ${MLIBDIR}/env-rebuild.sh
341    
342     echo -e "\nPackage \"$PKGNAME\" sucessfully removed.\n"
343     }
344    
345    
346     case "$1" in
347     download)
348     choppkgname
349     getcategorie
350     get_highest_magefile
351     source ${MAGEFILE}
352     getpackages
353     ;;
354     pretend)
355     choppkgname
356     getcategorie
357     get_highest_magefile
358     ${MLIBDIR}/depwanderer.sh pretend ${MAGEFILE}
359     ;;
360     install)
361     choppkgname
362     getcategorie
363     get_highest_magefile
364     ALLDEPS="$(/usr/lib/mage/depwanderer.sh install ${MAGEFILE})"
365     for i in ${ALLDEPS}
366     do
367     mage_install ${i}
368     done
369     ;;
370    
371     uninstall)
372     mage_uninstall
373     ;;
374    
375     unpack)
376     build_unpackpkg
377     ;;
378    
379     update)
380     syncmage
381     ;;
382     clean)
383     cleanpkg
384     ;;
385     keepfiles)
386     keepfiles "$2" "$3"
387     ;;
388     inject)
389     injectpkg "$2"
390     ;;
391     reminjected)
392     reminjected
393     ;;
394     *)
395     print_usage
396     ;;
397     esac

Properties

Name Value
svn:executable *