~larry-e-works/uci-engine/amqp-to-kombu

« back to all changes in this revision

Viewing changes to cupstream2distro/chroot-tools/buildsource-chroot

  • Committer: Francis Ginther
  • Date: 2014-06-10 20:42:46 UTC
  • mto: This revision was merged to the branch mainline in revision 571.
  • Revision ID: francis.ginther@canonical.com-20140610204246-b1bsrik7nlcolqy7
Import lp:cupstream2distro rev 605.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
# Copyright (C) 2012-2013 Canonical
 
3
#
 
4
# Authors:
 
5
#  Didier Roche
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify it under
 
8
# the terms of the GNU General Public License as published by the Free Software
 
9
# Foundation; version 3.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
# details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along with
 
17
# this program; if not, write to the Free Software Foundation, Inc.,
 
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
19
#
 
20
 
 
21
set -e
 
22
 
 
23
# go to the working directory
 
24
cd "$1"
 
25
shift
 
26
 
 
27
while [ -n "$1" ]; do 
 
28
    case "$1" in 
 
29
        --debug)
 
30
            set -x
 
31
            shift;
 
32
            ;;
 
33
        --distro-version)
 
34
            DISTRO_VERSION=$2
 
35
            shift; shift;
 
36
            ;;
 
37
        --gid)
 
38
            CHROOT_GID=$2
 
39
            shift; shift;
 
40
            ;;
 
41
        --gnupg-parentdir)
 
42
            # set home directory to real HOME for signing the source packaging
 
43
            CHROOT_HOME="${2}";
 
44
            shift; shift;
 
45
            ;;
 
46
        --help)
 
47
            echo "$0: Enable building a source package inside a chroot
 
48
 
 
49
    Usage: $0 WORKDIR --uid=UID --gid=GID --gnupg-parentdir=DIR --gnupg-keyid=KEYID --distro-version=version_from_distro [--ppa ppa_name]
 
50
    All parameters below are mandatory:
 
51
    - WORKDIR is the current package source directory (in tree)
 
52
    - uid is the uid owning the current source tree (used so that root don't own the new created files)
 
53
    - gid is the gid owning the current source tree (used so that root don't own the new created files)
 
54
    - gnupg-parentdir is the directory containing the .gnupg/ directory. Certainly $HOME for you.
 
55
    - gnupg-keyid is the keyid with which signing the source package.
 
56
    - distro-version is the latest version published to the distro
 
57
    - ppa is the optional ppa to add to the chroot
 
58
 
 
59
 
 
60
    Note that WORKDIR and gnupg-keyid should be bindmounted into the chroot.
 
61
    This will create a signed source package using bzr bd -S, after installing all build-deps, ran into the WORKDIR, with the correct permission.
 
62
 
 
63
 
 
64
    Example on how to run it with pbuilder (cowbuilder can be used with exactly the same parameters, replace pbuilder with cowbuilder):"'
 
65
    
 
66
    $ pbuilder --execute --distribution TARGET_DIST --bindmounts ${PWD} --bindmounts ${HOME} -- '$0' ${PWD} --gnupg-parentdir ${HOME} --uid $(id -u) --gid $(id -g) --gnupg-keyid E4AC208E'
 
67
            shift;
 
68
            exit 0
 
69
            ;;
 
70
        --gnupg-keyid)
 
71
            KEYID=$2
 
72
            shift; shift;
 
73
            ;;
 
74
        --ppa)
 
75
            PPA=$2
 
76
            shift; shift;
 
77
            ;;
 
78
        --uid)
 
79
            CHROOT_UID=$2
 
80
            shift; shift;
 
81
            ;;
 
82
        --*)
 
83
            echo "E: Unknown option [$1] was specified "
 
84
            exit 1;
 
85
            ;;
 
86
        *)
 
87
            break;
 
88
            ;;
 
89
    esac
 
90
done
 
91
 
 
92
if [ -z "$CHROOT_HOME" ] || [ -z "$CHROOT_UID" ] || [ -z "$CHROOT_GID" ]  || [ -z "KEYID" ]  || [ -z "DISTRO_VERSION" ] ; then
 
93
    echo "Every parameters is mandatory to run $0. Use --help for more info."
 
94
    exit 1
 
95
fi
 
96
 
 
97
HOME="$CHROOT_HOME"
 
98
export HOME;
 
99
 
 
100
apt-get update
 
101
apt-get -yq --force-yes dist-upgrade
 
102
 
 
103
# this isn't needed (you should install them in the chroot), but easier for debugging
 
104
apt-get install pbuilder bzr-builddeb libwww-perl -yq --force-yes
 
105
 
 
106
# add the optional ppa and update from it
 
107
if [ -n "$PPA" ]; then
 
108
    apt-get -yq --force-yes install software-properties-common
 
109
    add-apt-repository -y ppa:$PPA
 
110
    apt-get update
 
111
fi
 
112
 
 
113
# install build-deps
 
114
. /usr/lib/pbuilder/pdebuild-checkparams
 
115
export PBCURRENTCOMMANDLINEOPERATION="pdebuild"
 
116
"$PBUILDERSATISFYDEPENDSCMD"-classic --force-version --continue-fail
 
117
 
 
118
# create the user similar to that used outside.
 
119
cmd_retry_exec () {
 
120
    # Tries to execute $@ $loop times with a delay of $delay between retries
 
121
    # before aborting
 
122
    loop=10
 
123
    delay=1
 
124
    set +e
 
125
    while [ $loop -gt 0 ]; do
 
126
        $@ && break
 
127
        loop=$((loop - 1))
 
128
        sleep $delay
 
129
    done
 
130
    set -e
 
131
}
 
132
 
 
133
# Workaround a bug where /etc/group or /etc/passwd are locked when several
 
134
# jobs run in parallel (LP: #1155510)
 
135
cmd_retry_exec groupadd -g $CHROOT_GID -o pbgroup
 
136
cmd_retry_exec useradd -g pbgroup -u $CHROOT_UID -d "${HOME}" -o pbuser
 
137
 
 
138
# build the source in split mode
 
139
if [ "$KEYID" == "testkey" ]; then
 
140
    CMD="bzr bd -S -- -us -uc -d -v$DISTRO_VERSION"
 
141
else
 
142
    CMD="bzr bd -S -- -k$KEYID -d -v$DISTRO_VERSION"
 
143
fi
 
144
echo "Creating source with $CMD"
 
145
echo "$CMD" | su -p pbuser;