source: orange/install-scripts/mac/fink-daily-build-packages.sh @ 10500:be3ad5d2023c

Revision 10500:be3ad5d2023c, 10.6 KB checked in by Ales Erjavec <ales.erjavec@…>, 2 years ago (diff)

Added fink-daily-build-packages script.

Line 
1#!/bin/bash -e
2#
3# Run daily fink build
4#
5
6# Daily orange packages to build
7DAILY_PACKAGES="orange-hg-py26 orange-gui-hg-py26 orange-bioinformatics-hg-py26 orange-bioinformatics-gui-hg-py26 orange-text-hg-py26 orange-text-gui-hg-py26 orange-hg-py27 orange-gui-hg-py27 orange-bioinformatics-hg-py27 orange-bioinformatics-gui-hg-py27 orange-text-hg-py27 orange-text-gui-hg-py27"
8
9# Packages which, when installing, want special confirmation from the user
10# We keep those packages installed all the time
11SPECIAL_PACKAGES="passwd xinitrc"
12
13# A list of packages (dependencies) from which user can choose upon installing our packages
14# We would like to build all those so that it does not need to compile anything whichever packages he or she chooses
15# The problem is that they are often mutually conflicting so we cannot have them simply installed (so that update-all
16# would update them) but have to build them explicitly
17OTHER_PACKAGES="ghostscript ghostscript-esp ghostscript6 ghostscript-nox ghostscript6-nox gnuplot gnuplot-nox gnuplot-nogtk tetex-base tetex-nox-base texlive-nox-base texlive-base tetex-texmf texlive-texmf"
18
19
20# Miscellaneous extra packages which are maybe not really needed for Orange but are useful for CS research
21EXTRA_PACKAGES="fuse gcc42 gcc43 gcc44 gnuplot gnuplot-nox gnuplot-nogtk db48 db48-aes git imagemagick-nox rrdtool maxima nmap wireshark openssl pstree python26 python27 python3 rdiff-backup svn swi-prolog lynx links w3m elinks matplotlib-py26 matplotlib-py27 mercurial-py26 mercurial-py27"
22
23FINK_ARGS="--yes --build-as-nobody"
24FINK_SELFUPDATE_ARGS="--yes"
25APT_ARGS="--assume-yes"
26
27# Path to Fink root
28FINK_ROOT=/sw
29
30# Repo dir
31REPO_DIR=/private/tmp/repos
32
33ARCH=`perl -MFink::FinkVersion -e 'print Fink::FinkVersion::get_arch'`
34
35# Sets error handler
36trap "echo \"Script failed\"" ERR
37
38((`id -u` == 0)) || { echo "Must run as root user (use sudo)."; exit 1; }
39
40test -r $FINK_ROOT/bin/init.sh || { echo "Fink cannot be found." exit 2; }
41
42[ -e /Volumes/fink/ ] || { echo "/Volumes/fink/ not mounted."; exit 3; }
43
44# Configures environment for Fink
45. $FINK_ROOT/bin/init.sh
46
47if ! grep '^Trees:' $FINK_ROOT/etc/fink.conf | grep -q 'unstable/main' && grep '^SelfUpdateMethod:' $FINK_ROOT/etc/fink.conf | grep -q 'point'; then
48    echo "Fink does not seem to use unstable Fink packages tree with rsync or CVS updating."
49    exit 5
50fi
51
52if [ ! -x /usr/bin/xcodebuild ]; then
53    echo "It seems Xcode is not installed on a system."
54    exit 6
55fi
56
57MAC_VERSION=`sw_vers -productVersion | cut -d '.' -f 2`
58if [[ "$MAC_VERSION" -ne 5 && "$MAC_VERSION" -ne 6 ]]; then
59    echo "It seems system is not Mac OS X version 10.5 or 10.6."
60    exit 7
61fi
62
63if [ ! "`/usr/X11/bin/X -version 2>&1 | grep '^X.Org X Server' | grep -E -o '[0-9]+\.[0-9]+\.[0-9]+' | cut -d '.' -f 2`" -gt "3" ]; then
64    echo "It seems X11 version 2.3.0 or later is not installed on a system."
65    exit 8
66fi
67
68echo "Preparing local biolab Fink info files repository."
69mkdir -p $FINK_ROOT/fink/dists/biolab/main/finkinfo/
70rm -f $FINK_ROOT/fink/dists/biolab/main/finkinfo/*
71
72echo "Updating local biolab Fink info files repository."
73curl "http://orange.biolab.si/fink/dists/10.$MAC_VERSION/main/finkinfo/all.tgz" --output $FINK_ROOT/fink/dists/biolab/main/finkinfo/all.tgz
74tar -xzf $FINK_ROOT/fink/dists/biolab/main/finkinfo/all.tgz -C $FINK_ROOT/fink/dists/biolab/main/finkinfo/
75rm -f $FINK_ROOT/fink/dists/biolab/main/finkinfo/all.tgz
76
77# Copy info files from local/main/finkinfo
78echo "Updating new fink info files."
79mv $FINK_ROOT/fink/dists/local/main/finkinfo/*.info $FINK_ROOT/fink/dists/biolab/main/finkinfo/
80
81if ! grep '^Trees:' $FINK_ROOT/etc/fink.conf | grep -q 'biolab/main'; then
82    echo "Adding local biolab Fink info files repository to Fink configuration."
83    perl -p -i -l -e '$_ = "$_ biolab/main" if /^Trees/' $FINK_ROOT/etc/fink.conf
84fi
85
86# Adds our binary repository to local Fink (APT) configuration
87if ! grep -q "deb http://orange.biolab.si/fink 10.$MAC_VERSION main" $FINK_ROOT/etc/apt/sources.list; then
88    echo "Adding biolab Fink binary packages repository to Fink configuration."
89    echo "deb http://orange.biolab.si/fink 10.$MAC_VERSION main" >> $FINK_ROOT/etc/apt/sources.list
90fi
91
92if [ ! -e $FINK_ROOT/etc/apt/apt.conf.d/daily-build ]; then
93    echo "Configuring apt-get to assume yes to all questions."
94    echo 'APT::Get::Assume-Yes "true";' > $FINK_ROOT/etc/apt/apt.conf.d/daily-build
95fi
96
97# Configures any pending packages from possible interrupted past sessions
98dpkg --configure -a
99
100# Gets all official Fink package info files
101echo "Updating installed Fink packages."
102fink $FINK_SELFUPDATE_ARGS selfupdate --method=rsync
103fink $FINK_ARGS scanpackages
104
105# Updates everything (probably by compiling new packages)
106fink $FINK_ARGS update-all
107
108# Installs special packages (if they are not already installed)
109yes | fink $FINK_ARGS install $SPECIAL_PACKAGES
110
111# Removes possiblly installed packages which we want built
112fink $FINK_ARGS purge --recursive $DAILY_PACKAGES $OTHER_PACKAGES $EXTRA_PACKAGES
113# Sometimes Fink and APT are not in sync so we remove packages also directly
114for package in $DAILY_PACKAGES $OTHER_PACKAGES $EXTRA_PACKAGES ; do
115    echo $package "purge" | dpkg --set-selections
116done
117apt-get $APT_ARGS dselect-upgrade
118
119# Stores current packages status
120dpkg --get-selections '*' > /tmp/dpkg-selections.list
121
122for package in $OTHER_PACKAGES ; do
123    # Restores intitial packages status
124    dpkg --get-selections '*' | cut -f 1 | xargs -n 1 -J % echo % purge | dpkg --set-selections
125    dpkg --set-selections < /tmp/dpkg-selections.list
126    apt-get $APT_ARGS dselect-upgrade
127   
128    # Builds a package if it has not been rebuilt already (for example, as a dependency)
129    # We install it and not just build it because installation does not build package if it already exists as a binary package
130    echo "Specially building package $package."
131    fink $FINK_ARGS install $package
132done
133
134for package in $EXTRA_PACKAGES ; do
135    if fink $FINK_ARGS describe $package > /dev/null ; then
136        # Restores intitial packages status
137        dpkg --get-selections '*' | cut -f 1 | xargs -n 1 -J % echo % purge | dpkg --set-selections
138        dpkg --set-selections < /tmp/dpkg-selections.list
139        apt-get $APT_ARGS dselect-upgrade
140       
141        # Builds a package if it has not been rebuilt already (for example, as a dependency)
142        # We install it and not just build it because installation does not build package if it already exists as a binary package
143        echo "Specially building extra package $package."
144        fink $FINK_ARGS install $package
145    else
146        echo "Not building extra package $package."
147    fi
148done
149
150# We build our packages in "maintainer" mode - Fink makes tests and validates packages
151for package in $DAILY_PACKAGES ; do
152    DEPS=`perl -MFink -MFink::PkgVersion -l -e "Fink::Package->require_packages(); map { map { /(\\S+)/; print \\$1 } @\\$_ } @{Fink::PkgVersion->match_package('$package')->get_depends(1, 0)};"`
153   
154    # First builds all dependencies normally (so that we are not checking for others' errors)
155    for deps in $DEPS ; do
156        # Restores intitial packages status
157        dpkg --get-selections '*' | cut -f 1 | xargs -n 1 -J % echo % purge | dpkg --set-selections
158        dpkg --set-selections < /tmp/dpkg-selections.list
159        apt-get $APT_ARGS dselect-upgrade
160       
161        # We install it and not just build it because installation does not build package if it already exists as a binary package
162        echo "Specially building package $package dependency $deps."
163        fink $FINK_ARGS install $deps
164    done
165   
166    # Restores intitial packages status
167    dpkg --get-selections '*' | cut -f 1 | xargs -n 1 -J % echo % purge | dpkg --set-selections
168    dpkg --set-selections < /tmp/dpkg-selections.list
169    apt-get $APT_ARGS dselect-upgrade
170   
171    # Then builds a package
172    # We can just build it as our packages have been probably cached if they have been already built
173    echo "Specially building, testing and validating package $package."
174    fink $FINK_ARGS --maintainer build $package
175done
176
177echo "Restoring initial packages status."
178dpkg --get-selections '*' | cut -f 1 | xargs -n 1 -J % echo % purge | dpkg --set-selections
179dpkg --set-selections < /tmp/dpkg-selections.list
180apt-get $APT_ARGS dselect-upgrade
181rm -f /tmp/dpkg-selections.list
182
183# Cleans unncessary files (we cache them anyway in public repository)
184echo "Cleaning."
185fink $FINK_ARGS cleanup --all
186
187# TODO: Should be called only on a daily build server and not if building locally
188/Users/ailabc/mount-dirs.sh
189
190echo "Preparing public biolab Fink info and binary files repository."
191mkdir -p /Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/
192chmod +rx /Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/
193mkdir -p /Volumes/fink/dists/10.$MAC_VERSION/main/finkinfo/
194chmod +rx /Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/
195
196echo "Copying to repository all binary packages."
197cp $FINK_ROOT/fink/debs/*.deb /Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/
198if (shopt -s nullglob; f=($FINK_ROOT/var/cache/apt/archives/*.deb); ((${#f[@]}))); then
199    # We have to test if there are any deb files available as otherwise cp fails
200    cp $FINK_ROOT/var/cache/apt/archives/*.deb /Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/
201fi
202
203cd /Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/
204
205echo "Fixing possible problems with binary packages filenames."
206# Some packages include Fink epoch which uses colon as a delimiter and breaks package retrieval from the repository web server
207# We remove epoch as it should not be there in the first place
208perl -e '
209for (<*.deb>) {
210    if (m/^(.+)_\d+%3a(.+)$/) {
211        rename $_, "$1_$2";
212    }
213}
214'
215
216echo "Removing old binary packages."
217# (Versions of packages which have more then 5 versions and those old versions are more than one month old.)
218perl -e '
219for (<*.deb>) {
220    m/(.*?)_/;
221    $fs{$1}++;
222}
223while (($f,$n) = each(%fs)) {
224    next if $n <= 5;
225    unlink for grep {-M > 30} <$f_*.deb>;
226}
227'
228
229echo "Making packages list."
230cd /Volumes/fink/
231perl -MFink::Scanpackages -e "Fink::Scanpackages->scan('dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/');" | gzip - > dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/Packages.gz
232
233echo "Copying to repository all info files."
234rm -f /Volumes/fink/dists/10.$MAC_VERSION/main/finkinfo/*
235cp $FINK_ROOT/fink/dists/biolab/main/finkinfo/* /Volumes/fink/dists/10.$MAC_VERSION/main/finkinfo/
236
237echo "Making an archive of all info files."
238cd $FINK_ROOT/fink/dists/biolab/main/finkinfo/
239tar -czf /Volumes/fink/dists/10.$MAC_VERSION/main/finkinfo/all.tgz *
240
241echo "Setting permissions."
242chmod -R +r /Volumes/fink/dists/10.$MAC_VERSION/main/finkinfo/
243
244echo "Removing unnecessary source archives."
245perl -e "
246for (</Volumes/fink/dists/10.$MAC_VERSION/main/binary-darwin-$ARCH/orange-*.deb>) {
247    m/_(.+)-\\d+_darwin-$ARCH\\.deb/;
248    \$versions{\$1} = 1;
249}
250for (</Volumes/fink/dists/10.$MAC_VERSION/main/source/*.tgz>) {
251    m/.+-(.+)\\.tgz/;
252    next if \$versions{\$1} or -M() < 30;
253    unlink;
254}
255"
256
Note: See TracBrowser for help on using the repository browser.