source: trunk/tools/distro-env @ 1041

Last change on this file since 1041 was 932, checked in by bruno, 13 years ago

merge -r913:931 $SVN_M/branches/stable

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