/,/<\/div>/{/diese Hardware-Version der.*/p}" | grep -q 'diese Hardware-Version der' && echo "There is no Labor firmware for this Hardware version $LOCAL_HWID avalabel!" && sleep 20
IMG_REQ1="$(cat "$DLD_DIR/$IMG_REQ" | sed -n "/
/,/<\/div>/{/
/,/Datum/{/$X_version......-.*/p}" | sed "s/.*//" | sed "s/<\/td>//")"
XXVERSION="$(cat "$DLD_DIR/$IMG_REQ" | sed -n "/ /,/Datum/{/Version/{n;p}}" | sed "s/.* | //" | sed "s/<\/td>//")"
#echo "XXVERSION: $XXVERSION"
Y_version=${XXVERSION:0:2}
Y_mayorversion=${XXVERSION:3:2}
Y_minorversion=${XXVERSION:6:2}
Y_subversion=${XXVERSION:9:5}
AVMNUM="$(cat "$DLD_DIR/$IMG_REQ" | grep "H_$LOCAL_HWID" | sed -e "s/0 v//" | sed -e "s/<\/h3>//" | sed -e 's/^.*\(.\{4\}\).$/\1/' | tr -d '[:alpha:]' )"
echo "AVM Type: $AVMNUM, New Firmware Version: $Y_version.$Y_mayorversion.$Y_minorversion-$Y_subversion, New subversion: $REVISON"
#bool "AVM 7390 84.05.04 20173 (NAS)"
if ! [ -z "$REVISON" ] && ! [ -z "$AVMNUM" ] && ! [ -z "$OLDREVISON" ] && ! [ -z "$OLDAVMNUM" ]; then
cp "${HOMEDIR}"/Config.in "${HOMEDIR}"/Config.in.ori
sed -i -e "s|$X_version\...\... $X_subversion|$Y_version\.$Y_mayorversion\.$Y_minorversion $Y_subversion|g" "${HOMEDIR}"/Config.in
sed -i -e "s|$X_version\.$X_mayorversion\.$X_minorversion|$Y_version\.$Y_mayorversion\.$Y_minorversion|g" "${HOMEDIR}"/Config.in
sed -i -e "s|${X_version}_$X_mayorversion_${X_minorversion}|${Y_version}_$Y_mayorversion_${Y_minorversion}|g" "${HOMEDIR}"/Config.in
sed -i -e "s|${OLDAVMNUM}_${OLDREVISON}|${AVMNUM}_${REVISON}|g" "$HOMEDIR/Config.in"
[ "${AVMNUM:3:1}" != "0" ] && [ "${OLDAVMNUM:3:1}" != "0" ] && AVMNUM="${AVMNUM:0:3}0v${AVMNUM:3:1}" && OLDAVMNUM="${OLDAVMNUM:0:3}0v${OLDAVMNUM:3:1}"
sed -i -e "s|${OLDAVMNUM} ${OLDREVISON}|${AVMNUM} ${REVISON}|g" "$HOMEDIR/Config.in"
echo "Config.in changed, diff saved to Config.in.diff"
diff -Naur "${HOMEDIR}"/Config.in.ori "${HOMEDIR}"/Config.in > "${HOMEDIR}"/Config.in.diff
eval "export $7=DONTUSE"
fi
fi
fi
eval "export $4=${DLD_PATH}${IMG_REQ1}"
fi
else
eval "export $4=${DLD_PATH}${3:6}"
fi
return 0
}
function get_fw_from_ftp()
{
DLD_PATH="${1%/*}/"
! `echo $1 | grep -q '@'` && `echo $1 | grep -q 'update.avm.de'` && DLD_PATH="ftp://jason:274jgjg85hh36@${DLD_PATH##*//}"
IMG_REQ="${1##*/}"
DLD_DIR="$2"
IMG_DESC="$3"
IMG_TPL=$( echo "$IMG_REQ" | sed -e 's/\...\.image/\.\*\.image/' )
DLD_TPL="${DLD_PATH}/${IMG_TPL}"
echo "-- checking ftp.avm.de for latest firmware file ..."
rm -f $DLD_DIR/.listing
wget --spider --no-remove-listing -P "$DLD_DIR" "$DLD_PATH" 2>&1 > /dev/null
if [ ! -e $DLD_DIR/.listing ]; then
echo "-- could not retrieve listing from ftp.avm.de"
eval "export $4=${IMG_REQ}"
sleep 5
return 1
else
IMG_LIST=$( cat "$DLD_DIR/.listing" | grep -wo "FRITZ.*.image" )
IMG_CNTS=$( cat "$DLD_DIR/.listing" | grep -wc "FRITZ.*.image" )
SELECT=0
YESNO="n"
while [ "$YESNO" != "y" ]; do
CNT=1
for IMG_FILE in $IMG_LIST; do
IMG[$CNT]="$IMG_FILE"
echo " ${CNT}. --- ${IMG[$CNT]}"
let CNT=$CNT+1
done
NN=2 && [ $IMG_CNTS -lt 10 ] && NN=1
echo -n " Select index of firmware image to use: "; read -n $NN SELECT; echo
echo
if [ $SELECT -gt 0 ] && [ $SELECT -lt $CNT ]; then
echo -n " Your selection: '${IMG[$SELECT]}'. Correct (y/n)? "; read -n 1 -s YESNO; echo
echo
fi
done
[ "$YESNO" = "y" ] && [ $SELECT -gt 0 ] && eval "export $4=${DLD_PATH}${IMG[$SELECT]}"
fi
return 0
}
#########################################################################
# #
# Function fwselect() #
# #
# Usage: fwselect img_path dld_dir img_desc var_by_ref #
# $1: full download path to required image #
# $2: local directory where images are stored #
# $3: image description to be used in prompt #
# $4: image description 2 #
# $5: mirror download link #
# $6: alternativ local filename or HWrevision or mirror #
# $7: firmware number XXXX or NO_NUMBER #
# #
# fwselect() returns name of selected image in variable #
# name referenced by var_by_ref ($4) #
# #
#########################################################################
function fwselect()
{
DLD_TPL="$1"
DLD_DIR="$2"
FW_TYPE="$7"
X_ENTRY="$5"
[ "${1##*.}" == "php" ] && get_php "$DLD_TPL" "$DLD_DIR" "$6" "DLD_TPL" "$6" "$5" "X_ENTRY"
IMG_REQ="${DLD_TPL##*/}"
DLD_PATH="${DLD_TPL%/*}"
FIRST_ENTRY=""
SECOND_ENTRY="$6"
if [ "$SECOND_ENTRY" != "mirror" ] && [ "${6:0:2}" != "HW" ]; then
[ -z "$SECOND_ENTRY" ] || IMG_REQ=$SECOND_ENTRY
FIRST_ENTRY="$1"
else
if [ "${IMG_REQ##*.}" == "zip" ] || [ "${IMG_REQ##*.}" == "ZIP" ];then
[ "${6:0:2}" == "HW" ] && FIRST_ENTRY="$1 ${6:0:5}:$IMG_REQ"
! [ -f $DLD_DIR/$IMG_REQ ] && SECOND_ENTRY="${6:0:2}"
else
[ "${6:0:2}" == "HW" ] && FIRST_ENTRY="$1 ${6:0:5}"
fi
fi
get_fw "$DLD_TPL" "$2" "$3" "$4" "$X_ENTRY" "$SECOND_ENTRY" "$FIRST_ENTRY"
if [ $? -ne 0 ]; then
IMG_REQ_OLD=$IMG_REQ
DLD_TPL_OLD=$DLD_TPL
#echo ":1:$IMG_REQ_OLD"
X_version=""
X_subversion=""
X_minorversion=""
export X_X=`echo $IMG_REQ_OLD | grep '.0[45].' | sed -e 's|-|\.|' | sed -e 's|_|\.|' | sed -e 's|M||' | sed 's/.*\(...0[45].*\)/\1/'`
if `echo "${X_X:15:5}" | grep -q 'image'` || `echo "${X_X:15:3}" | grep -q 'zip'` || `echo "${X_X:15:3}" | grep -q 'ZIP'` ; then
X_version=${X_X:0:2}
X_minorversion=${X_X:6:2}
X_mayorversion=${X_Y:3:2}
X_subversion=${X_X:9:5}
#echo "Firmware Version: $X_version.$X_mayorversion.$X_minorversion-$X_subversion"
else
if `echo "${X_X:9:5}" | grep -q 'image'` || `echo "${X_X:9:3}" | grep -q 'zip'` || `echo "${X_X:9:3}" | grep -q 'ZIP'` ; then
X_version=${X_X:0:2}
X_mayorversion=${X_Y:3:2}
X_minorversion=${X_X:6:2}
#echo "Firmware Version: $X_version.$X_mayorversion.$X_minorversion"
fi
fi
` echo $DLD_TPL | grep -q 'ftp://'` && get_fw "$DLD_TPL" "$2" "$3" "$4" "select" "$SECOND_ENTRY" "$FIRST_ENTRY"
if [ $? -ne 0 ]; then
if [ $? -eq 1 ]; then
echo "Check your internet connection!"
echo "In some cases the download won't start even the file exists on the given locoction."
fi
echo "Unable to retrieve file '$IMG_REQ'"
echo "Please download the file to the following directory:"
echo " $DLD_DIR"
eval "$4=''"
return 1
fi
IMG_REQ="${DLD_TPL##*/}"
cp "${HOMEDIR}"/Config.in "${HOMEDIR}"/Config.in.ori
sed -i -e "s|$DLD_TPL_OLD|$DLD_TPL|g" "${HOMEDIR}"/Config.in
sed -i -e "s|$IMG_REQ_OLD|$IMG_REQ|g" "${HOMEDIR}"/Config.in
Y_version=""
Y_subversion=""
Y_minorversion=""
MULTI="_"
MULTI_T='"'
`echo $IMG_REQ_OLD | grep -q 'en-de'` && `echo $IMG_REQ | grep -q 'en-de'` && MULTI="m" && MULTI_T=".en-de"
X_Y=`echo $IMG_REQ | grep '.0[45].' | sed -e 's|-|\.|g' | sed -e 's|_|\.|g' | sed -e 's|M||' | sed 's/.*\(...0[45].*\)/\1/'`
if [ "X_Y" != "" ] && [ "X_X" != "" ] ; then
if `echo "${X_Y:15:5}" | grep -q 'image'` || `echo "${X_Y:15:3}" | grep -q 'zip'` || `echo "${X_Y:15:3}" | grep -q 'ZIP'` ; then
Y_version=${X_Y:0:2}
Y_mayorversion=${X_Y:3:2}
Y_minorversion=${X_Y:6:2}
Y_subversion=${X_Y:9:5}
echo "Version:${MULTI}$Y_version.$Y_mayorversion.$Y_minorversion-$Y_subversion"
else
if `echo "${X_Y:9:5}" | grep -q 'image'` || `echo "${X_Y:9:3}" | grep -q 'zip'` || `echo "${X_Y:9:3}" | grep -q 'ZIP'` ; then
Y_version=${X_Y:0:2}
Y_mayorversion=${X_Y:3:2}
Y_minorversion=${X_Y:6:2}
echo "Version:${MULTI}$X_version.$X_mayorversion.$X_minorversion"
fi
fi
if [ "$X_version" != "" ] && [ "$Y_version" != "" ] && [ "$X_version$X_minorversion" != "$Y_version$Y_minorversion" ]; then
echo "Config.in changed, diff saved to Config.in.diff"
sed -i -e "s|$X_version\.$X_mayorversion\.$X_minorversion${MULTI_T}|$Y_version\.$Y_mayorversion\.$Y_minorversion${MULTI_T}|g" "${HOMEDIR}"/Config.in
sed -i -e "s|${MULTI}${X_version}_$X_mayorversion_${X_minorversion}|${MULTI}${Y_version}_$Y_mayorversion_${Y_minorversion}|g" "${HOMEDIR}"/Config.in
fi
if [ "$X_subversion" != "" ] && [ "$Y_subversion" != "" ] && [ "$X_subversion" != "$Y_subversion" ] ; then
sed -i -e "s|$X_subversion${MULTI_T}|$Y_subversion${MULTI_T}|g" "${HOMEDIR}"/Config.in
sed -i -e "s|_$X_subversion|_$Y_subversion|g" "${HOMEDIR}"/Config.in
fi
fi
diff -Naur "${HOMEDIR}"/Config.in.ori "${HOMEDIR}"/Config.in > "${HOMEDIR}"/Config.in.diff
fi
}
function get_fw()
{
DLD_TPL="$1"
DLD_DIR="$2"
IMG_DESC="$3"
IMG_DESC2="$4"
if [ "$5" == "select" ]; then
get_fw_from_ftp "$DLD_TPL" "$DLD_DIR" "$IMG_DESC" "DLD_TPL"
MIRROR_DLD_PATH=""
MIRROR_DLD_TPL=""
FILENAME_DLD_TPL=""
else
MIRROR_DLD_PATH="${5%/*}"
MIRROR_DLD_TPL="$5"
FILENAME_DLD_TPL="$6"
[ "${6:0:2}" == "HW" ] && ! [ -z "$5" ] && FILENAME_DLD_TPL="$5"
[ "${6:0:2}" == "HW" ] && MIRROR_DLD_TPL=""
fi
FIRST_ENTRY="$7"
IMG_REQ="${DLD_TPL##*/}"
DLD_PATH="${DLD_TPL%/*}"
EXT="${DLD_TPL##*.}"
#echo "test----------------------------"
#echo "DLD_TPL:$DLD_TPL"
#echo "MIRROR_DLD_TPL:$MIRROR_DLD_TPL"
#echo "FILENAME_DLD_TPL:$FILENAME_DLD_TPL"
#echo "test----------------------------"
IMG_REQ_N="${IMG_REQ%.*}"
if [ -f "$DLD_DIR/${FILENAME_DLD_TPL##*/}" ]; then
#echo "#alternative local filename -->"
IMG_REQ="${FILENAME_DLD_TPL##*/}"
EXT="${FILENAME_DLD_TPL##*.}"
DLD_PATH="${FILENAME_DLD_TPL%/*}"
else #<--alternative local filename --
if [ -f "$DLD_DIR/$IMG_REQ_N.image" ]; then
#echo "---->>>> IMG_REQ_N: $IMG_REQ_N"
IMG_REQ="$IMG_REQ_N.image"
EXT="image"
else
if [ "$MIRROR_DLD_TPL" ]; then
#echo "#---use mirrorimage-->"
if ! [ -f "$DLD_DIR/$IMG_REQ" ]; then
case "$MIRROR_DLD_PATH" in
ftp://*)
wget --passive-ftp --output-document="$DLD_DIR/$IMG_REQ" "$MIRROR_DLD_TPL" 2>&1
;;
http://*)
wget --output-document="$DLD_DIR/$IMG_REQ" "$MIRROR_DLD_TPL" 2>&1
;;
esac
fi
#echo "#<---use mirrorimage"
else
if ! [ -f "$DLD_DIR/$IMG_REQ" ]; then
case "$DLD_PATH" in
@AVM*)
#echo "# Fill array 'sites' with download server URLs, first primary site (if specified)"
DLD_0=${DLD_PATH/@AVM\//}
sites[0]=ftp://ftp.avm.de/$DLD_0
sites[1]=http://download.avm.de/$DLD_0
sites[2]=ftp://download.avm.de/$DLD_0
# Loop over servers until a download succeeds or all requests have failed.
for i in ${sites[@]} ; do
do_download "$DLD_DIR" "$i/$IMG_REQ" && break
done
;;
ftp://*)
#do_download "$DLD_DIR" "$DLD_TPL"
wget --passive-ftp -P "$DLD_DIR" "$DLD_TPL" 2>&1
;;
http://*)
#echo " html download ..."
# DLD_TPL_NEW=""
# rm -f $DLD_DIR/404*
wget -P "$DLD_DIR" "$DLD_TPL" 2>&1
# if [ ! -e $DLD_DIR/404.html ]; then
# # follows if last digit of miniorversion is diffent
# DLD_TPL_NEW=`wget --spider -P "$DLD_DIR" "$DLD_TPL" 2>&1 | grep 'Location:' | sed -e 's/Location://' | sed -e 's/ //' | sed 's/\(ZIP\).*/\1/' | sed 's/\(zip\).*/\1/'`
# if ! `echo "$DLD_TPL_NEW" | grep -q '404.html' `;then
# if [ "$DLD_TPL_NEW" != "" ] && [ "$DLD_TPL_NEW" != "$DLD_TPL" ]; then
# echo ":old :$DLD_TPL"
# echo ":select:$DLD_TPL_NEW"
# cp "${HOMEDIR}"/Config.in "${HOMEDIR}"/Config_ori.in
# sed -i -e "s|"$DLD_TPL.*$"|$DLD_TPL_NEW\"|g" "${HOMEDIR}"/Config.in
# diff -Naur "${HOMEDIR}"/Config_ori.in "${HOMEDIR}"/Config.in >> "${HOMEDIR}"/diff-config.in
# IMG_REQ="${DLD_TPL_NEW##*/}"
# fi
# fi
# fi
;;
esac
fi
fi
fi #<--alternative local filename --
fi
if [ -f "$DLD_DIR/$IMG_REQ" ]; then
#act_size=`ls -l "$DLD_DIR/$IMG_REQ" | sed -e 's/[^0-9]/#/g' | sed -e 's/#\+[0-9]\+#\+\([0-9]\+\).*/\1/'`
#echo "size: $act_size"
#[ "$act_size" == "0" ] && rm -f $DLD_DIR/$IMG_REQ
check_or_write_md5_to_DB "$DLD_DIR/$IMG_REQ" && check_html "$DLD_DIR/$IMG_REQ" && \
eval "$4=''" && return 2
fi
if [ -f "$DLD_DIR/$IMG_REQ" ]; then
if [ "$EXT" = "zip" ] || [ "$EXT" = "ZIP" ]; then
IMG_REQ1="${IMG_REQ%.*}"
echo "-- extracting $IMG_REQ1 from archive "$IMG_REQ" ..."
rm -fr "$DLD_DIR/$IMG_REQ1"
mkdir "$DLD_DIR/$IMG_REQ1"
check_or_write_md5_to_DB "$DLD_DIR/$IMG_REQ"
unzip -qoj "$DLD_DIR/$IMG_REQ" -d "$DLD_DIR/$IMG_REQ1" #option j added because AVM added path inside zipfile with fritz_box-labor-7270-13362.zip
#--> look for file supplied via Config.in as 2nd parameter -->
if [ -f "$DLD_DIR/$IMG_REQ1/${FILENAME_DLD_TPL##*/}" ]; then
IMG_EXTRACTED="${FILENAME_DLD_TPL##*/}"
else
#echo "#<--look for file supplied via Config.in as 2nd parameter"
#-->only used if more than one .image file is within the zipfile-->
IMG_EXTRACTED=`ls "$DLD_DIR/$IMG_REQ1" | grep 'image'`
IMG_CNTS=`ls "$DLD_DIR/$IMG_REQ1" | grep -c 'image'`
SELECT=0
YESNO="y"
if [ $IMG_CNTS -gt 1 ]; then
YESNO="n"
echo "-- more than one match for '*.image' found:"
echo
fi
while [ "$YESNO" != "y" ]; do
CNT=1
for IMG_FILE in $IMG_EXTRACTED; do
IMG[$CNT]="$IMG_FILE"
echo " ${CNT}. --- ${IMG[$CNT]}"
let CNT=$CNT+1
done
echo -n " Select index of firmware image to use: "; read -n 1 SELECT; echo
echo
if [ $SELECT -gt 0 ] && [ $SELECT -lt $CNT ]; then
echo -n " Your selection: '${IMG[$SELECT]}'. Correct (y/n)? "; read -n 1 -s YESNO; echo
fi
[ "$YESNO" = "y" ] && IMG_EXTRACTED="${IMG[$SELECT]}"
done
#<--only used if more than one .image file is within the zipfile
fi #<--look for file supplied via Config.in as 2nd parameter
#workaround problem with filenames including SPC
IMG_EXTRACTED_SPC="$(echo $IMG_EXTRACTED | sed -e "s/ /-/g")"
mv "$DLD_DIR/$IMG_REQ1/$IMG_EXTRACTED" "$DLD_DIR/$IMG_EXTRACTED_SPC"
if [ -f "$DLD_DIR/$IMG_EXTRACTED_SPC" ]; then
check_or_write_md5_to_DB "$DLD_DIR/$IMG_EXTRACTED_SPC"
#echo "-----> $FIRST_ENTRY"
echo "$IMG_EXTRACTED" | grep -q ' ' || ([ "$MIRROR_DLD_TPL" == "" ] && sed -i -e "s|\"$FIRST_ENTRY\"|\"$FIRST_ENTRY \./$FWORIGDIR/$IMG_EXTRACTED_SPC\"|" "$HOMEDIR/Config.in")
[ "$MIRROR_DLD_TPL" == "" ] && sed -i -e "s|\"$FIRST_ENTRY\"|\"$FIRST_ENTRY \./$FWORIGDIR/$IMG_EXTRACTED_SPC\"|" "$HOMEDIR/$firmwareconf_file_name"
# workaroud because LaborCORE zip includes now DOS filenames with !, delite did hang.
for file in $(ls "$DLD_DIR/$IMG_REQ1"); do
#echo "$file"
rm -fr "$DLD_DIR/$IMG_REQ1/$file"
done
rm -fr "$DLD_DIR/$IMG_REQ1/"
rmdir --ignore-fail-on-non-empty "$DLD_DIR/$IMG_REQ1" > /dev/null 2>&1
##### rm -f "$DLD_DIR/$IMG_REQ"
fi
echo "image extracted: $IMG_EXTRACTED_SPC"
eval "$4=$IMG_EXTRACTED_SPC"
return 0
else
eval "$4=$IMG_REQ"
#echo "existing image: $IMG_REQ"
return 0
fi
fi
#echo "No image"
eval "$4=''"
return 1
}
function check_html()
{
echo "--------> wrong mtd5-checksum!"
sleep 1
if $(grep -q ' |