Magellan Linux

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

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

revision 2225 by niro, Wed Oct 16 07:49:19 2013 UTC revision 3040 by niro, Fri Jun 30 12:34:44 2017 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 71  mchecksum() Line 71  mchecksum()
71   *) die "mchecksum(): unknown method '${method}'" ;;   *) die "mchecksum(): unknown method '${method}'" ;;
72   esac   esac
73    
74   if [[ -d ${rundir} ]]   if [[ -f ${file} ]]
75   then   then
76   pushd ${rundir} &> /dev/null   if [[ -d ${rundir} ]]
77     then
78     pushd ${rundir} &> /dev/null
79    
80   # all file must be non-zero   # all file must be non-zero
81   retval=0   retval=0
82   while read sum dest   while read sum dest
83   do   do
84   if [ -s ${dest} ]   if [ ! -s ${dest} ]
85     then
86     echo "${dest}: file is empty ;("
87     retval=127
88     fi
89     done < ${file}
90     if [[ ${retval} != 127 ]]
91   then   then
92   echo "${dest}: file-size OK"   # be verbose here
93   else   ${cmd} -c ${file} #&> /dev/null
94   echo "${dest}: file is empty ;("   retval="$?"
  retval=127  
95   fi   fi
  done < ${file}  
  if [[ ${retval} != 127 ]]  
  then  
  # insert an empty line for cosmetic  
  echo  
96    
97   # be verbose here   popd &> /dev/null
98   ${cmd} -c ${file} #&> /dev/null   else
99   retval="$?"   retval=1
100   fi   fi
   
  popd &> /dev/null  
101   else   else
102     echo "missing checksum file '${file}' ;("
103   retval=1   retval=1
104   fi   fi
105    
# Line 127  mcheckemptydir() Line 128  mcheckemptydir()
128  unpack_package()  unpack_package()
129  {  {
130   local magefile="$1"   local magefile="$1"
131   local pkg   local pkgname
132     local pkgfile
133   local pkgtype   local pkgtype
134   local tar_opts   local tar_opts
135    
136   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
137     pkgfile="${pkgname}.${PKGSUFFIX}"
138   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
139    
140   xtitle "[ Unpacking ${pkg} ]"   xtitle "[ Unpacking ${pkg} ]"
# Line 140  unpack_package() Line 143  unpack_package()
143   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
144   then   then
145   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
146   echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "   echo " !unpack virtual ${pkgname} ... "
147   continue   continue
148   fi   fi
149    
# Line 148  unpack_package() Line 151  unpack_package()
151   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
152   then   then
153   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
154   echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "   echo " !unpack sources ${pkgname} ... "
155   continue   continue
156   fi   fi
157    
# Line 160  unpack_package() Line 163  unpack_package()
163   tar_opts="xjmf"   tar_opts="xjmf"
164   fi   fi
165    
166   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
167   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
168  }  }
169    
170  unpack_packages()  unpack_packages()
# Line 764  remove_database_entry() Line 767  remove_database_entry()
767   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
768    
769   # remove virtuals only if no other exist   # remove virtuals only if no other exist
770   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
771   then   then
772   # first unregister virtuals   # first unregister virtuals
773   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 793  count_installed_pkgs() Line 796  count_installed_pkgs()
796   local i   local i
797    
798   # very basic getops   # very basic getops
799   for i in $*   for i in $@
800   do   do
801   case $1 in   case ${i} in
802   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
803   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
804   esac   esac
  shift  
805   done   done
806    
807   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 1387  convertmirrors() Line 1389  convertmirrors()
1389    
1390   # check known uri schemes   # check known uri schemes
1391   case ${uri} in   case ${uri} in
1392   http://*|https://*|ftp://*|ftps://*) mirrors="" ;;   http://*|https://*|ftp://*|ftps://*|file://*) mirrors="" ;;
1393   mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;   mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1394   package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;   package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1395   gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;   gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
# Line 1406  convertmirrors() Line 1408  convertmirrors()
1408   output+="${mirror}${addon}/${uri/${scheme}/}"   output+="${mirror}${addon}/${uri/${scheme}/}"
1409   done   done
1410   else   else
1411   output="${uri}"   output="${uri}"
1412   fi   fi
1413    
1414   echo "${output}"   echo "${output}"
# Line 1454  mdownload() Line 1456  mdownload()
1456   # get the name of the output file   # get the name of the output file
1457   outputfile="${mirror##*/}"   outputfile="${mirror##*/}"
1458    
1459   wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"   case ${mirror} in
1460   retval="$?"   file://*)
1461     cp -v "${mirror//file:\/\/}" "${outputdir}/${outputfile}"
1462     retval="$?"
1463     ;;
1464     *)
1465     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1466     retval="$?"
1467     ;;
1468     esac
1469    
1470   if [[ ${retval} = 0 ]]   if [[ ${retval} = 0 ]]
1471   then   then
1472   break   break
# Line 1473  fetch_packages() Line 1484  fetch_packages()
1484  {  {
1485   local i   local i
1486   local list="$@"   local list="$@"
1487   local pkg   local pkgname
1488     local pkgfile
1489     local pcat
1490     local pname
1491   local mirr   local mirr
1492   local magefile   local magefile
1493   local md5file   local md5file
# Line 1481  fetch_packages() Line 1495  fetch_packages()
1495   local count_current   local count_current
1496   local count_total   local count_total
1497   local wget_opts   local wget_opts
1498     local fetching
1499    
1500   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1501    
# Line 1495  fetch_packages() Line 1510  fetch_packages()
1510    
1511   for magefile in ${list}   for magefile in ${list}
1512   do   do
1513   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1514     pkgfile="${pkgname}.${PKGSUFFIX}"
1515   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1516    
1517     pcat=$(magename2pcat ${magefile})
1518     pname=$(magename2pname ${magefile})
1519     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1520    
1521   (( count_current++ ))   (( count_current++ ))
1522   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1523    
1524   # abort on virtual pkg   # abort on virtual pkg
1525   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1526   then   then
1527   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1528   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1529   continue   continue
1530   fi   fi
1531    
# Line 1513  fetch_packages() Line 1533  fetch_packages()
1533   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1534   then   then
1535   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1536   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1537   continue   continue
1538   fi   fi
1539    
1540   # abort if already exist   # check if FETCHING is required
1541   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1542     then
1543     fetching=true
1544     else
1545     if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
1546     then
1547     # md5's ok, no fetching required
1548     fetching=false
1549     else
1550     fetching=true
1551     fi
1552     fi
1553    
1554     if [[ ${fetching} = false ]]
1555   then   then
1556   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1557   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1558   continue   continue
1559     else
1560     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1561     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1562     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1563   fi   fi
1564    
1565   echo -ne " ${COLBLUE}***${COLDEFAULT}"   # sanity check, not really needed but to be sure
1566   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} ]  
1567   then   then
1568   die "Package '${pkg}' after download not found in '${PKGDIR}'"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1569   fi   fi
1570   done   done
1571    
# Line 2235  sminclude() Line 2270  sminclude()
2270   then   then
2271   for i in $*   for i in $*
2272   do   do
2273   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2274   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2275   done   done
2276   echo   [[ ${SILENT} = 1 ]] || echo
2277   fi   fi
2278  }  }
2279    
# Line 2542  get_value_from_magefile() Line 2577  get_value_from_magefile()
2577   local SDEPEND   local SDEPEND
2578   local PROVIDE   local PROVIDE
2579   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2580   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2581   local preinstall   local preinstall
2582   local postinstall   local postinstall
# Line 2664  mage_install() Line 2698  mage_install()
2698   echo B:${pbuild}   echo B:${pbuild}
2699   fi   fi
2700    
2701   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} ]]  
2702   then   then
2703   # basic svn compat   # basic svn compat
2704   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
# Line 2808  md5sum_packages() Line 2829  md5sum_packages()
2829   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2830   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2831   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2832   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2833   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2834    
2835   (( count_current++ ))   (( count_current++ ))
# Line 2818  md5sum_packages() Line 2839  md5sum_packages()
2839   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2840   then   then
2841   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2842   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2843   continue   continue
2844   fi   fi
2845    
# Line 2826  md5sum_packages() Line 2847  md5sum_packages()
2847   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2848   then   then
2849   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2850   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2851   continue   continue
2852   fi   fi
2853    
# Line 2874  uninstall_packages() Line 2895  uninstall_packages()
2895   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2896   can_pcat="${pcat}"   can_pcat="${pcat}"
2897   can_pname="${pname}"   can_pname="${pname}"
2898    
2899   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2900   then   then
2901   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 3047  mage_uninstall() Line 3068  mage_uninstall()
3068   unset -f postremove   unset -f postremove
3069  }  }
3070    
3071    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3072    rerun_pkgfunctions()
3073    {
3074     local method
3075     local list
3076     local pcat
3077     local pname
3078     local pver
3079     local pbuild
3080     local magefile
3081     local i
3082    
3083     # very basic getops
3084     case $1 in
3085     --method) shift; method="$1" ;;
3086     esac
3087     shift
3088     local list="$@"
3089    
3090     # sanity check
3091     case ${method} in
3092     preinstall|postinstall) ;;
3093     preremove|postremove) ;;
3094     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3095     esac
3096    
3097     if [[ -n ${MROOT} ]]
3098     then
3099     echo -ne ${COLRED}
3100     echo "!! running in MROOT=${MROOT}"
3101     echo -ne ${COLDEFAULT}
3102     echo
3103     fi
3104    
3105     for pkg in ${list}
3106     do
3107     pcat=$(dep2pcat ${pkg})
3108     pname=$(magename2pname ${pkg})
3109     pver=$(magename2pver ${pkg})
3110     pbuild=$(magename2pbuild ${pkg})
3111     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3112    
3113     if [ -e ${magefile} ]
3114     then
3115     source ${magefile}
3116     if [ -n "$(typeset -f ${method})" ]
3117     then
3118     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3119     ${method}
3120     else
3121     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3122     fi
3123     unset -f preinstall postinstall preremove postremove
3124     else
3125     die "Magefile '${magefile}' does not exist."
3126     fi
3127     done
3128    }
3129    
3130  show_etc_update_mesg()  show_etc_update_mesg()
3131  {  {
3132   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
# Line 3458  msetfeature() Line 3538  msetfeature()
3538   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )   MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3539   fi   fi
3540    
3541   export MAGE_FEATURE_CURRENT   export MAGE_FEATURES_CURRENT
3542   done   done
3543  }  }
3544    

Legend:
Removed from v.2225  
changed lines
  Added in v.3040