Magellan Linux

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

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

revision 1548 by niro, Tue Dec 27 10:00:34 2011 UTC revision 1549 by niro, Tue Dec 27 10:43:40 2011 UTC
# Line 38  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 1283  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 1339  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    

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