forked from macdice/cfbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfbot_patchburner_docker_ctl.sh
executable file
·85 lines (75 loc) · 2.16 KB
/
cfbot_patchburner_docker_ctl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
#
# This script applies patches inside a docker container.
set -e
TEMPLATE_DIR=patchburner_template
MOUNTED_DIR=patchburner_docker
usage()
{
echo "Usage: $1 init|create|apply|destroy"
echo
echo "init-template -- create 'patchburner_template'"
echo
echo "create -- create a new chroot under 'patchburner'"
echo "apply -- apply all the patches found in patchburner/work/patches'"
echo "destroy -- destroy 'patchburner' if it exists"
echo
echo "template-repo-patch -- report path of template git repo"
echo "burner-patch-path -- report path where patches should be placed"
echo "burner-repo-path -- report path of burner git repo"
exit 1
}
init_template()
{
# This is just a clean checkout of the git repo, which cfbot will keep
# updated, and we'll copy whever we need a throw-away copy to apply patches
# to. This just avoids having to clone it every time, which would suck.
# You should only need to init once.
mkdir $TEMPLATE_DIR
mkdir $TEMPLATE_DIR/work
git clone git://git.postgresql.org/git/postgresql.git $TEMPLATE_DIR/work/postgresql
}
destroy_patchburner_if_exists()
{
rm -fr $MOUNTED_DIR
}
create_patchburner()
{
# Copy the template to get a clean up-to-date repo.
cp -r $TEMPLATE_DIR $MOUNTED_DIR
mkdir $MOUNTED_DIR/work/patches
docker build . -t cfbot-patchburner --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)
}
apply_patches_in_patchburner()
{
docker run --mount=type=bind,source=$PWD/$MOUNTED_DIR/work,target=/work --workdir=/work/postgresql -u $(id -u):$(id -g) cfbot-patchburner /usr/local/bin/apply-patches.sh
rm -rf $MOUNTED_DIR/work/postgresql/.git/hooks
rm -rf $MOUNTED_DIR/work/postgresql/.git/config
cp $TEMPLATE_DIR/work/postgresql/.git/config $MOUNTED_DIR/work/postgresql/.git/config
}
case $1 in
init-template)
init_template
;;
create)
create_patchburner
;;
destroy)
destroy_patchburner_if_exists
;;
apply)
apply_patches_in_patchburner
;;
template-repo-path)
echo $TEMPLATE_DIR/work/postgresql
;;
burner-patch-path)
echo $MOUNTED_DIR/work/patches
;;
burner-repo-path)
echo $MOUNTED_DIR/work/postgresql
;;
*)
usage
;;
esac