Magellan Linux

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

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

revision 2167 by niro, Wed Aug 14 14:07:00 2013 UTC revision 2867 by niro, Thu Mar 19 15:28:54 2015 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
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 $  # $Id$
4    
5  COLRED="\033[1;6m\033[31m"  COLRED="\033[1;6m\033[31m"
6  COLGREEN="\033[1;6m\033[32m"  COLGREEN="\033[1;6m\033[32m"
# Line 46  mchecksum() Line 46  mchecksum()
46   local method   local method
47   local cmd   local cmd
48   local retval   local retval
49     local sum
50     local dest
51    
52   # very basic getops   # very basic getops
53   for i in $*   for i in $*
# Line 72  mchecksum() Line 74  mchecksum()
74   if [[ -d ${rundir} ]]   if [[ -d ${rundir} ]]
75   then   then
76   pushd ${rundir} &> /dev/null   pushd ${rundir} &> /dev/null
77   # be verbose here  
78   ${cmd} -c ${file} #&> /dev/null   # all file must be non-zero
79   retval="$?"   retval=0
80     while read sum dest
81     do
82     if [ ! -s ${dest} ]
83     then
84     echo "${dest}: file is empty ;("
85     retval=127
86     fi
87     done < ${file}
88     if [[ ${retval} != 127 ]]
89     then
90     # be verbose here
91     ${cmd} -c ${file} #&> /dev/null
92     retval="$?"
93     fi
94    
95   popd &> /dev/null   popd &> /dev/null
96   else   else
97   retval=1   retval=1
# Line 105  mcheckemptydir() Line 122  mcheckemptydir()
122  unpack_package()  unpack_package()
123  {  {
124   local magefile="$1"   local magefile="$1"
125   local pkg   local pkgname
126     local pkgfile
127   local pkgtype   local pkgtype
128   local tar_opts   local tar_opts
129    
130   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
131     pkgfile="${pkgname}.${PKGSUFFIX}"
132   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
133    
134   xtitle "[ Unpacking ${pkg} ]"   xtitle "[ Unpacking ${pkg} ]"
# Line 118  unpack_package() Line 137  unpack_package()
137   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
138   then   then
139   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
140   echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "   echo " !unpack virtual ${pkgname} ... "
141   continue   continue
142   fi   fi
143    
# Line 126  unpack_package() Line 145  unpack_package()
145   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
146   then   then
147   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
148   echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "   echo " !unpack sources ${pkgname} ... "
149   continue   continue
150   fi   fi
151    
# Line 138  unpack_package() Line 157  unpack_package()
157   tar_opts="xjmf"   tar_opts="xjmf"
158   fi   fi
159    
160   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
161   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
162  }  }
163    
164  unpack_packages()  unpack_packages()
# Line 742  remove_database_entry() Line 761  remove_database_entry()
761   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
762    
763   # remove virtuals only if no other exist   # remove virtuals only if no other exist
764   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
765   then   then
766   # first unregister virtuals   # first unregister virtuals
767   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 771  count_installed_pkgs() Line 790  count_installed_pkgs()
790   local i   local i
791    
792   # very basic getops   # very basic getops
793   for i in $*   for i in $@
794   do   do
795   case $1 in   case ${i} in
796   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
797   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
798   esac   esac
  shift  
799   done   done
800    
801   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 1365  convertmirrors() Line 1383  convertmirrors()
1383    
1384   # check known uri schemes   # check known uri schemes
1385   case ${uri} in   case ${uri} in
1386   http://*|https://*|ftp://*|ftps://*) mirrors="" ;;   http://*|https://*|ftp://*|ftps://*|file://*) mirrors="" ;;
1387   mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;   mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1388   package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;   package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1389   gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;   gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
# Line 1384  convertmirrors() Line 1402  convertmirrors()
1402   output+="${mirror}${addon}/${uri/${scheme}/}"   output+="${mirror}${addon}/${uri/${scheme}/}"
1403   done   done
1404   else   else
1405   output="${uri}"   output="${uri}"
1406   fi   fi
1407    
1408   echo "${output}"   echo "${output}"
# Line 1432  mdownload() Line 1450  mdownload()
1450   # get the name of the output file   # get the name of the output file
1451   outputfile="${mirror##*/}"   outputfile="${mirror##*/}"
1452    
1453   wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"   case ${mirror} in
1454   retval="$?"   file://*)
1455     cp -v "${mirror//file:\/\/}" "${outputdir}/${outputfile}"
1456     retval="$?"
1457     ;;
1458     *)
1459     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1460     retval="$?"
1461     ;;
1462     esac
1463    
1464   if [[ ${retval} = 0 ]]   if [[ ${retval} = 0 ]]
1465   then   then
1466   break   break
# Line 1451  fetch_packages() Line 1478  fetch_packages()
1478  {  {
1479   local i   local i
1480   local list="$@"   local list="$@"
1481   local pkg   local pkgname
1482     local pkgfile
1483     local pcat
1484     local pname
1485   local mirr   local mirr
1486   local magefile   local magefile
1487   local md5file   local md5file
# Line 1459  fetch_packages() Line 1489  fetch_packages()
1489   local count_current   local count_current
1490   local count_total   local count_total
1491   local wget_opts   local wget_opts
1492     local fetching
1493    
1494   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1495    
# Line 1473  fetch_packages() Line 1504  fetch_packages()
1504    
1505   for magefile in ${list}   for magefile in ${list}
1506   do   do
1507   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1508     pkgfile="${pkgname}.${PKGSUFFIX}"
1509   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1510    
1511     pcat=$(magename2pcat ${magefile})
1512     pname=$(magename2pname ${magefile})
1513     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1514    
1515   (( count_current++ ))   (( count_current++ ))
1516   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1517    
1518   # abort on virtual pkg   # abort on virtual pkg
1519   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1520   then   then
1521   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1522   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1523   continue   continue
1524   fi   fi
1525    
# Line 1491  fetch_packages() Line 1527  fetch_packages()
1527   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1528   then   then
1529   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1530   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1531   continue   continue
1532   fi   fi
1533    
1534   # abort if already exist   # check if FETCHING is required
1535   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1536     then
1537     fetching=true
1538     else
1539     if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
1540     then
1541     # md5's ok, no fetching required
1542     fetching=false
1543     else
1544     fetching=true
1545     fi
1546     fi
1547    
1548     if [[ ${fetching} = false ]]
1549   then   then
1550   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1551   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1552   continue   continue
1553     else
1554     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1555     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1556     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1557   fi   fi
1558    
1559   echo -ne " ${COLBLUE}***${COLDEFAULT}"   # sanity check, not really needed but to be sure
1560   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   if [ ! -f ${PKGDIR}/${pkgfile} ]
  mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"  
  if [ ! -f ${PKGDIR}/${pkg} ]  
1561   then   then
1562   die "Package '${pkg}' after download not found in '${PKGDIR}'"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1563   fi   fi
1564   done   done
1565    
# Line 1771  get_highest_magefile() Line 1822  get_highest_magefile()
1822   then   then
1823   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1824   #for debug only   #for debug only
1825   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1826   fi   fi
1827   done   done
1828    
# Line 2213  sminclude() Line 2264  sminclude()
2264   then   then
2265   for i in $*   for i in $*
2266   do   do
2267   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2268   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2269   done   done
2270   echo   [[ ${SILENT} = 1 ]] || echo
2271   fi   fi
2272  }  }
2273    
# Line 2520  get_value_from_magefile() Line 2571  get_value_from_magefile()
2571   local SDEPEND   local SDEPEND
2572   local PROVIDE   local PROVIDE
2573   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2574   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2575   local preinstall   local preinstall
2576   local postinstall   local postinstall
# Line 2642  mage_install() Line 2692  mage_install()
2692   echo B:${pbuild}   echo B:${pbuild}
2693   fi   fi
2694    
2695   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
  then  
  # basic svn compat  
  if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]  
  then  
  for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  do  
  smage2file="${i}"  
  done  
  else  
  smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  fi  
   
  elif [[ -n ${SPLIT_PACKAGE_BASE} ]]  
2696   then   then
2697   # basic svn compat   # basic svn compat
2698   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
# Line 2786  md5sum_packages() Line 2823  md5sum_packages()
2823   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2824   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2825   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2826   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2827   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2828    
2829   (( count_current++ ))   (( count_current++ ))
# Line 2796  md5sum_packages() Line 2833  md5sum_packages()
2833   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2834   then   then
2835   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2836   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2837   continue   continue
2838   fi   fi
2839    
# Line 2804  md5sum_packages() Line 2841  md5sum_packages()
2841   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2842   then   then
2843   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2844   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2845   continue   continue
2846   fi   fi
2847    
# Line 2852  uninstall_packages() Line 2889  uninstall_packages()
2889   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2890   can_pcat="${pcat}"   can_pcat="${pcat}"
2891   can_pname="${pname}"   can_pname="${pname}"
2892    
2893   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2894   then   then
2895   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 3025  mage_uninstall() Line 3062  mage_uninstall()
3062   unset -f postremove   unset -f postremove
3063  }  }
3064    
3065    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3066    rerun_pkgfunctions()
3067    {
3068     local method
3069     local list
3070     local pcat
3071     local pname
3072     local pver
3073     local pbuild
3074     local magefile
3075     local i
3076    
3077     # very basic getops
3078     case $1 in
3079     --method) shift; method="$1" ;;
3080     esac
3081     shift
3082     local list="$@"
3083    
3084     # sanity check
3085     case ${method} in
3086     preinstall|postinstall) ;;
3087     preremove|postremove) ;;
3088     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3089     esac
3090    
3091     if [[ -n ${MROOT} ]]
3092     then
3093     echo -ne ${COLRED}
3094     echo "!! running in MROOT=${MROOT}"
3095     echo -ne ${COLDEFAULT}
3096     echo
3097     fi
3098    
3099     for pkg in ${list}
3100     do
3101     pcat=$(dep2pcat ${pkg})
3102     pname=$(magename2pname ${pkg})
3103     pver=$(magename2pver ${pkg})
3104     pbuild=$(magename2pbuild ${pkg})
3105     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3106    
3107     if [ -e ${magefile} ]
3108     then
3109     source ${magefile}
3110     if [ -n "$(typeset -f ${method})" ]
3111     then
3112     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3113     ${method}
3114     else
3115     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3116     fi
3117     unset -f preinstall postinstall preremove postremove
3118     else
3119     die "Magefile '${magefile}' does not exist."
3120     fi
3121     done
3122    }
3123    
3124  show_etc_update_mesg()  show_etc_update_mesg()
3125  {  {
3126   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 3288  need_busybox_support() Line 3384  need_busybox_support()
3384   do   do
3385   if [[ -x ${busybox} ]]   if [[ -x ${busybox} ]]
3386   then   then
3387   if [[ $(readlink $(which ${cmd})) = ${busybox} ]]   if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3388   then   then
3389   # needs busybox support   # needs busybox support
3390   return 0   return 0
# Line 3436  msetfeature() Line 3532  msetfeature()
3532   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3533   fi   fi
3534    
3535   export MAGE_FEATURE_CURRENT   export MAGE_FEATURES_CURRENT
3536   done   done
3537  }  }
3538    

Legend:
Removed from v.2167  
changed lines
  Added in v.2867