Advertisement
Guest User

Untitled

a guest
Aug 7th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.76 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. diff=kamimemo-05v2-encode-patch.vcdiff
  4.  
  5. v1=`xdelta3 printhdr ${diff} | grep "(source)" | cut -c31-`
  6. v2=`xdelta3 printhdr ${diff} | grep "(output)" | cut -c31-`
  7.  
  8. # declare argv array and argc is total args from $1..$n + 1 for $0
  9. declare -a argv
  10. declare -i argc force
  11. argc=$#
  12. let "argc++"
  13. let "force = 0"
  14.  
  15. # build argv array
  16. for (( a=0; a < $argc; a++ ))
  17. do
  18.   case "$a" in
  19.     0)  argv=( "${argv[@]}" "${0##*/}" )
  20.       ;;
  21.     *)  argv=( "${argv[@]}" "${!a}" )
  22.       ;;
  23.   esac
  24. done
  25.  
  26. if [ $argc -gt 1 ]; then
  27.   case ${argv[1]} in
  28.     -f) let "force++"
  29.       ;;
  30.     *)  echo "Usage: ${argv[0]} [-f]"
  31.         exit 0
  32.       ;;
  33.   esac
  34. fi
  35.  
  36. proc_main()
  37. {
  38.   #check if v2 file exists and rm if force flag is set
  39.   if [ -f "${v2}" ]; then
  40.     if [ $force -eq 1 ]; then
  41.       echo -n "Removing ${v2} by force..."
  42.       rm -f "${v2}"
  43.  
  44.       if [ $? -eq 0 ]; then
  45.         echo " done."
  46.       else
  47.         echo " failed returning $?."
  48.         exit 1
  49.       fi
  50.     else
  51.       echo "${v2} exists. Please rm or run with -f argument."
  52.       exit 1
  53.     fi
  54.   fi
  55.  
  56.   if [ ! -f "${v1}" ]; then
  57.     echo "${v1} does not exist. Make sure ${v1} exists in the same path as ${argv[0]}."
  58.     exit 1
  59.   fi
  60.  
  61.   echo -n "Patching ${v1} to v2..."
  62.   xdelta3 -qd ${diff}
  63.   tmperr=$?
  64.   case $tmperr in
  65.     0)  if [ -f "${v2}" ]; then
  66.           if [ $force -eq 1 ]; then
  67.             echo " successful. Removing ${v1}"
  68.             rm -f "${v1}"
  69.           else
  70.             echo " successful. ${v1} can be removed now."
  71.           fi
  72.         else
  73.           echo " returned 0 but ${v2} does not exist."
  74.           exit 1
  75.         fi
  76.       ;;
  77.     *)  echo " failed. xdelta3 returned exit code $tmperr"
  78.         exit $tmperr
  79.       ;;
  80.   esac
  81.  
  82. }
  83.  
  84. proc_main
  85.  
  86. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement