source: trunk/tools/distro-env @ 793

Last change on this file since 793 was 764, checked in by bruno, 13 years ago

merge -r728:763 $SVN_M/branches/stable

  • Property svn:executable set to *
File size: 3.7 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) BUILDDIR (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        else
30            export ddir="redhat"
31            export dver=`awk '{print $5}' /etc/redhat-release`
32        fi
33    elif [ -e /etc/SuSE-release ]; then
34        grep -q Enterprise /etc/SuSE-release
35        if [ $? -eq 0 ]; then
36            export ddir="sles"
37            export dver=`head -1 /etc/SuSE-release | awk '{print $5}'`
38        else
39            export ddir="suse"
40            export dver=`head -1 /etc/SuSE-release | awk '{print $3}'`
41        fi
42    elif [ -e /etc/gentoo-release ]; then
43        export ddir="gentoo"
44        export dver=`awk '{print $5}' /etc/gentoo-release | cut -d. -f1-2`
45    elif [ -e /etc/debian_version ]; then
46        export ddir="debian"
47        export dver=`cat /etc/debian_version`
48        # Debian assigns release names only once a release actually happens.
49        # Debian does not distinguish between testing and unstable because
50        # unstable today is what testing will be in about ten days time. So,
51        # in case we encounter "tesing/unstable", we assume unstable, i.e. sid.
52        # Note that for released versions, the numeric version will be contained
53        # in debian_version, e.g. on a sarge system, the value will be '3.1'.
54        if [ $dver = "testing/unstable" ]; then
55            export dver = "sid"
56        fi
57    else
58        export ddir="unknown"
59        export dver=""
60    fi
61fi
62
63#
64# Generate all other parameters
65#
66if [ $ddir = "debian" ]; then
67    dfam="debian"
68    dtype="deb"
69    suf=".${dfam}${dver}"
70    BUILDDIR=${TOPDIR}/debian
71elif [ $ddir = "gentoo" ]; then
72    dfam="gentoo"
73    dtype="ebuild"
74    dver1=`echo ${dver} | sed "s/\.//"`
75    suf=".${ddir}${dver1}"
76    BUILDDIR=${TOPDIR}/ebuild
77elif [ $ddir = "slackware" ]; then
78    dfam="slack"
79    dtype="tgz"
80    suf=".${dfam}${dver}"
81    BUILDDIR=${TOPDIR}/slack
82elif [ $ddir = "sles" -o $ddir = "suse" ]; then
83    dfam="suse"
84    dtype="rpm"
85    suf=".${ddir}${dver}"
86    BUILDDIR=${TOPDIR}/SPECS
87elif [ $ddir = "fedora" -o $ddir = "redhat" -o $ddir = "rhel" ]; then
88    dfam="redhat"
89    dtype="rpm"
90    dver1=`echo ${dver} | sed "s/\.//"`
91    if [ $ddir = "fedora" ]; then
92        suf=".fc${dver1}"
93    elif [ $ddir = "redhat" ]; then
94        suf=".rh${dver1}"
95    else
96        suf=".rhel${dver1}"
97    fi
98    BUILDDIR=${TOPDIR}/SPECS
99elif [ $ddir = "mandrake" -o $ddir = "mandriva" ]; then
100    dfam="mandriva"
101    dtype="rpm"
102    suf=".`echo $dver | sed 's/\.//'`mdk"
103    BUILDDIR=${TOPDIR}/SPECS
104else
105    dfam="unknown"
106    dtype="unknown"
107    BUILDDIR=${TOPDIR}/SPECS
108    suf="unknown"
109fi
110
111export dfam
112export dtype
113export BUILDDIR
114export suf
115
116#
117# Additional exports and preparation for some distros
118#
119if [ _"$dtype" = _"rpm" ]; then
120    export ARCH=`rpm --showrc | egrep "^build arch" | awk '{print $4}'`
121    if [ -f ${HOME}/.rpmmacros ]; then
122        export TOPBUILDDIR=`egrep '^%_topdir' ${HOME}/.rpmmacros | awk '{print $2}'`
123    else
124        export TOPBUILDDIR=${BASE}/build
125    fi
126    mkdir -p ${TOPBUILDDIR}/{RPMS,SRPMS,SPECS,SOURCES,BUILD}
127elif [ _"$dtype" = _"deb" ]; then
128    export TOPBUILDDIR=${BASE}/build
129    mkdir -p ${TOPBUILDDIR}
130elif [ _"$dtype" = _"ebuild" ]; then
131    export TOPBUILDDIR=${BASE}/build
132    mkdir -p ${TOPBUILDDIR}/portage
133fi
Note: See TracBrowser for help on using the repository browser.