#!/bin/sh # mkpatch.sh # This shell script allows you to create a patch based on changes made to options.h, options.mk, toggle.h and toggle.mk. # Set old (current) directory CD="$(pwd)" CP() { cp docs/options.def.h /tmp/options.h cp docs/options.def.mk /tmp/options.mk cp docs/toggle.def.h /tmp/toggle.h cp docs/toggle.def.mk /tmp/toggle.mk cp docs/keybinds.def.h /tmp/keybinds.h } MKDIFF() { cd /tmp # Create patches diff -up ./options.h $CD/options.h > $CD/options.h_settings.patch && echo "Created options.h patch (see options.h_settings.patch)" diff -up ./options.mk $CD/options.mk > $CD/options.mk_settings.patch && echo "Created options.mk patch (see options.mk_settings.patch)" diff -up ./toggle.h $CD/toggle.h > $CD/toggle.h_settings.patch && echo "Created toggle.h patch (see toggle.h_settings.patch)" diff -up ./keybinds.h $CD/keybinds.h > $CD/keybinds.h_settings.patch && echo "Created keybinds.h patch (see keybinds.h_settings.patch)" diff -up ./toggle.mk $CD/toggle.mk > $CD/toggle.mk_settings.patch && echo "Created toggle.mk patch (see toggle.mk_settings.patch)" # Delete rm -f /tmp/options.h rm -f /tmp/options.mk rm -f /tmp/toggle.h rm -f /tmp/keybinds.h rm -f /tmp/toggle.mk } # Patch the source if [ "$1" = "-p" ]; then ls *.patch || exit 1 patch < options.h_settings.patch patch < options.mk_settings.patch patch < toggle.h_settings.patch patch < toggle.mk_settings.patch patch < keybinds.h_settings.patch cd $CD exit 0 fi # Remove the patch if [ "$1" = "-r" ]; then ls *.patch || exit 1 patch -R < options.h_settings.patch patch -R < options.mk_settings.patch patch -R < toggle.h_settings.patch patch -R < toggle.mk_settings.patch patch -R < keybinds.h_settings.patch cd $CD exit 0 fi # Create patches if [ "$1" = "-mk" ]; then CP MKDIFF cd $CD exit 0 fi printf "mkpatch help\n\n" printf "Usage:\n" printf "\nmkpatch -p Apply the patch directly." printf "\nmkpatch -r Remove the patch directly." printf "\nmkpatch -h Display this help." printf "\nmkpatch -mk Create patches based on changes." printf "\nNo arguments will print help.\n"