Page 1 of 1

How can I improve on my update script?SOLVED

Posted: Sat 29 Jun 2013, 08:10
by oldyeller
Hello Everyone,

I would like to add the ability for my update script to check if there is a file in the folder. I did try this, But it did not work. What am I missing?

Code: Select all

if [ -f  http://smokey01.com/Oldyeller/update/manna.pet ]; then
rxvt -e wget http://smokey01.com/Oldyeller/update/manna.pet
petget $INSTALLDIR/manna.pet
rm /root/Downloads/manna.pet &
yaf-splash -bg red -fg white -placement center -timeout 1 -text updated
/usr/local/Manna/version
`xmessage -center -bg blue -fg white "please exit and restart Manna to apply update"`
fi
Here is the code

Code: Select all

#!/bin/sh

INSTALLDIR="/root/Downloads"

#Install Software
cd /root/Downloads


rxvt -e wget http://smokey01.com/Oldyeller/update/manna.pet
petget $INSTALLDIR/manna.pet
rm /root/Downloads/manna.pet &
yaf-splash -bg red -fg white -placement center -timeout 1 -text updated
/usr/local/Manna/version
`xmessage -center -bg blue -fg white "please exit and restart Manna to apply update"`
Thanks for any help

Posted: Sat 29 Jun 2013, 11:39
by Karl Godt
Hmmm .. Seems that test does not know about protocols like http or ftp .

wget has the --spider option : --spider don't download anything.

That can be used to generate a return value of 0 if found or 1 if not found :

Code: Select all

bash-3.00# wget --spider http://smokey01.com/Oldyeller/update/manna.pet;echo $?
--12:37:20--  http://smokey01.com/Oldyeller/update/manna.pet
           => `manna.pet'
Resolving smokey01.com... 174.132.189.156
Connecting to smokey01.com|174.132.189.156|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
12:37:22 ERROR 404: Not Found.

1
bash-3.00# 
Verbose code for it could look like this :

Code: Select all

do_install(){
true ##placeholder
##lots of oldyeller install code here
##with lots of error return value checking eg
##petget $OPTIONS $FILENAME
##[ $? = 0 ] || error_msg 1 "Failed to do petget $OPTION $FILENAME"
}

error_msg(){
xmessage -bg red "$*"
exit $1
}

 wget --spider http://smokey01.com/Oldyeller/update/manna.pet && do_install || error_msg 1 "Not found ."
I am pretty sure that curl has a similar option as wget, might be named -n or --dry-run .

Re: How can I improve on my update script

Posted: Sat 29 Jun 2013, 17:37
by L18L

Code: Select all

#!/bin/sh

INSTALLDIR="/root/Downloads"

#Install Software
cd /root/Downloads


rxvt -e wget --tries=1  http://smokey01.com/Oldyeller/update/manna.pet

# check local file existence here
if [ ! -f manna.pet ]; then
 echo no new manna today
 exit
fi

petget $INSTALLDIR/manna.pet
rm /root/Downloads/manna.pet &
yaf-splash -bg red -fg white -placement center -timeout 1 -text updated
/usr/local/Manna/version
`xmessage -center -bg blue -fg white "please exit and restart Manna to apply update"`

Posted: Sat 29 Jun 2013, 20:12
by Karl Godt
Update on curl : It has no simple " --dry-run " option like wget --spider .

Update on petget : Should work also as

Code: Select all

# petget http://smokey01.com/Oldyeller/update/manna.pet
My ole petget chokes on
sed: -e expression #2, char 0: no previous regular expression
somewhere, but I can see a manna.pet in my $HOME directory ( /root ) now .

Posted: Sat 29 Jun 2013, 20:18
by musher0
Suggested edits:

Code: Select all

#!/bin/sh 
# /folder/location/title.sh # of script ?
# by ... oldyeller and L18L ??
####
 INSTALLDIR="/root/Downloads" 

 #Install Software 
 cd /root/Downloads 
 rxvt -e wget --tries=1  http://smokey01.com/Oldyeller/update/manna.pet 

 # check local file existence here 
 if [ ! -f manna.pet ]; then 
  echo no new manna today # if not in console this will not show # musher0
 else # instead of awkward exit # suggestion 
 petget $INSTALLDIR/manna.pet 
 rm /root/Downloads/manna.pet & 
 yaf-splash -bg red -fg white -placement center -timeout 1 -text updated 
 /usr/local/Manna/version # is this a text file or an executable? If text, should be in quotes with "cat"? Like so?
# yaf-splash [other parameters] -text "updated `cat /usr/local/Manna/version`"
# Also, why use three message handlers ? "echo" plus these two. 
# Focus on same one throughout, for consistency. # musher0
 `xmessage -center -bg blue -fg white "Please exit and restart Manna to apply update"`
 fi 
In co-operation,

musher0

Posted: Sat 29 Jun 2013, 23:23
by oldyeller
Hello Everyone,

@All I have tried each option presented here and nothing worked the way I see it happening. I have been working on this script since 12am yesterday/this morning. Did get a little rest. Here is what I got so far.

But I would still like to get it to check for new versions. This one will offer the user to download again if they desire. If there is no pet there, then it say will installed failed through ppm.

Any ideas on how to check for newer version?

Code: Select all

#!/bin/sh

INSTALLDIR="/root/Downloads" 


#Download and install
if [ "`which Manna`" ]; then
Xdialog --title "Manna Install" --cancel-label "No" --ok-label "Yes"  --yesno "\n     Manna is already installed.     \n\n     Do you want to install again?     \n" 0 0
if [[ $? == 0 ]]; then
cd /root/Downloads
rxvt -e wget http://smokey01.com/Oldyeller/update/manna.pet
petget $INSTALLDIR/manna.pet
rm $INSTALLDIR/manna.pet
fi
else
 cd /root/Downloads
rxvt -e wget http://smokey01.com/Oldyeller/update/manna.pet
petget $INSTALLDIR/manna.pet
rm $INSTALLDIR/manna.pet
fi

exit 0

Posted: Sun 30 Jun 2013, 11:49
by Karl Godt
First of all you shoud name your manna.pet to something like
manna_update_2013-07-01-nightly.pet
or
manna_update-1.0.1.pet
.

To be able to distinguish between versions .

petget should produce a file

$HOME/.packages/manna_update_VERSION.files
( $HOME probably not recommended for system updates -> /root )

and
sed something like

manna_update_VERSION|manna_update|1.0.1-aurora|BuildingBlock|2408K|pet_packages-Manna|manna_update_VERSION.pet||Manna|puppy|5|oldyeller|

into user_installed_packages .

You would need to read these files to check if already installed .

Then you probably need two directories like /Updates and /Current and

Code: Select all

GET_UPDATE_OK=`wget --spider http://smokey01.com/Oldyeller/update/Current/manna_update*.pet`
[ $? = 0 ] || echo "No current update available."
UPDATE_VERSION=`echo "$GET_UPDATE" | grep -m1 -e '[[:blank:]]*=> .*\.pet'`

if grep "$UPDATE_VERSION" /root/.packages/user_installed_packages && [ -f "/root/.packages/${UPDATE_VERSION%\.pet*}.files" ] ; then 
echo "$UPDATE_VERSION" already installed"
else
petget http://smokey01.com/Oldyeller/update/Current/$UPDATE_VERSION
fi

Posted: Sun 30 Jun 2013, 17:05
by rhadon
Hi,

maybe

Code: Select all

stat -c %y
can do the job? You get a timestamp and can compare it. Like:

Code: Select all

VAR=$(stat -c %y manna.pet)
wget -N -a  http://.../manna.pet
I used something similar to compare pictures of webcams. If there was a newer one on the net then download it, else, let it be.

HTH,
Rolf

Posted: Sun 30 Jun 2013, 19:13
by oldyeller
Karl Godt wrote:First of all you shoud name your manna.pet to something like
manna_update_2013-07-01-nightly.pet
or
manna_update-1.0.1.pet
.

To be able to distinguish between versions .

petget should produce a file

$HOME/.packages/manna_update_VERSION.files
( $HOME probably not recommended for system updates -> /root )

and
sed something like

manna_update_VERSION|manna_update|1.0.1-aurora|BuildingBlock|2408K|pet_packages-Manna|manna_update_VERSION.pet||Manna|puppy|5|oldyeller|

into user_installed_packages .

You would need to read these files to check if already installed .

Then you probably need two directories like /Updates and /Current and

Code: Select all

GET_UPDATE_OK=`wget --spider http://smokey01.com/Oldyeller/update/Current/manna_update*.pet`
[ $? = 0 ] || echo "No current update available."
UPDATE_VERSION=`echo "$GET_UPDATE" | grep -m1 -e '[[:blank:]]*=> .*\.pet'`

if grep "$UPDATE_VERSION" /root/.packages/user_installed_packages && [ -f "/root/.packages/${UPDATE_VERSION%\.pet*}.files" ] ; then 
echo "$UPDATE_VERSION" already installed"
else
petget http://smokey01.com/Oldyeller/update/Current/$UPDATE_VERSION
fi
Hi Karl Godt,

This seems like it will work, But it aborts the download because it can't find the size of the package. Any ideas?

Cheers

EDIT: there is a pet at smokey01.com/Oldyeller with the other directories for testing purposes for this script.

Posted: Sun 30 Jun 2013, 20:46
by Karl Godt
Next obstacle : wget seems to use wildcards ( * ) only for ftp protocol - not for http :( - And then if the ftp server supports unix like ls output - as I read the man page .

Using this :

Code: Select all

wget -A pet -r --no-parent http://smokey01.com/Oldyeller/update/Current
downloads the pet and creates folder hierarchy inside the current working directory
and

Code: Select all

if [ -f smokey01.com/Oldyeller/update/Current/manna_update* ] ; then 
echo IS THERE
#UPDATE_PET=`ls -1 smokey01.com/Oldyeller/update/Current/manna_update* |tail -n1`
#petget  "$UPDATE_PET"
fi
works for me , too .

Needs cleanup afterwards like
rm -rf smokey01.com
inside the local HDD or save-file .

NOTE : petget "$UPDATE_PET" not tested due not running Manna .
NOTE : [ -f smokey01.com/Oldyeller/update/Current/manna_update* ] using wildcard needs no double quotes around filename - otherwise * is treated literally .

Posted: Sun 30 Jun 2013, 21:13
by oldyeller
Karl Godt wrote:Next obstacle : wget seems to use wildcards ( * ) only for ftp protocol - not for http :( - And then if the ftp server supports unix like ls output - as I read the man page .

Using this :

Code: Select all

wget -A pet -r --no-parent http://smokey01.com/Oldyeller/update/Current
downloads the pet and creates folder hierarchy inside the current working directory
and

Code: Select all

if [ -f smokey01.com/Oldyeller/update/Current/manna_update* ] ; then 
echo IS THERE
#UPDATE_PET=`ls -1 smokey01.com/Oldyeller/update/Current/manna_update* |tail -n1`
#petget  "$UPDATE_PET"
fi
works for me , too .

Needs cleanup afterwards like
rm -rf smokey01.com
inside the local HDD or save-file .

NOTE : petget "$UPDATE_PET" not tested due not running Manna .
NOTE : [ -f smokey01.com/Oldyeller/update/Current/manna_update* ] using wildcard needs no double quotes around filename - otherwise * is treated literally .
Where do I add this in the code?

Cheers

Posted: Sun 30 Jun 2013, 22:01
by Karl Godt
Am playing around with rsync, that works with wildcards , but needs ssh capability on the server or rsync --daemon running on the server to connect to .

Everything unsatisfactory .

Remembered
The Service Pack is supposed to be automatically detected when the Puppy Package Manager is started, but that is broken for Wary and Racy -- so this Service Pack has a fix for that.
But, for this first Service Pack, you have to manually install it -- just download it and click on it.
http://bkhome.org/blog2/?viewDetailed=00176
Dunno, but could be useful to look how Barry does it .

Otherwise download of the index.html and trying to grep out the the content :

Code: Select all

wget  http://smokey01.com/Oldyeller/update/Current
gives index.html as
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><title>Index of /Oldyeller/update/Current</title> </head><body><h1>Index of /Oldyeller/update/Current</h1><pre> <a href="?C=N;O=D">Name</a> <a href="?C=M;O=A">Last modified</a> <a href="?C=S;O=A">Size</a> <a href="?C=D;O=A">Description</a>
<img src="/icon/folder24.png" alt="[DIR]" height="24"> <a href="/Oldyeller/update/">Parent Directory</a> -
<img src="/icon/pet.png" alt="[ ]" height="24"> <a href="manna_update-1.00.pet">manna_update-1.00.pet</a> 30-Jun-2013 14:42 2.8K
</pre><address>Apache Server at smokey01.com Port 80</address></body></html>

Posted: Fri 26 Jul 2013, 00:50
by oldyeller
I decided to modify my ov-precise Get SFS downloader and made it into Manna-Updater


Cheers