123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #!/bin/ksh
- filetize() {
- echo "$1" | sed 's|/|\^|g'
- }
- unfiletize() {
- echo "$1" | sed 's|\^|/|g'
- }
- space() {
- typeset -i i=0
- while [ $i != $1 ]
- do
- printf " "
- i=i+1
- done
- }
- rep() {
- local file_ft="$(filetize "$3")"
- if [ -e "$PATCH_DIR/$file_ft" ]
- then
- sed 's^'"$1"'^'"$2"'^g' "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.tmp"
- mv "$PATCH_DIR/$file_ft.tmp" "$PATCH_DIR/$file_ft"
- diff "$SRC_DIR/$3" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.patch"
- else
- sed 's^'"$1"'^'"$2"'^g' "$SRC_DIR/$3" > "$PATCH_DIR/$file_ft"
- diff "$SRC_DIR/$3" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.patch"
- fi
- }
- strdel() {
- rep "$1" "" $2
- }
- lineadd() {
- local file_ft="$(filetize "$3")"
- if [ -e "$PATCH_DIR/$file_ft" ]
- then
- sed 's^'"$1"'^'"$1"' \
- '"$2"'^' "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.tmp"
- mv "$PATCH_DIR/$file_ft.tmp" "$PATCH_DIR/$file_ft"
- diff "$SRC_DIR/$3" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.patch"
- else
- sed 's^'"$1"'^'"$1"' \
- '"$2"'^' "$SRC_DIR/$3" > "$PATCH_DIR/$file_ft"
- diff "$SRC_DIR/$3" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.patch"
- fi
- }
- linedel() {
- local file_ft="$(filetize "$2")"
- if [ -e "$PATCH_DIR/$file_ft" ]
- then
- grep -v "$1" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.tmp"
- mv "$PATCH_DIR/$file_ft.tmp" "$PATCH_DIR/$file_ft"
- diff "$SRC_DIR/$2" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.patch"
- else
- grep -v "$1" "$SRC_DIR/$2" > "$PATCH_DIR/$file_ft"
- diff "$SRC_DIR/$2" "$PATCH_DIR/$file_ft" > "$PATCH_DIR/$file_ft.patch"
- fi
- }
- dircp() {
- if echo "$1" | grep -q "^files/"
- then
- cp -r "$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- else
- cp -r "$SRC_DIR/$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- fi
- }
- filecp() {
- if echo "$1" | grep -q "^files/"
- then
- cp "$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- else
- cp "$SRC_DIR/$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- fi
- }
- filedel() {
- echo "$PATCH_DIR $1"
- touch "$PATCH_DIR/RM_$(filetize "$1")"
- }
- apply() {
- local file
- for file in "$PATCH_DIR"/*
- do
- local realname_prefixed="$(unfiletize "$(basename "$file")")"
- if echo "$realname_prefixed" | grep -q "^RM_"
- then
- realname="${realname_prefixed#RM_}"
- echo "Deleting $realname..."
- if rm -rf "$SRC_DIR/$realname"
- then
- echo "$realname deleted" >> apply.log
- echo "$realname deleted"
- else
- echo "!!! $realname NOT deleted" >> apply.log
- echo "!!! $realname NOT deleted"
- fi
- elif echo "$file" | grep -q "ADD_"
- then
- realname="${realname_prefixed#ADD_}"
- echo "Copying $file to $realname..."
- if cp -r "$file" "$SRC_DIR/$realname"
- then
- echo "$realname copied from $file" >> apply.log
- else
- echo "!!! $realname NOT copied from $file" >> apply.log
- fi
- elif echo "$file" | grep -q ".patch$"
- then
- realname="$realname_prefixed"
- if patch "$SRC_DIR/${realname%.patch}" < "$file"
- then
- echo "$SRC_DIR/${realname%.patch} patched from $file" >> apply.log
- else
- echo "!!! $SRC_DIR/${realname%.patch} NOT patched from $file" \
- >> apply.log
- fi
- fi
- done
- }
- self_destruct_sequence() {
- echo "$1 will be deleted in three seconds."
- echo "CTRL-C now to avoid this fate!"
- echo "3"; sleep 1
- echo "2"; sleep 1
- echo "1"; sleep 1
- printf "0\nDestruction!"
- rm -rf "$1"
- }
|