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
  • 相关阅读:
    net core 2 读取appsettings.json
    转: C# 根据当前时间获取,本周,本月,本季度等时间段 .Net中Exception
    转:5种回到顶部的写法从实现到增强
    转:jQuery 常见操作实现方式
    NLog 自定义字段 写入 oracle
    转:C# 使用NLog记录日志
    转:NLog之:文件类型目标(File target)
    springboot2.x+jwt+shiro最简单、最快速整合方式
    windows部署mindoc
    docker安装mongodb
  • 原文地址:https://www.cnblogs.com/hadex/p/5720771.html
Copyright © 2011-2022 走看看