source: MondoRescue/branches/stable/tools/distro-env @ 1040

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

FreeBSD fixes

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