diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..1ff11b39afb720c84da961ffcc2dc1ebe31b0b7b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.GLUON_BRANCH
+.GLUON_RELEASE
+.patched
+.prepare
+.BROKEN
diff --git a/buildscript.sh b/buildscript.sh
new file mode 100755
index 0000000000000000000000000000000000000000..0343864eee72aa4a97410c2f8a68855358dcee2b
--- /dev/null
+++ b/buildscript.sh
@@ -0,0 +1,310 @@
+#!/bin/bash
+
+# get location of executed file.
+EXECDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# global list of gluon targets
+TARGET_LIST=()
+
+help_print(){
+  echo "Usage: $0 <command>"
+  echo "command:"
+  echo "  patch                 Apply patches on gluon build ENV"
+  echo "  clean_patches         Remove applied patches from gluon repo"
+  echo "  update-patches        Create patches from local gluon commits"
+  echo "  prepare <command>"
+  echo "    GLUON_BRANCH <str>  Set ENV variable"
+  echo "    GLUON_RELEASE <str> Set ENV variable"
+  echo "    fastd               Prepare site repo for fastd build"
+  echo "    l2tp                prepare site repo for l2tp build"
+  echo "    BROKEN              y or n (default n)"
+  echo "  build <command>       <command> can be replace with targets"
+  echo "    target_list         build all gluon targets"
+  echo "    all                 build all gluon targes for each VPN"
+  echo "  create_manifest       create manifest"
+  echo
+}
+
+patch_gluon() {
+  if ! [ -f "$EXECDIR/.patched" ]; then
+    if [ "$(find "$EXECDIR"/gluon_patches/*.patch 2> /dev/null | wc -l)" -ge 1 ]; then
+      local base="$EXECDIR"
+      cd "$EXECDIR"/.. || exit 1
+      for patch in "$EXECDIR"/gluon_patches/*.patch; do
+        git am --ignore-space-change --ignore-whitespace "$patch"
+      done
+      cd "$base" || exit 1
+    else
+      echo "No patches found"
+    fi
+    touch "$EXECDIR/.patched"
+  else
+    echo "gluon is already patched!"
+    echo "Please run clean_patches first to reset gluon git repo"
+  fi
+}
+
+clean_patches(){
+  if [ -f "$EXECDIR/.patched" ]; then
+    local base="$EXECDIR"
+    cd "$EXECDIR"/.. || exit 1
+    git reset --hard "origin/v2017.1.x"
+    cd "$EXECDIR" || exit 1
+    rm "$EXECDIR/.patched"
+  else
+    echo "gluon is not patched"
+  fi
+}
+
+update_patches() {
+  local base="$EXECDIR"
+  cd "$EXECDIR"/.. || exit 1
+  git format-patch "origin/v2017.1.x" -o "$EXECDIR/gluon_patches"
+  cd "$base" || exit 1
+}
+
+
+init_prepare(){
+  local vpn="$1"
+  local file="$2"
+  if ! [ -w "$EXECDIR/$file" ]; then
+    echo "$EXECDIR/$file not exsis or writeable"
+    exit 1
+  fi
+  echo "prepare $file for $vpn build ..."
+  # ensure reset possible local file changes
+  git checkout "$EXECDIR/$file"
+}
+
+prepare_siteconf(){
+  local vpn="$1"
+  init_prepare "$vpn" "site.conf"
+  # Start prepare site.conf for build
+  if grep -q "%A" < "$EXECDIR"/site.conf; then
+    sed -i "/^%A$/c\\modules = \\'http://mirror.ffnw.de/modules/$vpn/gluon-%GS-%GR/%S\\'," "$EXECDIR"/site.conf
+    echo "Set opkg modules URL ..."
+  else
+    echo "Placeholder %A not found"
+  fi
+  if grep -q "%B" < "$EXECDIR"/site.conf; then
+    sed -i "/^%B$/c\\\\'http://autoupdate-lede.ffnw/$vpn/stable\\'," "$EXECDIR"/site.conf
+    echo "Set autoupdater stable URL ..."
+  else
+    echo "Placeholder %B not found"
+  fi
+  if grep -q "%C" < "$EXECDIR"/site.conf; then
+    sed -i "/^%C$/c\\\\'http://autoupdate-lede.ffnw/$vpn/testing\\'," "$EXECDIR"/site.conf
+    echo "Set autoupdater testing URL ..."
+  else
+    echo "Placeholder %C not found"
+  fi
+  if grep -q "%D" < "$EXECDIR"/site.conf; then
+    sed -i "/^%D$/c\\\\'http://autoupdate-lede.ffnw/$vpn/nigthly_master\\'," "$EXECDIR"/site.conf
+    echo "Set autoupdater nigthly_master URL ..."
+  else
+    echo "Placeholder %D not found"
+  fi
+}
+
+prepare_sitemk(){
+  local  vpn="$1"
+  init_prepare "$vpn" "site.mk"
+  # Start prepare site.mk for build
+  if grep -q "%A" < "$EXECDIR"/site.mk; then
+    if [ "$vpn" == "l2tp" ]; then
+      sed -i "/^%A$/c\\\\tgluon-mesh-vpn-tunneldigger \\\\" "$EXECDIR"/site.mk
+      echo "Set gluon-mesh-vpn-tunneldigger package ..."
+    fi
+    if [ "$vpn" == "fastd" ]; then
+      sed -i "/^%A$/c\\\\tgluon-web-mesh-vpn-fastd \\\\" "$EXECDIR"/site.mk
+      echo "Set gluon-web-mesh-vpn-fastd package ..."
+    fi
+  else
+    echo "Placeholder %A not found"
+  fi
+
+  if grep -q "%B" < "$EXECDIR"/site.mk; then
+    sed -i "/^%B$/c\\GLUON_RELEASE ?= $(cat "$EXECDIR/.GLUON_RELEASE")" "$EXECDIR"/site.mk
+    echo "Set GLUON_RELEASE ..."
+  else
+    echo "Placeholder %B not found"
+  fi
+  if grep -q "%C" < "$EXECDIR"/site.mk; then
+    sed -i "/^%C$/c\\GLUON_BRANCH ?= $(cat "$EXECDIR/.GLUON_BRANCH")" "$EXECDIR"/site.mk
+    echo "Set GLUON_BRANCH ..."
+  else
+    echo "Placeholder %C not found"
+  fi
+}
+
+gluon_build(){
+  if [ "$2" == "fast" ] && [ -a "/proc/cpuinfo" ]; then
+    if [ -a "$EXECDIR/.BROKEN" ]; then
+      make -C "$EXECDIR/.." -j $(($(grep -c processor /proc/cpuinfo)*2)) BROKEN=1 GLUON_TARGET="$1" GLUON_IMAGEDIR="output/images/$(cat "$EXECDIR/.prepare")/$(cat "$EXECDIR/.GLUON_RELEASE")" GLUON_PACKAGEDIR="output/packages/$(cat "$EXECDIR/.prepare")"
+    else
+      make -C "$EXECDIR/.." -j $(($(grep -c processor /proc/cpuinfo)*2)) GLUON_TARGET="$1" GLUON_IMAGEDIR="output/images/$(cat "$EXECDIR/.prepare")/$(cat "$EXECDIR/.GLUON_RELEASE")" GLUON_PACKAGEDIR="output/packages/$(cat "$EXECDIR/.prepare")"
+    fi
+  else
+    if [ -a "$EXECDIR/.BROKEN" ]; then
+      make -C "$EXECDIR/.." BROKEN=1 GLUON_TARGET="$1" GLUON_IMAGEDIR="output/images/$(cat "$EXECDIR/.prepare")/$(cat "$EXECDIR/.GLUON_RELEASE")" GLUON_PACKAGEDIR="output/packages/$(cat "$EXECDIR/.prepare")"
+    else
+      make -C "$EXECDIR/.." GLUON_TARGET="$1" GLUON_IMAGEDIR="output/images/$(cat "$EXECDIR/.prepare")/$(cat "$EXECDIR/.GLUON_RELEASE")" GLUON_PACKAGEDIR="output/packages/$(cat "$EXECDIR/.prepare")"
+    fi
+  fi
+}
+
+prepare_precondition(){
+  if ! [ -s "$EXECDIR/.GLUON_BRANCH" ]; then
+    echo "please run '$0 prepare GLUON_BRANCH' first"
+    exit 1
+  fi
+  if ! [ -s "$EXECDIR/.GLUON_RELEASE" ]; then
+    echo "please run '$0 prepare GLUON_RELEASE' first"
+    exit 1
+  fi
+}
+
+get_target_list(){
+  while read -r line; do
+    if [[ $line == *GluonTarget* ]]; then
+      # extract arcitecture parameter value
+      local targ="$(echo "$line" | sed -e 's/^.*GluonTarget,//' -e 's/)).*//' -r -e 's/([^,]+,[^,]*).*/\1/' -e 's/[,]/-/')"
+      if [ -n "$targ" ]; then
+        TARGET_LIST[${#TARGET_LIST[@]}]="$targ"
+      fi
+    else
+      if [[ $line == *BROKEN* ]] && ! [ -a "$EXECDIR/.BROKEN" ]; then
+        break
+      fi
+    fi
+  done < "$EXECDIR/../targets/targets.mk"
+}
+
+
+if ! git -C "$EXECDIR"/.. rev-parse --abbrev-ref HEAD | grep -q "v2017.1.x"; then
+  echo "no gluon repo found or wrong branch (should be v2017.1.x). Please clone this git reposetory into the gluon git reposetory"
+  exit 1
+fi
+
+case "$1" in
+  "patch")
+    patch_gluon
+  ;;
+  "clean_patches")
+    clean_patches
+  ;;
+  "update-patches")
+    update_patches
+  ;;
+  "prepare")
+    case "$2" in
+      "fastd")
+        prepare_precondition
+        if ! [ -f "$EXECDIR/.patched" ]; then
+          patch_gluon
+        fi
+        prepare_siteconf "$2"
+        prepare_sitemk "$2"
+        make -C "$EXECDIR"/.. update
+        echo "$2" > "$EXECDIR/.prepare"
+      ;;
+      "l2tp")
+        prepare_precondition
+        if ! [ -f "$EXECDIR/.patched" ]; then
+          patch_gluon
+        fi
+        prepare_siteconf "$2"
+        prepare_sitemk "$2"
+        make -C "$EXECDIR/.." update
+        echo "$2" > "$EXECDIR/.prepare"
+      ;;
+      "GLUON_BRANCH")
+        if [ -n "$3" ]; then
+          echo "$3" > "$EXECDIR/.GLUON_BRANCH"
+        else
+          echo "$2 needs a parameter e.g. testing"
+        fi
+      ;;
+      "GLUON_RELEASE")
+        if [ -n "$3" ]; then
+          echo "$3" > "$EXECDIR/.GLUON_RELEASE"
+        else
+          echo "$2 needs a parameter e.g. 20170104"
+        fi
+      ;;
+      "BROKEN")
+        if [ "$3" == "y" ]; then
+          touch "$EXECDIR/.BROKEN"
+        elif [ "$3" == "n" ]; then
+          if [ -a "$EXECDIR/.BROKEN" ]; then
+            rm "$EXECDIR/.BROKEN"
+          fi
+        else
+          echo "$2 needs the parameter: y or n"
+        fi
+      ;;
+      *)
+        help_print
+      ;;
+    esac
+  ;;
+  "build")
+    if ! [ -r "$EXECDIR"/.prepare ]; then
+      echo "please run the prepare mode first"
+      exit 1
+    fi
+    get_target_list
+    case "$2" in
+      "target_list")
+        for targ in "${TARGET_LIST[@]}"; do
+          if [ "$3" == "fast" ]; then
+            gluon_build "$targ" "fast"
+          else
+            gluon_build "$targ"
+          fi
+        done
+      ;;
+      "all")
+        "$EXECDIR/$0" prepare fastd
+        "$EXECDIR/$0" build target_list "fast"
+        "$EXECDIR/$0" create_manifest
+        "$EXECDIR/$0" prepare l2tp
+        "$EXECDIR/$0" build target_list "fast"
+        "$EXECDIR/$0" create_manifest
+      ;;
+      *)
+        err="yes"
+        for targ in "${TARGET_LIST[@]}"; do
+          if [ "$targ" == "$2" ]; then
+            err="no"
+            if [ "$3" == "fast" ]; then
+              gluon_build "$targ" "fast"
+            else
+              gluon_build "$targ"
+            fi
+          fi
+        done
+        if [ "$err" == "yes" ]; then
+          echo "Please use targes from the following list as parameter:"
+          for targ in "${TARGET_LIST[@]}"; do
+            echo "$targ"
+          done
+        fi
+      ;;
+    esac
+  ;;
+  "create_manifest")
+    if ! [ -r "$EXECDIR"/.prepare ]; then
+      echo "please run the prepare mode first"
+      exit 1
+    fi
+    if [ -a "$EXECDIR/.BROKEN" ]; then
+      make -C "$EXECDIR/.." manifest BROKEN=1 GLUON_IMAGEDIR="output/images/$(cat "$EXECDIR/.prepare")/$(cat "$EXECDIR/.GLUON_RELEASE")" GLUON_PACKAGEDIR="output/packages/$(cat "$EXECDIR/.prepare")"
+    else
+      make -C "$EXECDIR/.." manifest GLUON_IMAGEDIR="output/images/$(cat "$EXECDIR/.prepare")/$(cat "$EXECDIR/.GLUON_RELEASE")" GLUON_PACKAGEDIR="output/packages/$(cat "$EXECDIR/.prepare")"
+    fi
+  ;;
+  *)
+    help_print
+  ;;
+esac
diff --git a/gluon_patches/0001-brcm2708-bcm2709-add-manifest_alias-for-raspberry-pi.patch b/gluon_patches/0001-brcm2708-bcm2709-add-manifest_alias-for-raspberry-pi.patch
new file mode 100644
index 0000000000000000000000000000000000000000..55037d3207fe2899380808f33bc6ff9f4f5cadd2
--- /dev/null
+++ b/gluon_patches/0001-brcm2708-bcm2709-add-manifest_alias-for-raspberry-pi.patch
@@ -0,0 +1,22 @@
+From 522a23b8385c55510720c3ae24eb16b1ec1c7d37 Mon Sep 17 00:00:00 2001
+From: Jan-Tarek Butt <tarek@ring0.de>
+Date: Fri, 29 Dec 2017 17:52:29 +0100
+Subject: [PATCH 1/2] brcm2708-bcm2709: add manifest_alias for
+ raspberry-pi-2-model-b-rev-1.1
+
+---
+ targets/brcm2708-bcm2709 | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/targets/brcm2708-bcm2709 b/targets/brcm2708-bcm2709
+index cb4adbb1..6ede78a4 100644
+--- a/targets/brcm2708-bcm2709
++++ b/targets/brcm2708-bcm2709
+@@ -1,3 +1,4 @@
+ device raspberry-pi-2 rpi-2
++manifest_alias raspberry-pi-2-model-b-rev-1.1
+ factory -ext4-sdcard .img.gz
+ sysupgrade -ext4-sdcard .img.gz
+-- 
+2.11.0
+
diff --git a/gluon_patches/0002-brcm2708-bcm2708-add-manifest_alias-for-raspberry-pi.patch b/gluon_patches/0002-brcm2708-bcm2708-add-manifest_alias-for-raspberry-pi.patch
new file mode 100644
index 0000000000000000000000000000000000000000..e8bec58b47fd2b2c8e12767bb7dee79aa37594eb
--- /dev/null
+++ b/gluon_patches/0002-brcm2708-bcm2708-add-manifest_alias-for-raspberry-pi.patch
@@ -0,0 +1,23 @@
+From 8d36ae89f17e04589c10970080d85e32a4426a0f Mon Sep 17 00:00:00 2001
+From: Jan-Tarek Butt <tarek@ring0.de>
+Date: Fri, 29 Dec 2017 17:52:38 +0100
+Subject: [PATCH 2/2] brcm2708-bcm2708: add manifest_alias for
+ raspberry-pi-model-b-rev-2
+
+---
+ targets/brcm2708-bcm2708 | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/targets/brcm2708-bcm2708 b/targets/brcm2708-bcm2708
+index b9f59999..51ff11fc 100644
+--- a/targets/brcm2708-bcm2708
++++ b/targets/brcm2708-bcm2708
+@@ -1,4 +1,5 @@
+ device raspberry-pi rpi
++manifest_alias raspberry-pi-model-b-rev-2
+ factory -ext4-sdcard .img.gz
+ sysupgrade -ext4-sdcard .img.gz
+ packages '-wpad-mini' # clashes with hostapd-mini
+-- 
+2.11.0
+
diff --git a/prepare.sh b/prepare.sh
deleted file mode 100755
index 06b9fa8de7cf70f42ab7a922bb44b406d801c9bb..0000000000000000000000000000000000000000
--- a/prepare.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-
-patch_target() {
-  if [ "$(find "$PWD"/gluon_patches/*.patch 2> /dev/null | wc -l)" -ge 1 ]; then
-    for patch in "$PWD"/gluon_patches/*.patch; do
-      patch --no-backup-if-mismatch -p0 -d "../" -i "$patch"
-    done
-  fi
-}
-
-patch_gluon() {
-  if git -C ".." status | head -n1 | grep "v2016.2.x"; then
-    patch_target
-  else
-    echo "no gluon repo founden or wrong branch"
-    exit 1
-  fi
-}
-
-update_patches() {
-  if git -C ".." status | head -n1 | grep "v2016.2.x"; then
-    make -C ".." update-patches
-    #rm -f gluon_patches/*.patch
-    local base=$PWD
-    cd ..
-    n=0
-    for patch in $(git ls-files --others --exclude-standard); do
-      let n=n+1
-      local filename="$(diff -Naur /dev/null "$patch" | grep "+Subject: " | tr " " _ )"
-      diff -Naur /dev/null "$patch" > "$base/gluon_patches/$(printf '%04u' $n)-${filename//+Subject:_/}.patch"
-      echo "creating: $(printf '%04u' $n)-${filename//+Subject:_/}.patch"
-    done
-    cd "$base" || exit 1
-  else
-    echo "no gluon repo founden or wrong branch"
-    exit 1
-  fi
-}
-
-case "$1" in
-  "patch")
-    patch_gluon
-  ;;
-  "update-patches")
-    update_patches
-  ;;
-  *)
-    echo "Usage: $0 command"
-    echo "command:"
-    echo "  patch"
-    echo "  update-patches"
-    echo
-  ;;
-esac
diff --git a/site.conf b/site.conf
index c294ffe71ec0dedd49e70b6075f16c00e78e450a..4aafea0b18d6d225cf5cb06a97358edee433d906 100644
--- a/site.conf
+++ b/site.conf
@@ -11,7 +11,7 @@
 
 	opkg = {
 		extra = {
-			modules = 'http://mirror.ffnw.de/modules/gluon-%GS-%GR/%S',
+%A
 		},
 	},
 
@@ -105,7 +105,7 @@
 			stable = {
 				name = 'stable',
 				mirrors = {
-					'http://autoupdate-lede.ffnw/stable',
+%B
 				},
 				good_signatures = 4,
 				pubkeys = {
@@ -123,7 +123,7 @@
 			testing = {
 				name = 'testing',
 				mirrors = {
-					'http://autoupdate-lede.ffnw/testing',
+%C
 				},
 				good_signatures = 1,
 				pubkeys = {
@@ -141,7 +141,7 @@
 			nightly_master = {
 				name = 'nightly_master',
 				mirrors = {
-					'http://autoupdate-lede.ffnw/nightly/master',
+%D
 				},
 				good_signatures = 1,
 				pubkeys = {
diff --git a/site.mk b/site.mk
index a05240561621023a59b46b5c6e9f88e708e9d327..3f313a1c8f86e542b6c9dc1c14d0bd6ac69a7974 100644
--- a/site.mk
+++ b/site.mk
@@ -13,7 +13,7 @@ GLUON_SITE_PACKAGES := \
 	gluon-web-private-wifi \
 	gluon-radvd \
 	gluon-status-page \
-	gluon-web-mesh-vpn-fastd \
+%A
 	haveged \
 	iwinfo \
 	ffnw-banner \
@@ -55,7 +55,8 @@ endif
 GLUON_ATH10K_MESH := ibss
 
 # Allow overriding from the command line
-GLUON_RELEASE ?= $(shell date '+%Y%m%d')-$(shell git log -1 --pretty=format:%h)
+%B
+%C
 GLUON_PRIORITY ?= 0
 GLUON_REGION ?= eu
 GLUON_LANGS ?= de en