blender module build script

Here is a place for your projects which are not officially supported by the Porteus Team. For example: your own kernel patched with extra features; desktops not included in the standard ISO like Gnome; base modules that are different than the standard ISO, etc...
Post Reply
User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 2207
Joined: 20 Mar 2012, 03:42
Distribution: 5.0rc1-64bit all-DE+more
Location: australia
Contact:

blender module build script

Post#1 by ncmprhnsbl » 07 Sep 2019, 05:26

here is a script that fetches and makes a module for porteus-5.0 from the latest stable blender binary release
or from a binary tar.bz2 placed in /tmp or a (POSIX) dir of your choice
Suitable binary tar.bz2 s include the development builds from builder.blender.org/download/ or blender.community/c/graphicall/
Most of the bundled python is removed, since porteus 5.0 includes python3.7, which blender is tricked into using via links.
Opengl stuff is also left out.
Unused language packs are also removed.
A module is here: update-blender-20190907.xzm
contents:

Code: Select all

update-blender-20190907
└── usr
    └── local
        └── bin
            └── update-blender
to use: open a terminal and type "update-blender"
options are: -h (shows usage info)
and -d (which makes all build operations done in current directory instead of /tmp(must be POSIX ie.not fat or ntfs... useful for limited RAM)

update-blender:

Code: Select all

#!/bin/bash
## update-blender
## A script to make a module for porteus-5.0 from the latest stable blender binary release
## or from a binary tar.bz2 placed in /tmp or a (POSIX) dir of your choice
## suitable binary tar.bz2 include the development builds from builder.blender.org/download/ or blender.community/c/graphicall/
## Most of the bundled python is removed, since porteus 5.0 includes python3.7, which blender is tricked into using via links.
##
## by ncmprhnsbl  forum.porteus.org
## version: 20190907

# Source porteus-functions
. /usr/share/porteus/porteus-functions
get_colors

txtbld=$(tput bold)
txtred=${txtbld}$(tput setaf 1)
txtgreen=${txtbld}$(tput setaf 2)
txtwhite=${txtbld}$(tput setaf 7)
txtcyan=${txtbld}$(tput setaf 6)
rst=$(tput sgr0)
function bold(){ echo -e $txtbld "$1" $rst; }
function green() { echo -e $txtgreen "$1" $rst; }
function red(){ echo $txtred "$1" $rst; }	
function cyan(){ echo $txtcyan "$1" $rst; }

saypass(){ echo "[${txtbold}${txtgreen}PASS$rst] $1"; }
sayfail(){ echo "[${txtbold}${txtred}FAIL$rst] $1"; }

# Check for root
if [ `whoami` != "root" ]; then
	   if [ `whoami` != "root" ]; then
      echo "Please enter root's password below"
      su - -c "update-blender $1"
      exit
   fi
fi

# functions set work directory(default is /tmp) to current work directory
set_tmp() {
WRKDIR=/tmp 
}

set_pwd() {
WRKDIR=`pwd` 
}

# echo usage
show_help() {
        echo " update-blender "        
        echo " This script will download the latest stable release of blender "
        echo " and create a porteus module. "
        echo " A predownloaded tarball can also be used by placing it in /tmp" 
        echo " or your chosen directory(-d) which needs to be POSIX compatible."
        echo
	echo " options:  -d : do operations in the present directory, instead of /tmp . "
	echo "           -h : show this usage. " 
}

while getopts ":-d:-h:" o; do
case "$1" in
 
    -d)
       set_pwd;;
    
    -h)
      show_help
      exit 0;;
              
     *)
      show_help
      exit 1;;
    
esac
done
case "$1" in
      
    "")
      set_tmp;;
      
esac

# tell us where the work will be done
echo "Work will be done in: $WRKDIR "
 
## Check if there's enough working space
[ `df -l --output=avail $WRKDIR | tail -1` -lt 384000 ] && { red "There's not enough space to run this script"; exit 1; }

case `uname -m` in
	x86_64)
	ARCH=x86_64
	SUFFIX=64
	SARCH=x86_64
	;;
	*)
	ARCH=i686
	SUFFIX=
	SARCH=i586
	;;
esac


## functions for setting locale
array_menu(){
echo
echo "$1"
echo "$2"
select LOCALE in ${ARESULT[@]}; do
    if [ -z "$LOCALE" ]; then
        bold "English locale chosen." && echo
			else
		bold "$LOCALE locale chosen"
    fi
    break
done
}

get_locale(){
# Set locales in array
for a in ab ar ca cs de eo en-US es es_ES eu fa fr ha he hi hr hu id it ja ko ky nl pl pt pt-BR ru sk sr sr@latin sv th tr uk vi zh-CN zh-TW; do
	ARESULT+=( $a )
done
array_menu "Choose a locale from the list." 
unset ARESULT 
}

cleanup(){
echo
rm -rf $TARG
[ -d $TMPDIR ] && rm -rf $TMPDIR
exit	
}
trap cleanup SIGHUP SIGINT SIGTERM

## (soft)checksum check
checksum () {
if [ -z $CHOICE ]; then	
echo "Verifying download integrity.."
echo "Server  : $SUM1"
echo "Download: $SUM2"
if [ "$SUM1" = "$SUM2" ]; then 
     echo "Download verified." 
else 
     echo "Warnig: Integrity check failed."
     echo "Continuing anyway.. if there's a problem, this could be it."
fi
fi
}

## Check for tarball in $WRKDIR
if [ `ls $WRKDIR | grep -i blender 2>/dev/null | wc -l` -ge 1 ]; then
	# Make sure it is a tarball
	cfile=( `ls -1 $WRKDIR/blender-*.bz2 2>/dev/null | awk -F/ '{print$NF}' ` )
	if [ ${#cfile[@]} -gt 0 ]; then
		RESULT=${cfile[@]}
		echo
		green "A blender tarball was found in $WRKDIR"
		echo " We will use this archive to create blender."
		menu_from_array "Choose the blender file you want to process."
		echo "CHOICE:$txtgreen $CHOICE $rst"
	fi
fi


## Variables
URL=https://download.blender.org/release/

TMPDIR=$WRKDIR/.blen.$$
CWD=`pwd`

if [ -z $CHOICE ]; then
   echo " Fetching latest Blender version info.."
   VER=`lynx -dump --nonumbers --listonly $URL | grep -o "[0-9].[0-9][0-9]" | sort | tail -n1`
   echo " Latest version is:" $txtgreen "$VER" $rst
else
   if [ "`tr -dc '-' <<< $CHOICE | wc -c`" = "5" ]; then
      LVER=`cut -d"-" -f2,3 <<< $CHOICE`
      VER=${LVER%-*}
   elif [ "`tr -dc '-' <<< $CHOICE | wc -c`" = "4" ]; then
      LVER=`cut -d"-" -f2 <<< $CHOICE`
      VER=${LVER}
   else
      echo " Unable to get version info.. "
      echo " The tarball's name does not conform to known parameters. "
      echo " Exiting.."
      exit 1 
   fi      
fi

if [ "$ARCH = x86_64" ]; then
  GLIBC="glibc217";
else  
  GLIBC="glibc224";
fi
if [ -z $CHOICE ]; then
  read -p " Would you like to create a module of the latest version? [y/n]" -n 1 -r -s && echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then cleanup; fi  
else
  read -p " Would you like to continue with this tarball? [y/n]" -n 1 -r -s && echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then cleanup; fi
fi

get_locale

if [ -z $CHOICE ]; then
EXT="tar.bz2"
TAR="blender-${VER}-linux-${GLIBC}-${ARCH}.${EXT}"
SRC="blender-${VER}-linux-${GLIBC}-${ARCH}"
DURL="${URL}Blender${VER}/${TAR}"
#VER2=`echo $VER | tr -d '.'` 
SUM1=`lynx -dump --dont_wrap_pre $DURL/release${VER//./}.md5 | grep $TAR | cut -d" " -f1`

fi

## Create temp dir
[ ! -d $TMPDIR ] && mkdir -p $TMPDIR || rm -rf $TMPDIR/*
if [ -z $CHOICE ]; then
   download $DURL $TMPDIR
else 
   cp -a $WRKDIR/$CHOICE $TMPDIR
fi

## Check that we have an archive in TMPDIR
if [ -z $CHOICE ]; then
    if [ ! -f $TMPDIR/$TAR ]; then
	echo
	sayerror "File $TAR not found"
	cleanup
elif [ ! -f $TMPDIR/$CHOICE ]; then
	echo
	sayerror "File $CHOICE not found"
	cleanup
fi    
fi

## checksum check
if [ -z $CHOICE ]; then 
SUM2=`md5sum $TMPDIR/$TAR | cut -d" " -f1`
checksum 
fi

## go to module build dir
cd $TMPDIR

if [ -z $CHOICE ]; then 
   tar xvf $TAR
else
   tar xvf $CHOICE
   SRC="blender-${LVER}-linux-${GLIBC}-${ARCH}"
fi

echo " Locale is $LOCALE"
echo " Removing unwanted locales ..."
if [ "$LOCALE" != "en-US" ]; then
   find $SRC/$VER/datafiles/locale -type f -name "*" | egrep -v "${LOCALE}" | xargs -n1 -i rm {}
else      
   rm -rvf $SRC/$VER/datafiles/locale
fi

chown -R root:root $SRC
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;


echo "making build directories.."
mkdir -p $TMPDIR/build/opt/blender-$VER/$VER/python
mkdir -p $TMPDIR/build/usr/share/applications
mkdir -p $TMPDIR/build/usr/bin
mkdir -p $TMPDIR/build/usr/lib64/python3.7


cd $TMPDIR/build

echo " copying the files we want.."
cp -a $TMPDIR/$SRC/$VER/datafiles opt/blender-$VER/$VER/
cp -a $TMPDIR/$SRC/$VER/scripts opt/blender-$VER/$VER/
cp -a $TMPDIR/$SRC/blender opt/blender-$VER/
cp -a $TMPDIR/$SRC/blender* opt/blender-$VER/
cp -a $TMPDIR/$SRC/*.txt opt/blender-$VER/
cp -a $TMPDIR/$SRC/readme.html opt/blender-$VER/
cp -a $TMPDIR/$SRC/icons opt/blender-$VER/
## don't use shipped libgl
#cp -a $TMPDIR/$SRC/lib opt/blender-$VER/
## move the .desktop to somewhere useful
mv opt/blender-$VER/blender.desktop usr/share/applications/


## use only the site-packages (porteus has the rest of python3.7) ..this is potentially messy if the user has some of these installed already...
cp -a $TMPDIR/$SRC/$VER/python/lib/python3.7/site-packages usr/lib64/python3.7/

echo " linking some stuff so blender can find them.."
ln -s /usr/lib64 opt/blender-$VER/$VER/python/lib
ln -s /usr/bin opt/blender-$VER/$VER/python/bin
ln -s /opt/blender-$VER/blender usr/bin/blender

cd ${WRKDIR}

echo " Making module"
if [ -z $CHOICE ]; then 
    dir2xzm $TMPDIR/build ${WRKDIR}/blender-${VER}-${ARCH}-${LOCALE}.xzm
else
   dir2xzm $TMPDIR/build ${WRKDIR}/blender-${LVER}-${ARCH}-${LOCALE}.xzm
fi
echo " Your module is ready at ${WRKDIR}"
echo " Please move it to somewhere safe.."

cleanup

example contents of a blender module:

Code: Select all

$ tree -L 5
.
├── opt
│   └── blender-2.81
│       ├── 2.81
│       │   ├── datafiles
│       │   │   ├── colormanagement
│       │   │   ├── fonts
│       │   │   ├── icons
│       │   │   └── studiolights
│       │   ├── python
│       │   │   ├── bin -> /usr/bin
│       │   │   └── lib -> /usr/lib64
│       │   └── scripts
│       │       ├── addons
│       │       ├── addons_contrib
│       │       ├── freestyle
│       │       ├── modules
│       │       ├── presets
│       │       ├── startup
│       │       ├── templates_osl
│       │       └── templates_py
│       ├── GPL-license.txt
│       ├── GPL3-license.txt
│       ├── LICENSE-bfont.ttf.txt
│       ├── LICENSE-bmonofont-i18n.ttf.txt
│       ├── LICENSE-droidsans.ttf.txt
│       ├── Python-license.txt
│       ├── blender
│       ├── blender-softwaregl
│       ├── blender-symbolic.svg
│       ├── blender-thumbnailer.py
│       ├── blender.svg
│       ├── copyright.txt
│       ├── icons
│       │   ├── scalable
│       │   │   └── apps
│       │   └── symbolic
│       │       └── apps
│       ├── jemalloc-license.txt
│       ├── ocio-license.txt
│       └── readme.html
└── usr
    ├── bin
    │   └── blender -> /opt/blender-2.81/blender
    ├── lib64
    │   └── python3.7
    │       └── site-packages
    │           ├── certifi
    │           ├── chardet
    │           ├── idna
    │           ├── libextern_draco.so
    │           ├── numpy
    │           ├── requests
    │           └── urllib3
    └── share
        └── applications
            └── blender.desktop
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

Post Reply