source: MondoRescue/branches/2.2.4/tools/distro-env @ 1538

Last change on this file since 1538 was 1538, checked in by Bruno Cornec, 13 years ago

Adds support for fedora 7 to 2.2.4

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