Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- diff=kamimemo-05v2-encode-patch.vcdiff
- v1=`xdelta3 printhdr ${diff} | grep "(source)" | cut -c31-`
- v2=`xdelta3 printhdr ${diff} | grep "(output)" | cut -c31-`
- # declare argv array and argc is total args from $1..$n + 1 for $0
- declare -a argv
- declare -i argc force
- argc=$#
- let "argc++"
- let "force = 0"
- # build argv array
- for (( a=0; a < $argc; a++ ))
- do
- case "$a" in
- 0) argv=( "${argv[@]}" "${0##*/}" )
- ;;
- *) argv=( "${argv[@]}" "${!a}" )
- ;;
- esac
- done
- if [ $argc -gt 1 ]; then
- case ${argv[1]} in
- -f) let "force++"
- ;;
- *) echo "Usage: ${argv[0]} [-f]"
- exit 0
- ;;
- esac
- fi
- proc_main()
- {
- #check if v2 file exists and rm if force flag is set
- if [ -f "${v2}" ]; then
- if [ $force -eq 1 ]; then
- echo -n "Removing ${v2} by force..."
- rm -f "${v2}"
- if [ $? -eq 0 ]; then
- echo " done."
- else
- echo " failed returning $?."
- exit 1
- fi
- else
- echo "${v2} exists. Please rm or run with -f argument."
- exit 1
- fi
- fi
- if [ ! -f "${v1}" ]; then
- echo "${v1} does not exist. Make sure ${v1} exists in the same path as ${argv[0]}."
- exit 1
- fi
- echo -n "Patching ${v1} to v2..."
- xdelta3 -qd ${diff}
- tmperr=$?
- case $tmperr in
- 0) if [ -f "${v2}" ]; then
- if [ $force -eq 1 ]; then
- echo " successful. Removing ${v1}"
- rm -f "${v1}"
- else
- echo " successful. ${v1} can be removed now."
- fi
- else
- echo " returned 0 but ${v2} does not exist."
- exit 1
- fi
- ;;
- *) echo " failed. xdelta3 returned exit code $tmperr"
- exit $tmperr
- ;;
- esac
- }
- proc_main
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement