makepackage 8.2 KB
Newer Older
1
#!/bin/bash
Ruben Rodriguez's avatar
Ruben Rodriguez committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#
#    Copyright (C) 2011  Ruben Rodriguez <ruben@trisquel.info>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

set -e

22
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}/usr/lib/libeatmydata/libeatmydata.so"
Ruben Rodriguez's avatar
Ruben Rodriguez committed
23 24 25 26 27 28 29 30
export DEBIAN_FRONTEND=noninteractive
MEM=$(cat /proc/meminfo |grep MemTotal| awk '{print $2}')
GPGKEY=8D8AEBF1

for VAR in LANG LANGUAGE LC_ALL LC_TIME LC_MONETARY LC_ADDRESS LC_TELEPHONE LC_MESSAGES LC_NAME LC_MEASUREMENT LC_IDENTIFICATION LC_IDENTIFICATION LC_NUMERIC LC_PAPER LANG
do
    unset $VAR
done
31
export LANG=C
Ruben Rodriguez's avatar
Ruben Rodriguez committed
32
export HOME=/root
33
export DATE=$(date +'%a, %d %b %Y %T %z')
Ruben Rodriguez's avatar
Ruben Rodriguez committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

cd $(dirname $0)

if [ $# -lt 1 ]
then
    echo "Usage: $0 package"
    echo example: $0 linux lucid
    exit 1
fi

PACKAGE=$1
CODENAME=$(grep 'export CODENAME=' helpers/config |sed 's/.*=//')
UPSTREAM=$(grep 'export UPSTREAM=' helpers/config |sed 's/.*=//')
WORKDIR=tmp/makepackage
REPOSITORY=$PWD/repos/$CODENAME
HELPERS=$PWD/helpers
50
for REPO in $(git branch|sed 's/.* //;/master/d')
Ruben Rodriguez's avatar
Ruben Rodriguez committed
51
do
Ruben Rodriguez's avatar
Ruben Rodriguez committed
52
[ -d $REPOSITORY ] && continue
Ruben Rodriguez's avatar
Ruben Rodriguez committed
53 54
mkdir -p repos/$REPO/conf repos/$REPO/incoming
cat << EOF > repos/$REPO/conf/distributions
Ruben Rodriguez's avatar
Ruben Rodriguez committed
55 56
Origin: Trisquel
Label: Trisquel
Ruben Rodriguez's avatar
Ruben Rodriguez committed
57
Suite: $REPO
Ruben Rodriguez's avatar
Ruben Rodriguez committed
58
Version: 42
Ruben Rodriguez's avatar
Ruben Rodriguez committed
59
Codename: $REPO
Ruben Rodriguez's avatar
Ruben Rodriguez committed
60 61 62 63 64 65
Architectures: i386 amd64 source
Components: main
UDebComponents: main
DebIndices: Packages Release . .gz .bz2
UDebIndices: Packages . .gz .bz2
DscIndices: Sources Release .gz .bz2
Ruben Rodriguez's avatar
Ruben Rodriguez committed
66
Log: $REPO.log
Ruben Rodriguez's avatar
Ruben Rodriguez committed
67 68 69 70 71
Description: Trisquel GNU/Linux packages for the $UPSTREAM based release
EOF

if gpg -K | grep -q $GPGKEY
then
Ruben Rodriguez's avatar
Ruben Rodriguez committed
72
    echo "SignWith: $GPGKEY" >> repos/$REPO/conf/distributions
Ruben Rodriguez's avatar
Ruben Rodriguez committed
73 74
fi

Ruben Rodriguez's avatar
Ruben Rodriguez committed
75
cd repos/$REPO
Ruben Rodriguez's avatar
Ruben Rodriguez committed
76 77
reprepro -v export
cd ../..
Ruben Rodriguez's avatar
Ruben Rodriguez committed
78
done
Ruben Rodriguez's avatar
Ruben Rodriguez committed
79 80 81 82 83 84 85 86 87 88 89 90

disablescripts(){
    # Disable service starter scripts
    for i in /usr/sbin/invoke-rc.d /sbin/start /sbin/start-stop-daemon
    do
        mv $CHROOT/$i $CHROOT/$i.real
        cp $CHROOT/bin/true $CHROOT/$i
    done
}

createjail () {
    [ -d jails ] || mkdir jails
91
    CHROOT=jails/$UPSTREAM-$JAILARCH
Ruben Rodriguez's avatar
Ruben Rodriguez committed
92 93 94 95 96
    C="chroot $CHROOT"
    MIRROR=http://mir1.ovh.net/mirrors/ftp.ubuntu.com/ubuntu

    mkdir $CHROOT-tmp
    mount -t tmpfs -o size=500M none $CHROOT-tmp
97
    debootstrap --arch=$JAILARCH $UPSTREAM $CHROOT-tmp $MIRROR
Ruben Rodriguez's avatar
Ruben Rodriguez committed
98
    fuser -k $CHROOT-tmp
Ruben Rodriguez's avatar
Ruben Rodriguez committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    cp -a $CHROOT-tmp $CHROOT
    umount $CHROOT-tmp
    rm $CHROOT-tmp -rf
    echo "127.0.0.1 localhost" > $CHROOT/etc/hosts
    mount none $CHROOT/proc -t proc
    mount none $CHROOT/dev/pts -t devpts

    disablescripts

    if gpg -K | grep $GPGKEY -q
    then
        cp /root/.gnupg $CHROOT/root -a
    else
        echo GPG private key for $GPGKEY not found, the packages and repositories will not be signed.
    fi

115
    echo $UPSTREAM-$JAILARCH  > $CHROOT/etc/debian_chroot
Ruben Rodriguez's avatar
Ruben Rodriguez committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
cat << EOF > $CHROOT/etc/apt/sources.list
deb $MIRROR $UPSTREAM main universe
deb $MIRROR $UPSTREAM-updates main universe
deb $MIRROR $UPSTREAM-security main universe
deb $MIRROR $UPSTREAM-backports main universe
deb-src $MIRROR $UPSTREAM main universe
deb-src $MIRROR $UPSTREAM-updates main universe
deb-src $MIRROR $UPSTREAM-security main universe
deb-src $MIRROR $UPSTREAM-backports main universe
EOF

cat << EOF > $CHROOT/etc/apt/apt.conf.d/90recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF

    export DEBIAN_FRONTEND=noninteractive

    [ $UPSTREAM != hardy -a $UPSTREAM != lucid -a $UPSTREAM != maverick ] &&  echo "force-unsafe-io" > $CHROOT/etc/dpkg/dpkg.cfg.d/02apt-speedup
    $C apt-get update
136
    [ $UPSTREAM != hardy ] && $C apt-get --force-yes -y install sysv-rc dpkg sysvinit-utils upstart
137
    disablescripts
138
    $C apt-get --force-yes -y dist-upgrade
Ruben Rodriguez's avatar
Ruben Rodriguez committed
139 140 141 142 143 144 145
    $C apt-get --force-yes -y install devscripts build-essential liburi-perl python-setuptools pkgbinarymangler wget rpl aptitude quilt fakeroot ccache
    $C apt-get clean

    wget -o /dev/null -O $CHROOT/tmp/key.gpg http://archive.trisquel.info/trisquel/trisquel-archive-signkey.gpg 
    $C apt-key add /tmp/key.gpg

    # Hack for i386
146
    if [ $JAILARCH = "i386" ]
Ruben Rodriguez's avatar
Ruben Rodriguez committed
147 148 149
    then
        for BIN in /bin/uname /usr/bin/arch
        do
150
        [ -f $CHROOT/$BIN ] || continue
Ruben Rodriguez's avatar
Ruben Rodriguez committed
151 152
        mv $CHROOT/$BIN $CHROOT/$BIN.orig
cat << EOF > $CHROOT/$BIN
153
#!/bin/bash
Ruben Rodriguez's avatar
Ruben Rodriguez committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

if [ \$# -eq 0 ]
then   
        $BIN.orig | sed s/x86_64/i686/g
else   
        $BIN.orig "\$*" | sed s/x86_64/i686/g
fi
EOF
        chmod 755 $CHROOT/$BIN
done
    fi
umount $CHROOT/proc $CHROOT/dev/pts
}

prepare(){
169 170
[ -d jails/$UPSTREAM-$JAILARCH ] || createjail
cat << EOF > jails/$UPSTREAM-$JAILARCH/tmp/update
Ruben Rodriguez's avatar
Ruben Rodriguez committed
171 172 173 174
mount -t proc none /proc
export DEBIAN_FRONTEND=noninteractive
export LANG=C
apt-get update
175 176 177 178 179 180
apt-get --force-yes -y install sysv-rc dpkg sysvinit-utils upstart
for i in /usr/sbin/invoke-rc.d /sbin/start /sbin/start-stop-daemon
do
    mv \$i \$i.real
    cp /bin/true \$i
done
181
export DEBIAN_FRONTEND=noninteractive
Ruben Rodriguez's avatar
Ruben Rodriguez committed
182 183 184
apt-get --force-yes -y dist-upgrade
umount /proc
EOF
185 186
chroot jails/$UPSTREAM-$JAILARCH bash /tmp/update
if [ -f jails/$UPSTREAM-$JAILARCH/CurrentlyBuilding ]
Ruben Rodriguez's avatar
Ruben Rodriguez committed
187
then
188
    echo The $UPSTREAM-$JAILARCH jail appears to be running $(cat jails/$UPSTREAM-$JAILARCH/CurrentlyBuilding |grep Package: |sed 's/Package:\ //'), aborting.
Ruben Rodriguez's avatar
Ruben Rodriguez committed
189 190
    exit 1
fi
191
    CHROOT=jails/$UPSTREAM-$JAILARCH disablescripts
Ruben Rodriguez's avatar
Ruben Rodriguez committed
192 193 194
}

tmpumount(){
195 196 197
  grep jails/$UPSTREAM-$JAILARCH/tmp /proc/mounts -q || return 0
  umount jails/$UPSTREAM-$JAILARCH/tmp && return
  echo ERROR: could not umount tmpfs at jails/$UPSTREAM-$JAILARCH/tmp
Ruben Rodriguez's avatar
Ruben Rodriguez committed
198 199 200 201
  exit 1
}
tmpmount(){
  [ $MEM -lt 16000000 ] && return
202
  grep jails/$UPSTREAM-$JAILARCH/tmp /proc/mounts -q && tmpumount
203
  echo $PACKAGE | grep -q "linux" && return
Ruben Rodriguez's avatar
Ruben Rodriguez committed
204
  mount -t tmpfs -o size=20G none jails/$UPSTREAM-$JAILARCH/tmp
Ruben Rodriguez's avatar
Ruben Rodriguez committed
205 206 207
}

compile(){
208
    [ -d jails/$UPSTREAM-$JAILARCH/$WORKDIR ] && rm -rf jails/$UPSTREAM-$JAILARCH/$WORKDIR/
Ruben Rodriguez's avatar
Ruben Rodriguez committed
209
tmpmount
210
    cp -a helpers/ jails/$UPSTREAM-$JAILARCH/$WORKDIR/
Ruben Rodriguez's avatar
Ruben Rodriguez committed
211

212
cat << EOF > jails/$UPSTREAM-$JAILARCH/usr/local/sbin/makepackage-handler
213
#!/bin/bash
Ruben Rodriguez's avatar
Ruben Rodriguez committed
214 215 216 217 218 219
WORKDIR=$WORKDIR
PACKAGE=$PACKAGE
cd $WORKDIR
[ -d LOGS ] || mkdir LOGS
[ -d PACKAGES ] || mkdir PACKAGES
export PATH="/usr/lib/ccache:${PATH}"
220
bash -e make-$PACKAGE 2>&1 || exit 1
Ruben Rodriguez's avatar
Ruben Rodriguez committed
221 222
EOF

223
cat << EOF > jails/$UPSTREAM-$JAILARCH/etc/pkgbinarymangler/striptranslations.conf
Ruben Rodriguez's avatar
Ruben Rodriguez committed
224 225 226 227 228 229 230
enable: true
components: main
invalid_currentlybuilding: ignore
posuffix: translations
oem_blacklist: partner
EOF

231
cat << EOF > jails/$UPSTREAM-$JAILARCH/etc/pkgbinarymangler/sanitychecks.conf
Ruben Rodriguez's avatar
Ruben Rodriguez committed
232 233 234
enable: true
EOF

235
cat << EOF > jails/$UPSTREAM-$JAILARCH/etc/pkgbinarymangler/maintainermangler.conf
Ruben Rodriguez's avatar
Ruben Rodriguez committed
236 237 238 239
enable: true
invalid_currentlybuilding: ignore
EOF

240
cat << EOF > jails/$UPSTREAM-$JAILARCH/etc/pkgbinarymangler/maintainermangler.overrides
Ruben Rodriguez's avatar
Ruben Rodriguez committed
241 242 243 244 245
default: Trisquel GNU/Linux developers <trisquel-devel@listas.trisquel.info>
ignore_domains: trisquel.info sognus.com listas.trisquel.info gnu.org fsf.org
ignore_emails: ruben@trisquel.info
EOF

246
    chmod 755 jails/$UPSTREAM-$JAILARCH/usr/local/sbin/makepackage-handler
Ruben Rodriguez's avatar
Ruben Rodriguez committed
247

248
    if ! chroot jails/$UPSTREAM-$JAILARCH makepackage-handler /$WORKDIR/make-$PACKAGE
Ruben Rodriguez's avatar
Ruben Rodriguez committed
249
    then
250
        rm jails/$UPSTREAM-$JAILARCH/CurrentlyBuilding
Ruben Rodriguez's avatar
Ruben Rodriguez committed
251 252
        exit 1
    fi
253
    find jails/$UPSTREAM-$JAILARCH/$WORKDIR/PACKAGES/$PACKAGE/ -maxdepth 1 -type f -exec cp {} $REPOSITORY/incoming/ \;
Ruben Rodriguez's avatar
Ruben Rodriguez committed
254 255 256
tmpumount
}

257 258 259 260
 JAILARCH=i386 prepare
 JAILARCH=amd64 prepare
 JAILARCH=i386 compile
 JAILARCH=amd64 compile
Ruben Rodriguez's avatar
Ruben Rodriguez committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

cd $REPOSITORY

for dsc in incoming/*.dsc
do
    if gpg -K | grep $GPGKEY -q
    then
        debsign -k$GPGKEY $dsc
    else
        echo GPG private key for $GPGKEY not found, the packages and repositories will not be signed.
    fi
    reprepro -v -C main includedsc $CODENAME $dsc || reprepro -S admin -P optional -v -b . -C main includedsc $CODENAME $dsc
done

find incoming -name *.deb -exec reprepro -v -C main includedeb $CODENAME {} \;
find incoming -name *.udeb -exec reprepro -v -C main includeudeb $CODENAME {} \;

rm incoming/*