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