lorikeet-heimdal: modernize URLs in helper scripts
[metze/heimdal/wip.git] / import-lorikeet.sh
1 #!/bin/bash
2 #
3 # Usage copy import-lorikeet.sh and rebase-lorikeet.sh
4 # into an empty directory maybe call it update-heimdal
5 # and don't use it for any other work than importing lorikeet heimdal
6 # into samba.
7 #
8 # You need to pass the name of the lorikeet branch
9 # within the heimdal/ repository as first argument.
10 #
11 # You can pass skip_fetch=yes, skip_create=yes, skip_build=yes, skip_test=yes
12 # as env vars
13 #
14
15 DATE=`date --utc +%Y%m%d%H%M`
16
17 lorikeet_branch="$1"
18 tmp_samba_branch="import-lorikeet-tmp"
19 new_samba_branch="import-${lorikeet_branch}"
20 samba_master_branch="$2"
21 test -n "$samba_master_branch" || {
22     samba_master_branch="origin/master"
23 }
24
25 export CC="ccache gcc"
26
27 bailout() {
28         exit $1;
29 }
30
31 # 1. check if the heimdal repository created with rebase-lorikeet.sh already
32 # exist
33 heimdal_check() {
34         test -d heimdal || {
35                 ls heimdal/
36                 bailout 255
37         }
38
39         test -n "$lorikeet_branch" || {
40                 echo "usage: $0 <lorikeet-branch> [<samba-branch>]"
41                 bailout 1
42         }
43
44         return 0;
45 }
46
47 # 2. initialize the samba repository in the samba subdir
48 samba_init() {
49         test -d samba || {
50                 mkdir samba || bailout $?
51                 pushd samba
52                 git init || bailout $?
53                 git remote add origin https://git.samba.org/samba.git
54                 git remote add local-heimdal ../heimdal
55                 popd
56         }
57
58         return 0;
59 }
60
61 # 3. bring the repository uptodate
62 samba_fetch() {
63         test x"$skip_fetch" = x"yes" || {
64                 pushd samba
65                 git fetch origin || bailout $?
66                 git fetch local-heimdal || bailout $?
67                 popd
68         }
69
70         return 0;
71 }
72
73 #
74 # It would be good if you have a lex:yacc combination which can rebuild this
75 # files...
76 #
77
78 build_samba() {
79         test x"$skip_build" = x"yes" || {
80                 ./configure.developer || return $?
81                 make -j || return $?
82                 test x"$skip_test" = x"yes" || {
83                         TDB_NO_FSYNC=1 make -j test || return $?
84                 }
85         }
86
87         return 0;
88 }
89
90 samba_create() {
91         test x"$skip_create" = x"yes" || {
92                 pushd samba
93                 lorikeet_commit=`git log -1 local-heimdal/$lorikeet_branch | head -1 | cut -d ' ' -f2`
94                 echo "local-heimdal/$lorikeet_branch => commit:$lorikeet_commit"
95                 echo "git update-ref"
96                 git update-ref refs/heads/$tmp_samba_branch $samba_master_branch || bailout $?
97                 echo "git checkout"
98                 git checkout $tmp_samba_branch || bailout $?
99                 echo "git reset --hard HEAD"
100                 git reset --hard HEAD
101                 echo "git clean -d -x -f"
102                 git clean -d -x -f
103                 echo "git read-tree..."
104                 git read-tree -u --prefix=source4/heimdal-new/ local-heimdal/$lorikeet_branch || bailout $?
105                 echo "git reset --mixed HEAD"
106                 git reset --mixed HEAD
107                 echo "swap old -> new"
108                 mv source4/heimdal source4/heimdal-old || bailout $?
109                 rsync -a source4/heimdal-new/ source4/heimdal || bailout $?
110                 echo "restore autogenerated files (run lexyacc.sh)"
111                 ( 
112                     pushd source4
113                     heimdal_build/lexyacc.sh 
114                     git add heimdal/lib/asn1/asn1parse.c heimdal/lib/asn1/asn1parse.h
115                     popd
116                 )
117         #       echo "PS1=\"'import-heimdal shell'>\"" > ../.bashrc.samba_create
118         #       bash --rcfile ../.bashrc.samba_create
119         #       bailout 255
120                 echo "add changed files to the index"
121                 git add -u source4/heimdal
122                 echo "commit the changed files blindly"
123                 git commit --no-verify -m "s4:heimdal: import $lorikeet_branch (commit $lorikeet_commit)"
124                 echo "cleanup source4/heimdal"
125                 rm -rf source4/heimdal
126                 git checkout source4/heimdal
127                 echo "try to build samba"
128                 build_samba || {
129                         echo ""
130                         echo "Now build the tree and make it compile."
131                         echo "Missing files can be copied from source4/heimdal-new/"
132                         echo "Also run make test!"
133                 }
134                 echo ""
135                 echo "Then do a 'git add source4/heimdal' and a 'git commit --amend'"
136                 echo "and write a useful commit message..."
137                 echo "Then commit all needed changes outside of source4/heimdal"
138                 echo "maybe splitted into multiple commits."
139                 echo ""
140                 echo "!!!!!!!!!"
141                 echo ""
142                 echo "if you this shell exit with 0, then $new_samba_branch will be created"
143                 echo ""
144                 echo "PS1=\"'import-heimdal shell'>\"" > ../.bashrc.samba_create
145                 bash --rcfile ../.bashrc.samba_create || bailout $?
146                 git branch $new_samba_branch $tmp_samba_branch || bailout $?
147                 echo "branch $new_samba_branch created"
148                 popd
149         }
150
151         return 0;
152 }
153
154 heimdal_check
155 samba_init
156
157 samba_fetch
158 samba_create