File: build-qmailanalog

package info (click to toggle)
qmailanalog-installer 0.70-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 64 kB
  • ctags: 2
  • sloc: sh: 197; makefile: 43
file content (201 lines) | stat: -rwxr-xr-x 4,972 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash -e
#
# build-<package>
#
# $Id: build-PACKAGE,v 1.5 1998/05/01 08:35:36 phil Exp $
#
# Written by Philip Hands <phil@hands.com>
# Modified by Adam McKenna <adam@debian.org> 3/5/2002
# Modified by Klaus Reimer <kay@debian.org> 7 Jun 2003
# Copyright (C) 1998 Free Software Foundation, Inc.
# Copying: GPL

# ask_user ---  function prompts the user with y/n style prompt
#
# It's behaviour is controlled via the parameters:
#  1  -  the initial prompt
#  2  -  default return value (set to 0, 1 or "none")
#  3  -  the patern match for acceptable Yes responses
#  4  -  the patern match for acceptable No responses
#  5  -  the error prompt, displayed when the user fails to provide valid input
#
# e.g.  ask_user  "Foo, or Bar [fb] " none '[fF]*' '[bB]*' "try again"

ask_user() {
  P=${1:-'Should I do this ? [yN] '}
  D=${2:-1}
  Y=${3:-'[yY]*'}
  N=${4:-'[nN]*'}
  E=${5:-'\nPlease enter either y)es or n)o, followed by <RETURN>\n'}

  while true ; do
    echo -ne "$P"
    read response
    case "$response" in
      ${Y} ) return 0 ;;
      ${N} ) return 1 ;;
      "" ) [ "$D" = 0 -o "$D" = 1 ] && return $D ;;
    esac
    echo -e $E
  done
}

package=qmailanalog
version="0.70"
NEWDIR=/tmp/$package

cat <<!END!

This script unpacks the ${package} source into a directory, and
compiles it to produce a binary ${package}*.deb file.

The directory where this is done will end up containing the source
and package files for the $package binary package, along with a
directory containing the unpacked source.

!END!

line=kjfdsh
read  -e -p "Enter a directory where you would like to do this [$NEWDIR] " line
NEWDIR="${line:-$NEWDIR}"

if test -d $NEWDIR
then
  echo -e "$NEWDIR already exists, please remove it and run $0 again\n"
  exit 1
else
  mkdir $NEWDIR
fi

cd $NEWDIR
tar zxf /usr/src/${package}-installer/${package}_${version}.orig.tar.gz
cd ${package}-${version}
tar zxf /usr/src/${package}-installer/debian.tar.gz

CANBEROOT=no
SU=""
if [ 0 = `id -u` ]
then
  BUILDROOT=""
  CANBEROOT=yes
else
  hash fakeroot 2>/dev/null && HAVE_FAKEROOT=fakeroot || HAVE_FAKEROOT=""
  hash sudo     2>/dev/null && HAVE_SUDO=sudo         || HAVE_SUDO=""
  if [ -n "$HAVE_FAKEROOT" -a -n "$HAVE_SUDO" ]
  then
    echo ""
    if ask_user "Should I use sudo or fakeroot to build the package ? [sF] " 1 '[sS]*' '[fF]*' "\nPlease enter either s)udo or f)akeroot, followed by <RETURN>\n"
    then
      BUILDROOT=sudo
    else
      BUILDROOT=fakeroot
    fi
  elif [ -n "$HAVE_FAKEROOT" -o -n "$HAVE_SUDO" ]
  then
    BUILDROOT="${HAVE_FAKEROOT:-$HAVE_SUDO}"
  else
    # sanity check, dependencies should provide one of them
    echo ""
    echo 'oops! you have not installed fakeroot or sudo!'
    echo ""
    exit 1
  fi
  
  if [ -n "$HAVE_SUDO" ]
  then
    cat<<!END!

In addition to building the package, there are certain other actions that
you may want me to do (i.e. installing the new package) that need real root
access.  If you want, I can a achieve this by use of sudo.

In each case, you will be prompted before I attempt one of these actions

!END!
    if ask_user "Should I use sudo to gain real root access when required ? [Yn] " 0
    then
      SU=sudo
      CANBEROOT=yes
    fi
  fi
fi

echo ""
echo "Binary package $package will be compiled now"
echo "This can take long time, depending on your machine"
echo ""
echo "If you want me to apply any patches, please make sure that"
echo "they are located in /usr/src/qmailanalog-installer/patches/."
echo ""
echo -n "Press ENTER to continue..."
read blah

echo "Attempting to apply patches located in /usr/src/qmailanalog-installer/patches..."
for i in /usr/src/qmailanalog-installer/patches/*; do
 if [ -f "$i" ]
 then
  echo $i
  patch -p0 < $i
 fi
done

$BUILDROOT debian/rules binary-arch

cd ..

if [ -f ${package}*.deb ]
then
  echo ""
  echo "It seems that all went ok"
  echo ""
else
  echo ""
  echo "Some error happened, stopping here."
  echo ""
  exit 1
fi

if ask_user "Do you want to remove all files in $NEWDIR,\nexcept `echo ${package}*.deb` now? [Yn] " 0
then
  [ "$BUILDROOT" = sudo ] && ROOT4RM=sudo
  echo -n "Removing files... "
  $ROOT4RM rm -rf ./${package}-*/
  $ROOT4RM rm -f ./${package}*{.dsc,.diff.gz,.orig.tar.gz}
  echo "done"
fi

echo ""

if [ "$CANBEROOT" = yes ] 
then
  if ask_user "Do you want to install `echo ${package}*.deb` now? [Yn] " 0
  then
    $SU dpkg --install ${package}*.deb || true
  fi
else
  echo "`echo ${package}*.deb` is in $NEWDIR"
  echo "You have to execute the following to install it, being root:"
  echo ""
  echo "        dpkg --install `echo ${package}*.deb`"
fi

echo ""

if [ "$CANBEROOT" = yes ]
then
  if ask_user "Do you want to purge ${package}-installer now? [yN] " 1
  then
    $SU dpkg --purge ${package}-installer || true
  fi
else
  echo ""
  echo "You can now remove package ${package}-installer running as root"
  echo ""
  echo "        dpkg --remove ${package}-installer"
fi

echo ""
echo 'Good luck!'
echo ""

exit 0