[39a3656] | 1 | #!/bin/bash |
---|
[ebc5ae5] | 2 | |
---|
[39a3656] | 3 | # Copyright 2008, 2009, 2010, 2011, 2012, 2017, 2018, 2020, 2021 Patrick J. Volkerding, Sebeka, MN, USA |
---|
[ebc5ae5] | 4 | # All rights reserved. |
---|
| 5 | # |
---|
| 6 | # Redistribution and use of this script, with or without modification, is |
---|
| 7 | # permitted provided that the following conditions are met: |
---|
| 8 | # |
---|
| 9 | # 1. Redistributions of this script must retain the above copyright |
---|
| 10 | # notice, this list of conditions and the following disclaimer. |
---|
| 11 | # |
---|
| 12 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
---|
| 13 | # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
---|
| 14 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
---|
| 15 | # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
| 16 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 17 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
---|
| 18 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
---|
| 19 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
---|
| 20 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
---|
| 21 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 22 | |
---|
[39a3656] | 23 | cd $(dirname $0) ; CWD=$(pwd) |
---|
[ebc5ae5] | 24 | |
---|
| 25 | PKGNAM=dhcp |
---|
| 26 | # Leave this one .gz as other compressors do not help much and we can keep |
---|
| 27 | # the original upstream .asc |
---|
| 28 | VERSION=${VERSION:-$(basename $(echo $PKGNAM-*.tar.gz | cut -f 2- -d -) .tar.gz)} |
---|
| 29 | BUILD=${BUILD:-1} |
---|
| 30 | |
---|
| 31 | PKG_VERSION=$(echo $VERSION | tr - _) |
---|
| 32 | |
---|
[39a3656] | 33 | NUMJOBS=${NUMJOBS:-" -j$(expr $(nproc) + 1) "} |
---|
[ebc5ae5] | 34 | |
---|
| 35 | # Automatically determine the architecture we're building on: |
---|
| 36 | if [ -z "$ARCH" ]; then |
---|
| 37 | case "$( uname -m )" in |
---|
| 38 | i?86) export ARCH=i586 ;; |
---|
| 39 | arm*) export ARCH=arm ;; |
---|
| 40 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
| 41 | *) export ARCH=$( uname -m ) ;; |
---|
| 42 | esac |
---|
| 43 | fi |
---|
| 44 | |
---|
[39a3656] | 45 | # If the variable PRINT_PACKAGE_NAME is set, then this script will report what |
---|
| 46 | # the name of the created package would be, and then exit. This information |
---|
| 47 | # could be useful to other scripts. |
---|
| 48 | if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then |
---|
| 49 | echo "$PKGNAM-$PKG_VERSION-$ARCH-$BUILD.txz" |
---|
| 50 | exit 0 |
---|
| 51 | fi |
---|
| 52 | |
---|
[ebc5ae5] | 53 | TMP=${TMP:-/tmp} |
---|
| 54 | PKG=$TMP/package-dhcp |
---|
| 55 | |
---|
| 56 | if [ "$ARCH" = "i586" ]; then |
---|
[39a3656] | 57 | SLKCFLAGS="-O2 -march=i586 -mtune=i686 -fcommon" |
---|
[ebc5ae5] | 58 | LIBDIRSUFFIX="" |
---|
| 59 | elif [ "$ARCH" = "s390" ]; then |
---|
[39a3656] | 60 | SLKCFLAGS="-O2 -fcommon" |
---|
[ebc5ae5] | 61 | LIBDIRSUFFIX="" |
---|
| 62 | elif [ "$ARCH" = "x86_64" ]; then |
---|
[39a3656] | 63 | SLKCFLAGS="-O2 -fPIC -fcommon" |
---|
[ebc5ae5] | 64 | LIBDIRSUFFIX="64" |
---|
| 65 | else |
---|
[39a3656] | 66 | SLKCFLAGS="-O2 -fcommon" |
---|
[ebc5ae5] | 67 | LIBDIRSUFFIX="" |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | rm -rf $PKG |
---|
| 71 | mkdir -p $TMP $PKG |
---|
| 72 | |
---|
| 73 | cd $TMP |
---|
| 74 | rm -rf dhcp-$VERSION |
---|
| 75 | tar xvf $CWD/dhcp-$VERSION.tar.gz || exit 1 |
---|
| 76 | cd dhcp-$VERSION || exit 1 |
---|
| 77 | |
---|
| 78 | chown -R root:root . |
---|
| 79 | find . \ |
---|
| 80 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
[39a3656] | 81 | -exec chmod 755 {} \+ -o \ |
---|
[ebc5ae5] | 82 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
[39a3656] | 83 | -exec chmod 644 {} \+ |
---|
[ebc5ae5] | 84 | |
---|
| 85 | # Add PATH setting to /sbin/dhclient-script |
---|
| 86 | zcat $CWD/dhclient-script.PATH.diff.gz | patch -p1 || exit 1 |
---|
| 87 | |
---|
| 88 | # Fix paths in manual pages |
---|
| 89 | sed -i \ |
---|
| 90 | -e "s,ETCDIR,/etc,g" \ |
---|
| 91 | -e "s,DBDIR,/var/state/dhcp,g" \ |
---|
| 92 | -e "s,RUNDIR,/var/run,g" \ |
---|
| 93 | client/*.{5,8} \ |
---|
| 94 | server/*.{5,8} \ |
---|
| 95 | doc/*/*.{5,8} |
---|
| 96 | |
---|
| 97 | CFLAGS="$SLKCFLAGS" \ |
---|
| 98 | ./configure \ |
---|
| 99 | --prefix=/usr \ |
---|
| 100 | --sysconfdir=/etc \ |
---|
| 101 | --localstatedir=/var \ |
---|
| 102 | --infodir=/usr/info \ |
---|
| 103 | --mandir=/usr/man \ |
---|
| 104 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
| 105 | --docdir=/usr/doc/dhcp-$VERSION \ |
---|
| 106 | --build=$ARCH-slackware-linux \ |
---|
| 107 | --with-srv-lease-file=/var/state/dhcp/dhcpd.leases \ |
---|
| 108 | --with-srv6-lease-file=/var/state/dhcp/dhcpd6.leases \ |
---|
| 109 | --with-cli-lease-file=/var/state/dhcp/dhclient.leases \ |
---|
[39a3656] | 110 | --with-cli6-lease-file=/var/state/dhcp/dhclient6.leases || exit 1 |
---|
| 111 | |
---|
[ebc5ae5] | 112 | # Default pid dir is still /var/run, so no need to declare it |
---|
| 113 | |
---|
| 114 | make $NUMJOBS || make || exit 1 |
---|
| 115 | make install DESTDIR=$PKG || exit 1 |
---|
| 116 | |
---|
| 117 | # DHCP libraries need not be included, yet. |
---|
| 118 | rm -rf $PKG/usr/{include,lib${LIBDIRSUFFIX}} |
---|
| 119 | |
---|
| 120 | # We need this in /sbin |
---|
| 121 | mkdir -p $PKG/sbin |
---|
| 122 | mv $PKG/usr/sbin/dhclient $PKG/sbin |
---|
| 123 | |
---|
| 124 | # Install the dhclient-script for linux |
---|
| 125 | cat client/scripts/linux > $PKG/sbin/dhclient-script |
---|
| 126 | chmod 700 $PKG/sbin/dhclient-script |
---|
| 127 | |
---|
| 128 | # Create the initial *.leases files: |
---|
| 129 | mkdir -p $PKG/var/state/dhcp |
---|
| 130 | touch $PKG/var/state/dhcp/dhcpd.leases.new |
---|
| 131 | touch $PKG/var/state/dhcp/dhcpd6.leases.new |
---|
| 132 | touch $PKG/var/state/dhcp/dhclient.leases.new |
---|
| 133 | touch $PKG/var/state/dhcp/dhclient6.leases.new |
---|
| 134 | |
---|
| 135 | cat << EOF > $PKG/etc/dhcpd.conf.new |
---|
| 136 | # dhcpd.conf |
---|
| 137 | # |
---|
| 138 | # Configuration file for ISC dhcpd (see 'man dhcpd.conf') |
---|
| 139 | # |
---|
| 140 | EOF |
---|
| 141 | |
---|
| 142 | cat << EOF > $PKG/etc/dhclient.conf.new |
---|
| 143 | # dhclient.conf |
---|
| 144 | # |
---|
| 145 | # Configuration file for ISC dhclient (see 'man dhclient.conf') |
---|
| 146 | # |
---|
| 147 | EOF |
---|
| 148 | |
---|
| 149 | # Compress and if needed symlink the man pages: |
---|
| 150 | if [ -d $PKG/usr/man ]; then |
---|
| 151 | ( cd $PKG/usr/man |
---|
| 152 | for manpagedir in $(find . -type d -name "man*") ; do |
---|
| 153 | ( cd $manpagedir |
---|
| 154 | for eachpage in $( find . -type l -maxdepth 1) ; do |
---|
| 155 | ln -s $( readlink $eachpage ).gz $eachpage.gz |
---|
| 156 | rm $eachpage |
---|
| 157 | done |
---|
| 158 | gzip -9 *.? |
---|
| 159 | ) |
---|
| 160 | done |
---|
| 161 | ) |
---|
| 162 | fi |
---|
| 163 | |
---|
| 164 | find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \ |
---|
| 165 | | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
| 166 | |
---|
| 167 | mkdir -p $PKG/usr/doc/dhcp-$VERSION/examples |
---|
| 168 | cp -a \ |
---|
| 169 | LICENSE README RELNOTES \ |
---|
| 170 | $PKG/usr/doc/dhcp-$VERSION |
---|
[39a3656] | 171 | mv $PKG/etc/dhcpd.conf $PKG/etc/dhclient.conf \ |
---|
| 172 | $PKG/usr/doc/dhcp-$VERSION/examples || true |
---|
[ebc5ae5] | 173 | |
---|
| 174 | # If there's a ChangeLog, installing at least part of the recent history |
---|
| 175 | # is useful, but don't let it get totally out of control: |
---|
| 176 | if [ -r ChangeLog ]; then |
---|
| 177 | DOCSDIR=$(echo $PKG/usr/doc/*-$VERSION) |
---|
| 178 | cat ChangeLog | head -n 1000 > $DOCSDIR/ChangeLog |
---|
| 179 | touch -r ChangeLog $DOCSDIR/ChangeLog |
---|
| 180 | fi |
---|
| 181 | |
---|
| 182 | mkdir -p $PKG/install |
---|
| 183 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
| 184 | zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh |
---|
| 185 | |
---|
| 186 | cd $PKG |
---|
| 187 | /sbin/makepkg -l y -c n $TMP/dhcp-$PKG_VERSION-$ARCH-$BUILD.txz |
---|
| 188 | |
---|