From 1cc0948597bc97485ddb1d3b30f4930cea417358 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 28 Dec 2013 15:31:11 +0100
Subject: [PATCH] Add update-patches target

---
 Makefile                                          |  4 ++++
 .../0001-Make-Unifi-images-flashable.patch        |  4 ++--
 scripts/patch.sh                                  |  8 ++++----
 scripts/unpatch.sh                                |  6 +++---
 scripts/update-patches.sh                         | 15 +++++++++++++++
 scripts/update.sh                                 | 14 +++++++-------
 6 files changed, 35 insertions(+), 16 deletions(-)
 create mode 100755 scripts/update-patches.sh

diff --git a/Makefile b/Makefile
index 73eb12ef3..3e8d26ba3 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,10 @@ patch: FORCE
 unpatch: FORCE
 	$(GLUONDIR)/scripts/unpatch.sh $(GLUONDIR)
 
+update-patches: FORCE
+	$(GLUONDIR)/scripts/update-patches.sh $(GLUONDIR)
+	$(GLUONDIR)/scripts/patch.sh $(GLUONDIR)
+
 -include $(TOPDIR)/include/host.mk
 
 _SINGLE=export MAKEFLAGS=$(space);
diff --git a/patches/openwrt/0001-Make-Unifi-images-flashable.patch b/patches/openwrt/0001-Make-Unifi-images-flashable.patch
index d6e797118..1cd498d52 100644
--- a/patches/openwrt/0001-Make-Unifi-images-flashable.patch
+++ b/patches/openwrt/0001-Make-Unifi-images-flashable.patch
@@ -1,5 +1,5 @@
-From 9331b9e86ff3cd1a368ba61721c1555807fa772e Mon Sep 17 00:00:00 2001
-Message-Id: <9331b9e86ff3cd1a368ba61721c1555807fa772e.1388167228.git.mschiffer@universe-factory.net>
+From e541a190d4f54d35043a804f42af746793181405 Mon Sep 17 00:00:00 2001
+Message-Id: <e541a190d4f54d35043a804f42af746793181405.1388240789.git.mschiffer@universe-factory.net>
 From: Matthias Schiffer <mschiffer@universe-factory.net>
 Date: Fri, 27 Dec 2013 18:48:19 +0100
 Subject: [PATCH] Make Unifi images flashable
diff --git a/scripts/patch.sh b/scripts/patch.sh
index 5dbcb46a9..6302141f3 100755
--- a/scripts/patch.sh
+++ b/scripts/patch.sh
@@ -3,12 +3,12 @@
 set -e
 shopt -s nullglob
 
-. $1/modules
+. "$1"/modules
 
 for module in $GLUON_MODULES; do
-	dir=$1/$module
+	dir="$1"/$module
 	git -C $dir checkout -B patched base
 
-	if [ -z $1/patches/$module/*.patch ]; then continue; fi
-	git -C $dir am $1/patches/$module/*.patch
+	if [ -z "$1"/patches/$module/*.patch ]; then continue; fi
+	git -C "$dir" am "$1"/patches/$module/*.patch
 done
diff --git a/scripts/unpatch.sh b/scripts/unpatch.sh
index e94d236b7..4e5cfaaac 100755
--- a/scripts/unpatch.sh
+++ b/scripts/unpatch.sh
@@ -2,9 +2,9 @@
 
 set -e
 
-. $1/modules
+. "$1"/modules
 
 for module in $GLUON_MODULES; do
-	dir=$1/$module
-	git -C $dir checkout base
+	dir="$1"/$module
+	git -C "$dir" checkout base
 done
diff --git a/scripts/update-patches.sh b/scripts/update-patches.sh
new file mode 100755
index 000000000..3d5e023df
--- /dev/null
+++ b/scripts/update-patches.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -e
+shopt -s nullglob
+
+. "$1"/modules
+
+for module in $GLUON_MODULES; do
+	dir="$1"/$module
+	git -C "$dir" checkout patched
+
+	rm -f "$1"/patches/$module/*.patch
+	mkdir -p "$1"/patches/$module
+	git -C "$dir" format-patch -o "$1"/patches/$module base 
+done
diff --git a/scripts/update.sh b/scripts/update.sh
index 64ffc9c43..40d2b50c4 100755
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -2,15 +2,15 @@
 
 set -e
 
-. $1/modules
+. "$1"/modules
 
 for module in $GLUON_MODULES; do
-	dir=$1/$module
-	mkdir -p $dir
-	var=$(echo "$module" | tr '[:lower:]/' '[:upper:]_')
+	dir="$1"/$module
+	mkdir -p "$dir"
+	var=$(echo $module | tr '[:lower:]/' '[:upper:]_')
 	eval repo=\${MODULE_${var}_REPO}
 	eval commit=\${MODULE_${var}_COMMIT}
-	git -C $dir init
-	git -C $dir fetch $repo
-	git -C $dir checkout -B base $commit
+	git -C "$dir" init
+	git -C "$dir" fetch $repo
+	git -C "$dir" checkout -B base $commit
 done
-- 
GitLab