View Single Post
Posts: 840 | Thanked: 823 times | Joined on Nov 2009
#7
Here is the script but do not run it. The functions that start with DL are called at places I would like to download a file from the servers.

P.S. linuxeventually, your PM box is full.

Code:
#!/bin/bash
# A front-end to flasher-3.5, to make flashing the N900 internet tablet easier.

flasherpkg="flasher-3.5"
flasherpkgfilename="flasher-3.5.deb"
PRVersions=test.cfg

isValidYesNo()
{
 case "$1" in
  "yes" | "Yes" | "y" | "Y" ) return 0;;
  "no" | "No" | "n" | "N" ) return 0;;
  "") if [ "$2" = "" ]; then return 1; else return 0; fi ;;
   *) return 1 ;;
 esac
}

isYes()
{
 while test true ; do
  read -p "$1 [y,n]:" input </dev/tty
  if isValidYesNo "$input" "$2" ; then break; fi
 done 
 case "$input" in
  "yes" | "Yes" | "y" | "Y" ) return 0;;
  "no" | "No" | "n" | "N" ) return 1;;
  "") return $2;;
 esac
}

isInstalled()
{
if dpkg -s "$1" | grep "Status: install ok installed" ; then
 return 0
else
 return 1
fi
}


get_PR_list()
{
   config_file=$1
   awk -F '[][]' '
      NF==3 && $0 ~ /^\[.*\]/ { print $2 }
   ' ${config_file}
}

get_PR_vars()
{
   config_file=$1 #file name
   config=$2 #set name
   var_prefix=$3 #prefix variable with this
 
        awk -F= -v Config="${config}" -v Prefix="${var_prefix}" '
        BEGIN { 
           Config = toupper(Config);
           patternConfig = "\\[" Config "]";
        }
        toupper($0)  ~ patternConfig,(/\[/ && toupper($0) !~ patternConfig)  { 
           if (/\[/ || NF <2) next;
           sub(/^[[:space:]]*/, "");
           sub(/[[:space:]]*=[[:space:]]/, "=");
           print Prefix $0;
        } ' ${config_file}
}

OKmd5()
{
if md5sum -c MD5SUMS | grep "$1: OK"); then
 return 0
else
 return 1
fi
}

DLflasherpkgfile()
{
 wget $1
}

DLfirmwareimage()
{
 wget $1
}

DLeMMCimage()
DLImagemd5sums()

######################################################################

if isInstalled "$flasherpkg" ; then
 echo "$flasherpkg found"
else
 echo -e "\033[1;31m $flasherpkg has not been installed or is broken \033[0m"
 if isYes "Do you wish to install ${flasherpkg}?" ; then
  if [ ! -f "$flasherpkgfilename" ] ; then DLflasherpkgfile ; fi
  sudo dpkg -i "$flasherpkgfilename"
 else
  exit
 fi
fi

if [ $# -gt 1 ]; then
 shift
 echo -e "\033[1;34m flasher-3.5 $@ \033[0m"
 exit
fi 

echo -e "\033[1;31m Flashing an older firmware than that found on your N900 can result in no 2G/3G and would require a reflash. \033[0m"

PS3="Select a number corresponding to the PR version you wish to flash (NOT the PR version number itself):"
select PRVersion in $(get_PR_list ${PRVersions}) ; do
 PS3="Select a region"
 select PRVar in $(get_PR_vars ${PRVersions} ${PRVersion}) ; do
  PRimagefilename=${PRVar#*=}
  break 2
 done
done

if isYes "Do you want to delete all user data too?" ; then
 flasheMMC=true
else
 flasheMMC=false
fi

emmcimagefilename="emmcImage.bin"

DLImagemd5sums
if [ flasheMMC == false ]; then
 if [ ! -f $PRimagefilename ]; then DLfirmwareimage; fi
 if OKmd5 $PRimagefilename ; then
  echo -e "\033[1;34m flasher-3.5 -F $PRImagefilename -f -R \033[0m"
 else
  echo -e "\033[1;31m Image file $PRImagefilename is corrupt \033[0m"
 fi
else
 if [ ! -f $PRimagefilename ]; then DLfirmwareimage; fi
 if [ ! -f $emmcimagefilename ]; then DLeMMCimage; fi
 if OKmd5 $PRimagefilename ; then
  if OKmd5 $emmcimagefilename ; then
   echo -e "\033[1;34m flasher-3.5 -F $PRImagefilename -f \033[0m"
   echo -e "\033[1;34m flasher-3.5 -F $emmcimagefilename -f -R \033[0m"
  else
   echo -e "\033[1;31m Image file $emmcimagefilename is corrupt \033[0m"
  fi
 else
  echo -e "\033[1;31m Image file $PRImagefilename is corrupt \033[0m"
 fi
fi

Last edited by Cue; 2010-11-23 at 19:06.