#!/bin/bash #Automatically Created by slkbuild 0.5.1 #Maintainer: JRD ######Begin Redundant Code###################################### check_for_root() { if [ "$UID" != "0" ]; then echo "You need to be root" exit 1 fi } clean_dirs () { for COMPLETED in src pkg; do if [ -e $COMPLETED ]; then rm -rf $COMPLETED fi done } clean_old_builds () { rm -rf $package.{t[xlgb]z,md5} clean_dirs } set_pre_permissions() { cd $startdir/src find . -perm 664 -exec chmod 644 {} \; find . -perm 600 -exec chmod 644 {} \; find . -perm 444 -exec chmod 644 {} \; find . -perm 400 -exec chmod 644 {} \; find . -perm 440 -exec chmod 644 {} \; find . -perm 777 -exec chmod 755 {} \; find . -perm 775 -exec chmod 755 {} \; find . -perm 511 -exec chmod 755 {} \; find . -perm 711 -exec chmod 755 {} \; find . -perm 555 -exec chmod 755 {} \; } gzip_man_and_info_pages() { for DOCS in man info; do if [ -d "$startdir/pkg/usr/share/$DOCS" ]; then mv $startdir/pkg/usr/share/$DOCS $startdir/pkg/usr/$DOCS if [[ ! "$(ls $startdir/pkg/usr/share)" ]]; then rm -rf $startdir/pkg/usr/share fi fi if [ -d "$startdir/pkg/usr/$DOCS" ]; then # I've never seen symlinks in info pages.... if [ "$DOCS" == "man" ]; then (cd $startdir/pkg/usr/$DOCS for manpagedir in $(find . -type d -name "man*" 2> /dev/null) ; do ( cd $manpagedir for eachpage in $( find . -type l -maxdepth 1 2> /dev/null) ; do ln -s $( readlink $eachpage ).gz $eachpage.gz rm $eachpage done ) done) fi find $startdir/pkg/usr/$DOCS -type f -exec gzip -9 '{}' \; fi done [ -a $startdir/pkg/usr/info/dir.gz ] && rm -f $startdir/pkg/usr/info/dir.gz } set_post_permissions() { for DIRS in usr/share/icons usr/doc; do if [ -d "$startdir/pkg/$DIRS" ]; then if [ "$DIRS" == "usr/doc" ]; then find $startdir/pkg/$DIRS -type f -exec chmod 644 {} \; find $startdir/pkg/$DIRS -type d -exec chmod 755 {} \; fi fi [ -d $startdir/pkg/$DIRS ] && chown root:root -R $startdir/pkg/$DIRS done [ -d $startdir/pkg/usr/bin ] && find $startdir/pkg/usr/bin -user root -group bin -exec chown root:root {} \; } copy_build_script() { mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver/ cp $startdir/build-$pkgname.sh $startdir/pkg/usr/src/$pkgname-$pkgver/build-$pkgname.sh [ -f $startdir/SLKBUILD ] && cp $startdir/SLKBUILD $startdir/pkg/usr/src/$pkgname-$pkgver/SLKBUILD } create_package() { ls -lR $startdir/pkg cd $startdir/pkg /sbin/makepkg -l y -c n $startdir/$package.txz cd $startdir md5sum $package.txz > $startdir/$package.md5 } #########End Redundant Code##################################### #########Begin Non Redundant Code############################## prepare_directory() { mkdir $startdir/src mkdir $startdir/pkg } build() { cd $startdir/pkg mkdir sbin cd sbin cat <<'EOF' > fake-uname #!/bin/sh export FAKEVER=2.6.31 if [ "$1" = "-r" ]; then echo $FAKEVER elif [ "$1" = "-a" ]; then /bin/uname -a | sed "s/2\.6[0-9.]*\(-[^ ]*\)\?/$FAKEVER/" else /bin/uname $1 fi EOF cat <<'EOF' > fake-uname-activate #!/bin/sh if [ "$1" = "" ]; then echo 'fake-uname-activate FAKE_KERNEL_VERSION' exit 1 else FAKEVER=$1 if [ ! -h /sbin/uname ]; then sed -i -e "s/\(export FAKEVER=\).*/\1$FAKEVER/" /sbin/fake-uname (cd /sbin && ln -s fake-uname uname) echo 'please relaunch this shell to take effect' else echo 'fake-uname already active' exit 1 fi fi EOF cat <<'EOF' > fake-uname-disactivate #!/bin/sh if [ -h /sbin/uname ]; then rm -f /sbin/uname echo 'please relaunch this shell to take effect' else echo 'fake-uname not active' exit 1 fi EOF chmod u+x fake-uname fake-uname-activate fake-uname-disactivate } create_slackdesc() { mkdir $startdir/pkg/install cat <<"EODESC" >$startdir/pkg/install/slack-desc fake-uname: fake-uname (hack to fake the kernel version) fake-uname: fake-uname: This could be usefull to build a driver or anything relative to the fake-uname: kernel, where the currently running kernel is not of the same version fake-uname: you build the driver to. fake-uname: Of course the kernel headers (or sources) for the fakly kernel should fake-uname: be present in order for this to work. fake-uname: Just run 'fake-uname-activate kernel_ver' to use it. fake-uname: fake-uname: fake-uname: EODESC } copy_docs() { for stuff in ${docs[@]}; do if [ ! -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then mkdir -p $startdir/pkg/usr/doc/$pkgname-$pkgver fi find $startdir/src -type f -iname "$stuff" -exec cp -R '{}' $startdir/pkg/usr/doc/$pkgname-$pkgver \; done } create_source_file(){ [ -f $package.src ] && rm $package.src if [ ! -z $sourcetemplate ]; then echo $sourcetemplate/SLKBUILD >> $package.src echo $sourcetemplate/build-$pkgname.sh >> $package.src for SOURCES in ${source[@]}; do protocol=$(echo $SOURCES | sed 's|:.*||') if ! [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then if [ ! -z $sourcetemplate ]; then echo $sourcetemplate/$(basename $SOURCES) >> $package.src else echo $(basename $SOURCES) >> $package.src fi else echo $SOURCES >> $package.src fi done fi } post_checks(){ # Ideas taken from src2pkg :) if [ -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then for DIRS in usr/doc/$pkgname-$pkgver usr/doc; do cd $startdir/pkg/$DIRS if [[ $(find . -type f) = "" ]] ; then cd .. rmdir $DIRS fi done fi # if the docs weren't deleted ... if [ -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then cd $startdir/pkg/usr/doc/$pkgname-$pkgver #remove zero lenght files if [[ $(find . -type f -size 0) ]]; then echo "Removing some zero lenght files" find . -type f -size 0 -exec rm -f {} \; fi fi # check if we need to add code to handle info pages if [[ -d $startdir/pkg/usr/info ]] && [[ ! $(grep install-info $startdir/pkg/install/doinst.sh &> /dev/null) ]] ; then echo "Found info files - Adding install-info command to doinst.sh" INFO_LIST=$(ls -1 $startdir/pkg/usr/info) echo "" >> $startdir/pkg/install/doinst.sh echo "if [ -x usr/bin/install-info ] ; then" >> $startdir/pkg/install/doinst.sh for page in $(echo $INFO_LIST) ; do echo " usr/bin/install-info --info-dir=usr/info usr/info/$page 2>/dev/null" >> $startdir/pkg/install/doinst.sh done echo "fi" >> $startdir/pkg/install/doinst.sh fi [[ -e $startdir/pkg/usr/info/dir ]] && rm -f $startdir/pkg/usr/info/dir if [ -d $startdir/pkg/etc ]; then cd $startdir/pkg/ for conf in $(find ./etc -type f) ; do conf=${conf: 2} dotnew=( "${dotnew[@]}" "$conf" ) done fi if [[ "$dotnew" ]]; then for files in ${dotnew[@]} ; do fullfile="${startdir}/pkg/${files}" if [ -e "$fullfile" ]; then mv $fullfile ${fullfile}.new else echo "$fullfile was not found" exit 2 fi done cat<<"EODOTNEW" >>$startdir/pkg/install/doinst.sh #Added by slkbuild 0.5.1 dotnew() { NEW="${1}.new" OLD="$1" if [ ! -e $OLD ]; then mv $NEW $OLD elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then rm $NEW fi } EODOTNEW for i in ${dotnew[@]}; do echo "dotnew $i" >> $startdir/pkg/install/doinst.sh done fi } ####End Non Redundant Code############################ #Variables startdir=$(pwd) SRC=$startdir/src PKG=$startdir/pkg pkgname=fake-uname pkgver=0.1 pkgrel=1cp arch=noarch package=$pkgname-$pkgver-$arch-1cp source=() sourcetemplate=http://enialis.net/~jrd/salix/fake-uname/0.1- docs=(readme install copying changelog authors news todo) export CFLAGS="-O2 -march=noarch -mtune=i686" export CXXFLAGS="-O2 -march=noarch -mtune=i686" #Execution check_for_root clean_old_builds prepare_directory set_pre_permissions build if [ ! "$?" = "0" ]; then echo "build() failed." exit 2 fi create_slackdesc post_checks copy_docs gzip_man_and_info_pages set_post_permissions copy_build_script create_package create_source_file echo "Package has been built."