#!/bin/sh # Copyright (c) 2004 by SWsoft, Inc. # All rights reserved # #ident "@(#)plesk 7.0 04/02/02 SWsoft" # # Plesk locale pack install script # # accumulates chown and chmod set_ac() { u_owner="$1" g_owner="$2" perms="$3" node="$4" chown $u_owner:$g_owner $node || die "chown $u_owner:$g_owner $node" chmod $perms $node || die "chmod $perms $node" } p_echo() { echo "$*" >> "$product_log" 2>&1 echo "$*" } pno_echo() { echo "$*" >> "$product_log" 2>&1 } pnnl_echo() { if [ -z $necho_defined ]; then # set up echo case "`echo 'x\c'`" in 'x\c') echo="echo -n" nnl= ;; x) echo="echo" nnl="\c" ;; *) echo "ERROR: unable to set up echo." ;; esac necho_defined=true fi $echo "$*${nnl}" >> "$product_log" 2>&1 $echo "$*${nnl}" } die() { printf "\a\a" p_echo p_echo "ERROR while trying to $*" p_echo "Check the error reason, fix and try again" p_echo p_echo "Aborting..." p_echo exit 1 } err() { p_echo p_echo "ERROR!" p_echo "Check the error reason, fix and try again" p_echo p_echo "Exiting..." p_echo exit 1 } echo_try() { msg="$*" pnnl_echo " Trying to $msg... " } suc() { p_echo "done" } test_for_root() { my_id="`id`" case "$my_id" in uid=0\(root\)*) ;; *) p_echo "$0: This script must be run as root" p_echo "Became a root and then run this script" p_echo exit 1 ;; esac } chk_version() { if [ -d "$product_root" ]; then product_real_ver="`cat $product_root/version | awk '{print $1}' -| awk -F'.' '{print $1"."$2}' -`" case "$product_real_ver" in $product_version) ;; *) p_echo p_echo "You have $product_bb version $product_real_ver" p_echo "In order for this script to work properly, please ensure that the version" p_echo "of the $product_bb that you're attempting to localizate is $product_version." p_echo "OK. Goodbye! See you later" p_echo exit 0 ;; esac fi p_echo p_echo p_echo p_echo p_echo "This script install locale $locale on your system" p_echo "$product_root directory will be used as a root for this product" p_echo if [ "$INTERACTIVE" = "NO" ]; then return fi pnnl_echo "Do you want to continue? [N] " read answer case "$answer" in y*|Y*) ;; *) p_echo p_echo "OK. Goodbye! See you later" p_echo exit 0 ;; esac p_echo } get_etc_conf() { if [ ! -f $config ]; then p_echo "ERROR: Unable to open $config file." exit 3 fi product_root=`grep PRODUCT_ROOT_D $config | grep -v '^#' | awk '{print $2}'` if [ -z "$product_root" ]; then p_echo "ERROR: Unable to define $product root directory." exit 3 fi rc_dir=`grep PRODUCT_RC_D $config | grep -v '^#' | awk '{print $2}'` if [ -z "$rc_dir" ]; then rc_dir=$product_root/rc.d fi mysql_bin_dir=`grep MYSQL_BIN_D $config | grep -v '^#' | awk '{print $2}'` if [ -z "$mysql_bin_dir" ]; then mysql_bin_dir=$product_root/mysql/bin fi } check_integrity() { #check of $product_bb intallation if [ ! -d ${product_root} ]; then p_echo "ERROR: $product_bb directory '${product_root}' not found! Install $product_bb first." exit 1 fi #check for free space DISTSIZE=@LOCALE_PACKET_DISTSIZE@ FREESPACE=`df -kP ${product_root} | grep /dev/| awk '{ print $4 }'` if [ "${DISTSIZE}" -ge "${FREESPACE}" ]; then p_echo "ERROR: No free space for install Locale Pack." p_echo "ERROR: No free space for install Locale Pack." >> $product_log exit 2 fi } extract_report() { case $? in 0) p_echo " Extraction successfully completed" p_echo ;; *) p_echo p_echo "ERROR: something wrong with distribution archive file" p_echo "Exiting..." p_echo exit 1 ;; esac } set_def_perms() { for dir in htdocs plib; do chown -R root:$admin_group $product_root/admin/$dir/locales/$locale/ chmod -R 440 $product_root/admin/$dir/locales/$locale/ find $product_root/admin/$dir/locales/$locale/ -type d -exec chmod 550 {} \; set_ac root $admin_group 550 "$product_root/admin/$dir/locales" set_ac root $admin_group 550 "$product_root/admin/$dir/locales/$locale" done } get_pid() { proc_name="$1" case "$machine" in solaris) PID=`ps -ef | grep "$proc_name" | grep -v grep | awk '{print $2}'` ;; *) PID=`ps axww | awk '$5 ~ "'$proc_name']*$" {print $1}'` ;; esac } patch_symlink() { if [ ! -d "$product_root/mysql/share/mysql" -a ! -L "$product_root/mysql/share/mysql" ]; then mkdir -p "$product_root/mysql/share" && ln -sf /usr/share/mysql "$product_root/mysql/share/mysql" || die "create symlink for MySQL default_charset fix" fi } f_help=NO INTERACTIVE=YES while [ -n "$1" ]; do case $1 in --interactive) INTERACTIVE=YES ;; --no-interactive) INTERACTIVE=NO ;; --help | -h) f_help=YES ;; *) echo $1: unknown argument exit 1 ;; esac shift done if [ "$f_help" = "YES" ]; then cat <> $product_log #initializing log echo "START LOGGING: `date`" >> $product_log check_integrity chk_version p_echo p_echo "So, it's time to unpack distribution files" p_echo "All files will be extracted into $product_root directory" p_echo "This operation takes some time," p_echo "please, wait..." p_echo p_echo "===> Extracting files ..." cat "$my_name" | $uudecode | tar -C / -xz -m -f - extract_report set_def_perms get_pid "mysqld" if [ -z "$PID" ]; then inten="start MySQL server" echo_try $inten $rc_dir/mysqld start >> $product_log 2>&1 && suc || die $inten sleep 2 fi res=`$mysql <> $product_log 2>&1 && suc || die $inten sleep 2 fi patch_symlink printf "\a\a\a" p_echo p_echo p_echo p_echo p_echo " Congratulations!" p_echo " All stages of installation were successfully completed" p_echo p_echo p_echo " If the number of LP's installed exceeds the number of possible LP's" p_echo " defined within the key, then the installed Locale packs that exceed" p_echo " the number defined by the key will not be available via Plesk interface." p_echo " Please contact your Plesk sales representative in order to purchase" p_echo " an appropriate key." p_echo p_echo exit 0