Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (77 sloc) 2.459 kb
#!/bin/bash
# #
# edit.lunar - functions to edit files #
# #
####################################################################
# #
# Parts copyright Jason Johnston 2002 under GPLv2 #
# #
# Parts copyright Auke Kok 2002 under GPLv2 #
# #
####################################################################
# function : patch_it
# usage : patch_it patch_file patch_level
# purpose : calls "patch -px < $filename", where filename may be a variety
# of formats
patch_it () {
local PATCH TARCMD GZCMD TMPFILE1 TMPFILE2
verbose_msg "patch_it \"$1\" \"$2\"";
# get patch from $SOURCE_CACHE automatically
if [ ! -f "$1" -a -f "$SOURCE_CACHE/$1" ] ; then
PATCH="$SOURCE_CACHE/$1"
else
PATCH="$1"
fi
if [[ -n `echo $PATCH | grep '\.tar'` ]] ; then
TARCMD="tar x -O"
else
TARCMD="cat"
fi
if [[ -n `echo $PATCH | grep '\.bz2$'` ]] ; then
GZCMD="bzcat"
elif [[ -n `echo $PATCH | grep '\.gz$'` ]] ; then
GZCMD="zcat"
elif [[ -n `echo $PATCH | grep -e '\.xz$' -e '\.lzma$'` ]] ; then
GZCMD="xzcat"
else
GZCMD="cat"
fi
TMPFILE1=$(temp_create "patch_1")
TMPFILE2=$(temp_create "patch_2")
if $GZCMD "$PATCH" > $TMPFILE1 ; then
# uncompress OK
if cat "$TMPFILE1" | $TARCMD > $TMPFILE2 ; then
# untar OK
if patch -N -p$2 < $TMPFILE2 ; then
# patch cmd is OK
temp_destroy $TMPFILE1
temp_destroy $TMPFILE2
return 0
fi
fi
fi
message "${PROBLEM_COLOR}! Broken patch file ${DEFAULT_COLOR}${FILE_COLOR}$PATCH${DEFAULT_COLOR}"
temp_destroy $TMPFILE1
temp_destroy $TMPFILE2
return 255
}
# function : sedit
# usage : sedit sed-statement file [file [file] ...]
# purpose : edit [files] with a sed function
sedit () {
local SEDIT
debug_msg "sedit ($@)"
SEDIT=$1
shift
for FILE in $@ ; do
verbose_msg "Editing \"$FILE\""
sed -i "$SEDIT" "$FILE"
done
}
# function : edit_file
# usage : edit_file FILENAME
# purpose : to edit a file
edit_file() {
debug_msg "edit_file ($@)"
${EDITOR:-nano} $1
}
Jump to Line
Something went wrong with that request. Please try again.