--- trunk/mage/usr/lib/mage/smage2.sh 2005/02/15 00:37:07 57 +++ trunk/mage/usr/lib/mage/smage2.sh 2005/02/16 17:50:54 66 @@ -4,14 +4,14 @@ # needs pkgbuild_dir (mage) # SMAGE2 -# version: 0.3.6-r12 +# version: 0.3.6-r15 #01.10.2004 # added ccache support # added distcc support ## setup ## -SMAGEVERSION=0.3.6-r11 +SMAGEVERSION=0.3.6-r15 PKGSUFFIX="mpk" SMAGENAME="$1" SMAGESUFFIX="smage2" @@ -84,6 +84,127 @@ xtitleclean } +# $1 filename +get_db_md5_sum() { + local DB_FILE + local MD5_FILE + local i + + DB_ENTRY="$(basename $1)" + MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" + + i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" + + echo "${i}" +} + +download_sources() { + + [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 + + local EOA=${#SRC_URI[*]} + local my_SRC_URI + local my_SRC_URI_DEST + local my_SRC_URI_MIRROR + local my_SOURCEDIR + local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" + local FETCHING + local i mirror + + + #install SRCDIR/PNAME if not exist + [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME} + + # check if FETCHING is needed + ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null ) + if [[ $? == 0 ]] + then + # md5's ok, not fetching needed + FETCHING=false + else + FETCHING=true + fi + + for ((i=0; i < EOA; i++)) + do + # url to file + my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" + + # subdir in sources dir; the my_SRCI_URI file goes to there + my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" + + # if my_src_uri_dest is not equal my_src_uri; than an other dir is used + if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] + then + my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}" + else + my_SOURCEDIR="${SOURCEDIR}/${PNAME}" + fi + + # if an mirrored file than replace first the mirror uri + if [ -n "$(echo ${my_SRC_URI} | grep 'mirror://')" ] + then + for mirror in ${MIRRORS} + do + my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")" + + #echo "DEBUG: ${MY_SRC_URI}" + if [[ ${FETCHING} == true ]] + then + echo "==> fetching ${my_SRC_URI_MIRROR}" + wget \ + --passive-ftp \ + --tries 3 \ + --continue \ + --progress bar \ + --directory-prefix="${my_SOURCEDIR}" \ + "${my_SRC_URI_MIRROR}" + if [ "$?" == "0" ] + then + break + else + continue + fi + fi + done + else + #echo "DEBUG: ${SRC_URI[${i}]}" + if [[ ${FETCHING} == true ]] + then + echo "==> fetching ${my_SRC_URI}" + wget \ + --passive-ftp \ + --tries 3 \ + --continue \ + --progress bar \ + --directory-prefix="${my_SOURCEDIR}" \ + "${my_SRC_URI}" + if [ "$?" == "0" ] + then + break + else + continue + fi + fi + fi + + # unset them to be shure + unset my_SRC_URI + unset my_SRC_URI_DEST + unset my_SRC_URI_MIRROR + unset my_SOURCEDIR + done + + # recheck md5 sums + echo + echo ">== Checking MD5 sums:" + ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed" + echo + + # not needed anymore + unset SRC_URI +} + # dummy function, used if that not exist in smage file src_prepare() { echo "no src_prepare defined" @@ -258,10 +379,12 @@ fi } +# print out our version +showversion +echo + if [ -z "$1" ] then - showversion - echo echo "No .smage2 file given. Exiting." echo exit 1 @@ -270,16 +393,102 @@ #updating smage2-scripts if [ "$1" == "update" ] then + if [ ! -d ${SOURCEDIR} ] + then + install -d ${SOURCEDIR} + fi + syncsmage2 + exit 0 +fi + +#creates md5sums for smages to given dir +if [ "$1" == "calcmd5" ] +then + if [ $# -ge 3 ] + then + SMAGENAME="$2" + MD5DIR="$3" + source ${SMAGENAME} || die "download source failed" + + # overridable sourcedir; must be declared after source of the smage2 + CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}" + + [ -z "${SRC_URI}" ] && die "Nothing declared to calculate." + + # end of array + EOA=${#SRC_URI[*]} + + [ ! -d ${MD5DIR} ] && install -d ${MD5DIR} + + # clear md5sum file + MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" + echo -n > ${MY_MD5_FILE} + + for ((i=0; i < EOA; i++)) + do + # url to file + my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" + + # subdir in sources dir; the my_SRCI_URI file goes to there + my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" + + # if my_src_uri_dest is not equal my_src_uri; than an other dir is used + if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] + then + MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})" + else + MY_SRC_FILE="$(basename ${SRC_URI[${i}]})" + fi + + if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ] + then + echo "calculating $(basename ${MY_SRC_FILE}) ..." + ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE} + else + echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}." + fi + + # unset them to be shure + unset my_SRC_URI + unset my_SRC_URI_DEST + unset my_SRC_URI_MIRROR + unset my_SOURCEDIR + done + + echo + echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done." + echo + else + echo "Usage: Calculating MD5 Sums:" + echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR" + echo + echo + echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs." + echo + exit 1 + fi + + exit 0 +fi + +#download sources +if [ "$1" == "download" -a -n "$2" ] +then showversion if [ ! -d ${SMAGESCRIPTSDIR} ] then install -d ${SMAGESCRIPTSDIR} fi - syncsmage2 + + # get smage + SMAGENAME="$2" + MD5DIR="$(dirname ${SMAGENAME})/md5" + source ${SMAGENAME} || die "download source failed" + + download_sources exit 0 fi - if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] then die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." @@ -329,8 +538,14 @@ source ${SMAGENAME} || die "source failed" PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}" +MD5DIR="$(dirname ${SMAGENAME})/md5" xtitle "Compiling ${PKGNAME}" +echo "Compiling ${PKGNAME}" + +#download sources +download_sources + #fixes some issues with these functions export -f src_prepare || die "src_prepare export failed" export -f src_compile || die "src_compile export failed"