source: MondoRescue/branches/2.2.1/tools/distro-env @ 1038

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

Work on FreeBSD

  • 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/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    elif [ -e /etc/motd && grep -q FreeBSD /etc/motd ]; then
67        export ddir="freebsd"
68        export dver=`awk '{print $2}' /etc/motd | cut -d- -f1`
69    else
70        export ddir="unknown"
71        export dver=""
72    fi
73fi
74
75#
76# Generate all other parameters
77#
78if [ $ddir = "debian" ]; then
79    dfam="debian"
80    dtype="deb"
81    suf=".${dfam}${dver}"
82elif [ $ddir = "gentoo" ]; then
83    dfam="gentoo"
84    dtype="ebuild"
85    dver1=`echo ${dver} | sed "s/\.//"`
86    suf=".${ddir}${dver1}"
87elif [ $ddir = "slackware" ]; then
88    dfam="slackware"
89    dtype="tgz"
90    suf=".${dfam}${dver}"
91elif [ $ddir = "sles" -o $ddir = "suse" ]; then
92    dfam="suse"
93    dtype="rpm"
94    suf=".${ddir}${dver}"
95elif [ $ddir = "fedora" -o $ddir = "redhat" -o $ddir = "rhel" -o $ddir = "centos" ]; then
96    dfam="redhat"
97    dtype="rpm"
98    dver1=`echo ${dver} | sed "s/\.//"`
99    if [ $ddir = "fedora" ]; then
100        suf=".fc${dver1}"
101    elif [ $ddir = "centos" ]; then
102        dver1=`echo ${dver} | sed "s/\.[0-9]//"`
103        suf=".centos${dver1}"
104    elif [ $ddir = "redhat" ]; then
105        suf=".rh${dver1}"
106    else
107        suf=".rhel${dver1}"
108    fi
109elif [ $ddir = "mandrake" ]; then
110    dfam="mandriva"
111    dtype="rpm"
112    suf=".`echo $dver | sed 's/\.//'`mdk"
113elif [ $ddir = "mandriva" ]; then
114    dfam="mandriva"
115    dtype="rpm"
116    suf=".`echo $dver | sed 's/\.//'`mdv"
117elif [ $ddir = "freebsd" ]; then
118    dfam="freebsd"
119    dtype="port"
120    suf=".`echo $dver | sed 's/\.//'`fbsd"
121else
122    dfam="unknown"
123    dtype="unknown"
124    suf="unknown"
125fi
126
127export dfam
128export dtype
129export suf
130
131#
132# Additional exports and preparation for some distros
133#
134
135# Default
136export TOPBUILDDIR=${TOPDIR}/../build
137
138if [ _"$dtype" = _"rpm" ]; then
139    export TOPBUILDDIR=`rpmquery --eval '%{_topdir}' 2> /dev/null`
140    export ARCH=`rpm --showrc | egrep "^build arch" | awk '{print $4}'`
141    mkdir -p ${TOPBUILDDIR}/{RPMS,SRPMS,SPECS,SOURCES,BUILD}
142    if [ $? -ne 0 ]; then
143        echo "Please ensure that you can write into ${TOPBUILDDIR}"
144        echo "Solution: setup _topdir in your ~/.rpmmacros or"
145        echo "chown the ${TOPBUILDDIR} to your uid"
146        exit -1
147    fi
148elif [ _"$dtype" = _"deb" ]; then
149    mkdir -p ${TOPBUILDDIR}
150elif [ _"$dfam" = _"slackware" ]; then
151    mkdir -p ${TOPBUILDDIR}/install
152elif [ _"$dtype" = _"ebuild" ]; then
153    mkdir -p ${TOPBUILDDIR}/portage
154fi
Note: See TracBrowser for help on using the repository browser.