diff --git a/Makefile b/Makefile
index 73eb12ef39272f39750040dd8b737c83024e9864..3e8d26ba35d7913c738085335a14138b958062dd 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 d6e7971184c34e4c0b25a5751d9de4848373bfce..1cd498d52197911c7a954b054e282df7d8166608 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 5dbcb46a9838f25901938b892022e8610418e35b..6302141f3e1a9a43233ace0054c93608bbb96b8d 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 e94d236b75c4fb5409c5be1a0853c2cc16db13a2..4e5cfaaac2eae543f0883490110a8aeee78d1b8a 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 0000000000000000000000000000000000000000..3d5e023dfe3df31542642bc12426b8a667f7dc06
--- /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 64ffc9c435a1f43d0a02c5d9a9d5e3df83c8bb2d..40d2b50c409d41f4e2d7ae84a6cc1c10c3aba202 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