Nieaktualne! Imagemagick domyślnie wbudowany w obecną wersje PHP serwera QNAP NAS.
(Notka: Wymagany zainstalowany Optware/IPKG)
FYI: kod źródłowy skryptu:
(Notka: Wymagany zainstalowany Optware/IPKG)
- Z centrum aplikacji zainstaluj Optware.
- Za pomocą klienta SSH (np. PuTTY) zaloguj się na serwer i wykonaj poniższe polecenia aby pobrać automatyczny skrypt instalujący ImageMagick:
Bash:
cd /share/Public wget http://pool.qnapclub.pl/site/tools/utils/ImageMagick.sh chmod +x ImageMagick.sh ./ImageMagick.sh install rm ImageMagick.sh /etc/init.d/ImageMagick.sh start
- Enjoy!
FYI: kod źródłowy skryptu:
Bash:
#!/bin/sh
##
## PHP ImageMagick and imagick extension auto-compiler tool
## designed for QNAP TurboNAS, QTS4 compilant
##
## Copyright © 2013, Silas Mariusz <silas@qnap.com.antispam>
##
## QNAP Club Polska
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software Foundation,
## Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
## The latest version of this software can be obtained here:
##
## https://forum.qnap.net.pl/
##
##
## FILE: qlogWatcher.sh
##
## RELEASE: 1.0
## DATE: 2013-08-11
##
## (dependencies: Optware)
NAME=imagick-module
QNAME=ImageMagick
## find my name and real current directory
## ###########################################################################
PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path
PROGDIR=`dirname $PROGNAME` # extract directory of program
PROGNAME=`basename $PROGNAME` # base name of program
[ "$PROGDIR" == "." ] && PROGDIR=`cd $PROGDIR && pwd || echo $PROGDIR`
## Fully qualify directory path (remove relative components and symlinks)
## WARNING: The "bash" "pwd" builtin does not resolve symbolic links
## "sh" (as a link to "bash") also does not, but "csh" does handle it.
## Symbolic link removal however is not critical.
ORIGDIR=`pwd` # original directory (builtin)
PROGDIR=`cd $PROGDIR && pwd || echo $PROGDIR` # program directory
## Results...
## $ORIGDIR -- where the users was when called
## $PROGDIR -- script directory location (and now current directory)
## $PROGNAME -- This scripts executable name
# Get the fully qualified path to the script
case $0 in
/*)
SCRIPT="$0"
;;
*)
PWD=`pwd`
SCRIPT="$PWD/$0"
;;
esac
## Change spaces to ":" so the tokens can be parsed.
SCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
## Get the real path to this script, resolving any symbolic links
TOKENS=`echo $SCRIPT | sed -e 's;/; ;g'`
REALPATH=
for C in $TOKENS; do
REALPATH="$REALPATH/$C"
while [ -h "$REALPATH" ] ; do
LS="`ls -ld "$REALPATH"`"
LINK="`expr "$LS" : '.*-> \(.*\)$'`"
if expr "$LINK" : '/.*' > /dev/null; then
REALPATH="$LINK"
else
REALPATH="`dirname "$REALPATH"`""/$LINK"
fi
done
done
# Change ":" chars back to spaces.
REALPATH=`echo $REALPATH | sed -e 's;:; ;g'`
REALPATH="`dirname "$REALPATH"`"
[ "`basename $REALPATH`" == "." ] && \
REALPATH="`echo $REALPATH | awk '{$0=substr($0,1,length($0)-2); print $0}'`"
# Change the current directory to the location of the script
PROGDIR="`cd $REALPATH && pwd || echo $PROGDIR`"
cd $PROGDIR
## ###########################################################################
## Write error log message and exit
err(){
local write_err="/sbin/log_tool -t2 -uSystem -p127.0.0.1 -mlocalhost -a"
[ -n "$1" ] && local message="$NAME ${1:-"Unknown Error"}" && $write_err "$message"
echo -e "\n\n [!] $message"
exit 1
}
## ###########################################################################
## Keep old PATH...
OLD_PATH=$PATH
## BASIC SETTINGS
PHP_INI_EXTENSION_DIR="/mnt/ext/opt/apache/modules"
PHP_INI_CLI_EXT_DIR="/opt/lib/php/extensions"
_opt_php_ini="/opt/etc/php.ini"
_sys_php_ini="/mnt/HDA_ROOT/.config/php.ini"
## ###########################################################################
## Get volume and .qpkg directory
publicdir=`/sbin/getcfg Public path -f /etc/config/smb.conf`
qpkgdir=`cd $publicdir && cd ../.qpkg && pwd`
base=$qpkgdir/$QNAME
## ###########################################################################
## Who Am I?
USER=`whoami`
[[ $USER != "admin" ]] && echo "STOP: sorry $USER user shall be admin" && exit
echo "
---------------------------------------------------------------------
:: $NAME (for QNAP TurboNAS) installer [2013-08-03] ::
---------------------------------------------------------------------
.. written by Silas Mariusz Grzybacz www.qnapclub.pl
---------------------------------------------------------------------
Hello $USER ..."
## ###########################################################################
## Install me to .qpkg
installMe(){
[ ! -d "$base" ] && mkdir -p $base
local _dir1=`cd $PROGDIR && pwd || echo $PROGDIR`
local _dir2=`cd $base && pwd || echo $base`
if [ "$_dir1" != "$_dir2" ]; then
rm -rf $base
mkdir -p $base
cd $base
echo -e "\n\n. Installing me \n (from) $_dir1 \n >> (to) $_dir2"
cp -af "$_dir1/$PROGNAME" "$_dir2/$PROGNAME"
chmod +x "$base/$PROGNAME"
fi
}
## ##########################################################################
## Check for Optware/IPKG QPKG
needIpkg(){
type -f ipkg 2>&1 >/dev/null
INSTALLED_IPKG=$?
if [ $INSTALLED_IPKG -ne 0 ] || [ ! -f "/opt/bin/ipkg" ] || [ ! -x "/opt/bin/ipkg" ]; then
err "Cannot find Optware/IPKG! Please install and enable it first."
fi
}
updateIpkg(){
echo -e "\n\n. Update Optware repository.
---------------------------------------------------------------------"
/opt/bin/ipkg update 2>&1 >/dev/null
RETVAL_1=$?
}
installDeps(){
echo -e "\n\n. Install dependencies and build tools...
---------------------------------------------------------------------"
/opt/bin/ipkg install at autoconf automake bc binutils bzip2 \
coreutils diffutils findutils freetype gawk gcc getopt \
gettext glib grep gzip libcurl libcurl-dev libjpeg \
libmemcache libpng libsigc++ libstdc++ libtiff libtool \
libxml2 libxslt make m4 memcached patch patchutils \
pcre pcre-dev perl php php-curl php-dev php-gd \
php-iconv php-pear pkgconfig re2c readline sed tar \
textutils tree tz util-linux wget which whois yasm zip \
zlib 2>&1 >/dev/null
RETVAL_2=$?
if [ $RETVAL_1 -ne 0 ] || [ $RETVAL_2 -ne 0 ]; then
err "Dependencies install failed! (IPKG)"
fi
}
compileLibMagick(){
echo -e "\n\n. Looking for libMagick...
---------------------------------------------------------------------"
#/sbin/ldconfig -v /opt/lib 2>/dev/null | grep libMagick
#RETVAL=$?
ipkg install imagemagick || err "$PROGNAME: Error on line $LINENO."
RETVAL=0
if [ $RETVAL -ne 0 ]; then
echo -e "\n\n. Downloading latest version of ImageMagick library...
---------------------------------------------------------------------"
# wget -q ftp://sunsite.icm.edu.pl/packages/ImageMagick/ImageMagick.tar.gz \
# || err "$PROGNAME: Error on line $LINENO."
wget -q ftp://sunsite.icm.edu.pl/packages/ImageMagick/ImageMagick-6.8.6-7.tar.gz \
-O ImageMagick.tar.gz || err "$PROGNAME: Error on line $LINENO."
tar zxf ImageMagick.tar.gz || err "$PROGNAME: Error on line $LINENO."
rm ImageMagick.tar.gz || err "$PROGNAME: Error on line $LINENO."
SRCDIR=`ls -1 | grep ImageMagick-`
cd $SRCDIR || err "$PROGNAME: Error on line $LINENO."
# Compiler options
export CC="gcc -std=gnu99 -std=gnu99"
export CFLAGS="-g -O2 -Wall -pthread"
export CPP="gcc -E"
export CPPFLAGS="-O2 -pipe -I/opt/include"
export CXX="g++"
export CXXFLAGS="-g -O2 -pthread"
export DEFS="-DHAVE_CONFIG_H"
export LDFLAGS="-L/opt/lib -Wl,-rpath,/opt/lib -Wl,-rpath-link,/opt/lib"
export LD_LIBRARY_PATH=/opt/lib
echo -e "\n\n. Installing: $SRCDIR (1: configure)
---------------------------------------------------------------------"
./configure --prefix=/opt --disable-openmp --without-perl \
--without-x --with-zlib --with-jpeg --with-png \
--with-tiff --with-freetype --without-gslib \
--with-modules --enable-shared --enable-static \
--with-sysroot=/opt \
|| err "$PROGNAME: Error on line $LINENO."
echo -e "\n\n. Installing: $SRCDIR (2: compiling. This may take a while...)
---------------------------------------------------------------------"
make || err "$PROGNAME: Error on line $LINENO."
echo -e "\n\n. Installing: $SRCDIR (3: copying library files to /opt)
---------------------------------------------------------------------"
make install || err "$PROGNAME: Error on line $LINENO."
cd ..
rm -rf $SRCDIR || err "$PROGNAME: Error on line $LINENO."
fi
}
linkLibMagickIncludes(){
# Linking Includes
_t="/opt/include/ImageMagick"
[ ! -L "$_t" ] && ln -sf /opt/include/ImageMagick-6 $_t
_t="/opt/include/Magick++"
[ ! -L "$_t" ] && ln -sf /opt/include/ImageMagick/Magick++ $_t
_t="/opt/include/magick"
[ ! -L "$_t" ] && ln -sf /opt/include/ImageMagick/magick $_t
_t="/opt/include/wand"
[ ! -L "$_t" ] && ln -sf /opt/include/ImageMagick/wand $_t
_t="/opt/include/Magick++.h"
[ ! -L "$_t" ] && ln -sf /opt/include/ImageMagick/Magick++.h $_t
}
compileImagick(){
echo -e "\n\n. Looking for imagick.so...
---------------------------------------------------------------------"
if [ ! -f "/opt/lib/php/extensions/imagick.so" ] || [ ! -x "/opt/lib/php/extensions/imagick.so" ]; then
echo -e "\n\n. Downloading imagick source...
---------------------------------------------------------------------"
wget -q http://pecl.php.net/get/imagick-3.0.1.tgz -O imagick.tgz \
|| err "$PROGNAME: Error on line $LINENO."
tar zxf imagick.tgz || err "$PROGNAME: Error on line $LINENO."
rm imagick.tgz package.xml || err "$PROGNAME: Error on line $LINENO."
SRCDIR=`ls -1 | grep imagick-`
cd $SRCDIR || err "$PROGNAME: Error on line $LINENO."
# Compiler options
export CC="gcc -std=gnu99 -std=gnu99"
export CFLAGS="-g -O2 -Wall -pthread"
export CPP="gcc -E"
export CPPFLAGS="-O2 -pipe -I/opt/include"
export CXX="g++"
export CXXFLAGS="-g -O2 -pthread"
export DEFS="-DHAVE_CONFIG_H"
export LDFLAGS="-L/opt/lib -Wl,-rpath,/opt/lib -Wl,-rpath-link,/opt/lib"
export LD_LIBRARY_PATH=/opt/lib
echo -e "\n\n. Installing: $SRCDIR (1: phpize)
---------------------------------------------------------------------"
/opt/bin/phpize || err "$PROGNAME: Error on line $LINENO."
echo -e "\n\n. Installing: $SRCDIR (2: configure)
---------------------------------------------------------------------"
./configure PREFIX=/opt/bin --enable-static --enable-static \
--with-libdir=/opt/lib \
--with-php-config=/opt/bin/php-config \
--with-imagick=/opt \
|| err "$PROGNAME: Error on line $LINENO."
echo -e "\n\n. Installing: $SRCDIR (3: compiling. This may take a while...)
---------------------------------------------------------------------"
make || err "$PROGNAME: Error on line $LINENO."
echo -e "\n\n. Installing: $SRCDIR (4: copying library files to /opt)
---------------------------------------------------------------------"
make install || err "$PROGNAME: Error on line $LINENO."
cd ..
rm -rf $SRCDIR || err "$PROGNAME: Error on line $LINENO."
else
echo " /opt/lib/php/extensions/imagick.so"
fi
}
makeLinks(){
# Installing files
echo -e "\n\n. Installing imagick.so module file.
---------------------------------------------------------------------"
MODULE=/opt/lib/php/extensions/imagick.so
if [ ! -f "$MODULE" ]; then
err "Module imagick.so not found... Installation failed!"
fi
cp -af $MODULE $PHP_INI_EXTENSION_DIR
# Create libraries links
[ ! -L "/usr/lib/libMagickCore.so.3" ] && \
ln -sf /usr/lib/libMagickCore.so.3.0.0 \
/usr/lib/libMagickCore.so.3
[ ! -L "/usr/lib/libMagickCore.so.3.0.0" ] && \
ln -sf /mnt/ext/opt/ImageMagick/usr/lib/libMagickCore.so.3.0.0 \
/usr/lib/libMagickCore.so.3.0.0
[ ! -L "/usr/lib/libMagickWand.so.3" ] && \
ln -sf /usr/lib/libMagickWand.so.3.0.0 \
/usr/lib/libMagickWand.so.3
[ ! -L "/usr/lib/libMagickWand.so.3.0.0" ] && \
ln -sf /mnt/ext/opt/ImageMagick/usr/lib/libMagickWand.so.3.0.0 \
/usr/lib/libMagickWand.so.3.0.0
[ ! -L "/usr/local/sbin/convert" ] && \
ln -sf /mnt/ext/opt/ImageMagick/usr/local/sbin/convert \
/usr/local/sbin/convert
[ ! -L "/usr/local/sbin/identify" ] && \
ln -sf /mnt/ext/opt/ImageMagick/usr/local/sbin/identify \
/usr/local/sbin/identify
[ ! -L "/usr/sbin/convert" ] && \
ln -sf /mnt/ext/opt/ImageMagick/usr/local/sbin/convert \
/usr/sbin/convert
[ ! -L "/usr/sbin/identify" ] && \
ln -sf /mnt/ext/opt/ImageMagick/usr/local/sbin/identify \
/usr/sbin/identify
}
installAsQPKG(){
# Install me as QPKG App
echo -e "\n\n. Installing $QNAME as QPKG-App and imagick-module as extension...
---------------------------------------------------------------------"
/sbin/setcfg $QNAME Name "$QNAME" -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME Version "1.0" -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME Author "Silas Mariusz" -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME Date `date +%F` -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME QPKG_File "${QNAME}.qpkg" -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME Shell "$base/$PROGNAME" -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME Install_Path "$base" -f /etc/config/qpkg.conf
/sbin/setcfg $QNAME Enable "TRUE" -f /etc/config/qpkg.conf
# Create control script links
[ -L "/etc/init.d/$PROGNAME" ] && rm -f "/etc/init.d/$PROGNAME"
[ -L "/etc/rcS.d/QS104$PROGNAME" ] && rm -f "/etc/rcS.d/QS104$PROGNAME"
[ -L "/etc/rcK.d/QK104$PROGNAME" ] && rm -f "/etc/rcK.d/QK104$PROGNAME"
[ ! -L "/etc/init.d/$PROGNAME" ] && \
ln -sf "$base/$PROGNAME" "/etc/init.d/$PROGNAME"
[ ! -L "/etc/rcS.d/QS104$PROGNAME" ] && \
ln -sf "$base/$PROGNAME" "/etc/rcS.d/QS104$PROGNAME"
[ ! -L "/etc/rcK.d/QK104$PROGNAME" ] && \
ln -sf "$base/$PROGNAME" "/etc/rcK.d/QK104$PROGNAME"
cp -f "/home/httpd/RSS/images/no_qpkg_icon_64.gif" \
"$base/no_qpkg_icon_64.gif"
cp -f "/home/httpd/RSS/images/no_qpkg_icon_64_gray.gif" \
"$base/no_qpkg_icon_64_gray.gif"
cp -f "/home/httpd/RSS/images/no_qpkg_icon_80.gif" \
"$base/no_qpkg_icon_80.gif"
cp -f "/home/httpd/RSS/images/no_qpkg_icon_64.gif" \
"/home/httpd/RSS/images/${QNAME}_64.gif"
cp -f "/home/httpd/RSS/images/no_qpkg_icon_64_gray.gif" \
"/home/httpd/RSS/images/${QNAME}_64_gray.gif"
cp -f "/home/httpd/RSS/images/no_qpkg_icon_80.gif" \
"/home/httpd/RSS/images/${QNAME}_80.gif"
}
applyImagick(){
# Create include link
[ ! -d "/etc/config/php" ] && mkdir -p "/etc/config/php"
if [ ! -L "/etc/config/php/imagick" ] || [ ! -d "/etc/config/php/imagick" ]; then
ln -sf /opt/include/php/ext/imagick /etc/config/php/imagick
fi
cat $_opt_php_ini | grep "/etc/config/php:/opt/include/php/ext:/opt/share/pear:/php/includes" >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
_opt_php_include=`/sbin/getcfg PHP include_path -d "." -f $_opt_php_ini | tr -d "\""`
/sbin/setcfg PHP include_path "\""$_opt_php_include:/etc/config/php:/opt/include/php/ext:/opt/share/pear:/php/includes\""" -f $_opt_php_ini
fi
cat $_opt_php_ini | grep "/opt/lib/php/extensions" >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
_opt_php_extension=`/sbin/getcfg PHP extension_dir -d "." -f $_opt_php_ini | tr -d "\""`
/sbin/setcfg PHP extension_dir "\""$_opt_php_extension:/opt/lib/php/extensions\""" -f $_opt_php_ini
fi
cat $_sys_php_ini | grep "/opt/include/php/ext:/opt/share/pear:/php/includes" >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
_sys_php_include=`/sbin/getcfg PHP include_path -d "." -f $_sys_php_ini | tr -d "\""`
/sbin/setcfg PHP include_path "\""$_sys_php_include:/opt/include/php/ext:/opt/share/pear:/php/includes\""" -f $_sys_php_ini
fi
#cat $_sys_php_ini | grep "/opt/lib/php/extensions:$PHP_INI_EXTENSION_DIR" >/dev/null
cat $_sys_php_ini | grep "/usr/local/apache/modules" >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
_sys_php_extension=`/sbin/getcfg PHP extension_dir -d "." -f $_sys_php_ini | tr -d "\""`
/sbin/setcfg PHP extension_dir "\""$_sys_php_extension:/usr/local/apache/modules\""" -f $_sys_php_ini
fi
cat $_opt_php_ini | grep "extension = imagick.so" >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
cp -af $_opt_php_ini ${_opt_php_ini}.bak
echo "[Imagick]
extension = imagick.so" >> $_opt_php_ini
fi
cat $_sys_php_ini | grep "extension = imagick.so" >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
cp -af $_sys_php_ini ${_sys_php_ini}.bak
echo "[Imagick]
extension = imagick.so" >> $_sys_php_ini
fi
}
case "$1" in
start)
needIpkg
makeLinks
applyImagick
# Restart HTTPD server
echo -e "\n\n. Restarting Qhttpd server $_q
---------------------------------------------------------------------"
/etc/init.d/Qthttpd.sh restart
;;
stop)
# Thereo is no stop
echo "Nothing to do."
;;
restart)
$0 stop
$0 start
;;
install)
needIpkg
updateIpkg
installDeps
installMe
# Set strict PATH to required tools
export PATH=/opt/bin:/opt/sbin
[ -d "temp.$QNAME" ] && rm -rf "temp.$QNAME"
mkdir -p "temp.$QNAME"
cd "temp.$QNAME"
compileLibMagick
linkLibMagickIncludes
compileImagick
cd ..
rm -rf "temp.$QNAME"
installAsQPKG
makeLinks
applyImagick
export PATH=$OLD_PATH:$PATH
;;
*)
echo -e "\n\n Usage: $0 {install|start|stop}"
esac
echo -e "\n\n. Bye bye...
---------------------------------------------------------------------"
Ostatnio edytowane: