source: branches/stable/tools/distro-env @ 1474

Last change on this file since 1474 was 1474, checked in by bruno, 12 years ago

Ubuntu support added for build process

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1#!/bin/bash
2#
3# Create env depending on the distro on which we are
4#
5# $Id$
6#
7# Input parameters : $ddir (distro name) and $dver (distro version)
8# If they do not exist then deduce from current distro
9# Exports : $dfam (distro family) $suf (pkg suffix) $dtype (distro type) TOPBUILDDIR (dir to build packages)
10
11#
12# Guess ddir and dver from the underlying distro
13#
14if [ _"$ddir" = _"" ]; then
15    if [ -e /etc/mandriva-release ]; then
16        export ddir="mandriva"
17        export dver=`awk '{print $4}' /etc/mandriva-release`
18    elif [ -e /etc/mandrake-release ]; then
19        export ddir="mandrake"
20        export dver=`awk '{print $3}' /etc/mandrake-release`
21    elif [ -e /etc/redhat-release ]; then
22        grep -q Enterprise /etc/redhat-release
23        if [ $? -eq 0 ]; then
24            export ddir="rhel"
25            export dver=`awk '{print $7}' /etc/redhat-release`
26        elif grep -q Fedora /etc/redhat-release ; then
27            export ddir="fedora"
28            export dver=`awk '{print $4}' /etc/redhat-release`
29        elif grep -q CentOS /etc/redhat-release ; then
30            export ddir="centos"
31            export dver=`awk '{print $3}' /etc/redhat-release | cut -d. -f1`
32        else
33            export ddir="redhat"
34            export dver=`awk '{print $5}' /etc/redhat-release`
35        fi
36    elif [ -e /etc/SuSE-release ]; then
37        grep -q Enterprise /etc/SuSE-release
38        if [ $? -eq 0 ]; then
39            export ddir="sles"
40            export dver=`head -1 /etc/SuSE-release | awk '{print $5}'`
41        elif grep -q openSUSE /etc/SuSE-release ; then
42            export ddir="suse"
43            export dver=`head -1 /etc/SuSE-release | awk '{print $2}'`
44        else
45            export ddir="suse"
46            export dver=`head -1 /etc/SuSE-release | awk '{print $3}'`
47        fi
48    elif [ -e /etc/slackware-version ]; then
49        export ddir="slackware"
50        export dver=`awk '{print $2}' /etc/slackware-version | cut -d. -f1-2`
51    elif [ -e /etc/gentoo-release ]; then
52        export ddir="gentoo"
53        export dver=`awk '{print $5}' /etc/gentoo-release | cut -d. -f1-2`
54    elif [ -e /etc/debian_version ]; then
55        export ddir="debian"
56        export dver=`cat /etc/debian_version`
57        # Debian assigns release names only once a release actually happens.
58        # Debian does not distinguish between testing and unstable because
59        # unstable today is what testing will be in about ten days time. So,
60        # in case we encounter "tesing/unstable", we assume unstable, i.e. sid.
61        # Note that for released versions, the numeric version will be contained
62        # in debian_version, e.g. on a sarge system, the value will be '3.1'.
63        if [ $dver = "testing/unstable" ]; then
64            export dver = "sid"
65        fi
66        if [ -e /etc/lsb-release ]; then
67            grep -qi ubuntu /etc/lsb-release
68            if  [ $? -eq 0 ]; then
69                export ddir="ubuntu"
70                export dver=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d= -f2`
71            fi
72        fi
73    elif [ -e /etc/motd ]; then
74        head -1 /etc/motd | grep -q FreeBSD
75        if [ $? -eq 0 ]; then
76            export ddir="freebsd"
77            export dver=`head -1 /etc/motd | awk '{print $2}' /etc/motd | cut -d- -f1`
78        else
79            export ddir="unknown"
80            export dver=""
81        fi
82    else
83        export ddir="unknown"
84        export dver=""
85    fi
86fi
87
88#
89# Generate all other parameters
90#
91if [ $ddir = "debian" -o $ddir = "ubuntu" ]; then
92    dfam="debian"
93    dtype="deb"
94    suf=".${ddir}${dver}"
95elif [ $ddir = "gentoo" ]; then
96    dfam="gentoo"
97    dtype="ebuild"
98    dver1=`echo ${dver} | sed "s/\.//"`
99    suf=".${ddir}${dver1}"
100elif [ $ddir = "slackware" ]; then
101    dfam="slackware"
102    dtype="tgz"
103    suf=".${dfam}${dver}"
104elif [ $ddir = "sles" -o $ddir = "suse" ]; then
105    dfam="suse"
106    dtype="rpm"
107    suf=".${ddir}${dver}"
108elif [ $ddir = "fedora" -o $ddir = "redhat" -o $ddir = "rhel" -o $ddir = "centos" ]; then
109    dfam="redhat"
110    dtype="rpm"
111    dver1=`echo ${dver} | sed "s/\.//"`
112    if [ $ddir = "fedora" ]; then
113        suf=".fc${dver1}"
114    elif [ $ddir = "centos" ]; then
115        dver1=`echo ${dver} | sed "s/\.[0-9]//"`
116        suf=".centos${dver1}"
117    elif [ $ddir = "redhat" ]; then
118        suf=".rh${dver1}"
119    else
120        suf=".rhel${dver1}"
121    fi
122elif [ $ddir = "mandrake" ]; then
123    dfam="mandriva"
124    dtype="rpm"
125    suf=".`echo $dver | sed 's/\.//'`mdk"
126elif [ $ddir = "mandriva" ]; then
127    dfam="mandriva"
128    dtype="rpm"
129    suf=".`echo $dver | sed 's/\.//'`mdv"
130elif [ $ddir = "freebsd" ]; then
131    dfam="freebsd"
132    dtype="port"
133    suf=".`echo $dver | sed 's/\.//'`fbsd"
134else
135    dfam="unknown"
136    dtype="unknown"
137    suf="unknown"
138fi
139
140export dfam
141export dtype
142export suf
143
144#
145# Additional exports and preparation for some distros
146#
147
148# Default
149export TOPBUILDDIR=${TOPDIR}/../build
150
151if [ _"$dtype" = _"rpm" ]; then
152    export TOPBUILDDIR=`rpmquery --eval '%{_topdir}' 2> /dev/null`
153    export ARCH=`rpm --showrc | egrep "^build arch" | awk '{print $4}'`
154    mkdir -p ${TOPBUILDDIR}/{RPMS,SRPMS,SPECS,SOURCES,BUILD}
155    if [ $? -ne 0 ]; then
156        echo "Please ensure that you can write into ${TOPBUILDDIR}"
157        echo "Solution: setup _topdir in your ~/.rpmmacros or"
158        echo "chown the ${TOPBUILDDIR} to your uid"
159        exit -1
160    fi
161elif [ _"$dtype" = _"deb" ]; then
162    mkdir -p ${TOPBUILDDIR}
163elif [ _"$dtype" = _"port" ]; then
164    mkdir -p ${TOPBUILDDIR}
165elif [ _"$dfam" = _"slackware" ]; then
166    mkdir -p ${TOPBUILDDIR}/install
167elif [ _"$dtype" = _"ebuild" ]; then
168    mkdir -p ${TOPBUILDDIR}/portage
169fi
Note: See TracBrowser for help on using the repository browser.