zoukankan      html  css  js  c++  java
  • 『BASH』——Learn BashScript from Daniel Robbins——[003]

    ABSTRACT:

      Daniel Robbins is best known as the creator of Gentoo Linux and author of many IBM developerWorks articles about Linux. Daniel currently serves as Benevolent Dictator for Life (BDFL) of Funtoo Linux. Funtoo Linux is a Gentoo-based distribution and continuation of Daniel's original Gentoo vision.


    Section 3

    Operation logic of the original version of Portage(a package manager used by Gentoo,Funtoo,etc.)


    ebuild.conf: 

    1 # /etc/ebuild.conf:set system-wide ebuild options in this file
    2 # MAKEOPTS are options passed to make
    3 MAKEOPTS="-j2" 

    package.ebuild:

    1 #this ebuild file overrides the default user_compile()
    2 P=e2fsprogs-1.18
    3 A=${P}.tar.gz
    4 user_compile() {
    5   ./configure --enable-elf-shlibs
    6 make
    7 }  #e2fsprogs.ebuild

    ebuild:

     1 #!/usr/bin/env bash
     2 if [ $# -ne 2 ]
     3 then
     4   echo "Please specify ebuild file and unpack, compile or all"
     5 exit 1
     6 fi
     7 source /etc/ebuild.conf
     8 if [ -z "$DISTDIR" ]
     9 then
    10 # set DISTDIR to /usr/src/distfiles if not already set
    11   DISTDIR=/usr/src/distfiles
    12 fi
    13 export DISTDIR
    14 ebuild_unpack() {
    15   #make sure we're in the right directory
    16   cd ${ORIGDIR}
    17 if [ -d ${WORKDIR} ]
    18 then
    19   rm -rf ${WORKDIR}
    20 fi
    21 mkdir ${WORKDIR}
    22 cd ${WORKDIR}
    23 if [ ! -e ${DISTDIR}/${A} ]
    24 then
    25   echo "${DISTDIR}/${A} does not exist. Please download first."
    26 exit 1
    27 fi
    28 tar xzf ${DISTDIR}/${A}
    29 echo "Unpacked ${DISTDIR}/${A}."
    30 #source is now correctly unpacked
    31 }
    32 user_compile()
    33 {
    34 #we're already in ${SRCDIR}
    35 if [ -e configure ]
    36 then
    37 #run configure script if it exists
    38   ./configure --prefix=/usr
    39 fi
    40   #run make
    41   make $MAKEOPTS MAKE="make $MAKEOPTS"
    42 }
    43 ebuild_compile() {
    44 if [ ! -d "${SRCDIR}" ]
    45 then
    46   echo "${SRCDIR} does not exist -- please unpack first."
    47 exit 1
    48 fi
    49 #make sure we're in the right directory
    50 cd ${SRCDIR}
    51 user_compile
    52 }
    53 export ORIGDIR=`pwd`
    54 export WORKDIR=${ORIGDIR}/work
    55 if [ -e "$1" ]
    56 then
    57   source $1
    58 else
    59   echo "Ebuild file $1 not found."
    60 exit 1
    61 fi
    62 export SRCDIR=${WORKDIR}/${P}
    63 case "${2}" in
    64   unpack)
    65     ebuild_unpack ;;
    66   compile)
    67     ebuild_compile ;;
    68   all)
    69     ebuild_unpack ebuild_compile ;;
    70   *)
    71     echo "Please specify unpack, compile or all as the second arg"
    72     exit 1 ;;
    73 esac

    REFERENCES:

    • http://www.funtoo.org/Bash_by_Example,_Part_1
    • http://www.funtoo.org/Bash_by_Example,_Part_2
    • http://www.funtoo.org/Bash_by_Example,_Part_3
    • http://www.jb51.net/article/51342.htm
  • 相关阅读:
    windows下phpunit installing[转]
    一个简单的文件后缀获取——不是通过文件名,而是文件内容
    二进制加法
    收藏一个韩国棒子的未知高度居中方法
    带超时+POST/GET方式的获取远程文件,利用file_get_contents
    较深度地递归转义过滤
    利用单元测试在每个层上对 PHP 代码进行检查[转IBM]
    提取TP的一个格式化为json的针对的原始类型函数
    分享一个正则方式的UTF8/GBK中文切割
    NewBaldwinFlash的登场(稍简单的DNN模块)
  • 原文地址:https://www.cnblogs.com/hadex/p/5720771.html
Copyright © 2011-2022 走看看