Magellan Linux

Diff of /trunk/mage/usr/lib/mage/mage4.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1273 by niro, Wed Apr 27 09:45:07 2011 UTC revision 1549 by niro, Tue Dec 27 10:43:40 2011 UTC
# Line 2  Line 2 
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $
4    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
30   [ ! -d ${MROOT}${INSTALLDB} ] && \   [ ! -d ${MROOT}${INSTALLDB} ] && \
# Line 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49    
50     # very basic getops
51     for i in $*
52     do
53     case $1 in
54     --rundir|-r) shift; rundir="$1" ;;
55     --file|-f) shift; file="$1" ;;
56     --method|-m) shift; method="$1" ;;
57     esac
58     shift
59     done
60    
61     # sanity checks
62     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
63     [[ -z ${file} ]] && die "mchecksum(): file missing"
64     [[ -z ${method} ]] && die "mchecksum(): method missing"
65    
66     case ${method} in
67     md5) cmd="md5sum" ;;
68     sha256) cmd="sha256sum" ;;
69     *) die "mchecksum(): unkown method '${method}'" ;;
70     esac
71    
72     if [[ -d ${rundir} ]]
73     then
74     pushd ${rundir} &> /dev/null
75     ${cmd} -c ${file} &> /dev/null
76     retval="$?"
77     popd &> /dev/null
78     else
79     retval=1
80     fi
81    
82     return "${retval}"
83    }
84    
85  unpack_packages()  unpack_packages()
86  {  {
87   local list="$@"   local list="$@"
# Line 141  install_directories() Line 208  install_directories()
208   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
209   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
210    
   
211   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
212   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
213    
# Line 228  install_files() Line 294  install_files()
294   "${user}" \   "${user}" \
295   "${group}" \   "${group}" \
296   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
297   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
298   "${md5sum}"   "${md5sum}"
299   ;;   ;;
300    
# Line 255  install_files() Line 321  install_files()
321   "${user}" \   "${user}" \
322   "${group}" \   "${group}" \
323   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
324   "${dest_protected}")" \   "${dest_protected}")" \
325   "${md5sum}"   "${md5sum}"
326    
327   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 272  install_files() Line 338  install_files()
338   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
339   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
340   fi   fi
341   # simply do nothing here   # simply do nothing here - only fix mtime
342     fix_descriptor ${pkgname}/.files \
343     "${pathto}" \
344     "${posix}" \
345     "${user}" \
346     "${group}" \
347     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
348     "${MROOT}${pathto}")" \
349     "${md5sum}"
350   ;;   ;;
351   esac   esac
352   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 476  build_doinstall() Line 550  build_doinstall()
550    
551   # sanity checks; abort if not given   # sanity checks; abort if not given
552   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
553    
554   # this is only a wrapper   # this is only a wrapper
555    
556   # NOTE:   # NOTE:
# Line 1253  build_douninstall() Line 1327  build_douninstall()
1327   done   done
1328  }  }
1329    
1330    # convertmirrors [uri]
1331    convertmirrors()
1332    {
1333     local uri="$1"
1334     local scheme
1335     local mirror
1336     local mirrors
1337     local addon
1338     local real_uri
1339     local output
1340    
1341     # needs
1342     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1343     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1344     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1345     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1346     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1347    
1348     # check known uri schemes
1349     case ${uri} in
1350     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1351     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1352     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1353     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1354     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1355     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1356     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1357     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1358     esac
1359    
1360     if [[ ! -z ${mirrors} ]]
1361     then
1362     for mirror in ${mirrors}
1363     do
1364     # add a whitespace to the output
1365     [[ -z ${output} ]] || output+=" "
1366     output+="${mirror}${addon}/${uri/${scheme}/}"
1367     done
1368     else
1369     output="${uri}"
1370     fi
1371    
1372     echo "${output}"
1373    }
1374    
1375    mdownload()
1376    {
1377     local i
1378     local uri
1379     local real_uris
1380     local mirror
1381     local outputfile
1382     local outputdir
1383     local retval
1384     local wget_opts
1385    
1386     # very basic getops
1387     for i in $*
1388     do
1389     case $1 in
1390     --uri|-u) shift; uri="$1" ;;
1391     --dir|-d) shift; outputdir="$1" ;;
1392     esac
1393     shift
1394     done
1395    
1396     # sanity checks; abort if not given
1397     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1398     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1399    
1400     # convert mirrored uris to the real ones
1401     real_uris="$(convertmirrors ${uri})"
1402    
1403     # verbose or not
1404     [[ ${VERBOSE} = off ]] && wget_opts="--quiet"
1405    
1406     # filter wget options if busybox was found
1407     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1408    
1409     # create outputdir
1410     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1411    
1412     for mirror in ${real_uris}
1413     do
1414     # get the name of the output file
1415     outputfile="${mirror##*/}"
1416    
1417     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1418     retval="$?"
1419     if [[ ${retval} = 0 ]]
1420     then
1421     break
1422     else
1423     continue
1424     fi
1425     done
1426    
1427     # return wget retval
1428     return "${retval}"
1429    }
1430    
1431  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1432  fetch_packages()  fetch_packages()
1433  {  {
1434     local i
1435   local list="$@"   local list="$@"
1436   local pkg   local pkg
1437   local mirr   local mirr
# Line 1309  fetch_packages() Line 1485  fetch_packages()
1485   continue   continue
1486   fi   fi
1487    
1488   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1489   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1490   echo -ne " ${COLBLUE}***${COLDEFAULT}"   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  ${wget_opts} \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
1491    
1492   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1493   then   then
1494   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1495   fi   fi
1496   done   done
1497    
# Line 1357  syncmage() Line 1519  syncmage()
1519   done   done
1520    
1521   # clean up backup files (foo~)   # clean up backup files (foo~)
1522   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1523    
1524   # check if a newer mage version is available   # check if a newer mage version is available
1525   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1371  syncmage_tarball() Line 1533  syncmage_tarball()
1533   local mirr mymirr   local mirr mymirr
1534   local opt   local opt
1535   local tar_opts   local tar_opts
1536     local wget_opts
1537    
1538   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1539   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1378  syncmage_tarball() Line 1541  syncmage_tarball()
1541   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1542   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1543    
1544     # filter wget command if busybox was found
1545     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1546    
1547   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1548   do   do
1549   # path without distribution   # path without distribution
# Line 1387  syncmage_tarball() Line 1553  syncmage_tarball()
1553   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1554   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1555   wget \   wget \
1556   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1557   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1558   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1559    
1560   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1561   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1562   wget \   wget \
1563   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1564   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1565   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1566   if [[ $? = 0 ]]   if [[ $? = 0 ]]
# Line 1480  xtitleclean() Line 1646  xtitleclean()
1646  }  }
1647    
1648    
1649  # cuts full pathnames or versioniezed names down to basename  # cuts full pathnames or versionized names down to basename
1650  choppkgname()  choppkgname()
1651  {  {
1652   #we want this only if full name was used   #we want this only if full name was used
# Line 1563  get_highest_magefile() Line 1729  get_highest_magefile()
1729   local magefile   local magefile
1730    
1731   # do not list the content of a directory, only the name (-d)   # do not list the content of a directory, only the name (-d)
1732   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1733   do   do
1734   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1735   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1576  get_highest_magefile() Line 1742  get_highest_magefile()
1742   fi   fi
1743   done   done
1744    
 # do not so anything  
 # # stop here if HIGHEST_MAGEFILE is zero  
 # # this package must be unstable or old  
 # if [ -z "${HIGHEST_MAGEFILE}" ]  
 # then  
 # echo  
 # echo -n "All packages named "  
 # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  
 # echo -n " are marked "  
 # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  
 # echo "."  
 # echo "You need to declare USE_UNSTABLE=true to install this."  
 # echo  
 # echo "Example:"  
 # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  
 # echo  
 # echo "Be warned that these packages are not stable and may cause serious problems."  
 # echo "You should know what you are doing, so don't complain about any damage."  
 # echo  
 # return 1  
 # fi  
   
1745   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1746   return 0   return 0
1747  }  }
# Line 2450  mage_install() Line 2594  mage_install()
2594   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${MAGE_TARGETS} ]]
2595   then   then
2596   # basic svn compat   # basic svn compat
2597   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2598   then   then
2599   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2600   do   do
2601   smage2file="${i}"   smage2file="${i}"
2602   done   done
# Line 2463  mage_install() Line 2607  mage_install()
2607   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]   elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2608   then   then
2609   # basic svn compat   # basic svn compat
2610   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2611   then   then
2612   for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2613   do   do
2614   smage2file="${i}"   smage2file="${i}"
2615   done   done
# Line 2475  mage_install() Line 2619  mage_install()
2619    
2620   else   else
2621   # basic svn compat   # basic svn compat
2622   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2623   then   then
2624   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2625   do   do
2626   smage2file="${i}"   smage2file="${i}"
2627   done   done
# Line 3077  need_busybox_support() Line 3221  need_busybox_support()
3221   then   then
3222   # needs busybox support   # needs busybox support
3223   return 0   return 0
  else  
  # no busybox  
  return 1  
3224   fi   fi
3225   fi   fi
3226    
3227     # no busybox
3228     return 1
3229  }  }
3230    
3231  # busybox_filter_wget_options ${wget_opts}  # busybox_filter_wget_options ${wget_opts}
# Line 3116  busybox_filter_wget_options() Line 3260  busybox_filter_wget_options()
3260   echo "${opts}"   echo "${opts}"
3261   fi   fi
3262  }  }
3263    
3264    have_root_privileges()
3265    {
3266     local retval
3267    
3268     if [[ $(id -u) = 0 ]]
3269     then
3270     retval=0
3271     else
3272     retval=1
3273     fi
3274    
3275     return ${retval}
3276    }

Legend:
Removed from v.1273  
changed lines
  Added in v.1549