#!/bin/bash die() { echo "Error: $@"; exit 1; } # include all needed files [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global || die "/etc/mage.rc.global missing" [ -f ${MAGERC} ] && source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting." [ -f ${MLIBDIR}/mage4.functions.sh ] && source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing" [ -f ${MLIBDIR}/smage2.functions.sh ] && source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing" [ -f /etc/up2date.conf ] && source /etc/up2date.conf || die "/etc/up2date.conf missing" # respect repos from env or load repos from config file if [[ -z ${REPOS} ]] && [[ -n ${SMAGE_REPOS} ]] then REPOS="${SMAGE_REPOS}" fi # sane default : ${REPOS="${SMAGESCRIPTSDIR}/core ${SMAGESCRIPTSDIR}/extras ${SMAGESCRIPTSDIR}/nonfree ${SMAGESCRIPTSDIR}/todo"} ## only for tests -> normally in /etc/rc.d/init.d/functions COLRED="\033[1;6m\033[31m" COLGREEN="\033[1;6m\033[32m" COLYELLOW="\033[1;6m\033[33m" COLBLUE="\033[1;6m\033[34m" COLMAGENTA="\033[1;6m\033[35m" COLWHITE="\033[1;6m\033[37m" COLGRAY="\033[0;6m\033[37m" COLBOLD="\033[1m" COLDEFAULT="\033[0m" if [[ ${NOCOLORS} = true ]] then COLRED="" COLGREEN="" COLYELLOW="" COLBLUE="" COLMAGENTA="" COLWHITE="" COLGRAY="" COLBOLD="" COLDEFAULT="" fi # always be silent SILENT=1 FVERBOSE=off # load all up2date includes for inc in ${MLIBDIR}/up2date/*.sh do source ${inc} done updatecmd() { local uppver local useragent [[ ! -z ${UP2USERAGENT} ]] && useragent="-useragent '${UP2USERAGENT}'" uppver=$(lynx -connect_timeout=${LYNX_CONNECT_TIMEOUT} -read_timeout=${LYNX_READ_TIMEOUT} -dump "${useragent}" $@) if [[ $? -ne 0 ]] then echo "Error connecting '$@'" sleep 1 return 1 fi if [[ ! -z ${UP2SUBSTITUTE} ]] then echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g" else echo "${uppver}" fi } updateme() { local smage="$1" local ONLY_PRINT_UPSTREAM if [[ $1 = --upstream ]] || [[ $1 = -u ]] then if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]] then echo "you must give me a smagefile." exit 1 fi ONLY_PRINT_UPSTREAM=1 smage="$2" fi local PNAME local PCATEGORIE local PCAT local PVER local UP2DATE local UP2PVER local UP2TARBALL local UP2SUBDIR local UP2SUBSTITUTE local UP2USERAGENT local UP2EXCLUDE local UP2SEPERATOR local UP2OPTS local UPSTREAM_PVER PNAME="$(get_value_from_magefile PNAME ${smage})" PCATEGORIE="$(get_value_from_magefile PCATEGORIE ${smage})" PCAT="$(get_value_from_magefile PCAT ${smage})" PVER="$(get_value_from_magefile PVER ${smage})" UP2PVER="$(get_value_from_magefile UP2PVER ${smage})" UP2TARBALL="$(get_value_from_magefile UP2TARBALL ${smage})" UP2SUBDIR="$(get_value_from_magefile UP2SUBDIR ${smage})" UP2SUBSTITUTE="$(get_value_from_magefile UP2SUBSTITUTE ${smage})" UP2USERAGENT="$(get_value_from_magefile UP2USERAGENT ${smage})" UP2EXCLUDE="$(get_value_from_magefile UP2EXCLUDE ${smage})" UP2SEPERATOR="$(get_value_from_magefile UP2SEPERATOR ${smage})" UP2OPTS="$(get_value_from_magefile UP2OPTS ${smage})" [[ -z ${UP2PVER} ]] && UP2PVER="${PVER}" UP2DATE=$(get_value_from_magefile UP2DATE ${smage}) if [[ -z ${UP2DATE} ]] then continue fi UPSTREAM_PVER=$(eval "${UP2DATE}") if [[ ${ONLY_PRINT_UPSTREAM} = 1 ]] then echo "${UPSTREAM_PVER}" else local retval retval=$(${MLIBDIR}/vercomp "${UP2PVER}" "${UPSTREAM_PVER}") [ ${retval} -eq 0 ] && echo -e "${PNAME}: ${COLGREEN}'${UP2PVER}' = '${UPSTREAM_PVER}'${COLDEFAULT}" [ ${retval} -lt 0 ] && echo -e "${PNAME}: ${COLRED}'${UP2PVER}' < '${UPSTREAM_PVER}'${COLDEFAULT}" [ ${retval} -gt 0 ] && echo -e "${PNAME}: ${COLYELLOW}'${UP2PVER}' > '${UPSTREAM_PVER}'${COLDEFAULT}" fi } updateall() { #local REPOS local PACKAGE local smage local repo local UP2DATE_SLEEP_COUNT=15 local UP2DATE_SLEEP_TIMEOUT=3 local ONLY_PRINT_UPSTREAM=0 local c PACKAGE="*" [[ ! -z $1 ]] && PACKAGE="$1" if [[ $1 = --upstream ]] || [[ $1 = -u ]] then if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]] then echo "you must give me a smagefile." exit 1 fi updateme $1 $2 return 0 fi ############################################################################## # recurse all depends if requested # if [[ $1 = --depend ]] || [[ $1 = -d ]] then if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]] then echo "you must give me a smagefile." exit 1 fi SMAGEFILE="$2" PACKAGE="$(magename2pname ${SMAGEFILE})" echo "processing '${SMAGEFILE}' ..." echo "running dependency checks for package '${PACKAGE}'..." DEPEND=$(get_value_from_magefile DEPEND ${SMAGEFILE}) SDEPEND=$(get_value_from_magefile SDEPEND ${SMAGEFILE}) declare -i c=0 while read sign dep do case ${dep} in "") continue;; esac # sleep every 15 packages for 5 seconds (( c++ )) if [[ ${c} -eq ${UP2DATE_SLEEP_COUNT} ]] then declare -i c=0 echo "DEBUG: Sleep Count (${UP2DATE_SLEEP_COUNT}x) reached, sleeping for ${UP2DATE_SLEEP_TIMEOUT} seconds ..." sleep ${UP2DATE_SLEEP_TIMEOUT} fi #echo "debug: ${dep}" updateme "$(dep2pname ${dep})" done << EOF ${DEPEND} ${SDEPEND} EOF fi # # eof recurse ############################################################################## for repo in ${REPOS} do # exclude not existing [[ ${PACKAGE} != \* ]] && [[ ! -d ${repo}/${PACKAGE} ]] && continue declare -i c=0 for smage in ${repo}/${PACKAGE}/*.smage2 do updateme ${smage} # sleep every 15 packages for 5 seconds (( c++ )) if [[ ${c} -eq ${UP2DATE_SLEEP_COUNT} ]] then declare -i c=0 echo "DEBUG: Sleep Count (${UP2DATE_SLEEP_COUNT}x) reached, sleeping for ${UP2DATE_SLEEP_TIMEOUT} seconds ..." sleep ${UP2DATE_SLEEP_TIMEOUT} fi done done } updateall $@