This script file can be used for any patch release of wrapfs.
authorrohit <rohit>
Tue, 10 Apr 2018 09:34:11 +0000 (09:34 +0000)
committerrohit <rohit>
Tue, 10 Apr 2018 09:34:11 +0000 (09:34 +0000)
USAGE: ./wrapfs-patch-release.sh -p <patch-file-name> [-v <linux-version>]

wrapfs-patch-release.sh [new file with mode: 0755]

diff --git a/wrapfs-patch-release.sh b/wrapfs-patch-release.sh
new file mode 100755 (executable)
index 0000000..14bee9b
--- /dev/null
@@ -0,0 +1,147 @@
+#! /bin/bash
+
+set -u -e
+
+_=${LINUX_VERSION:=""}
+_=${LINUX_BRANCH:=""}
+_=${LOCATION:=$(pwd)}
+_=${PATCH_FILE:=""}
+
+# check if the script is running for a git repository or not 
+if [ ! -d .git ]; then
+    echo "Please run this script in a git directory."
+    exit
+fi
+
+TEMP=`getopt -o v:p: --long version:patch: -n 'parse-options' -- "$@"`
+
+eval set -- "$TEMP"
+
+while true; do
+  case "$1" in
+    -v | --version ) LINUX_VERSION=$2; shift 2;;
+    -p | --patch ) PATCH_FILE=$2; shift 2;;
+    -- ) shift;break;;
+    * ) echo $1; break;;
+  esac
+done
+
+if [ -z "${PATCH_FILE:+x}" ]; then
+  echo "Please give a path file name using -patch or -p option."
+  exit 1
+fi
+
+# function to execute commands 
+runcmd() {
+    echo "----------------------------------------------------------------------"
+    echo "CMD: $@" 
+    $@
+    ret=$?
+    if [ $ret -ne 0 ] ; then
+        echo "ERROR in running cmd: $@"
+       exit $ret
+    fi
+}
+
+patch() {
+  local src="v$1"
+  local dest="wrapfs"
+  local file="$2"
+  runcmd git diff -u $src..$dest > $2
+}
+
+trim() {
+    local var="$*"
+    # remove leading whitespace characters
+    var="${var#"${var%%[![:space:]]*}"}"
+    # remove trailing whitespace characters
+    var="${var%"${var##*[![:space:]]}"}"   
+    echo -n "$var"
+}
+
+get_linux_version() {
+  local file=$1
+  local ret=""
+  while IFS='' read -r line || [[ -n "$line" ]]; do
+    key=$(trim ${line%%=*})
+    value=$(trim ${line#*=})
+    if [[ $key == "VERSION" ]]; then
+      ret=${ret}${value}
+    fi
+    if [[ $key == "PATCHLEVEL" ]]; then
+      ret=${ret}.${value}
+    fi
+    if [[ $key == "SUBLEVEL" ]]; then
+      ret=${ret}.${value}
+    fi
+    if [[ $key == "EXTRAVERSION" ]]; then
+      ret=${ret}${value}
+    fi
+    if [ -z "$key" ] || [ -z "$value" ]; then
+      break;
+    fi
+  done < $file
+  echo -n $ret
+}
+
+# fetch the wrapfs url from .git/config 
+WRAPFS_URL=`git config --get-regexp remote.origin.url wrapfs | cut -f 2 -d ' '`
+
+if [ -z "${WRAPFS_URL:+x}" ]; then
+    echo "Wrapfs url missing .git/config"
+    exit 1
+fi
+
+# fetch the wrapfs repository name from the wrapfs-url
+WRAPFS_REPO=`git config --get-regexp remote.origin.url wrapfs | sed 's/.*\///g'`
+
+if [ -z "${WRAPFS_REPO:+x}" ]; then
+    echo "Missing repository name in url $WRAPFS_URL"
+    exit 1
+fi
+
+WRAPFS_KERNEL_VERSION=$(get_linux_version $LOCATION/Makefile)
+
+case "$WRAPFS_REPO" in
+    wrapfs-latest*)
+        LINUX_BRANCH="master"
+       ;;
+    wrapfs-2.* | wrapfs-3.* | wrapfs-4.* ) 
+        LINUX_BRANCH=$(echo $WRAPFS_REPO | sed s/wrapfs/linux/g | sed s/\.git//g)
+       ;;
+    * )
+        echo "$WRAPFS_REPO: Unidentified repository. Script support only for wrapfs repository."
+        exit 1
+esac
+
+# checkout master branch
+runcmd git checkout master
+
+# Pull the latest changes on master
+runcmd git fetch korg --tags $LINUX_BRANCH
+
+if [[ "$LINUX_VERSION" != "" ]]; then
+  runcmd git reset --hard "v$LINUX_VERSION"
+else 
+  runcmd git reset --hard "v$WRAPFS_KERNEL_VERSION"
+fi
+
+# Push the latest chnages from korg to origin
+runcmd git push -f origin master
+
+# checkout wrapfs branch
+runcmd git checkout wrapfs
+
+# Pull latest changes from remote branch wrapfs
+runcmd git pull wrapfs wrapfs
+
+# Merge master on wrapfs
+runcmd git merge master
+
+# Release patch with latest linux
+if [[ "$LINUX_VERSION" != "" ]]; then
+  patch $LINUX_VERSION $PATCH_FILE
+else 
+  patch $WRAPFS_KERNEL_VERSION $PATCH_FILE
+fi
+