Crane
Table_bottom

Search
Loading
Table_bottom

分类
Table_bottom

随机文章
Table_bottom

标签云
Table_bottom

最新评论
Table_bottom

链接
Table_bottom

功能
Table_bottom

打造ArchLinux下的类apt-get source工具

Crane posted @ 2011年5月13日 00:04 in Linux with tags ArchLinux linux abs , 17212 阅读

首先广告一下,Arch Linux 是我用过的最喜欢的一个Linux发行版,它是一个滚动升级模式的i686/x86-64 Linux发行版,它的开发注重于系设计简洁、结构优雅、代码 准确、体验新潮的完美权衡。它给你一个最小的系统,但是提供很强大的包管理,从而你可以自由的构建一个理想的系统,它的包管理强大之处在于它有两套包管理系统,一个是基于pacman的二进制包管理系统,类似ubuntu下的apt-get 系统,使用官方仓库,提供大量打包好的软件包可供直接使用,另外一个就是全功能的类ports的ABS(Arch Build System)软件包管理系统,类似gentoo的emerge系统,可以很方便的从源码构建软件,而且构建出来的软件也纳入pacman的包管理系统,这样就可以方便的缷载软件,避免了最普通的configure&&make&&make install这一种从源码构建方式不易缷载的问题。ABS实际上维护了一个PKGBUILD文件集合,其中每个PKGBUILD文件对应一个软件,可以使用makepkg命令来通过PKGBUILD构建软件。ABS其中的软件包是社区维护用户的,任何人都可以提交可以构建软件的PKGBUILD,从而形成了一个非常巨大的仓库,这个仓库就叫AURArch Linux User-community Repository)。

很多人习惯了用apt-get source来下载一个软件的源码包,但是pacman却没有直接提供这样的功能,显得有些不便,其实ArchLinux把包源码相关的事都交给ABS去做了,下载源码可以通过abs命令及其它的命令组合来完成,稍显麻烦,所以写了一个脚本进行了包装,实现把源码下载到当前目录的功能,同时也把下载好的源码包解开,同时打上patch(如果有的话)。

#!/bin/sh
# This script is used for downloading package source tarball under Archlinux,  just like apt-get source pkg in ubuntu.

#make sure abs is installed
pacman -Q abs >/dev/null 2>&1
if [ $? -ne 0 ];then
    echo "abs is not installed."
    echo "installing abs..."
    if [ `whoami` == "root" ];then
        pacman -S abs 
        abs -t
    else
        sudo pacman -S abs 
        if [ $? -ne 0 ];then
            exit
        fi  
        sudo abs -t
    fi  
fi

#geting source through the PKGBUILD file
find /var/abs -type d -name $1 -exec cp -a {} /tmp/ \;
if [  -d /tmp/$1 ];then
    echo package found.
else
    echo package not found.
    exit
fi
pushd /tmp/$1 >/dev/null 2>&1
sed -i 's:\./configure.*$:exit:' PKGBUILD
makepkg
popd >/dev/null 2>&1
cp -a /tmp/$1/src ./$1 >/dev/null 2>&1




脚本原理就是利用abs得到AUR中的软件的PKGBUILD,然后修改一下PKGBUILD从而让makepkg只做下载源码包并解开和打补丁的工作,在配置和编译前停下来,这样就得到了需要的软件包的源码。

dark 说:
2011年12月06日 20:50

修正一下楼主的代码:

 

#!/bin/bash
# This script is used for downloading package source tarball under Archlinux,  just like apt-get source pkg in ubuntu.
 
#make sure abs is installed
pacman -Q abs >/dev/null 2>&1
if [ $? -ne 0 ];then
    echo "abs is not installed."
    echo "installing abs..."
    if [ `whoami` == "root" ];then
        pacman -S abs 
        abs -t
    else
        sudo pacman -S abs 
        if [ $? -ne 0 ];then
            exit
        fi 
        sudo abs -t
    fi 
fi
 
#geting source through the PKGBUILD file
find /var/abs -type d -name $1 -exec cp -a {} /tmp/ \;
if [  -d /tmp/$1 ];then
    echo package found.
else
    echo package not found.
    exit
fi
pushd /tmp/$1 >/dev/null 2>&1
sed -i 's:\./configure.*$:exit:' PKGBUILD
makepkg -od --asroot
dark 说:
2011年12月06日 21:11

美化一下,捎带着增加一个人性化功能,将源码统一下载到~/Source目录中:

 

<pre class="brush: bash" title="pkgsrc">
 
#!/bin/bash
# This script is used for downloading package source tarball under Archlinux,  just like apt-get source pkg in ubuntu.
 
#make sure abs is installed
pacman -Q abs >/dev/null 2>&1
if [ $? -ne 0 ];then
    echo "abs is not installed."
    echo "installing abs..."
    if [ `whoami` == "root" ];then
        pacman -S abs
        abs -t
    else
        sudo pacman -S abs
        if [ $? -ne 0 ];then
            exit
        fi
        sudo abs -t
    fi
fi
 
#geting source through the PKGBUILD file
find /var/abs -type d -name $1 -exec cp -a {} /tmp/ \;
if [  -d /tmp/$1 ];then
    echo package found.
else
    echo package not found.
    exit
fi
pushd /tmp/$1 >/dev/null 2>&1
#sed -i 's:\./configure.*$:exit:' PKGBUILD
makepkg -od --asroot
popd >/dev/null 2>&1
#cp -a /tmp/$1/src ./$1 >/dev/null 2>&1
mkdir -p ~Source/$1
cp -a /tmp/$1/src/* ~/Source/$1
 
</pre>
dark 说:
2011年12月06日 21:13

郁闷了 回复中不能使用代码样式表啊。。。 楼主改天整理一下吧

Avatar_small
Crane 说:
2011年12月16日 17:04

@dark: 谢谢回复
makepkg的参数asroot是给root用的,这个脚本要让普通用户也能用。
另外关于od参数,我之前也考虑过,d参数可以加上去,o的话之所以没加是因为对于一般的包不做build可以达到效果,但是对于要用版本控制工具拉取源代码的程序来说,就不行,比如vim的拉取代码就是在build()中做的,用o参数就完全得不到源码。
关于源代码放到哪的问题,就是个人习惯了,的确放在一个统一的地方比较整齐,只是我个人随手写成当前文件夹

home cleaning servic 说:
2022年5月18日 02:57

Based on the National Start of Allergic reaction and Infectious Illnesses (NIAID), approximately 1 billion colds tend to be reported each year in the usa alone. The Middle for Illness Control reviews that children miss regarding 22 zillion school days each year because of the common chilly. DIALAMAID strives to lessen this quantity by helping a large number of families in the united states live solution, healthier life.

cleaning services 说:
2022年5月18日 02:57

Let’s are up against it – any oven is actually through quite a lot. While various models experience self-cleaning alternate options, they don’t make a thorough sparkling. Our high quality house cleaners can get done the work from the self-cleaning oven thereafter some. We’re confident that we all can remove many of the residue and additionally grime within your valuable item of equipment.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter