Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 20 Sep 2014, 02:14
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How can I improve on my update script?SOLVED
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
oldyeller


Joined: 15 Nov 2011
Posts: 802
Location: Mishawaka IN

PostPosted: Sat 29 Jun 2013, 04:10    Post subject:  How can I improve on my update script?SOLVED  

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:

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:

#!/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

Last edited by oldyeller on Thu 25 Jul 2013, 20:48; edited 1 time in total
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sat 29 Jun 2013, 07:39    Post subject:  

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:
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:
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 .
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Sat 29 Jun 2013, 13:37    Post subject: Re: How can I improve on my update script
Subject description: check local file existence
 

Code:
#!/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"`
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sat 29 Jun 2013, 16:12    Post subject:  

Update on curl : It has no simple " --dry-run " option like wget --spider .

Update on petget : Should work also as
Code:
# petget http://smokey01.com/Oldyeller/update/manna.pet

My ole petget chokes on
Quote:
sed: -e expression #2, char 0: no previous regular expression

somewhere, but I can see a manna.pet in my $HOME directory ( /root ) now .
Back to top
View user's profile Send private message Visit poster's website 
musher0


Joined: 04 Jan 2009
Posts: 4236
Location: Gatineau (Qc), Canada

PostPosted: Sat 29 Jun 2013, 16:18    Post subject:  

Suggested edits:

Code:
#!/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

_________________
"Logical entities must not be multiplied needlessly." / "Il ne faut pas multiplier les êtres logiques inutilement." (Ockham)
Back to top
View user's profile Send private message Visit poster's website 
oldyeller


Joined: 15 Nov 2011
Posts: 802
Location: Mishawaka IN

PostPosted: Sat 29 Jun 2013, 19:23    Post subject:  

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:

#!/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
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sun 30 Jun 2013, 07:49    Post subject:  

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:
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
Back to top
View user's profile Send private message Visit poster's website 
rhadon


Joined: 27 Mar 2008
Posts: 1293
Location: Germany

PostPosted: Sun 30 Jun 2013, 13:05    Post subject:  

Hi,

maybe
Code:
stat -c %y
can do the job? You get a timestamp and can compare it. Like:
Code:
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

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 802
Location: Mishawaka IN

PostPosted: Sun 30 Jun 2013, 15:13    Post subject:  

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:
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.
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sun 30 Jun 2013, 16:46    Post subject:  

Next obstacle : wget seems to use wildcards ( * ) only for ftp protocol - not for http Sad - And then if the ftp server supports unix like ls output - as I read the man page .

Using this :
Code:
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:
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 .
Back to top
View user's profile Send private message Visit poster's website 
oldyeller


Joined: 15 Nov 2011
Posts: 802
Location: Mishawaka IN

PostPosted: Sun 30 Jun 2013, 17:13    Post subject:  

Karl Godt wrote:
Next obstacle : wget seems to use wildcards ( * ) only for ftp protocol - not for http Sad - And then if the ftp server supports unix like ls output - as I read the man page .

Using this :
Code:
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:
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
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sun 30 Jun 2013, 18:01    Post subject:  

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
Quote:
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:
wget  http://smokey01.com/Oldyeller/update/Current

gives index.html as
Quote:
<!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>
Back to top
View user's profile Send private message Visit poster's website 
oldyeller


Joined: 15 Nov 2011
Posts: 802
Location: Mishawaka IN

PostPosted: Thu 25 Jul 2013, 20:50    Post subject:  

I decided to modify my ov-precise Get SFS downloader and made it into Manna-Updater


Cheers
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1045s ][ Queries: 12 (0.0064s) ][ GZIP on ]