Register
It is currently Tue Oct 21, 2014 1:57 pm

Help with This bash script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon Feb 07, 2011 6:09 pm   

Joined: Mon Feb 07, 2011 5:45 pm
Posts: 4
So I am not so experienced in bash,Seems easy enough tho

Question one
-d ;True if file exists and is a directory so If I pointed this at /xxx/xxx/xxx/1.png it would return true?

Question two
What dose 'ls -d /xxx/xxx/xxx' Do?

Question three
How dose this bit of code work?
Quote:
if [ "$1" == "configure" ] ; then


Preinst
Code:
#!/bin/sh
# preinst script
  app=`ls -d /var/mobile/Applications/*/Documents/SwordSave.bin`


  if [ ! -f "${app}" ] ; then
    echo "Infinity Blade not found"
    echo "Infinity Blade not found"
    echo "Infinity Blade not found"
    echo "Infinity Blade not found"
    exit 1
  fi

if [ "$1" == "upgrade" ] ; then
  if [ ! -f "${app}.bak" ] ; then
    cp -p "${app}" "${app}.bak"
  fi
else
  if [ ! -f "${app}.bak" ] ; then
  if [ -f "${app}" ] ; then
    cp -p "${app}" "${app}.bak"
  fi
  fi
fi
exit 0

Postinst
Code:
#!/bin/sh
# postinst script

if [ "$1" == "configure" ] ; then
    src="/var/mobile/infinityblade_tmp/"
    patchbin="SwordSave.bin"
    patchprog="$src/${patchbin}"

    app=`ls -d /var/mobile/Applications/*/Documents/SwordSave.bin`

    if [ -f "${app}" ] ; then
      if [ -e "$patchprog" ] ; then
   cp -p "$patchprog" "${app}"
        rm -fr ${src}
        echo "Infinity Blade patched"
        exit 0
      fi
    else
        echo "Infinity Blade not found"
        echo "Infinity Blade not found"
        echo "Infinity Blade not found"
        echo "Infinity Blade not found"
        exit 1
    fi
fi

Postrm
Code:
#!/bin/sh
# postrm script
  app=`ls -d /var/mobile/Applications/*/Documents/SwordSave.bin`

if [ "$1" != "upgrade" ] ; then
  if [ -f "${app}.bak" ] ; then
    cp -p "${app}.bak" "${app}"
    rm -f "${app}.bak"
  fi
fi
exit 0


Thanks,Stryk3rr3al


Top
 Profile  
 PostPosted: Mon Feb 07, 2011 7:01 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
Hi,

one: if 1.png is an image, then no.

two: don't use ls in scripts, you'd better use globs.

three: it doesn't; == doesn't exist between [ ], only =


Top
 Profile  
 PostPosted: Tue Feb 08, 2011 8:37 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Watael wrote:
three: it doesn't; == doesn't exist between [ ], only =


Not completely true. While the double-equals doesn't appear in most man pages of test, most of the time it does work.
I would not recommend using it though, please stick with a single equals for string comparison.

Code:
$>[ "1" == "2" ] && echo "true" || echo "false"
false
$>[ "1" == "1" ] && echo "true" || echo "false"
true


Top
 Profile  
 PostPosted: Tue Feb 08, 2011 12:48 pm   

Joined: Mon Feb 07, 2011 5:45 pm
Posts: 4
I used this exzact script to patch a .png so I know the script works flawlessley Now I am Wondering how I could Have it patch two files at once?

I really dont understand what the $1 == dose at all I am completley new.It could be part of the reason that == was used but these scipts are meant to be run on ios (iphone's os) Once jailbroken of course.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP