kdc: use the correct kvno number for PKINIT in the AS-REP
[metze/heimdal/wip.git] / apply_heimdal.sh
1 #!/bin/bash
2
3 [ $# == 2 ] || {
4     echo "Usage: apply_heimdal.sh <lorikeet_path>"
5     exit 1
6 }
7
8 LORIKEET_PATH="$1"
9 IMPORT_HASH="$2"
10 S4PATH="$PWD"
11
12 pushd $LORIKEET_PATH || exit 1
13 git reset --hard 
14 git am --abort
15 popd
16
17 # From https://gist.github.com/kfish/7425248
18
19 apply () {
20   filename=$1
21   shift
22   patch_args=$*
23
24   gotSubject=no
25   msg=""
26
27   cat $filename | while read line; do
28     if [ "$line" == "---" ]; then
29
30       patch $patch_args -p1 < $filename
31       git commit -a -m 'CHECK AUTHOR' -m "$msg"
32
33       break
34     fi
35     if [ "$gotSubject" == "no" ]; then
36       hdr=(${line//:/ })
37       if [ "${hdr[0]}" == "Subject" ]; then
38         gotSubject=yes
39         msg="${hdr[@]:3}"
40       fi
41     else
42       msg="$msg $line"
43     fi
44     msg="$msg
45 "
46   done
47 }
48
49 try_patch() {
50     commit="$1"
51     git format-patch --stdout $commit -1 source4/heimdal > "$commit".patch
52     sed -i 's|/source4/heimdal/|/|g' "$commit".patch
53     sed -i "s|^---$|(cherry picked from Samba commit $commit)\n---|g" "$commit".patch
54     pushd $LORIKEET_PATH || exit 1
55     git reset --hard
56     echo
57     if patch -p1 --forward < "$S4PATH/$commit.patch"; then
58         echo
59         echo "Commit $commit can apply - applying"
60         git reset --hard
61         git am "$S4PATH/$commit.patch" || apply "$S4PATH/$commit.patch"
62     else
63         echo
64         echo "Commit $commit does not apply cleanly"
65         echo
66     fi
67     git am --abort
68     popd || exit 1
69 }
70
71 commits="$(git log --pretty=oneline --reverse $IMPORT_HASH..HEAD -- source4/heimdal | cut -d' ' -f1)"
72 for c in $commits; do
73     git log $c -1
74     echo -n "Try apply? [Y/n] "
75     read answer
76     case $answer in
77         n*)
78             continue
79             ;;
80          *)
81             try_patch $c
82             ;;
83     esac
84 done