[30f002a] | 1 | #!/bin/bash |
---|
[c5c522c] | 2 | |
---|
[30f002a] | 3 | # Copyright 2005-2008, 2009, 2010, 2013, 2015, 2018, 2019 Patrick J. Volkerding, Sebeka, MN, USA |
---|
[c5c522c] | 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 | |
---|
[30f002a] | 23 | cd $(dirname $0) ; CWD=$(pwd) |
---|
| 24 | |
---|
| 25 | PKGNAM=file |
---|
[c5c522c] | 26 | VERSION=${VERSION:-$(echo file-*.tar.?z* | cut -d - -f 2 | rev | cut -f 3- -d . | rev)} |
---|
| 27 | BUILD=${BUILD:-1} |
---|
| 28 | |
---|
[30f002a] | 29 | NUMJOBS=${NUMJOBS:-" -j$(expr $(nproc) + 1) "} |
---|
[c5c522c] | 30 | |
---|
| 31 | # Automatically determine the architecture we're building on: |
---|
| 32 | if [ -z "$ARCH" ]; then |
---|
| 33 | case "$( uname -m )" in |
---|
[072d3d5] | 34 | i?86) export ARCH=i586 ;; |
---|
[c5c522c] | 35 | arm*) export ARCH=arm ;; |
---|
| 36 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
| 37 | *) export ARCH=$( uname -m ) ;; |
---|
| 38 | esac |
---|
| 39 | fi |
---|
| 40 | |
---|
[30f002a] | 41 | # If the variable PRINT_PACKAGE_NAME is set, then this script will report what |
---|
| 42 | # the name of the created package would be, and then exit. This information |
---|
| 43 | # could be useful to other scripts. |
---|
| 44 | if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then |
---|
| 45 | echo "$PKGNAM-$VERSION-$ARCH-$BUILD.txz" |
---|
| 46 | exit 0 |
---|
| 47 | fi |
---|
| 48 | |
---|
[072d3d5] | 49 | if [ "$ARCH" = "i586" ]; then |
---|
| 50 | SLKCFLAGS="-O2 -march=i586 -mtune=i686" |
---|
[c5c522c] | 51 | LIBDIRSUFFIX="" |
---|
| 52 | elif [ "$ARCH" = "i686" ]; then |
---|
| 53 | SLKCFLAGS="-O2 -march=i686 -mtune=i686" |
---|
| 54 | LIBDIRSUFFIX="" |
---|
| 55 | elif [ "$ARCH" = "x86_64" ]; then |
---|
| 56 | SLKCFLAGS="-O2 -fPIC" |
---|
| 57 | LIBDIRSUFFIX="64" |
---|
| 58 | else |
---|
| 59 | SLKCFLAGS="-O2" |
---|
| 60 | LIBDIRSUFFIX="" |
---|
| 61 | fi |
---|
| 62 | |
---|
| 63 | TMP=${TMP:-/tmp} |
---|
| 64 | PKG=$TMP/package-file |
---|
| 65 | |
---|
| 66 | rm -rf $PKG |
---|
| 67 | mkdir -p $TMP $PKG |
---|
| 68 | cd $TMP |
---|
| 69 | rm -rf file-$VERSION |
---|
| 70 | tar xvf $CWD/file-$VERSION.tar.?z* || exit 1 |
---|
| 71 | cd file-$VERSION || exit 1 |
---|
| 72 | chown -R root:root . |
---|
| 73 | find . \ |
---|
| 74 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
[30f002a] | 75 | -exec chmod 755 {} \+ -o \ |
---|
[c5c522c] | 76 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
[30f002a] | 77 | -exec chmod 644 {} \+ |
---|
[c5c522c] | 78 | |
---|
| 79 | # Make the default data directory /etc/file like it has always been: |
---|
| 80 | zcat $CWD/file.etc.file.diff.gz | patch -p1 --verbose || exit 1 |
---|
| 81 | # This is needed after the patch above: |
---|
[30f002a] | 82 | autoreconf -vif || exit 1 |
---|
[c5c522c] | 83 | |
---|
| 84 | # Since we're going to include the compiled magic database now (otherwise |
---|
| 85 | # there seem to be libmagic related crashes), this patch probably doesn't |
---|
| 86 | # need to be applied. |
---|
| 87 | # |
---|
| 88 | ## Don't spew warnings about using the flat text files |
---|
| 89 | #zcat $CWD/file.quiet.diff.gz | patch -p1 -E --verbose || exit 1 |
---|
| 90 | |
---|
| 91 | # Keep the output format for ELF binaries the same as it was in earlier |
---|
| 92 | # versions of file to avoid breaking existing scripts: |
---|
| 93 | zcat $CWD/file.short.diff.gz | patch -p1 -E --verbose || exit 1 |
---|
| 94 | |
---|
[30f002a] | 95 | # Output on ELF objects should be "dynamically linked" for PT_DYNAMIC too, not |
---|
| 96 | # just for PT_INTERP: |
---|
| 97 | zcat $CWD/file.PT_DYNAMIC.is.dynamically.linked.diff.gz | patch -p1 -E --verbose || exit 1 |
---|
| 98 | |
---|
[c5c522c] | 99 | # Add zisofs and crda regulatory bin detection |
---|
| 100 | zcat $CWD/file.zisofs.magic.gz >> magic/Magdir/compress |
---|
| 101 | zcat $CWD/file.crdaregbin.magic.gz >> magic/Magdir/crdaregbin |
---|
| 102 | |
---|
| 103 | CFLAGS="$SLKCFLAGS" \ |
---|
| 104 | ./configure \ |
---|
| 105 | --prefix=/usr \ |
---|
| 106 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
| 107 | --sysconfdir=/etc \ |
---|
| 108 | --datadir=/etc \ |
---|
| 109 | --mandir=/usr/man \ |
---|
| 110 | --infodir=/usr/info \ |
---|
| 111 | --docdir=/usr/doc/file-$VERSION \ |
---|
| 112 | --enable-fsect-man5 \ |
---|
| 113 | --disable-static \ |
---|
[072d3d5] | 114 | --build=$ARCH-slackware-linux || exit 1 |
---|
[c5c522c] | 115 | |
---|
| 116 | # The generated $TMP/file-$VERSION/libtool is buggy. I don't know if this is supposed |
---|
| 117 | # to work, but it certainly does, so... :-) |
---|
| 118 | cat $(which libtool) > libtool |
---|
| 119 | |
---|
| 120 | make $NUMJOBS || make || exit 1 |
---|
| 121 | make install DESTDIR=$PKG || exit 1 |
---|
| 122 | |
---|
[30f002a] | 123 | # Don't ship .la files: |
---|
| 124 | rm -f $PKG/{,usr/}lib${LIBDIRSUFFIX}/*.la |
---|
| 125 | |
---|
[072d3d5] | 126 | # Ignore for now - still labeled as experimental |
---|
| 127 | # Actually, let's ignore it until something needs it :) <volkerdi> |
---|
| 128 | #cd python/ |
---|
| 129 | # python setup.py build |
---|
| 130 | # python setup.py install --root=$PKG |
---|
| 131 | #cd .. |
---|
| 132 | |
---|
[c5c522c] | 133 | # Seems --disable-static has been ignored lately: |
---|
| 134 | rm -f $PKG/usr/lib${LIBDIRSUFFIX}/libmagic.a |
---|
| 135 | |
---|
| 136 | # Install the flat files. |
---|
| 137 | # We'll generate /etc/file/magic.mgc in the doinst.sh. |
---|
| 138 | rm -f $PKG/etc/file/magic.mgc |
---|
| 139 | mkdir -p $PKG/etc/file/magic |
---|
| 140 | cp -a magic/Magdir/* $PKG/etc/file/magic |
---|
[30f002a] | 141 | chmod 644 $PKG/etc/file/magic/* |
---|
[c5c522c] | 142 | |
---|
| 143 | # Add a script to recompile the flat files in the obvious location. |
---|
| 144 | # The package install script will compile the flat files initially. |
---|
| 145 | cp -a $CWD/recompile_magic.mgc.sh.gz $PKG/etc/file |
---|
| 146 | gzip -d $PKG/etc/file/recompile_magic.mgc.sh.gz |
---|
| 147 | chown root:root $PKG/etc/file/recompile_magic.mgc.sh |
---|
| 148 | chmod 755 $PKG/etc/file/recompile_magic.mgc.sh |
---|
| 149 | |
---|
| 150 | # IMHO, moving this sort of thing does not make sense. |
---|
| 151 | # We'll support both the traditional and new locations. |
---|
| 152 | # I hate to squat on a name as generic as "/etc/misc/", |
---|
| 153 | # but it wasn't my idea. |
---|
| 154 | ( cd $PKG/etc ; ln -sf file misc ) |
---|
| 155 | |
---|
| 156 | # Strip everything for good measure: |
---|
[30f002a] | 157 | #find $PKG | xargs file | grep -e "executable" -e "shared object" \ |
---|
| 158 | # | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
[c5c522c] | 159 | |
---|
| 160 | ( cd $PKG/usr/man || exit 1 |
---|
[30f002a] | 161 | find . -type f -exec gzip -9 {} \+ |
---|
[c5c522c] | 162 | for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done |
---|
| 163 | ) |
---|
| 164 | |
---|
| 165 | mkdir -p $PKG/usr/doc/file-$VERSION |
---|
| 166 | cp -a \ |
---|
| 167 | AUTHORS COPYING* INSTALL MAINT NEWS README* TODO \ |
---|
| 168 | $PKG/usr/doc/file-$VERSION |
---|
| 169 | |
---|
| 170 | mkdir -p $PKG/install |
---|
| 171 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
| 172 | zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh |
---|
| 173 | |
---|
| 174 | # Build the package: |
---|
| 175 | cd $PKG |
---|
| 176 | /sbin/makepkg -l y -c n $TMP/file-$VERSION-$ARCH-$BUILD.txz |
---|
| 177 | |
---|