View previous topic :: View next topic |
Author |
Message |
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Sun Apr 11, 2010 10:33 pm Post subject: Bash help |
|
|
This script is suppose to check filehippo for the name of the package input and see if there is a new version compared to what your xml file (if you have none it will create the xml and download the exe for you). This script is to be used along side wpkg.
Here is my whole script, I am getting a problem running it on line 50 (which I snipped out), It is saying that "./GetUpdatesFromFilehippo.sh: line 50: Saving to:: command not found ".
When I run line 50 from the cli it works fine. I don't understand why it's failing in this script?
Code: | # if the file to download already exists, we are done.
if [ ! -f "$EXEDIR/$NEWVERSION.exe" ]; then
echo "New version available... downloading..."
cd $EXEDIR && $WGET $WGETOPTIONS -U "$AGENT" $DOWNLOADURL2 -o $TEMPLOG
FILENAME=grep "Saving to" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }' |
Code: | #!/bin/bash
# script to check for new versions of a package from filehippo.com
# NOTE: If you call this for multiple packages, PLEASE put a delay (5-10 seconds)
# between each call so that you don't over-stress the server!
if [ -z "$1" ]; then
echo "Downloads the latest version of a package from filehippo.com."
echo
echo "Usage: $0 <package name>"
echo
echo " where <package name> is the name of the filehippo.com package."
echo
echo "Example, URL for Mozilla Firefox is http://www.filehippo.com/download_firefox/"
echo "so package name is part of the URL after \"download_\", or \"firefox\"."
exit 1
fi
PACKAGE=$1
BASEURL=http://www.filehippo.com
URL=$BASEURL/download_$PACKAGE
TEMPFILE=/tmp/$PACKAGE.html
TEMPLOG=/tmp/$PACKAGE.log
EXEDIR="$PACKAGE/"
XMLDIR="$PACKAGE/"
WGET="wget"
AWK="awk"
AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
WGETOPTIONS="-t 0 -T 300"
$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $URL
NEWVERSION=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }'`
DOWNLOADURL1=$BASEURL`grep "<b>Download<br/>Latest Version</b>" $TEMPFILE | $AWK 'BEGIN { FS="\"" } { print $2 }'`
# delay so don't overload the server.
sleep 1
$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $DOWNLOADURL1
DOWNLOADURL2=$BASEURL`grep "Refresh" $TEMPFILE | $AWK 'BEGIN { FS="=" } { print $4 }' | $AWK 'BEGIN { FS="\"" } { print $1 }'`
echo Current version = $VERSION
echo New Version = $NEWVERSION
echo Download URL = $DOWNLOADURL2
# if the file to download already exists, we are done.
if [ ! -f "$EXEDIR/$NEWVERSION.exe" ]; then
echo "New version available... downloading..."
cd $EXEDIR && $WGET $WGETOPTIONS -U "$AGENT" $DOWNLOADURL2 -o $TEMPLOG
FILENAME=grep "Saving to" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }'
# create a new package.xml file
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"\?>
<packages>
<package
id=\"$PACKAGE\"
name=\"$NEWVERSION\"
revision=\"$REVISION\"
reboot=\"false\"
priority=\"10\">
<install cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms' />
<upgrade cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms' />
</package>
</packages>
" > "$XMLDIR/$PACKAGE.xml"
else
echo "$EXEDIR/$NEWVERSION.exe exists, so not downloading anything."
fi
# clean up temp file
rm -f $TEMPFILE
rm -f $TEMPLOG
# delay so back-to-back calls of thie script don't overload the server.
sleep 10 |
_________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Sun Apr 11, 2010 11:28 pm Post subject: |
|
|
That's the line that starts with "FILENAME="? I don't think it does (run on the command line, I mean). Try Code: | FILENAME=$(grep "Saving to" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }') |
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Sun Apr 11, 2010 11:43 pm Post subject: |
|
|
John R. Graham wrote: | That's the line that starts with "FILENAME="? I don't think it does (run on the command line, I mean). Try Code: | FILENAME=$(grep "Saving to" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }') |
- John |
Thanks worked like a charm, I don't understand why it doesn't work on one line but that is fine. As long as it works now _________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Sun Apr 11, 2010 11:46 pm Post subject: |
|
|
It's becausedoesn't do what you think it does. It doesn't run the command but assigns the string "command" to the FILENAME variable. Look up "Command Substitution" in the bash man page.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Mon Apr 12, 2010 12:41 pm Post subject: |
|
|
One last thing,
I'm trying to replace a string sequence with another, and I can't seem to figure out how to do this. I have the line:
Code: | <install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.5.0.exe'" -ms' /> |
and I need to replace it with
Code: | <install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' /> |
Or something. Basically after the second \ and before the ending ". I need to replace the text with my variable $package. I've figured out how to isolate the sequence with Code: | $(grep "install" $INSTALL | awk ' BEGIN { FS="firefox" } { print $2 }' | awk ' BEGIN { FS="\\" } { print $2 }' | awk ' BEGIN { FS="'\''" } { print $1 }') |
However I can't replace that with my variable. I've tried gsub and sub with awk but it doesn't work.
Code: | awk '{ gsub(/$TEST/,firefox-test,$TEST1); print }'
|
Code: | awk '{ sub(/"$TEST"/,firefox-test/$TEST1); print }'
|
where Code: | $TEST=$(grep "install" $INSTALL | awk ' BEGIN { FS="firefox" } { print $2 }' | awk ' BEGIN { FS="\\" } { print $2 }' | awk ' BEGIN { FS="'\''" } { print $1 }') |
and
Code: | $TEST1=$(grep "install" packages/firefox.xml) |
(TEST1 is just finding the line)
Here is my updated entire script so far:
Code: | #!/bin/bash
# script to check for new versions of a package from filehippo.com
# NOTE: If you call this for multiple packages, PLEASE put a delay (5-10 seconds)
# between each call so that you don't over-stress the server!
if [ -z "$1" ]; then
echo "Downloads the latest version of a package from filehippo.com."
echo
echo "Usage: $0 <package name>"
echo
echo " where <package name> is the name of the filehippo.com package."
echo
echo "Example, URL for Mozilla Firefox is http://www.filehippo.com/download_firefox/"
echo "so package name is part of the URL after \"download_\", or \"firefox\"."
exit 1
fi
PACKAGE=$1
BASEURL=http://www.filehippo.com
URL=$BASEURL/download_$PACKAGE
TEMPFILE=/tmp/$PACKAGE.html
TEMPLOG=/tmp/$PACKAGE.log
EXEDIR="software/$PACKAGE"
XMLDIR="packages"
VERION='grep revision $XMLDIR/$PACKAGE.xml | $AWK 'BEGIN { FS="=" } { print $2 }''
if [ ! -d "$EXEDIR" ]; then
mkdir -p $EXEDIR
fi
if [ ! -d "$XMLDIR" ]; then
mkdir -p $XMLDIR
fi
WGET="wget"
AWK="awk"
AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
WGETOPTIONS="-t 0 -T 300"
$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $URL
NEWVERSION=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }'`
NEWREVISION1=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $1 }'`
NEWREVISION2=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $2 }'`
NEWREVISION3=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $3 }'`
if (( "${#NEWREVISION3}" < 2 )); then
NEWREVISION3=$(echo "0"$NEWREVISION3)
fi
NEWREVISION=$(echo $NEWREVISION1$NEWREVISION2$NEWREVISION3)
DOWNLOADURL1=$BASEURL`grep "<b>Download<br/>Latest Version</b>" $TEMPFILE | $AWK 'BEGIN { FS="\"" } { print $2 }'`
# delay so don't overload the server.
sleep 1
$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $DOWNLOADURL1
DOWNLOADURL2=$BASEURL`grep "Refresh" $TEMPFILE | $AWK 'BEGIN { FS="=" } { print $4 }' | $AWK 'BEGIN { FS="\"" } { print $1 }'`
echo Current version = $VERSION
echo New Version = $NEWVERSION
echo Download URL = $DOWNLOADURL2
# if the file to download already exists, we are done.
if [ -f $XMLDIR/$PACKAGE.xml ]; then
CURRENTREVISION=$(grep "revision" $XMLDIR/$PACKAGE.xml | $AWK ' BEGIN { FS="\"" } { print $2 }' )
else
CURRENTREVISION=0
fi
if [ $NEWREVISION > $CURRENTREVISION ]; then
echo "New version available... downloading..."
cd $EXEDIR && $WGET $WGETOPTIONS -U "$AGENT" $DOWNLOADURL2 -o $TEMPLOG && cd ../..
FILENAME=$(grep "Saving to:" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }')
# create a new package.xml file, but use old silent install commands if old version exists.
if [ -f $XMLDIR/$PACKAGE.xml ]; then
INSTALL=$(grep "install" $XMLDIR/$PACKAGE.xml)
TEST=$(grep "install" $INSTALL | awk ' BEGIN { FS="firefox" } { print $2 }' | awk ' BEGIN { FS="\\" } { print $2 }' | awk ' BEGIN { FS="'\''" } { print $1 }')
TEST1=
else
INSTALL="<install cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms' />"
fi
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"\?>
<packages>
<package
id=\"$PACKAGE\"
name=\"$NEWVERSION\"
revision=\"$NEWREVISION\"
reboot=\"false\"
priority=\"10\">
$INSTALL
<upgrade cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms' />
</package>
</packages>
" > $XMLDIR/$PACKAGE.xml
else
echo "$EXEDIR/$NEWVERSION.exe exists, so not downloading anything."
fi
# clean up temp file
rm -f $TEMPFILE
rm -f $TEMPLOG
# delay so back-to-back calls of thie script don't overload the server.
sleep 10 |
_________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value |
|
Back to top |
|
|
infamis n00b
Joined: 16 Dec 2009 Posts: 9
|
Posted: Mon Apr 12, 2010 12:56 pm Post subject: |
|
|
have you tried sed? |
|
Back to top |
|
|
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Mon Apr 12, 2010 1:04 pm Post subject: |
|
|
infamis wrote: | have you tried sed? |
Yep:
Code: | echo $TEST1 | sed 's/$TEST/firefox-test/'
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' />
|
I could seem to get that to work either. I can get each one to work if I just replace a single string, but I need to replace a sequence of strings with another. _________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value |
|
Back to top |
|
|
Mike Hunt Watchman
Joined: 19 Jul 2009 Posts: 5287
|
Posted: Mon Apr 12, 2010 1:13 pm Post subject: |
|
|
Did you try quoting the replacement string, i.e.: Code: | awk '{sub(/foo1/,"bar");sub(/foo2/,"baz");print}' |
or Code: | awk '{sub(/foo1 = blah/,"foo1 = bar,bling");sub(/foo2 = boink/,"bleep = boink,baz/bing,bang");print}' |
|
|
Back to top |
|
|
infamis n00b
Joined: 16 Dec 2009 Posts: 9
|
Posted: Mon Apr 12, 2010 2:02 pm Post subject: |
|
|
Shelnutt2 wrote: |
Code: | echo $TEST1 | sed 's/$TEST/firefox-test/'
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' />
|
|
are you sure you've used proper quotation ( " instead of ' - otherwise you'll try to replace $TEST with firefox-test instead of content of variable $TEST ) ? |
|
Back to top |
|
|
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Mon Apr 12, 2010 3:16 pm Post subject: |
|
|
Quoting the replacement string didn't help.
I think my problem with both awk and sed, is that I want to replace a set of strings with another. "Firefox Setup 3.6.3.exe" is really 3 strings not one. I want to replace this with my variable, which could be any number of strings.
The whole point of this is because when I am creating the new silent install script I need to base it on the old one, so I can keep the flags that made it silent. The easiest way is just to replace the name of the exe file with the name of the new exe file which is what I am trying to do.
I have found that if I had a \ in front of each space that sed will work, but that seems to be a pain. Plus even when I add \ to my variable it doesn't seem to work.
Code: | echo $TEST1 | sed 's/Firefox\ Setup\ 3.6.3.exe/firefox-test/'
<install cmd='"%SOFTWARE%\firefox\firefox-test'" -ms' />
|
That works but when I do
Code: | s.shelnutt@localhost ~/wine-dev/test $ $TEST2=$(echo $TEST | sed 's/ /\\ /g')
-bash: =Firefox\: command not found
s.shelnutt@localhost ~/wine-dev/test $ TEST2=$(echo $TEST | sed 's/ /\\ /g')
s.shelnutt@localhost ~/wine-dev/test $ echo $TEST2
Firefox\ Setup\ 3.6.3.exe
s.shelnutt@localhost ~/wine-dev/test $ echo $TEST1 | sed 's/${TEST2}/firefox-test/'
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' />
s.shelnutt@localhost ~/wine-dev/test $ echo $TEST1 | sed 's/$TEST2/firefox-test/'
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' />
|
I don't understand what the difference here is. _________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value
Last edited by Shelnutt2 on Mon Apr 12, 2010 3:26 pm; edited 1 time in total |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Mon Apr 12, 2010 3:26 pm Post subject: |
|
|
Well, first of all, the quoting is messed up on Code: | <install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.5.0.exe'" -ms' /> | so it's hard to see what you really are attempting. Even so, you're making it too hard. sed work for this, really easily: Code: | ~ $ cat fred
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.5.0.exe'" -ms' />
~ $ sed 's/Firefox Setup 3\.5\.0\.exe/Firefox Setup 3.6.3.exe/' fred
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' /> | Regarding your failure with sed and awk, shell parameters are not expanded within single quotes, so you're passing "$TEST" as a literal to gsub/sub. Also note that sed and awk expect regular expressions as their search term. That means that you have to (a) know what characters are special in regular expressions (e.g., the periods) and (b) escape those special characters to make them just mean the literal characters.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Mon Apr 12, 2010 4:43 pm Post subject: |
|
|
John R. Graham wrote: | Well, first of all, the quoting is messed up on Code: | <install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.5.0.exe'" -ms' /> | so it's hard to see what you really are attempting. Even so, you're making it too hard. sed work for this, really easily: Code: | ~ $ cat fred
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.5.0.exe'" -ms' />
~ $ sed 's/Firefox Setup 3\.5\.0\.exe/Firefox Setup 3.6.3.exe/' fred
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3.6.3.exe'" -ms' /> |
|
My quotations might be off for bash/sed but that string is from an xml file, and it has to be in that format. That is what wpkg expects. I suppose I will just have to escape all special characters and then remove all the backslashes after special characters.
Quote: |
Regarding your failure with sed and awk, shell parameters are not expanded within single quotes, so you're passing "$TEST" as a literal to gsub/sub. Also note that sed and awk expect regular expressions as their search term. That means that you have to (a) know what characters are special in regular expressions (e.g., the periods) and (b) escape those special characters to make them just mean the literal characters.
- John |
Double quotes... that just solved all my problems. I appreciate all the help you've given me, I'll post my final script here in a few just as reference, but double quotations around the sed command made everything work. It now recognizes the variable and I don't even need to escape special characters.
Code: | echo $TEST1 | sed "s/$TEST/firefox-test/" |
final script, including escaping the special characters
Code: | #!/bin/bash
#Copyright Seth Shelnutt under the GNU LGPL v2.1 or later
# script to check for new versions of a package from filehippo.com
# NOTE: If you call this for multiple packages, PLEASE put a delay (5-10 seconds)
# between each call so that you don't over-stress the server!
if [ -z "$1" ]; then
echo "Downloads the latest version of a package from filehippo.com."
echo
echo "Usage: $0 <package name>"
echo
echo " where <package name> is the name of the filehippo.com package."
echo
echo "Example, URL for Mozilla Firefox is http://www.filehippo.com/download_firefox/"
echo "so package name is part of the URL after \"download_\", or \"firefox\"."
exit 1
fi
PACKAGE=$1
BASEURL=http://www.filehippo.com
URL=$BASEURL/download_$PACKAGE
TEMPFILE=/tmp/$PACKAGE.html
TEMPLOG=/tmp/$PACKAGE.log
EXEDIR="software/$PACKAGE"
XMLDIR="packages"
VERION='grep revision $XMLDIR/$PACKAGE.xml | $AWK 'BEGIN { FS="=" } { print $2 }''
if [ ! -d "$EXEDIR" ]; then
mkdir -p $EXEDIR
fi
if [ ! -d "$XMLDIR" ]; then
mkdir -p $XMLDIR
fi
WGET="wget"
AWK="awk"
AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
WGETOPTIONS="-t 0 -T 300"
$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $URL
NEWVERSION=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }'`
NEWREVISION1=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $1 }'`
NEWREVISION2=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $2 }'`
NEWREVISION3=`grep "<h1>" $TEMPFILE | $AWK 'BEGIN { FS=">" } { print $2 }' | $AWK 'BEGIN { FS="<" } { print $1 }' | $AWK 'BEGIN { FS=" " } { print $2 }' | $AWK 'BEGIN { FS="." } { print $3 }'`
if (( "${#NEWREVISION3}" < 2 )); then
NEWREVISION3=$(echo "0"$NEWREVISION3)
fi
NEWREVISION=$(echo $NEWREVISION1$NEWREVISION2$NEWREVISION3)
DOWNLOADURL1=$BASEURL`grep "<b>Download<br/>Latest Version</b>" $TEMPFILE | $AWK 'BEGIN { FS="\"" } { print $2 }'`
# delay so don't overload the server.
sleep 1
$WGET $WGETOPTIONS -U "$AGENT" -O $TEMPFILE --header="Cookie: Filter=NOBETA=1&NODEMO=0" $DOWNLOADURL1
DOWNLOADURL2=$BASEURL`grep "Refresh" $TEMPFILE | $AWK 'BEGIN { FS="=" } { print $4 }' | $AWK 'BEGIN { FS="\"" } { print $1 }'`
echo Current version = $VERSION
echo New Version = $NEWVERSION
echo Download URL = $DOWNLOADURL2
# if the file to download already exists, we are done.
if [ -f $XMLDIR/$PACKAGE.xml ]; then
CURRENTREVISION=$(grep "revision" $XMLDIR/$PACKAGE.xml | $AWK ' BEGIN { FS="\"" } { print $2 }' )
else
CURRENTREVISION=0
fi
if [ $NEWREVISION > $CURRENTREVISION ]; then
echo "New version available... downloading..."
cd $EXEDIR && $WGET $WGETOPTIONS -U "$AGENT" $DOWNLOADURL2 -o $TEMPLOG && cd ../..
FILENAME=$(grep "Saving to:" $TEMPLOG | $AWK 'BEGIN { FS="`" } { print $2 }' | $AWK 'BEGIN { FS="\47" } { print $1 }')
# create a new package.xml file, but use old silent install commands if old version exists.
if [ -f $XMLDIR/$PACKAGE.xml ]; then
OLDFILENAME=$(grep "install" $XMLDIR/$PACKAGE.xml | awk ' BEGIN { FS="firefox" } { print $2 }' | awk ' BEGIN { FS="\\" } { print $2 }' | awk ' BEGIN { FS="'\''" } { print $1 }' | sed 's/\./\\./g' | sed 's/\$/\\$/g' | sed 's/\^/\\^/g')
INSTALL=$(grep "install" $XMLDIR/$PACKAGE.xml | sed "s/$OLDFILENAME/$FILENAME/")
UPGRADE=$(echo $INSTALL | sed "0,/"install"/s//"upgrade"/")
else
if [[ "$FILENAME" == *".msi" ]]; then
INSTALL="<install cmd='msiexec /i /qn \"%SOFTWARE%\\$PACKAGE\\$FILENAME\"' />"
UPGRADE="<upgrade cmd='msiexec /i /qn \"%SOFTWARE%\\$PACKAGE\\$FILENAME\"' />"
else
INSTALL="<install cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms /s /S /Silent /silent /VERYSILENT /SILENT' />"
UPGRADE="<upgrade cmd='\"%SOFTWARE%\\$PACKAGE\\$FILENAME\" -ms /s /S /Silent /silent /VERYSILENT /SILENT' />"
fi
fi
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"\?>
<packages>
<package
id=\"$PACKAGE\"
name=\"$NEWVERSION\"
revision=\"$NEWREVISION\"
reboot=\"false\"
priority=\"10\">
$INSTALL
$UPGRADE
</package>
</packages>
" > $XMLDIR/$PACKAGE.xml
else
echo "$EXEDIR/$NEWVERSION.exe exists, so not downloading anything."
fi
# clean up temp files
rm -f $TEMPFILE
rm -f $TEMPLOG
# delay so back-to-back calls of thie script don't overload the server.
sleep 10 |
_________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value
Last edited by Shelnutt2 on Mon Apr 12, 2010 11:04 pm; edited 2 times in total |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Mon Apr 12, 2010 4:51 pm Post subject: |
|
|
The reason that you want to escape the "." metacharacters is for robustness. Your unescaped $TEST string matches things you don't want it to match. For example, Code: | ~ $ cat fred
<install cmd='"%SOFTWARE%\firefox\Firefox Setup 3a5b0cexe'" -ms' />
~ $ echo $TEST
Firefox Setup 3.5.0.exe
~ $ sed "s/$TEST/firefox-test/" fred
<install cmd='"%SOFTWARE%\firefox\firefox-test'" -ms' /> | It's a good habit to get into. Otherwise you'll occasionally be tripped up by unintended consequences. The "." metacharacter means "match any single character". It needs to be escaped to force it to match a literal "." character.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
Princess Nell l33t
Joined: 15 Apr 2005 Posts: 916
|
Posted: Mon Apr 12, 2010 10:11 pm Post subject: |
|
|
perl might be better suited for this type of string processing.
@Shelnutt2: what is your experience with wpkg? I was testing it and found it quite unreliable; client service not starting despite automatic setting, packages not being upgraded, silent installers breaking with newer software versions, bad support etc. |
|
Back to top |
|
|
Shelnutt2 Tux's lil' helper
Joined: 05 May 2007 Posts: 122
|
Posted: Thu Apr 15, 2010 2:06 pm Post subject: |
|
|
Princess Nell wrote: | perl might be better suited for this type of string processing.
@Shelnutt2: what is your experience with wpkg? I was testing it and found it quite unreliable; client service not starting despite automatic setting, packages not being upgraded, silent installers breaking with newer software versions, bad support etc. |
I have very little experience with wpkg, in fact I've never actually used it in a working form. I've messed with it in wine, however support is currently broken. What we are doing with it though, is using this as a bases for further application testing in wine. Automated testing is key to finding regressions and such, and high level test of applications are great sources to catch things that wine tests didn't. WPKG is of interest simply based on the large number of silent installers already available. I will be writting a lightweight wpkg alternative script, that will process and install software, without the need to replay on wpkg.js, which should work dandy in wine. _________________ E6300, Gigabyte P35-DS3R, 7800GT, 2x512 TeamGroup DDR2 (D9), Audigy 2 value |
|
Back to top |
|
|
Princess Nell l33t
Joined: 15 Apr 2005 Posts: 916
|
Posted: Fri Apr 16, 2010 7:04 pm Post subject: |
|
|
Cool. Thanks for the info! |
|
Back to top |
|
|
|
|
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
|
|