#!/bin/bash

# script  : tools/mkversion
# author  : willy tarreau
# function: creates the "patch-version" patch in the "pool" directory
# usage   : $0

# This script uses the variable CSETVER for the base changeset kernel version,
# and the variable KERNVER for the new kernel version.

[ -z "$BASEVER" ] && set -- $(grep -ih -m 1 "^++.*Based" CONTENTS)     && BASEVER=$5
[ -z "$KERNVER" ] && set -- $(grep -ih -m 1 "^++.*Kernel" CONTENTS)    && KERNVER=$4
[ -z "$CSETVER" ] && set -- $(grep -ih -m 1 "^++.*Changeset" CONTENTS) && CSETVER=$4
[ -z "$CSETVER" ] && CSETVER=$BASEVER

BV1=${CSETVER%%[^0-9]*} ; BV2=${CSETVER#$BV1[^0-9]}
BP1=${BV2%%[^0-9]*}     ; BP2=${BV2#$BP1[^0-9]}
BS1=${BP2%%[^0-9]*}     ; BS2=${BP2#$BS1}

KV1=${KERNVER%%[^0-9]*} ; KV2=${KERNVER#$KV1[^0-9]}
KP1=${KV2%%[^0-9]*}     ; KP2=${KV2#$KP1[^0-9]}
KS1=${KP2%%[^0-9]*}     ; KS2=${KP2#$KS1}

rm -f pool/patch-version
cat > pool/patch-version << EOF
--- linux-$CSETVER/Makefile        Sun Sep 23 18:49:13 2001
+++ linux-$KERNVER/Makefile        Sun Sep 23 18:55:55 2001
@@ -1,4 +1,4 @@
-VERSION = $BV1
-PATCHLEVEL = $BP1
-SUBLEVEL = $BS1
-EXTRAVERSION =${BS2:+ $BS2}
+VERSION = $KV1
+PATCHLEVEL = $KP1
+SUBLEVEL = $KS1
+EXTRAVERSION = $KS2
EOF
