WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: MRTG Compilation  (Read 415 times)

Offline centralware

  • Sr. Member
  • ****
  • Posts: 313
MRTG Compilation
« on: March 03, 2018, 07:29:22 AM »
The following script was built to compile MRTG and its general dependencies.
Since I needed this for a personal project, I figured you might wish to add it to ARM/x86.

* GD is set for PNG support; if added to the repo it might be worthwhile to add JPG, etc.
Code: [Select]
#!/bin/sh
. /etc/init.d/tc-functions

clear; cur=`pwd`; KERNEL=`uname -r`

myapps="gcc perl5 compiletc autoconf automake squashfs-tools"

#[COMMAND LINE]#
EN_ZLIB=0; EN_LPNG=0; EN_LBGD=0; EN_MRTG=0
if [ "${1}" == "" ]; then $0 all; exit 0; fi
case $1 in
    zlib*)    EN_ZLIB=1;;
    libpng*)  EN_LPNG=1;;
    gd*)      EN_LBGD=1;;
    mrtg*)    EN_MRTG=1;;
    all)      EN_ZLIB=1; EN_LPNG=1; EN_LBGD=1; EN_MRTG=1;;
esac

#[PREREQUISITE APPS]#
for app in $myapps
do
    app=${app/.tcz/}; app=${app/KERNEL/$KERNEL}
    if [ ! -d /tmp/tcloop/$app ]; then
        echo "${WHITE}Installing prerequisite extension ${MAGENTA}${app}${NORMAL} "
        tce-load -wi $app >/dev/null 2>&1
        if [ ! -d /tmp/tcloop/$app ]; then echo "${RED}Failed${NORMAL}"; exit 1; fi
        echo "${GREEN}OK${NORMAL}";
    fi
done

#[DIRECTORY STRUCTURE]#
if [ ! -d $cur/_built ]; then mkdir -p $cur/_built; fi
if [ ! -d $cur/_custom ]; then mkdir -p $cur/_custom; fi
if [ ! -d $cur/_src ]; then mkdir -p $cur/_src; fi

if [ ! -f $cur/_custom/extension_by ]; then echo "CentralWare Development Centers" > $cur/_custom/extension_by; fi

#[INFO FILE BUILDER]#
newinfo()
{
    name=$1; version=$2; file=$3
    extn=`cat $cur/_custom/extension_by`
    echo "Title:             ${name}.tcz" > $file    # Title of extension (filename)
    echo "Description:       " >> $file              # Manual entry - Description (brief) of extension
    echo "Version:           ${version}" >> $file    # Current version (of SOURCES)
    echo "Platform:          " >> $file              # Hardware Platform
    echo "Author:            " >> $file              # Manual entry - original author of sources
    echo "Original-site:     " >> $file              # Manual entry - website of sources
    echo "Copying-policy:    " >> $file              # Manual entry
    echo "Size:              ${size}" >> $file       # Filled in by builder
    echo "Extension_by:      ${extn}" >> $file       # Compiled/built by
    echo "Tags:              " >> $file              # Manual Entry - Tags/keywords
    echo "Comments:          " >> $file              # Long description
    echo "Change-log:        " >> $file              # Build (source) history
    echo "Current:           " >> $file              # Manual entry - DATE : Release Note : VERSION
}
updateinfo()
{
    src=$1; tcz=$2; ver=$3; size=`ls -lah $tcz | awk '{print $5}'`; date=`date +"%Y-%m-%d %T"`
    touch /tmp/update_info; rm /tmp/update_info -f
    while read -r line
    do
        test=`echo $line | grep "Size:"`; if [ ! "${test}" == "" ]; then line="Size:              ${size}"; fi
        test=`echo $line | grep "Current:"`; if [ ! "${test}" == "" ]; then line="Current:           ${date}"; fi
        echo "${line}" >> /tmp/update_info
    done < $src
    mv /tmp/update_info $src -f
}
newlist()
{
    srcdir=$1; output=$2; cd $srcdir
    touch /tmp/findfiles; rm /tmp/findfiles -f
    find > /tmp/findtemp
    while read -r line
    do                                                                                      #                  ----v
        line=${line:2}                                                                      # Remove path prefix ( ./path/to/file.name )
        test=`echo $line | awk -F/ '{print $2}'`; if [ "${test}" == "" ]; then line=""; fi  # Remove anything NOT in a sub-folder
        if [ -d $line ]; then line=""; fi                                                   # Remove directory listings (files only)
        if [ ! "${line}" == "" ]; then echo $line >> /tmp/findfiles; fi
    done < /tmp/findtemp; mv /tmp/findfiles $output; rm /tmp/findtemp -f
}
newmd5()
{
    app=$1; src=$2; dst=$3; md5=`md5sum $src | awk '{print $1}'`
    md5="${md5}                                                                    "
    echo "${md5:0:50} ${app}.tcz" > $dst
}

#[SOURCE DOWNLOADS]#
cd $cur/_src
FL_ZLIB="zlib-1.2.11.tar.gz";   ST_ZLIB="http://www.zlib.net/${FL_ZLIB}";                                     if [ ! -f $FL_ZLIB ]; then wget $ST_ZLIB; fi
FL_LPNG="libpng-1.6.34.tar.gz"; ST_LPNG="ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/${FL_LPNG}"; if [ ! -f $FL_LPNG ]; then wget $ST_LPNG; fi
FL_LBGD="GD_2_0_33.tar.gz";     ST_LBGD="https://github.com/libgd/libgd/archive/${FL_LBGD}";                  if [ ! -f $FL_LBGD ]; then wget $ST_LBGD; fi
FL_MRTG="mrtg-2.17.4.tar.gz";   ST_MRTG="https://oss.oetiker.ch/mrtg/pub/${FL_MRTG}";                         if [ ! -f $FL_MRTG ]; then wget $ST_MRTG; fi

#[ZLib v1.2.11]#
if [ $EN_ZLIB -gt 0 ]; then
app="zlib"
ver=1.2.11
    if [ ! -d $cur/${app} ]; then
        cd $cur/_src; gunzip -c ${app}-*.tar.gz | tar xf -
        mv ${app}*.tar.gz ..; mv ${app}-* ${app}; mv ${app} ..; mv $cur/*.gz .
    fi
    cd $cur/${app}
    if [ ! -f ./.configured ]; then
        echo -n "${WHITE}Configuring ${YELLOW}${app}    ${NORMAL} "; ./configure >/tmp/log_${app}_conf 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_conf; echo "${NORMAL}"; touch ./.configured
    fi
    if [ ! -f ./.compiled ]; then
        echo -n "${WHITE}Compiling   ${YELLOW}${app}    ${NORMAL} "; make >/tmp/log_${app}_make 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_make; echo "${NORMAL}"; touch ./.compiled
    fi

    echo -n "${WHITE}Building    ${YELLOW}${app}.tcz${NORMAL} ";
        echo -n "${GREEN}INST ";
        mkdir -p $cur/_custom/${app}; mkdir -p /tmp/src/${app}; make DESTDIR=/tmp/src/${app} install >/tmp/log_${app}_install 2>&1
        echo -n "${GREEN}LIST ";
        if [ ! -f $cur/_custom/${app}/${app}.init ]; then echo "#!/bin/sh" > $cur/_custom/${app}/${app}.init; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.info ]; then newinfo ${app} ${ver} $cur/_custom/${app}/${app}.tcz.info; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.dep ]; then touch $cur/_custom/${app}/${app}.tcz.dep; fi
        mkdir -p /tmp/src/${app}/usr/local/etc/tce.installed; cp $cur/_custom/${app}/${app}.init /tmp/src/${app}/usr/local/etc/tce.installed/${app}
        newlist "/tmp/src/${app}" "${cur}/_custom/${app}/${app}.tcz.list"
        echo -n "${GREEN}TCZ "; mksquashfs /tmp/src/${app} $cur/_built/${app}.tcz >/tmp/log_${app}_tcz 2>&1
        echo -n "${GREEN}MD5 "; newmd5 $app "${cur}/_built/${app}.tcz" "${cur}/_built/${app}.tcz.md5.txt"
        cp $cur/_custom/${app}/${app}.tcz.dep $cur/_built/
        updateinfo "${cur}/_custom/${app}/${app}.tcz.info" "${cur}/_built/${app}.tcz" $ver
        cp $cur/_custom/${app}/${app}.tcz.info $cur/_built/
        cp $cur/_custom/${app}/${app}.tcz.list $cur/_built/
        if [ ! -f $cur/_custom/${app}-src.tcz ]; then
            echo -n "${GREEN}SRC "
            if [ ! -f $cur/_custom/${app}/${app}-src.tcz.info ]; then newinfo ${app}-src ${ver} $cur/_custom/${app}/${app}-src.tcz.info; fi
            mkdir -p /tmp/custom/usr/local/src/${app}; cd /tmp/custom/usr/local/src/${app}
            cp $cur/_src/${app}*.tar.gz .; gunzip -c ${app}*.tar.gz | tar xf -; rm ${app}*.tar.gz
            newlist "/tmp/custom" "${cur}/_custom/${app}/${app}-src.tcz.list"
            mksquashfs /tmp/custom $cur/_built/${app}-src.tcz >/tmp/log_${app}-src_tcz 2>&1; rm /tmp/custom -fR
            newmd5 $app-src "${cur}/_built/${app}-src.tcz" "${cur}/_built/${app}-src.tcz.md5.txt"
            echo "tce-load -wi ${myapps}" > $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "./configure" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make install" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
        fi
    cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1; app=${app/-src/}; cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1
    echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_tcz; echo "${NORMAL}"
fi

#[LibPNG v1.6.34]#
if [ $EN_LPNG -gt 0 ]; then
app="libpng"
ver=1.6.34
    if [ ! -d $cur/${app} ]; then
        cd $cur/_src; gunzip -c ${app}-*.tar.gz | tar xf -
        mv ${app}*.tar.gz ..; mv ${app}-* ${app}; mv ${app} ..; mv $cur/*.gz .
    fi
    cd $cur/${app}
    if [ ! -f ./.configured ]; then
        echo -n "${WHITE}Configuring ${YELLOW}${app}    ${NORMAL} "
        env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR >/tmp/log_${app}_conf 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_conf; echo "${NORMAL}"; touch ./.configured
    fi
    if [ ! -f ./.compiled ]; then
        echo -n "${WHITE}Compiling   ${YELLOW}${app}    ${NORMAL} "; make >/tmp/log_${app}_make 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_make; echo "${NORMAL}"; touch ./.compiled
    fi
    echo -n "${WHITE}Building    ${YELLOW}${app}.tcz${NORMAL} ";
        echo -n "${GREEN}INST ";
        mkdir -p $cur/_custom/${app}; mkdir -p /tmp/src/${app}; make DESTDIR=/tmp/src/${app} install-strip >/tmp/log_${app}_inst 2>&1
        echo -n "${GREEN}LIST ";
        if [ ! -f $cur/_custom/${app}/${app}.init ]; then echo "#!/bin/sh" > $cur/_custom/${app}/${app}.init; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.info ]; then newinfo ${app} ${ver} $cur/_custom/${app}/${app}.tcz.info; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.dep ]; then touch $cur/_custom/${app}/${app}.tcz.dep; fi
        mkdir -p /tmp/src/${app}/usr/local/etc/tce.installed; cp $cur/_custom/${app}/${app}.init /tmp/src/${app}/usr/local/etc/tce.installed/${app}
        newlist "/tmp/src/${app}" "${cur}/_custom/${app}/${app}.tcz.list"
        echo -n "${GREEN}TCZ "; mksquashfs /tmp/src/${app} $cur/_built/${app}.tcz >/tmp/log_${app}_tcz 2>&1
        echo -n "${GREEN}MD5 "; newmd5 $app "${cur}/_built/${app}.tcz" "${cur}/_built/${app}.tcz.md5.txt"
        cp $cur/_custom/${app}/${app}.tcz.dep $cur/_built/
        updateinfo "${cur}/_custom/${app}/${app}.tcz.info" "${cur}/_built/${app}.tcz" $ver
        cp $cur/_custom/${app}/${app}.tcz.info $cur/_built/
        cp $cur/_custom/${app}/${app}.tcz.list $cur/_built/
        if [ ! -f $cur/_custom/${app}-src.tcz ]; then
            echo -n "${GREEN}SRC "
            mkdir -p /tmp/custom/usr/local/src/${app}; cd /tmp/custom/usr/local/src/${app}
            cp $cur/_src/${app}*.tar.gz .; gunzip -c ${app}*.tar.gz | tar xf -; rm ${app}*.tar.gz
            newlist "/tmp/custom" "${cur}/_custom/${app}/${app}-src.tcz.list"
            mksquashfs /tmp/custom $cur/_built/${app}-src.tcz >/tmp/log_${app}-src_tcz 2>&1
            newmd5 $app-src "${cur}/_built/${app}-src.tcz" "${cur}/_built/${app}-src.tcz.md5.txt"
            rm /tmp/custom -fR
            echo "tce-load -wi ${myapps}" > $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "env CFLAGS=\"-O3 -fPIC\" ./configure --prefix=\$INSTALL_DIR" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make install-strip" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
        fi
    cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1; app=${app/-src/}; cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1
    echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_tcz; echo "${NORMAL}"
fi

#[GD v2.0.33]#
if [ $EN_LBGD -gt 0 ]; then
app="gd"
ver=2.0.33
    if [ ! -d $cur/${app} ]; then
        cd $cur/_src; gunzip -c GD*.tar.gz |tar xf -; mv GD*.tar.gz ..
        mv libgd-* gdsrc; mv gdsrc/src ./${app}; mv ${app} ..; rm gdsrc -fR; mv $cur/*.gz .
    fi
    cd $cur/${app}
    if [ ! -f ./.configured ]; then
        echo -n "${WHITE}Configuring ${YELLOW}${app}    ${NORMAL} "
        env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" ./configure --disable-shared --without-freetype --without-jpeg >/tmp/log_${app}_conf 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_conf; echo "${NORMAL}"; touch ./.configured
    fi
    if [ ! -f ./.compiled ]; then
        echo -n "${WHITE}Compiling   ${YELLOW}${app}    ${NORMAL} "; make >/tmp/log_${app}_make 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_make; echo "${NORMAL}"; touch ./.compiled
    fi
    echo -n "${WHITE}Building    ${YELLOW}${app}.tcz${NORMAL} ";
        echo -n "${GREEN}INST ";
        mkdir -p $cur/_custom/${app}; mkdir -p /tmp/src/${app}; make DESTDIR=/tmp/src/${app} install-strip >/tmp/log_${app}_inst 2>&1
        #cp .libs/* .
        echo -n "${GREEN}LIST ";
        if [ ! -f $cur/_custom/${app}/${app}.init ]; then echo "#!/bin/sh" > $cur/_custom/${app}/${app}.init; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.info ]; then newinfo ${app} ${ver} $cur/_custom/${app}/${app}.tcz.info; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.dep ]; then touch $cur/_custom/${app}/${app}.tcz.dep; fi
        mkdir -p /tmp/src/${app}/usr/local/etc/tce.installed; cp $cur/_custom/${app}/${app}.init /tmp/src/${app}/usr/local/etc/tce.installed/${app}
        newlist "/tmp/src/${app}" "${cur}/_custom/${app}/${app}.tcz.list"
        echo -n "${GREEN}TCZ "; mksquashfs /tmp/src/${app} $cur/_built/${app}.tcz >/tmp/log_${app}_tcz 2>&1
        echo -n "${GREEN}MD5 "; newmd5 $app "${cur}/_built/${app}.tcz" "${cur}/_built/${app}.tcz.md5.txt"
        cp $cur/_custom/${app}/${app}.tcz.dep $cur/_built/
        updateinfo "${cur}/_custom/${app}/${app}.tcz.info" "${cur}/_built/${app}.tcz" $ver
        cp $cur/_custom/${app}/${app}.tcz.info $cur/_built/
        cp $cur/_custom/${app}/${app}.tcz.list $cur/_built/
        if [ ! -f $cur/_custom/${app}-src.tcz ]; then
            echo -n "${GREEN}SRC "
            mkdir -p /tmp/custom/usr/local/src/${app}; cd /tmp/custom/usr/local/src/${app}
            cp $cur/_src/GD*.tar.gz .; gunzip -c GD*.tar.gz | tar xf -; rm GD*.tar.gz
            newlist "/tmp/custom" "${cur}/_custom/${app}/${app}-src.tcz.list"
            mksquashfs /tmp/custom $cur/_built/${app}-src.tcz >/tmp/log_${app}-src_tcz 2>&1
            newmd5 $app-src "${cur}/_built/${app}-src.tcz" "${cur}/_built/${app}-src.tcz.md5.txt"
            rm /tmp/custom -fR
            echo "tce-load -wi ${myapps}" > $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "env CPPFLAGS=\"-I../zlib -I../libpng\" LDFLAGS=\"-L../zlib -L../libpng\" ./configure --disable-shared --without-freetype --without-jpeg" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make install-strip" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
        fi
    cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1; app=${app/-src/}; cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1
    echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_tcz; echo "${NORMAL}"
fi

#[MRTG v2.17.4]#
if [ $EN_MRTG -gt 0 ]; then
app="mrtg-2"
ver=2.17.4
    if [ ! -d $cur/${app} ]; then
        cd $cur/_src; gunzip -c mrtg*.tar.gz | tar xf -; mv mrtg*.tar.gz ..; mv mrtg-* ${app}; mv ${app} ..; mv $cur/*.gz .
    fi
    cd $cur/${app}
    if [ ! -f ./.configured ]; then
        echo -n "${WHITE}Configuring ${YELLOW}${app}    ${NORMAL} "
        ./configure --prefix=/usr/local/${app} --with-gd=../gd --with-z=../zlib --with-png=../libpng >/tmp/log_${app}_conf 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_conf; echo "${NORMAL}"; touch ./.configured
    fi
    if [ ! -f ./.compiled ]; then
        echo -n "${WHITE}Compiling   ${YELLOW}${app}    ${NORMAL} "; make >/tmp/log_${app}_make 2>&1
        echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_make; echo "${NORMAL}"; touch ./.compiled
    fi
    echo -n "${WHITE}Building    ${YELLOW}${app}.tcz${NORMAL} ";
        echo -n "${GREEN}INST ";
        mkdir -p $cur/_custom/${app}; mkdir -p /tmp/src/${app}; make DESTDIR=/tmp/src/${app} install >/tmp/log_${app}_inst 2>&1
        echo -n "${GREEN}LIST ";
        if [ ! -f $cur/_custom/${app}/${app}.init ]; then echo "#!/bin/sh" > $cur/_custom/${app}/${app}.init; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.info ]; then newinfo ${app} ${ver} $cur/_custom/${app}/${app}.tcz.info; fi
        if [ ! -f $cur/_custom/${app}/${app}.tcz.dep ]; then touch $cur/_custom/${app}/${app}.tcz.dep; fi
        mkdir -p /tmp/src/${app}/usr/local/etc/tce.installed; cp $cur/_custom/${app}/${app}.init /tmp/src/${app}/usr/local/etc/tce.installed/${app}
        newlist "/tmp/src/${app}" "${cur}/_custom/${app}/${app}.tcz.list"
        echo -n "${GREEN}TCZ "; mksquashfs /tmp/src/${app} $cur/_built/${app}.tcz >/tmp/log_${app}_tcz 2>&1
        echo -n "${GREEN}MD5 "; newmd5 $app "${cur}/_built/${app}.tcz" "${cur}/_built/${app}.tcz.md5.txt"
        cp $cur/_custom/${app}/${app}.tcz.dep $cur/_built/
        updateinfo "${cur}/_custom/${app}/${app}.tcz.info" "${cur}/_built/${app}.tcz" $ver
        cp $cur/_custom/${app}/${app}.tcz.info $cur/_built/
        cp $cur/_custom/${app}/${app}.tcz.list $cur/_built/
        if [ ! -f $cur/_custom/${app}-src.tcz ]; then
            echo -n "${GREEN}SRC "
            mkdir -p /tmp/custom/usr/local/src/${app}; cd /tmp/custom/usr/local/src/${app}
            cp $cur/_src/${app}*.tar.gz .; gunzip -c ${app}*.tar.gz | tar xf -; rm ${app}*.tar.gz
            newlist "/tmp/custom" "${cur}/_custom/${app}/${app}-src.tcz.list"
            mksquashfs /tmp/custom $cur/_built/${app}-src.tcz >/tmp/log_${app}-src_tcz 2>&1
            newmd5 $app-src "${cur}/_built/${app}-src.tcz" "${cur}/_built/${app}-src.tcz.md5.txt"
            rm /tmp/custom -fR
            echo "tce-load -wi ${myapps}" > $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "./configure --prefix=/usr/local/${app} --with-gd=../gd --with-z=../zlib --with-png=../libpng" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
            echo "make install" >> $cur/_custom/${app/-src/}/${app}-src.tcz.build-dep
        fi
    cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1; app=${app/-src/}; cp $cur/_custom/${app}/* $cur/_built/ -f >/dev/null 2>&1
    echo "${CYAN}Done.${MAGENTA}"; tail -n 10 /tmp/log_${app}_tcz; echo "${NORMAL}"
fi

rm $cur/_built/*.init -f