WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Build Script: gfortune + fortunes  (Read 3023 times)

Offline dentonlt

  • Sr. Member
  • ****
  • Posts: 318
    • the trombone analog
Build Script: gfortune + fortunes
« on: January 12, 2010, 08:00:21 AM »
I had intended to create a gfortune extension, but many fortune libraries are full of offensive content (language, suggestion, or just really bad attempts at humor ...).

I've researched how to pull all the offensive stuff out of some fortune databases, and I'm afraid it's just not going to happen. Each fortune library has hundreds to thousands of quotes, not always labeled/categorized. I just can't guarantee that avoiding the "offensive" libraries will keep things safe for work.

If you'd like to build a gfortune extension yourself, this is what I've used. You will need this script plus the following two files from Annares' gfortune page at http://www.anarres.org/projects/gfortune/

* gfortune cookies 1.0.0 (15/2/2000)
* gfortune 1.0.2 (26/9/2007)

Happy fortune-ing.

build-gfortune
Code: [Select]
#!/bin/sh

##########################
#
# build-gfortune.sh
# script originally written by bmarkus (200909xx)
# edited to build gfortune (dentonlt, 20090115)
#
# tested on TC 2.7
#
##########################

#########################
# useful variables
#########################
SOURCEFILE="gfortune-1.0.2.tar.gz"
FORTUNESFILE="gfortune-files-1.0.0.tar.gz"
TCEDIR=`cat /opt/.tce_dir`/optional
TMPDIR=/tmp/pkg
WRKDIR="gfortune-1.0.2"
EXTNAM="gfortune"
CLEANUP=1

#######################
# Extensions required for build
#########################
REQUIRED_EXTENSIONS="compiletc
squashfs-tools-4.0
"

##############
# FUNCTIONS
##############

loadextension () {

FILE="$1"

[ -f "$TCEDIR"/"$FILE".tcz ] && tce-load -i "$TCEDIR"/"$FILE".tcz && FILE="$NULL"
[ -f "$TCEDIR"/"$FILE".tczl ] && tce-load -i "$TCEDIR"/"$FILE".tczl && FILE="$NULL"
[ -f "$TCEDIR"/"$FILE".tczm ] && tce-load -i "$TCEDIR"/"$FILE".tczm && FILE="$NULL"

if [ "$FILE" != "$NULL" ]; then
echo "Error finding "$FILE" extension. Check /opt/.tce_dir and your mounts. Exiting."
exit 1
fi
}



#################
# MAIN TYPE STUFF
#################

# find source file
###############

# check for source file
#####################
[ ! -f "$SOURCEFILE" ] && echo "Run build in the same directory as source file ("$SOURCEFILE" not found)." && exit 1

# check whether to clean up afterward
#####################
#read -p "Do you want me to clean up things as I finish? " ANS
#[ "$ANS" == "n" ] || [ "$ANS" == "N" ] && CLEANUP=0


# check for required extensions
###################
for EXT in `echo $REQUIRED_EXTENSIONS`
do
if [ ! -f "/usr/local/tce.installed/"$EXT"" ]; then
echo "Extension "$EXT" is required. Trying to install."
loadextension "$EXT"
fi
done

# clean & remake temp/pkg directory
###################################
[ "$CLEANUP" == "1" ] && rm -rf $TMPDIR
mkdir $TMPDIR

# do the build! (this section as written out by bmarkus)
# see his posting online at the tinycore forum
#####################################

# Export variables needed for compilation

export CFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"
export CPPFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig

# Unpack source in current directory
tar -xf $SOURCEFILE

# Unpack all the fortune files, and put them into the temp dir for later.
tar -xf $FORTUNESFILE
mv ./fortunes /tmp

# Configure it

read -p "Read to run configure?" ANS
[ "$ANS" != "Y" ] && [ "$ANS" != "y" ] && exit 1

cd $WRKDIR
./configure --prefix=/usr/local

# Compile

read -p "Read to run make?" ANS
[ "$ANS" != "Y" ] && [ "$ANS" != "y" ] && exit 1

make

read -p "Read to run make install?" ANS
[ "$ANS" != "Y" ] && [ "$ANS" != "y" ] && exit 1

# Install in base temp dir
TIMESTAMP="/tmp/mark$$"
touch $TIMESTAMP
make install DESTDIR=$TMPDIR

# Delete compilation work directory

cd ..
#[ "$CLEANUP" == "1" ] && rm -r -f $WRKDIR

# Remove unneeded dirs and files

# Adjust directory access rigths

find $TMPDIR/ -type d | xargs chmod -v 755;

# Strip executables

find $TMPDIR | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded

# Move files to doc extension

mkdir -p $TMPDIR-doc/usr/local/share
[ -d "$TMPDIR/usr/local/share/man" ] && mv $TMPDIR/usr/local/share/man $TMPDIR-doc/usr/local/share
[ -d "$TMPDIR/usr/local/share/info" ] && mv $TMPDIR/usr/local/share/info $TMPDIR-doc/usr/local/share
[ -d "$TMPDIR/usr/local/share/emacs" ] && mv $TMPDIR/usr/local/share/emacs $TMPDIR-doc/usr/local/share

# Move files to dev extension

mkdir -p $TMPDIR-dev/usr/local/lib
[ -d "$TMPDIR/usr/local/include" ] && mv $TMPDIR/usr/local/include $TMPDIR-dev/usr/local
[ -e "$TMPDIR/usr/local/lib/*.a" ] && mv $TMPDIR/usr/local/lib/*.a $TMPDIR-dev/usr/local/lib
[ -e "$TMPDIR/usr/local/lib/*.la" ] && mv $TMPDIR/usr/local/lib/*.la $TMPDIR-dev/usr/local/lib
[ -d "$TMPDIR/usr/local/lib/pkgconfig" ] && mv $TMPDIR/usr/local/lib/pkgconfig $TMPDIR-dev/usr/local/lib

# Move files to locale extension

mkdir -p $TMPDIR-locale/usr/local/share
mv $TMPDIR/usr/local/share/locale $TMPDIR-locale/usr/local/share

# Move fortune files to base extension
mkdir -p $TMPDIR/var/lib/games
mv /tmp/fortunes $TMPDIR/var/lib/games

###################################################
# Create base extension in temp dir               #
###################################################

cd $TMPDIR
cd ..
mksquashfs $TMPDIR "$EXTNAM".tcz
cd $TMPDIR
find -not -type d > "$EXTNAM".tcz.list
mv ../"$EXTNAM".tcz .

# Create md5 file

md5sum "$EXTNAM".tcz > "$EXTNAM".tcz.md5.txt

# Cleanup temp directory

[ "$CLEANUP" == "1" ] && rm -r -f usr  

###################################################
# Create doc extension in temp dir                #
###################################################

cd $TMPDIR-doc
cd ..
mksquashfs $TMPDIR-doc $EXTNAM-doc.tcz
cd $TMPDIR-doc
find usr -not -type d > $EXTNAM-doc.tcz.list
mv ../$EXTNAM-doc.tcz .

# Create md5 file

md5sum $EXTNAM-doc.tcz > $EXTNAM-doc.tcz.md5.txt

# Cleanup temp directory

[ "$CLEANUP" == "1" ] && rm -r -f usr  

###################################################
# Create dev extension in temp dir                #
###################################################

cd $TMPDIR-dev
cd ..
mksquashfs $TMPDIR-dev $EXTNAM-dev.tcz
cd $TMPDIR-dev
find usr -not -type d > $EXTNAM-dev.tcz.list
mv ../$EXTNAM-dev.tcz .

# Create md5 file

md5sum $EXTNAM-dev.tcz > $EXTNAM-dev.tcz.md5.txt

# Cleanup temp directory

[ "$CLEANUP" == "1" ] && rm -r -f usr  

###################################################
# Create locale extension in temp dir             #
###################################################

cd $TMPDIR-locale
cd ..
mksquashfs $TMPDIR-locale $EXTNAM-locale.tcz
cd $TMPDIR-locale
find usr -not -type d > $EXTNAM-locale.tcz.list
mv ../$EXTNAM-locale.tcz .

# Create md5 file

md5sum $EXTNAM-locale.tcz > $EXTNAM-locale.tcz.md5.txt


###################################################
# Remove any empty package directories            #
###################################################

#read -p "Stopping before clearing out empty directories ... (press enter)" ANS

[ "`cat /tmp/pkg/$EXTNAM.tcz.list`" == "$NULL" ] && echo "/tmp/pkg was empty - removing." && rm -rf /tmp/pkg
[ "`cat /tmp/pkg-doc/$EXTNAM-doc.tcz.list`" == "$NULL" ] && echo "/tmp/pkg-doc was empty - removing." && rm -rf /tmp/pkg-doc
[ "`cat /tmp/pkg-dev/$EXTNAM-dev.tcz.list`" == "$NULL" ] && echo "/tmp/pkg-dev was empty - removing." && rm -rf /tmp/pkg-dev
[ "`cat /tmp/pkg-locale/$EXTNAM-locale.tcz.list`" == "$NULL" ] && echo "/tmp/pkg-locale was empty - removing." && rm -rf /tmp/pkg-locale

# Cleanup temp directory

[ "$CLEANUP" == "1" ] && rm -r -f usr
[ "$CLEANUP" == "1" ] && rm $TIMESTAMP

echo ".tcz files left at /tmp/pkg and /tmp/pkg-doc. Clean up this directory, too - it may have a spare source code folder."