当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 8 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-09 12:34 

注册: 2009-10-11 22:47
帖子: 28
送出感谢: 0 次
接收感谢: 0 次
附件中的安装脚本程序在红帽系统中运行正常,但是在ubuntu系统中运行就提示错误:
“./setup.ssh: 1: Syntax error: Unterminated quoted string”

附件中的seup.rar直接改名为“setup”即可。
附件:
文件注释: 请将文件名直接改为"setup"运行、查看
setup.rar [27.1 KiB]
被下载 12 次


请教高手,怎样让这个文件在ubuntu系统中正常运行?


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-09 13:13 
头像

注册: 2007-08-05 17:40
帖子: 4968
送出感谢: 0 次
接收感谢: 4
压缩文档错误。
引用:
“./setup.ssh: 1: Syntax error: Unterminated quoted string”

我想大概是在用“here string"/"here document"的时候没有注意到

代码:
cat <<EOF >a.txt
afdsafdsafsadf
fsadfsdfsdfsd
EOF
#上一行的EOF必须顶格


缺少一个与EOF对应的结尾。

或者是在使用引号的时候,特别是在使用了"\"断句的时候,忘记了还要加另一个引号。


-----
可以用bash -x 来运行脚本,方便除错。


_________________
free VPN
YouKuDownLoader
代码:
pip3 install ykdl

install YouKuDownLoader, have fun in downloading.
YouKuDownLoader所支持网站列表


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-10 15:44 

注册: 2009-10-11 22:47
帖子: 28
送出感谢: 0 次
接收感谢: 0 次
cnkilior 写道:
压缩文档错误。


没有错误,只要直接把文件名后面的".rar"去掉就行了,我是直接改名上传的,没有压缩。

这个脚本在红帽系统下运行完全正常,可是一到ubuntu下就不行了,不知道怎么回事


页首
 用户资料  
 
4 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-10 16:33 

注册: 2008-01-29 9:09
帖子: 32
送出感谢: 0 次
接收感谢: 0 次
bash还懂点,sh就不懂了
试着跑了一下的确rh能跑ub报错


# === Functions Start ===

#
# Function to show welcome title banner
#
show_title_banner() {
echo "$VERSION"
echo "The following software is available for installation:"
echo
ls -1 */*/*.* 2> /dev/null | cut -f1 -d"/" | sort | uniq | sed -e "s/_/ /g" -e "s/^/ * /"
echo
cat README */README 2> /dev/null
}

加参数调试看样子是这段,但是注释掉还是报一样的错...不懂了


页首
 用户资料  
 
5 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-10 16:36 

注册: 2008-01-29 9:09
帖子: 32
送出感谢: 0 次
接收感谢: 0 次
想起来了,rh的sh是链接到bash的,楼主用bash跑应该就可以了


页首
 用户资料  
 
6 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-10 17:05 

注册: 2009-10-11 22:47
帖子: 28
送出感谢: 0 次
接收感谢: 0 次
little_gg 写道:
想起来了,rh的sh是链接到bash的,楼主用bash跑应该就可以了


bash试过,也不行


页首
 用户资料  
 
7 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-10 19:13 

注册: 2008-01-29 9:09
帖子: 32
送出感谢: 0 次
接收感谢: 0 次
既然说了是用bash而不是用sh麽就把脚本里的sh替换成bash嘛,测试能跑的
代码:
#!/bin/bash
#
# Universal Installer
#
VERSION="
STAR-CCM+/STAR-CAD Series 4.04 Installer
========================================
"

#
# Test for GNU Textutil POSIX 200112 bug
#
if [ "`echo | head -1 2>&1 | grep \"option is obsolete\"`" ]; then
  _POSIX2_VERSION=199209; export _POSIX2_VERSION
fi

#
# Automatically fix PATH
#
case `PATH=/bin:/usr/bin:$PATH; uname -s` in
AIX)
  PATH=/usr/bin:/usr/ucb:$PATH
  ;;
HP-UX)
  PATH=/usr/bin:/usr/ccs/bin:/usr/contrib/bin/X11:$PATH
  ;;
IRIX*)
  PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:$PATH
  ;;
Linux)
  PATH=/usr/bin:/bin:$PATH
  ;;
OSF1)
  PATH=/bin:/usr/bin:$PATH
  ;;
SunOS)
  PATH=/bin:/sbin:/usr/sbin:/usr/ucb:/usr/ccs/bin:/usr/openwin/bin:$PATH
  ;;
*)
  PATH=/usr/bin:/bin:$PATH
  ;;
esac
export PATH
MYUNAME=`id | sed -e 's/^[^(]*(\([^)]*\)).*$/\1/'`

#
# Session Terminal
#
case `uname` in
Linux)
  if [ "`grep \"Red Hat Enterprise Linux.*release [4-9]\" /etc/redhat-release 2> /dev/null`" ];then
    stty werase 2> /dev/null; stty werase "^?" 2> /dev/null # Workaround bug in RHEL 4.0 and later
  else
    stty erase "^?" 2> /dev/null; stty werase 2> /dev/null
  fi
  ;;
OSF1)
  if [ "`stty -a 2> /dev/null | grep \"^erase = \^?\"`" ]; then
    stty erase "^?" 2> /dev/null; stty werase 2> /dev/null # OSF1 keyboard
  else
    stty erase 2> /dev/null; stty werase "^?" 2> /dev/null
  fi
  ;;
*)
  stty erase 2> /dev/null
  ;;
esac

#
# Trap and ignore SIGINT (CTRL+C by user) and SIGTERM signals
#
case `uname` in
OSF1)
  trap true 2; trap true 15
  ;;
* )
  trap true INT; trap true TERM
  ;;
esac

#
# Test for bash echo bug
#
if [ "`echo \"\n\"`" = "\n" ]; then
  ECHO="echo -e"
else
  ECHO=echo
fi

#
# Defaults
#
PAPER=white
INK=black
CURSOR=red
BORDER=purple
FONT=7x14
OPTION="-cu -s -j -sb -sl 4096 -fn $FONT -fg $INK -bg $PAPER -cr $CURSOR -bd $BORDER -geometry 80x40 -T Setup -n Setup"
case `uname` in
HI-UX/MPP|HP-UX)
  XTERM="/usr/bin/X11/xterm"
  ;;
SunOS)
  XTERM="/usr/openwin/bin/xterm"
  ;;
UNIX_System_V)
  XTERM="/usr/X11R6/bin/xterm"
  ;;
*)
  XTERM="/usr/bin/X11/xterm"
  ;;
esac
umask 022

# === Functions Start ===

#
# Function to show welcome title banner
#
show_title_banner() {
  echo "$VERSION"
  echo "The following software is available for installation:"
  echo
  ls -1 */*/*.* 2> /dev/null | cut -f1 -d"/" | sort | uniq | sed -e "s/_/ /g" -e "s/^/  *  /"
  echo
  cat README */README 2> /dev/null
}

#
# Check disk is full
#
check_disk() {
  if [ -d "$1" ]; then
    mkdir -p $1/.check_disk-$MYUNAME 2> /dev/null
    if [ -d $1/.check_disk-$MYUNAME ]; then
      rmdir $1/.check_disk-$MYUNAME 2> /dev/null
    else
      echo "Disk is full"
    fi
  fi
}

#
# which (avoid buggy csh which)
#
which() {
  if [ "$1" ]; then
    for DIR in `echo $PATH | sed -e "s/:/ /g"`; do
      if [ -x "$DIR/$1" -a ! -d "$DIR/$1" ]; then
        echo "$DIR/$1"; break
      fi
    done
  fi
}

#
# Function to read input line and trap stdin errors (ie CTRL+D)
#
read_line() {
  read READLINE
  if [ $? = 0 ]; then
    STDIN_ERRORS=0
  else
    STDIN_ERRORS=`expr $STDIN_ERRORS + 1`
    if [ $STDIN_ERRORS -ge 64 ]; then
      echo "***ERROR*** Too many errors encountered. Assuming input device problems."
      exit 1
    fi
  fi
  eval $1="\"$READLINE\""
}

#
# Function to install "tar.bz2" files
#
install_tar_bz2() {
  case `uname` in
  AIX)
    UNPACKER=`ls -1t bzip2*/aix*/bzip2 2> /dev/null | head -1`;;
  HP-UX)
    if [ "`uname -m`" = "ia64" ]; then
      UNPACKER=`ls -1t bzip2*/hpux*/bzip2 2> /dev/null | grep itanium | head -1`
    else
      UNPACKER=`ls -1t bzip2*/hpux*/bzip2 2> /dev/null | grep -v itanium | head -1`
    fi
    ;;
  IRIX*)
    UNPACKER=`ls -1t bzip2*/irix*/bzip2 2> /dev/null | head -1`
    ;;
  Linux)
    case `uname -m` in
    ia64)
      UNPACKER=`ls -1t bzip2*/linux*/bzip2 2> /dev/null | grep itanium | head -1`
      ;;
    ppc*)
      UNPACKER=`ls -1t bzip2*/linux*/bzip2 2> /dev/null | grep pwr | head -1`
      ;;
    *)
      UNPACKER=`ls -1t bzip2*/linux*/bzip2 2> /dev/null | egrep -v "itanium|pwr" | head -1`
      ;;
    esac
    ;;
  OSF1)
    UNPACKER=`ls -1t bzip2*/osf1*/* 2> /dev/null | head -1`
    ;;
  SunOS)
    UNPACKER=`ls -1t bzip2*/sunos*/* 2> /dev/null | head -1`
    ;;
  esac
  if [ ! "$UNPACKER" ]; then
    UNPACKER=`which bzip2`
    if [ ! "$UNPACKER" ]; then
      echo "***ERROR*** Cannot find the \"bzip2\" compression/uncompression software."
      return 1
    fi
  fi
  cp $UNPACKER /tmp/bzip2-$MYUNAME.$$ 2> /dev/null
  UNPACKER=/tmp/bzip2-$MYUNAME.$$
  if [ "`check_disk /tmp`" ]; then
    $ECHO "\r***ERROR*** Unable to cache bzip2 executable. /tmp disk is full."
    rm -f $UNPACKER
    return 1
  fi
  case `uname` in
  Linux)
    ($UNPACKER -d < $1 | (cd $2; tar --no-same-owner -xf -)) 2>&1
    ;;
  IRIX*|OSF1)
    ($UNPACKER -d < $1 | (cd $2; tar xof -)) 2>&1 | grep -v "blocksize ="
    ;;
  *)
    ($UNPACKER -d < $1 | (cd $2; tar xof -)) 2>&1
    ;;
  esac
  rm -f $UNPACKER
}

#
# Function to install "tar.gz" files
#
install_tar_gz() {
  case `uname` in
  AIX)
    UNPACKER=`ls -1t gzip*/aix*/gzip 2> /dev/null | head -1`
    ;;
  HP-UX)
    if [ "`uname -m`" = "ia64" ]; then
      UNPACKER=`ls -1t gzip*/hpux*/gzip 2> /dev/null | grep itanium | head -1`
    else
      UNPACKER=`ls -1t gzip*/hpux*/gzip 2> /dev/null | grep -v itanium | head -1`
    fi
    ;;
  IRIX*)
    UNPACKER=`ls -1t gzip*/irix*/gzip 2> /dev/null | head -1`
    ;;
  Linux)
    case `uname -m` in
    ia64)
      UNPACKER=`ls -1t gzip*/linux*/gzip 2> /dev/null | grep itanium | head -1`
      ;;
    ppc*)
      UNPACKER=`ls -1t gzip*/linux*/gzip 2> /dev/null | grep pwr | head -1`
      ;;
    *)
      UNPACKER=`ls -1t gzip*/linux*/gzip 2> /dev/null | egrep -v "itanium|pwr" | head -1`
      ;;
    esac
    ;;
  OSF1)
    UNPACKER=`ls -1t gzip*/osf1*/* 2> /dev/null | head -1`
    ;;
  SunOS)
    UNPACKER=`ls -1t gzip*/sunos*/* 2> /dev/null | head -1`
    ;;
  esac
  if [ ! "$UNPACKER" ]; then
    UNPACKER=`which gzip`
    if [ ! "$UNPACKER" ]; then
      echo "***ERROR*** Cannot find the \"gzip\" compression/uncompression software."
      return 1
    fi
  fi
  cp $UNPACKER /tmp/gzip-$MYUNAME.$$ 2> /dev/null
  UNPACKER=/tmp/gzip-$MYUNAME.$$
  if [ "`check_disk /tmp`" ]; then
    $ECHO "\r***ERROR*** Unable to cache gzip executable. /tmp disk is full."; rm -f $UNPACKER
    return 1
  fi
  case `uname` in
  Linux)
    ($UNPACKER -d < $1 | (cd $2; tar --no-same-owner -xf -)) 2>&1
    ;;
  IRIX*|OSF1)
    ($UNPACKER -d < $1 | (cd $2; tar xof -)) 2>&1 | grep -v "blocksize ="
    ;;
  *)
    ($UNPACKER -d < $1 | (cd $2; tar xof -)) 2>&1
    ;;
  esac
  rm -f $UNPACKER
}

#
# Function to install files by tar copying
#
install_tar_copy() {
  cd `dirname $1`
  case `uname` in
  Linux)
    if [ "`tar --help 2>&1 | grep \" --no-same-owner\"`" ]; then
      tar cf - `basename $1` | (cd $2; tar --no-same-owner -xf -)
    else
      tar cf - `basename $1` | (cd $2; tar -xf -)
    fi
    ;;
  OSF1)
    tar cf - `basename $1` | (cd $2; tar -xf -) 2>&1 | grep -v "blocksize =";;
  *)
    tar cf - `basename $1` | (cd $2; tar xof -)
    ;;
  esac
}

#
# Function to install package
#
install_package() {
  case $1 in
  *.tar.bz2)
    UNPACK_ERROR=`install_tar_bz2 $1 $2`
    ;;
  *.tar.gz)
    UNPACK_ERROR=`install_tar_gz $1 $2`
    ;;
  *.tgz)
    UNPACK_ERROR=`install_tar_gz $1 $2`
    ;;
  *)
    UNPACK_ERROR=`install_tar_copy $1 $2`
    ;;
  esac
  echo "$UNPACK_ERROR"
}

#
# Menu system
#
menu_system() {
  if [ "`echo \"$OPTIONS\" | grep \"^Other$\"`" ]; then # Put Other last
    OPTIONS="`echo "$OPTIONS | grep -v '^Other$'`
`echo "$OPTIONS | grep '^Other$'`"
  fi
  while [ 1 ]; do
    NUMBER=0; echo "$1"
    echo "The following options can be toggled on or off by entering their numbers."
    echo "A keyword can be used to toggle any option that contains the keyword."
    echo "You may enter more than one option on the same line separated by a space."
    echo "In order to continue to the next stage you must select at least one option:"
    echo
    for OPTION in $OPTIONS; do
      NUMBER=`expr $NUMBER + 1`
      case $OPTION in
      +*)
        echo $NUMBER | awk '{printf (" %2d. [X] ",$1)}'
        echo $OPTION | cut -c2- | sed -e "s/_/ /g" -e "s/\/.*\// > /" -e "s/[.]tar$//"
        ;;
        # pw - previous line was as shown below, modified to show all 3 parts of a version number.
        # echo $OPTION | cut -c2- | sed -e "s/_/ /g" -e "s/\/.*\// > /" -e "s/[.][^.]*$//" -e "s/[.]tar$//";;
      *)
        echo $NUMBER | awk '{printf (" %2d. [ ] ",$1)}'
        echo $OPTION | sed -e "s/_/ /g" -e "s/\// > /" -e "s/\/.*\// > /" -e "s/[.]tar$//"
        ;;
        # pw - previous line was as shown below, modified to show all 3 parts of a version number.
        # echo $OPTION | sed -e "s/_/ /" -e "s/\/.*\// > /" -e "s/\// > /" -e "s/[.][^.]*$//" -e "s/[.]tar$//";;
      esac
    done
    echo "  A.     Select all options"
    echo "  U.     Unselect all options"
    echo
    $ECHO "Please enter your selection (X=Exit B=Back N=Next): \c"
    read_line SELECTIONS
    for SELECTION in `echo $SELECTIONS | sed "s/,/ /g"`; do
      case $SELECTION in
      [1-9]|[1-9][0-9]*)
        if [ "`echo "$OPTIONS" | tail +$SELECTION | head -1 | cut -c1`" = "+" ]; then
          OPTIONS=`echo "$OPTIONS" | sed -e "${SELECTION}s/^+//"`
        else
          OPTIONS=`echo "$OPTIONS" | sed -e "${SELECTION}s/^/+/"`
        fi
        ;;
      a|A)
        OPTIONS=`echo "$OPTIONS" | sed -e "s/^/+/" -e "s/^++/+/"`
        ;;
      u|U)
        OPTIONS=`echo "$OPTIONS" | sed -e "s/^+//"`
        ;;
      x|X)
        echo "Installation aborted!"; STAGE=-1; break 2
        ;;
      b|B)
        STAGE=`expr $STAGE - 1`; break 2;;
      n|N)
        if [ "`echo \"$OPTIONS\" | grep \"^+\"`" ]; then
          STAGE=`expr $STAGE + 1`; break 2
        else
          echo "***ERROR*** You MUST select at least one option."; break
        fi
        ;;
      [A-Za-z]?*)
        for SELECTION in `echo "$OPTIONS" | grep -in "$SELECTION" | cut -f1 -d":"`; do
          if [ "`echo "$OPTIONS" | tail +$SELECTION | head -1 | cut -c1`" = "+" ]; then
            OPTIONS=`echo "$OPTIONS" | sed -e "${SELECTION}s/^+//"`
          else
            OPTIONS=`echo "$OPTIONS" | sed -e "${SELECTION}s/^/+/"`
          fi
        done
        ;;
      esac
    done
  done
}

#
# Time in seconds (must pass reference time in seconds)
#
time_sec() {
  SEC=`date +'%H %M %S' | awk '{print $1*3600+($2*60)+$3}'`
  if [ $SEC -lt $1 ]; then
    expr $SEC + 86400 - $1
  else
    expr $SEC - $1
  fi
}

create_new_dir() {
  if [ -d "$INSTALL_DIR" ]; then
    echo
    echo "The installation directory:"
    echo "   $INSTALL_DIR"
    echo "already exists."
    echo
    $ECHO "Do you still want to use that directory? (Y=Yes N=No): \c"
    read_line DIR_EXISTS_ANS
    case $DIR_EXISTS_ANS in
      y|Y)
        return 1
        ;;
      n|N)
        return 0
        ;;
      *)
        return 0
    esac
  else
    mkdir -p $INSTALL_DIR 2> /dev/null
    if [ ! -d "$INSTALL_DIR" ]; then
      echo "***ERROR*** Unable to create installation directory. Please check permissions."
      return 0
    elif [ ! -w "$INSTALL_DIR" ]; then
      echo "***ERROR*** Unable to write in installation directory. Please check permissions."
      return 0
    else
      return 1
    fi
  fi
}

# === Functions End ===

CWD=`pwd`
if [ ! -f "$0" ]; then
  bash ./setup # Call self (avoids ". setup" problems)
elif [ "`PATH=/usr/bin/X11:$PATH; xwininfo -root 2> /dev/null | grep Depth:`" -a -x "$XTERM" -a ! "$NO_SETUP_GUI" ]; then
  NO_SETUP_GUI=1
  export NO_SETUP_GUI
  exec $XTERM $OPTION -e bash $0
else
  clear
  if [ ! -f setup -o ! -d Packages ]; then
    cd `dirname $0 2> /dev/null` 2> /dev/null
  fi
  if [ ! -f setup -o ! -d Packages ]; then
    echo "***ERROR*** The \"setup\" script MUST be run in its own directory"
    echo "Installation aborted!"
  elif [ ! "`ls -1 Packages/*/*/*.* 2> /dev/null`" ]; then
    echo "***ERROR*** No software packages found."
    echo "Installation aborted!"

#
# Show title banner (STAGE=0)
#
  else
    cd Packages
    NUMBER=0
    RESTORE_OPTIONS=
    if [ STAGE != 0 ]; then
      if [ -f setup.0 ]; then # Stage 0 plug-in
        . ./setup.0
      elif [ "`which more`" ]; then
        (show_title_banner) | more
      else
        show_title_banner
      fi
    fi
  fi
#
# Main loop
#
  while [ 1 ]; do
    STAGE=1; STDIN_ERRORS=0
    while [ $STAGE -gt 0 ]; do
      case $STAGE in
#
# Read installation directory (STAGE=1)
#
      1)
        echo "
**************************************
* INSTALLATION DIRECTORY (Stage 1/6) *
**************************************
"
        if [ -f setup.1 ]; then # Stage 1 plug-in
          . ./setup.1
        else
          echo "Please enter the path of the installation directory, you can use relative directories (X=Exit):"
          read_line INSTALL_DIR
          case $INSTALL_DIR in
          x|X)
            echo "Installation aborted!"; STAGE=-1;;
          /*)
            create_new_dir
            if [ "$?" -eq "1" ]; then
              STAGE=2
            fi
            ;;

          ~*)
            INSTALL_DIR=`eval echo $INSTALL_DIR`
            case $INSTALL_DIR in
              ~*)
                echo
                echo "Could not expand:"
                echo "$INSTALL_DIR"
                echo ""
                echo "Either the path is invalid or your shell does not support tilde expansion."
                echo " You can use .. notation or specify the path from the root."
                echo ""
                $ECHO "Press [Enter] to continue: \c"
                read_line DIR_ANS
                ;;
              *)
                echo
                echo "You entered a relative path, is this the correct full path:"
                echo "  $INSTALL_DIR"
                echo
                $ECHO "Do you want to continue? (Y=Yes N=No X=Exit): \c"
                read_line DIR_ANS
                case $DIR_ANS in
                  y|Y)
                    create_new_dir
                    if [ "$?" -eq "1" ]; then
                      STAGE=2
                    fi
                    ;;
                  x|X)
                    echo "Installation aborted!"
                    STAGE=-1
                    ;;
                esac
            esac
            ;;


          ..*)
            CUR_DIR=`pwd`
            DONE=0
            cd $CWD
            while [ "$DONE" = "0" ]; do
              cd ..
              INSTALL_DIR=`echo $INSTALL_DIR | sed -e "s/..\///"`
              case $INSTALL_DIR in
                ..*)
                  DONE=0
                  ;;
                *)
                  TMP_DIR=`pwd`
                  cd $CUR_DIR
                  INSTALL_DIR=$TMP_DIR/$INSTALL_DIR
                  DONE=1
                  ;;
              esac
            done
            echo
            echo "You entered a relative path, is this the correct full path:"
            echo "  $INSTALL_DIR"
            echo
            $ECHO "Do you want to continue? (Y=Yes N=No X=Exit): \c"
            read_line DIR_ANS
            case $DIR_ANS in
              y|Y)
                create_new_dir
                if [ "$?" -eq "1" ]; then
                  STAGE=2
                fi
                ;;
              x|X)
                echo "Installation aborted!"
                STAGE=-1
                ;;
            esac
            ;;

          *)
            #CUR_DIR=`pwd`
            INSTALL_DIR=$CWD/$INSTALL_DIR
            echo
            echo "You entered a relative path, is this the correct full path:"
            echo "  $INSTALL_DIR"
            echo
            $ECHO "Do you want to continue? (Y=Yes N=No X=Exit): \c"
            read_line DIR_ANS
            case $DIR_ANS in
              y|Y)
                create_new_dir
                if [ "$?" -eq "1" ]; then
                  STAGE=2
                fi
                ;;
              x|X)
                echo "Installation aborted!"
                STAGE=-1
                ;;
            esac
            ;;
          esac
        fi
        ;;

#
# Software menu (STAGE=2)
#
      2)
        TITLE="
**************************************
* SOFTWARE SELECTION     (Stage 2/6) *
**************************************
"
        STAGE2_SKIP=
        if [ "$RESTORE_OPTIONS" ]; then
          OPTIONS="$RESTORE_OPTIONS"; RESTORE_OPTIONS=
        else
          OPTIONS=`ls -1 */*/*.* 2> /dev/null | cut -f1 -d"/" | sort | uniq`
        fi
        if [ -f setup.2 ]; then # Stage 2 plug-in
          echo "$TITLE"
          . ./setup.2
          if [ "$STAGE" != 2 ]; then
            continue
          fi
        fi
        if [ "`echo \"$OPTIONS\" | wc -l | awk '{print $1}'`" = 1 ]; then
          echo "$TITLE"
          echo "Automatically selecting the only software available."
          SOFTWARES="+$OPTIONS"
          STAGE=3
          STAGE2_SKIP=1
        else
          menu_system "$TITLE"
          SOFTWARES="$OPTIONS"
        fi
        ;;

#
# Platform menu (STAGE=3)
#
      3)
        TITLE="
**************************************
* PLATFORMS SELECTION    (Stage 3/6) *
**************************************
"
        STAGE3_SKIP=
        if [ "$RESTORE_OPTIONS" ]; then
          OPTIONS="$RESTORE_OPTIONS"; RESTORE_OPTIONS=
        else
          OPTIONS=`ls -1d \`echo "$SOFTWARES" | grep "^+" | cut -c2- | sed -e "s/$/\/*\/*.*/"\` 2> /dev/null | grep -v "/Shared/" | grep -v "/Common/" | cut -f2 -d"/" | sort | uniq`
        fi
        if [ -f setup.3 ]; then # Stage 3 plug-in
          echo "$TITLE"
          . ./setup.3
          if [ "$STAGE" != 3 ]; then
            continue
          fi
        fi
        OPTIONCOUNT=`echo \"$OPTIONS\" | wc -w | awk '{print $1}'`

        # some debugging
        #echo "softwares:"
        #echo "$SOFTWARES"
        #echo "options:"
        #echo "$OPTIONS"
        #echo "option count:$OPTIONCOUNT"

        if [ ! "$OPTIONS" ]; then
          echo "$TITLE"
          echo "Platform selection not required."
          PLATFORMS=
          STAGE=4
        elif [ "$OPTIONCOUNT" = 1 ]; then
          echo "$TITLE"
          echo "Automatically selecting $OPTIONS as the only platform available."
          PLATFORMS="+$OPTIONS"
          STAGE=4
          STAGE3_SKIP=1
        else
          menu_system "$TITLE"
          PLATFORMS="$OPTIONS"
          if [ "$STAGE" = 2 ]; then
            RESTORE_OPTIONS="$SOFTWARES"
            if [ "$STAGE2_SKIP" ]; then
              STAGE=1
            fi
          fi
        fi
        ;;
#
# Package menu (STAGE=4)
#
      4)
        OPTIONS=
        #echo "softwares:$SOFTWARES"
        for CODE in `echo "$SOFTWARES" | grep "^+" | cut -c2-`; do
          for ARCH in Common `echo "$PLATFORMS" | grep "^+" | cut -c2-`; do
            OPTIONS="$OPTIONS
+`ls -1 $CODE/$ARCH/*.* 2> /dev/null`"
          done
        done
        OPTIONS=`echo "$OPTIONS" | grep -v "^$"`
        PACKAGES="$OPTIONS"
        STAGE=5
        ;;

#
# Installation confirmation (STAGE=5)
#
      5)
        echo "
**************************************
* CONFIRMATION  (Stage 4/6)          *
**************************************
"
        echo "The selected software will install the following files into the following directories:"
        echo
        SOURCES=`echo "$PACKAGES" | grep "^+" | cut -c2-`

        # some debugging stuff
        #echo "packages:$PACKAGES"
        #echo "sources:$SOURCES"

        # Shared start
        SHARED=`ls -1 Shared/* 2> /dev/null`
        for SOFTWARE in `echo "$PACKAGES" | cut -c2- | cut -f1 -d"/" | sort | uniq`; do
          SHARED="$SHARED
  `ls -1 $SOFTWARE/Shared/* 2> /dev/null`"
        done
        if [ "`echo \"$SHARED\" | grep -v \"^$\"`" ]; then
          SOURCES="`echo \"$SHARED\" | grep -v \"^$\"`
$SOURCES"
        fi
       # Shared end

        SOURCES_OK=
        TARGET_DIRS=
        PACKAGES_EXIST=
        PACKAGES_ERROR=
        for SOURCE in $SOURCES; do
          if [ -f setup.5 ]; then # Stage 5 plug-in
            . ./setup.5
          else
            TARGET_DIR=`echo $SOURCE | sed -e "s@^Shared/@@" -e "s/\/.*\//\//" -e "s@-@/@" -e "s/[.][^.]*$//" -e "s/[.]tar$//"`
          fi

          # some debugging stuff
          #echo "in sources loop, source:$SOURCE"
          #echo "in sources loop, install directory:$INSTALL_DIR"
          #echo "in sources loop, target directory:$TARGET_DIR"

          SW=`echo $SOURCE | sed -e "s/\(.*\)\/.*\/.*/\1/" | sed -e "s/_/ /g"`
          FILE=`echo $SOURCE | sed -e "s/.*\/.*\/\(.*\)/\1/"`
          SHARED=
          if [ `echo "$SOURCE" | grep "Shared"` ]; then
            SHARED="shared file "
          fi
          echo "$SW will install $SHARED$FILE to:"
          echo "   $INSTALL_DIR$TARGET_DIR"
          echo
          TARGET_DIRS="$TARGET_DIRS$TARGET_DIR " # List of all target directories used
          if [ -d $INSTALL_DIR$TARGET_DIR ]; then
            if [ "`chmod -R u+w $INSTALL_DIR$TARGET_DIR 2>&1`" ]; then
              PACKAGES_ERROR="$PACKAGES_ERROR
$INSTALL_DIR$TARGET_DIR"
            else
              case $TARGET_DIR in
              */*)
                PACKAGES_EXIST="$PACKAGES_EXIST
$INSTALL_DIR$TARGET_DIR"
                SOURCES_OK="$SOURCES_OK$SOURCE ";;
              *)
                SOURCES_OK="$SOURCES_OK$SOURCE ";;
              esac
            fi
          else
            SOURCES_OK="$SOURCES_OK$SOURCE "
          fi
        done
        if [ "$PACKAGES_EXIST" ]; then
          echo "
***WARNING*** The following installation directories already exist:
$PACKAGES_EXIST

Please E(x)it and correct this if those directories should not be used.
"
        fi
        if [ "$PACKAGES_ERROR" ]; then
          echo "
***ERROR*** The following installation directories cannot be over-written.
$PACKAGES_ERROR

Please E(x)it and correct this if those directories should not be used."
        fi
        echo
#echo "sources ok:$SOURCES_OK"
#echo "target directories:$TARGET_DIRS"
        $ECHO "The next stage will start the installation process (X=Exit B=Back N=Next): \c"
        read_line SELECTION
        case $SELECTION in
        x|X)
          echo "Installation aborted!"; STAGE=-1;;
        b|B)
#          STAGE=3; RESTORE_OPTIONS="$PACKAGES"
#          if [ "$STAGE4_SKIP" ]; then
            STAGE=3; RESTORE_OPTIONS="$PLATFORMS"
            if [ ! "$PLATFORMS" -o "$STAGE3_SKIP" ]; then
              STAGE=2; RESTORE_OPTIONS="$SOFTWARES"
              if [ "$STAGE2_SKIP" ]; then
                STAGE=1
              fi
            fi;;
#          fi;;
        n|N)
          STAGE=6;;
        esac;;
#
# Installation process (STAGE=6)
#
      6)
        echo "
**************************************
* INSTALLATION PROCESS   (Stage 5/6) *
**************************************
"
        echo "Please wait. The installation process can take a few minutes..."
        WORK_TOTAL=`expr \`echo \\\`ls -l $SOURCES_OK | awk '{print $5}'\\\` | sed -e "s/ / + /g"\``
        WORK_DONE=0; TIME_INIT=`time_sec 0`
        INSTALL_ERROR=

        # some debugging stuff
        #echo "sources ok:$SOURCES_OK"

        for SOURCE in $SOURCES_OK; do
          SOURCE_FILE=`echo $SOURCE | sed -e "s/.*\/.*\/\(.*\)/\1/"`
          TARGET_DIR=`echo $SOURCE | sed -e "s@^Shared/@@" -e "s/\/.*\//\//" -e "s@-@/@" -e "s/[.][^.]*$//" -e "s/[.]tar$//"`
          if [ -f setup.6 ]; then # Stage 6 plug-in
            . ./setup.6
          fi
          $ECHO "\r$SOURCE_FILE..."
          mkdir -p $INSTALL_DIR/$TARGET_DIR 2> /dev/null
          if [ "`check_disk $INSTALL_DIR/$TARGET_DIR`" ]; then
            $ECHO "\r***ERROR*** Unable to create directory. Installation disk is full."
            echo "Installation failed!"; STAGE=0; break 2
          fi
          TIME_USED=`time_sec $TIME_INIT`
          if [ $TIME_USED != 0 -a $WORK_DONE != 0 ]; then
            if [ $WORK_DONE -le 1048576 ]; then # Estimates are inaccurate for less than 1MB of packages installed
              echo $WORK_TOTAL $WORK_DONE $TIME_USED | awk '{printf ("  %2d%% completed in %2d min %2d sec.  Estimated Time Left:?min ?sec. (updated after each file copy > 1MB)",$2/$1*100,$3/60+0.5,$3%60)}'
            else
              echo $WORK_TOTAL $WORK_DONE $TIME_USED | awk '{printf ("  %2d%% completed in %2d min %2d sec.  Estimated Time Left:%2dmin %2dsec.  (updated after each file copy > 1MB)",$2/$1*100,$3/60+0.5,$3%60,($1-$2)/($2*60)*$3+0.5,(($1-$2)/$2*$3)%60)}'
            fi
          else
            $ECHO "  0.00% completed in 0min 0sec.  Estimated Time Left: ? min ? sec (updated after each file copy > 1MB)\c"
          fi
          #$ECHO "\nsource: $SOURCE\ninstall directory:$INSTALL_DIR\ntarget directory: $TARGET_DIR\n"
          UNPACK_ERROR=`install_package $SOURCE $INSTALL_DIR/$TARGET_DIR`
          WORK_DONE=`expr $WORK_DONE + \`ls -l $SOURCE | awk '{print $5}'\``
          $ECHO "\r                                                                                                              \r\c" # 2 chars more than printout
          if [ "$UNPACK_ERROR" ]; then
            echo "$UNPACK_ERROR" | sed -e "s/^/***ERROR*** /"
            INSTALL_ERROR=1
          fi
          if [ "`check_disk $INSTALL_DIR/$TARGET_DIR`" ]; then
            $ECHO "\r***ERROR*** Package installation error. Installation disk is full."
            echo "Installation failed!"
            STAGE=0
            break 2
          fi
        done
        TIME_USED=`time_sec $TIME_INIT`
        echo $TIME_USED | awk '{printf ("  100.00%% completed in %2d min %2d sec.\n",$1/60+0.5, $1%60)}'
        echo
        echo "Installation completed!"

        export SOFTWARES PLATFORMS PACKAGES # For setup plugins to use
        echo "
**************************************
* POST INSTALLATION      (Stage 6/6) *
**************************************
"
        #echo "softwares:"
        #echo "$SOFTWARES"
        for SOFTWARE in `echo "$SOFTWARES" | grep "^+" | cut -c2-`; do
          #echo "in loop, software:$SOFTWARE"
          TARGET_DIRTOP=`echo $SOFTWARE | sed -e "s@-@/@"`
          #echo "in loop, target directory top:$TARGET_DIRTOP"
          if [ -d "$INSTALL_DIR/$TARGET_DIRTOP" ]; then
            if [ -f $SOFTWARE/README ]; then
              cp $SOFTWARE/README $INSTALL_DIR/$TARGET_DIRTOP/README 2> /dev/null
            fi
            if [ -f $SOFTWARE/setup ]; then
              #echo "Running \"Packages/$SOFTWARE/setup\"..."
              /bin/bash $SOFTWARE/setup $INSTALL_DIR/$TARGET_DIRTOP
            fi
            if [ "$INSTALL_ERROR" ]; then
              $ECHO "\r***ERROR*** One or more of the selected packages failed to install."
              echo "Installation failed!"; STAGE=0; break 2
            fi
            if [ "`check_disk $INSTALL_DIR/$TARGET_DIRTOP`" ]; then
              $ECHO "\r***ERROR*** README file write error. Installation disk is full."
              echo "Installation failed!"; STAGE=0; break 2
            fi
          fi
        done
        if [ -f README ]; then
          cp README $INSTALL_DIR/README 2> /dev/null
          chmod u+w $INSTALL_DIR/README
        fi
        if [ -f setup ]; then
          #echo "Running \"Packages/setup\"..."
          /bin/bash setup $INSTALL_DIR # Packages/setup
        fi
        echo "DONE!"; STAGE=0;;
      esac
    done
    while [ 1 ]; do
      echo
      $ECHO "Please enter your selection (R=Restart C=Close): \c"
      read_line SELECTION
      case $SELECTION in
      r|R)
        break;;
      c|C)
        break 2;;
      esac
    done
  done
fi



其实把ub自带的sh软链接删掉,链到bash上也可以


页首
 用户资料  
 
8 楼 
 文章标题 : Re: 请教怎样把只能在红帽系统上运行的脚本移植到ubuntu上?
帖子发表于 : 2009-11-11 9:47 

注册: 2009-10-11 22:47
帖子: 28
送出感谢: 0 次
接收感谢: 0 次
多谢楼上的帮忙,这个脚本改了之后不提示错误了,但是变成了一闪而过,什么提示都没有了。。。。。。还是不能正常运行 :em20


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 8 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译