Reply
Thread Tools
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#4561
Originally Posted by brkn View Post
It is not working because $COLUMNS for curl can't be initialised/accessed from your script unless you had tput for example to get the columns. Workarounds involve unbuffered use of grep and sed.

Note: Harmattan dev repository is down for me atm but I mirrored all ~ 15 gb of packages so I figured for the demo I would just upload those two needed packages to my dropbox account.
I put together some script below. Before you have to install newer version of grep and sed which support unbuffered option.

To do this, open terminal and type (only needed once):
Code:
devel-su
cd /home/user/MyDocs/Downloads/
wget https://www.dropbox.com/s/83k1xf63hg3pzzt/grep_2.6.3-3%2Bmaemo1%2B0m6_armel.deb?dl=1
dpkg -x grep_2.6.3-3+maemo1+0m6_armel.deb /opt/extrautils
wget https://www.dropbox.com/s/hsn5jggyx5mrioq/sed_4.2.1-7%2Bmaemo1%2B0m6_armel.deb?dl=1
dpkg -x sed_4.2.1-7+maemo1+0m6_armel.deb /opt/extrautils
Download script (feel free to modify):
Code:
#!/bin/sh
# little downloader for Schturman's awesome N9 QuickTweak app

download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | /opt/extrautils/bin/grep --line-buffered "%" | \
        /opt/extrautils/bin/sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

file="http://dl.dropbox.com/u/17706605/n9-qtweakall_9.4_armel.deb"
echo -n "Downloading stuff:"
download "$file"
Output looks like:
Code:
~/MyDocs/Downloads $ sh test.sh 
Downloading stuff: 59%
PS: thank you so much by the way for you app - it is great and I really do appreciate it!
Tested right now, work perfectly ! Thank you !
Tell me something.. We can not shorten the progress bar in CURL and what with WGET ? Can we add short (for portrait mode) progress bar to wget command, not only percentage?
Something like:
Code:
Downloading status:
[=====>       ] 59%
or
Code:
Downloading status:
[#######      ] 59%
or something else ?

Last edited by Schturman; 2012-11-08 at 22:41.
 
Posts: 299 | Thanked: 557 times | Joined on Aug 2012
#4562
Tested right now, work perfectly ! Thank you !
Thanks, glad it helps.

Tell me something.. We can not shorten the progress bar in CURL and what with WGET ?
No and no.

Can we add short (for portrait mode) progress bar to wget command, not only percentage?
Something like:
Code:
Downloading status:
[=====>       ] 59%
or
Code:
Downloading status:
[#######      ] 59%
or something else ?
Will check that one for you and post back.
 

The Following User Says Thank You to brkn For This Useful Post:
Posts: 299 | Thanked: 557 times | Joined on Aug 2012
#4563
Aaaaaand it's there:

Steps to take once:
Code:
devel-su
cd /home/user/MyDocs/Downloads/
wget https://www.dropbox.com/s/a7qncxnt4hs4e7w/dialog_1.0-20060221-3_armel.deb?dl=1
dpkg -x dialog_1.0-20060221-3_armel.deb /opt/extrautils


Download script:
Code:
#!/bin/sh
# downloader for schturman's n9qtweak
# author: brkn
# date: 2012-11-09
# v0.1.0

trap 'rm -r wget-log tmp.log && killall wget; exit 0' 2 15
URL="http://dl.dropbox.com/u/17706605/n9-qtweakall_9.4_armel.deb"
gui_wget()
{
   rm wget-log* tmp.log &> /dev/null
   wget -b $1 &> /dev/null
   cp wget-log tmp.log
   PERCENT="0"
   {
      while [ "${PERCENT}" != "100" ] ; do
         PERCENT=`awk -F: '$1 ~ /KB/ { print }' tmp.log | tail -n1 | cut -b 62-64`
         echo $PERCENT
         cp wget-log tmp.log
      done
   } | /opt/extrautils/usr/bin/dialog --title "Downloading ..." --gauge "$1" 8 40 0
   rm wget-log tmp.log
}

gui_wget ${URL}
/opt/extrautils/usr/bin/dialog --title "Download finished!" --infobox "oh boy, can't wait to see the update!" 4 40
exit 0

Result if everything went ok:





Note: don't set more than 47 columns because that's max on N9 in portrait mode. If you want dynamic resizing of boxes depending on portrait or landscape mode, it will take some time.

Have fun with modding!

Last edited by brkn; 2012-11-09 at 01:00.
 

The Following 2 Users Say Thank You to brkn For This Useful Post:
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#4564
WOW!.. Thanks
Will test it later.. I thought about something more simple, without dialog box , but it looks more interesting
Thanks
 
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#4565
Ok, I tested it...
It Cool, but work not so good.. Too much times this progress bar got stuck on some percentage and this dialog window can't close itself, but file already downloaded.. For close it I need to press "Ctrl+C"
Also, can you remove this blue background, that user can see the background of N9QT ?
Another question.. .Why it have so big space between the last words in N9QT until the blue background ?
And with this dialog we not need grep and sed anymore ?
Thanks
Attached Images
 
 

The Following User Says Thank You to Schturman For This Useful Post:
Posts: 299 | Thanked: 557 times | Joined on Aug 2012
#4566
Originally Posted by Schturman View Post
Ok, I tested it...
It Cool, but work not so good.. Too much times this progress bar got stuck on some percentage and this dialog window can't close itself, but file already downloaded.. For close it I need to press "Ctrl+C"
Also, can you remove this blue background, that user can see the background of N9QT ?
Another question.. .Why it have so big space between the last words in N9QT until the blue background ?
And with this dialog we not need grep and sed anymore ?
Thanks
Please attach the modified UPDATER script. No need for sed and grep anymore.
 
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#4567
Originally Posted by brkn View Post
Please attach the modified UPDATER script. No need for sed and grep anymore.
Here one for test:
Code:
#!/bin/sh

RED='\033[1;31m'
CYAN='\033[1;36m'
NORMAL='\033[0m'
YELLOW='\033[1;33m'
BLINK='\033[5m'

if [ ! -f /etc/apt/sources.list.d/sdk.list ]
   then
      echo 'deb http://harmattan-dev.nokia.com/ harmattan/sdk free non-free' > /etc/apt/sources.list.d/sdk.list
    apt-get update
fi                          
if [ ! -f /bin/bash ]; then
   echo "bash not installed, trying to install..."
   pkill pkgmgrd
   rm /var/lib/dpkg/lock
   echo "" | dpkg -i /opt/N9QTweak/SYS/bash* || echo "failed to install bash"
fi

if [ ! -f /home/user/MyDocs/Documents/N9_QuickTweak_*.pdf ]
   then
   echo "PDF instruction not here! Open PDF downloader.."
   echo "For Exit, just press Enter..."
   echo ""
    echo " ---------------------------------------------"
    echo -e "|        ${CYAN}N9 QuickTweak PDF downloader${NORMAL}         |"
    echo " ---------------------------------------------"
    echo -e "| ${YELLOW}A: English PDF instruction${NORMAL}                  |"
    echo -e "| ${YELLOW}B: Russian  PDF instruction${NORMAL}                 |"
    echo -e "| ${YELLOW}C: Both PDF instructions${NORMAL}                    |"
    echo " ---------------------------------------------"
    echo -e "| ${YELLOW}D: PDF file with links ONLY !${NORMAL}               |"
    echo " ---------------------------------------------"
    echo "After applying you will find PDF file in your:"
    echo -e "${CYAN}/home/user/MyDocs/Documents${NORMAL}"
    echo ""
        read -p "Choose a letter: " ANS
        case $ANS in
a|A)
if eval "ping -c 1 www.google.com" > /dev/null;then
 if [ ! -f /usr/bin/wget ]; then
  echo "wget not installed, trying to install..."
  pkill pkgmgrd
   rm /var/lib/dpkg/lock
   echo "" | dpkg -i /opt/N9QTweak/SYS/wget* || echo "failed to install wget"
    echo ""
     echo -e "${BLINK}${RED}WAIT!${NORMAL} ${YELLOW}Downloading PDF instruction...${NORMAL}"
      cd /home/user/MyDocs/Documents
download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | /opt/N9QTweak/SYS/bin/grep --line-buffered "%" | \
        /opt/N9QTweak/SYS/bin/sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

file="http://dl.dropbox.com/u/17706605/N9_QuickTweak_en_v9.5.pdf"
echo -n "Downloading status:"
download "$file"
       echo ""
       echo -e "${YELLOW}PDF instruction downloaded successfully...${NORMAL}"
   else
    echo ""
     echo -e "${BLINK}${RED}WAIT!${NORMAL} ${YELLOW}Downloading PDF instruction...${NORMAL}"
      cd /home/user/MyDocs/Documents
trap 'rm -r wget-log tmp.log && killall wget; exit 0' 2 15
URL="http://dl.dropbox.com/u/17706605/N9_QuickTweak_en_v9.4.pdf"
URL2="http://dl.dropbox.com/u/17706605/N9_QuickTweak_ru_v9.4.pdf"
gui_wget()                                                                                                      
{                                                                                                               
   rm wget-log* tmp.log &> /dev/null                                                                            
   wget -b $1 &> /dev/null                                                                                      
   cp wget-log tmp.log                                                                                          
   PERCENT="0"                                                                                                  
   {                                                                                                            
      while [ "${PERCENT}" != "100" ] ; do                                                                      
         PERCENT=`awk -F: '$1 ~ /KB/ { print }' tmp.log | tail -n1 | cut -b 62-64`                              
         echo $PERCENT                                                                                          
         cp wget-log tmp.log                                                                                    
      done                                                                                                      
   } | /opt/N9QTweak/SYS/bin/dialog --title "Downloading ..." --gauge "$1" 8 40 0                               
   rm wget-log tmp.log                                                                                          
}                                                                                                               
                                                                                                                
gui_wget ${URL}
gui_wget ${URL2}                    
       echo ""
       echo -e "${YELLOW}PDF instruction downloaded successfully...${NORMAL}"
   fi
 else
  echo ""
  echo -e "${RED}You are ${BLINK}NOT${NORMAL} ${RED}connected, CAN'T download...${NORMAL}"
  echo "You got only PDF file with links!"
  cp -f /opt/N9QTweak/N9_QuickTweak_*.pdf /home/user/MyDocs/Documents
  echo ""
  echo "Open N9 QuickTweak menu..."
fi ;;

b|B)
if eval "ping -c 1 www.google.com" > /dev/null;then
 if [ ! -f /usr/bin/wget ]; then
  echo "wget not installed, trying to install..."
  pkill pkgmgrd
   rm /var/lib/dpkg/lock
   echo "" | dpkg -i /opt/N9QTweak/SYS/wget* || echo "failed to install wget"
    echo ""
     echo -e "${BLINK}${RED}WAIT!${NORMAL} ${YELLOW}Downloading PDF instruction...${NORMAL}"
      cd /home/user/MyDocs/Documents
download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | /opt/N9QTweak/SYS/bin/grep --line-buffered "%" | \
        /opt/N9QTweak/SYS/bin/sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

file="http://dl.dropbox.com/u/17706605/N9_QuickTweak_ru_v9.5.pdf"
echo -n "Downloading status:"
download "$file"
       echo ""
       echo -e "${YELLOW}PDF instruction downloaded successfully...${NORMAL}"
   else
    echo ""
     echo -e "${BLINK}${RED}WAIT!${NORMAL} ${YELLOW}Downloading PDF instruction...${NORMAL}"
      cd /home/user/MyDocs/Documents
download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | /opt/N9QTweak/SYS/bin/grep --line-buffered "%" | \
        /opt/N9QTweak/SYS/bin/sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

file="http://dl.dropbox.com/u/17706605/N9_QuickTweak_ru_v9.5.pdf"
echo -n "Downloading status:"
download "$file"
       echo ""
       echo -e "${YELLOW}PDF instruction downloaded successfully...${NORMAL}"
   fi
 else
  echo ""
  echo -e "${RED}You are ${BLINK}NOT${NORMAL} ${RED}connected, CAN'T download...${NORMAL}"
  echo "You got only PDF file with links!"
  cp -f /opt/N9QTweak/N9_QuickTweak_*.pdf /home/user/MyDocs/Documents
  echo ""
  echo "Open N9 QuickTweak menu..."
fi ;;

c|C)
if eval "ping -c 1 www.google.com" > /dev/null;then
 if [ ! -f /usr/bin/wget ]; then
  echo "wget not installed, trying to install..."
  pkill pkgmgrd
   rm /var/lib/dpkg/lock
   echo "" | dpkg -i /opt/N9QTweak/SYS/wget* || echo "failed to install wget"
    echo ""
     echo -e "${BLINK}${RED}WAIT!${NORMAL} ${YELLOW}Downloading PDF instruction...${NORMAL}"
      cd /home/user/MyDocs/Documents
download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | /opt/N9QTweak/SYS/bin/grep --line-buffered "%" | \
        /opt/N9QTweak/SYS/bin/sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

file="http://dl.dropbox.com/u/17706605/N9_QuickTweak_en_v9.5.pdf http://dl.dropbox.com/u/17706605/N9_QuickTweak_ru_v9.5.pdf"
echo -n "Downloading status:"
download "$file"
       echo ""
       echo -e "${YELLOW}PDF instruction downloaded successfully...${NORMAL}"
   else
    echo ""
     echo -e "${BLINK}${RED}WAIT!${NORMAL} ${YELLOW}Downloading PDF instruction...${NORMAL}"
      cd /home/user/MyDocs/Documents
download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | /opt/N9QTweak/SYS/bin/grep --line-buffered "%" | \
        /opt/N9QTweak/SYS/bin/sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

file="http://dl.dropbox.com/u/17706605/N9_QuickTweak_en_v9.5.pdf http://dl.dropbox.com/u/17706605/N9_QuickTweak_ru_v9.5.pdf"
echo -n "Downloading status:"
download "$file"
       echo ""
       echo -e "${YELLOW}PDF instruction downloaded successfully...${NORMAL}"
   fi
 else
  echo ""
  echo -e "${RED}You are ${BLINK}NOT${NORMAL} ${RED}connected, CAN'T download...${NORMAL}"
  echo "You got only PDF file with links!"
  cp -f /opt/N9QTweak/N9_QuickTweak_*.pdf /home/user/MyDocs/Documents
  echo ""
  echo "Open N9 QuickTweak menu..."
fi ;;

d|D)
  echo "You got PDF file with links. Continue to menu.."
  cp -f /opt/N9QTweak/N9_QuickTweak_*.pdf /home/user/MyDocs/Documents ;;
    * ) read -p "You chose to not download. Continue to menu..." end; continue ;;
        esac
      echo " "
  else
    echo "Open N9 QuickTweak menu..."
fi

if [ -f /bin/bash ]
then bash /opt/N9QTweak/N9QT
else
    echo "bash not installed. exiting..."
    sleep 2
    exit 0
fi
Look in to option A after "else"...
I also tested with separated script with command: sh /pash/downloader.sh instead what you see above...
Both of them sometimes got stuck and can't be closed
 
Posts: 299 | Thanked: 557 times | Joined on Aug 2012
#4568
Originally Posted by Schturman View Post
Here one for test: ...
Ok I experienced the stuck issue as well and changed the script, please follow the instructions and test again. Once it works for you (I have 100% success rate with ~ 50 tests) I will build a dialog menu for you to make this look right.


Dependencies (only needed once): dialog + bc
Code:
devel-su
cd /home/user/MyDocs/Downloads/
wget https://www.dropbox.com/s/a7qncxnt4hs4e7w/dialog_1.0-20060221-3_armel.deb?dl=1
dpkg -x dialog_1.0-20060221-3_armel.deb /opt/extrautils
wget https://www.dropbox.com/s/y1jnb91cpxqgsx6/bc_1.06.95-2%2Bmaemo9%2B0m6_armel.deb?
dl=1
dpkg -x bc_1.06.95-2+maemo9+0m6_armel.deb /opt/extrautils

Script:
Code:
#!/bin/sh

URL="http://dl.dropbox.com/u/17706605/N9_QuickTweak_en_v9.4.pdf"
FILE=$(basename $URL)
rm -f $FILE
length=$(curl --head $URL 2>&1 | grep Content-Length | awk '{print $2}')
length_kb=$(($length >> 10))
scale=$(echo "scale=6; 100/$length" | /opt/extrautils/usr/bin/bc)
wget $URL 2>/dev/null &

(
while ( true )
do
    proc=$(ps aux | grep -v grep | grep wget | grep $FILE )
    if [[ "$proc" == "" ]]; then break; fi
    size=$(ls -l $FILE 2>/dev/null | awk '{print $5}' 2>/dev/null)
    if [ "$size" != "" ]; then
        {
            metre=$(printf %.0f $(echo "$size*$scale" | /opt/extrautils/usr/bin/bc))
        }
    fi

    echo "XXX"
    echo "file: $FILE"
    echo "size: $length_kb kb"
    echo "Please standby ..."
    echo "XXX"
    echo $metre

done
) | /opt/extrautils/usr/bin/dialog --title " N9 QuickTweak Updater " --no-collapse --gauge "Download Test" 8 40
/opt/extrautils/usr/bin/dialog --title " N9 QuickTweak Updater " --infobox "$FILE successfully downloaded" 4 40
exit 0

Don't worry about size of boxes, colours etc. All this is will be themed as you want once it works for you.
 

The Following User Says Thank You to brkn For This Useful Post:
Schturman's Avatar
Posts: 5,339 | Thanked: 4,133 times | Joined on Jan 2010 @ Israel
#4569
thank you!
i will try it when i will arrive at home
 
Posts: 299 | Thanked: 557 times | Joined on Aug 2012
#4570
Originally Posted by Schturman View Post
thank you!
i will try it when i will arrive at home
Petite astuce pour te donner une idée / this should get you started:

Code:
#!/bin/sh

/opt/extrautils/usr/bin/dialog --menu "N9 QuickTweak PDF downloader" 15 40 5\
 A "English PDF instruction"\
 B "Russian PDF instruction" 2>dialog.tmp
ANS=`cat dialog.tmp`


dl() {
    URL=$1
    FILE=$(basename $URL)
    rm -f $FILE
    LENGTH=$(curl --head $URL 2>&1 | grep Content-Length | awk '{print $2}')
    scale=$(echo "scale=6; 100/$LENGTH" | /opt/extrautils/usr/bin/bc)
    wget $URL 2>/dev/null &

    while ( true )
    do
        proc=$(ps aux | grep -v grep | grep wget | grep $FILE )
        if [[ "$proc" == "" ]]; then break; fi
        size=$(ls -l $FILE 2>/dev/null | awk '{print $5}' 2>/dev/null)
        if [ "$size" != "" ]; then
            {
                metre=$(printf %.0f $(echo "$size*$scale" | /opt/extrautils/usr/bin/bc))
            }
        fi

        echo "XXX"
        echo "file: $FILE"
        echo "size: $LENGTH bytes"
        echo "Please standby ..."
        echo "XXX"
        echo $metre

    done | /opt/extrautils/usr/bin/dialog --clear --title " N9 QuickTweak Updater " --no-collapse --gauge "Download Test" 8 40
    /opt/extrautils/usr/bin/dialog --clear --title " N9 QuickTweak Updater " --infobox "$FILE successfully downloaded" 4 40
}

case $ANS in
    A) dl "http://dl.dropbox.com/u/17706605/N9_QuickTweak_en_v9.4.pdf";;
    B) dl "http://dl.dropbox.com/u/17706605/N9_QuickTweak_ru_v9.4.pdf";;
esac
rm -f dialog.tmp
exit 0
 

The Following User Says Thank You to brkn For This Useful Post:
Reply

Tags
hebrew vkb, n9 qtweak, n9 quick tweak, n9 quicktweak, root-ssh


 
Forum Jump


All times are GMT. The time now is 14:25.