repack-deb 1.84 KB
Newer Older
Ian Baum's avatar
Ian Baum committed
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
#!/bin/sh

set -e

PROG="${0}"
DIR=$(dirname "${PROG}")

usage() {
    >&2 echo "Usage: ${PROG} -s SOURCE_DEB -d DEST_DEB"
    >&2 echo "Repacks SOURCE_DEB with relevant content from current branch into DEST_DEB"
    >&2 echo "Copies in config/package/templates, files/gitlabt-ctl-commands* and files/gitlab-cookbooks"
}

while getopts :s:d: opt
do
    case "${opt}" in
        s)
            source_deb="${OPTARG}"
            ;;
        d)
            dest_deb="${OPTARG}"
            ;;
        *)
            usage
            exit 0
            ;;
    esac
done

if [ -z "${source_deb}" ] || [ -z "${dest_deb}" ]
then
    usage
    exit 1
fi

for prog in dpkg-deb erb
do
    if ! type "${prog}" >/dev/null
    then
        >&2 echo "${prog} is required, please install"
        exit 1
    fi
done

work_dir=$(mktemp -d)
trap 'rm -rf "${work_dir}"' EXIT

dpkg-deb -R "${source_deb}" "${work_dir}"

project_dir="${DIR}/.."
source_info=$(dpkg-deb -I "${source_deb}")

# config/templates/package-scripts
template_dir="${project_dir}/config/templates/package-scripts"
external_url_script=$(cat "${project_dir}/config/templates/package-scripts/external_url.sh")
build_version=$(echo "${source_info}" | awk '/Version/ {print $NF}')
for script in postinst postrm posttrans preinst
do
    erb install_dir="/opt/gitlab" external_url_script="${external_url_script}" build_version="${build_version}" "${template_dir}/${script}.erb" > "${work_dir}/DEBIAN/${script}"
done

# files/gitlab-ctl-commands
rsync -axSH --delete files/gitlab-ctl-commands/ "${work_dir}/opt/gitlab/embedded/service/omnibus-ctl/"

# files/gitlab-ctl-commands-ee
rsync -axSH --delete files/gitlab-ctl-commands-ee/ "${work_dir}/opt/gitlab/embedded/service/omnibus-ctl-ee/"

# files/gitlab-cookbooks
rsync -axSH files/gitlab-cookbooks/ "${work_dir}/opt/gitlab/embedded/cookbooks/"

dpkg-deb -b "${work_dir}" "${dest_deb}"