自己写的一个linux下的bash安装

    每次安装linux下的包的时候都要一个个config make make install安装,烦,抽了个空,查了些资料,写了个bash安装脚本,分别安装了openldapujs、freeradiusujs及checkuserujs包,安装时只需./install.sh即可,这三个包放在与install同一个目录下的work目录夹里。安装的配置在jsradius.ebuild中。
install.sh
 
#!/usr/bin/env bash
 
CONF="jsradius.ebuild"
if [ ! -e $CONF ]
then
    echo "Can't find ujsradius.ebuild."
    exit 1
fi
 

if [ $# -ne 1 ]
then
    echo "Only one Parameter is permitted."
    exit 1
fi
 
source $CONF
 
export ORIGDIR=`pwd`
export WORKDIR=${ORIGDIR}/work
export SRCDIR1=${WORKDIR}/${P1}
export SRCDIR2=${WORKDIR}/${P2}
export SRCDIR2=${WORKDIR}/${P3}
 
ebuild_unpack() {
    #make sure we're in the right directory
    cd ${ORIGDIR}
 
    if [ -d ${WORKDIR} ]
    then
        rm -rf ${WORKDIR}
    fi
 
    mkdir ${WORKDIR}
    cd ${WORKDIR}
    if [ ! -e ${ORIGDIR}/${A1} ]
    then
        echo "${ORIGDIR}/${A1} does not exist.  Please download first."
        exit 1
    fi
    tar xzf ${ORIGDIR}/${A1}
    echo "Unpacked ${ORIGDIR}/${A1}."
    if [ ! -e ${ORIGDIR}/${A2} ]
    then
        echo "${ORIGDIR}/${A2} does not exist.  Please download first."
        exit 1
    fi
    tar xzf ${ORIGDIR}/${A2}
    echo "Unpacked ${ORIGDIR}/${A2}."
    if [ ! -e ${ORIGDIR}/${A3} ]
    then
        echo "${ORIGDIR}/${A3} does not exist.  Please download first."
        exit 1
    fi
    tar xzf ${ORIGDIR}/${A3}
    echo "Unpacked ${ORIGDIR}/${A2}."
 
    #source is now correctly unpacked
}
 
ebuild_compile() {
    if [ ! -d "${SRCDIR1}" ]
    then
        echo "${SRCDIR1} does not exist -- please unpack first."
        exit 1
    fi
    #make sure we're in the right directory
    cd ${SRCDIR1}
    user_compile_ldap
    if [ ! -d "${SRCDIR2}" ]
    then
        echo "${SRCDIR2} does not exist -- please unpack first."
        exit 1
    fi
    #make sure we're in the right directory
    cd ${SRCDIR2}
    user_compile_radius
    if [ ! -d "${SRCDIR3}" ]
    then
        echo "${SRCDIR3} does not exist -- please unpack first."
        exit 1
    fi
    #make sure we're in the right directory
    cd ${SRCDIR3}
    user_compile_checkuser
}
 
case "${1}" in
    unpack)
        ebuild_unpack
        ;;
    compile)
        ebuild_compile
        ;;
    install)
        ebuild_install
        ;;
    all)
        ebuild_unpack
        ebuild_compile
        ebuild_install
        ;;
    *)
        echo "Please specify unpack, compile, install or all as the parameter"
        exit 1
        ;;
esac
jsradius.ebuild
#jsradius ebuild conf write by cz_hyf
MAKEOPTS="-j2"
P1=openldapujs-2.0.25
P2=freeradiusujs-0.8.1
P3=checkuserujs-1.0
A1=${P1}.tar.gz
A2=${P2}.tar.gz
A3=${P3}.tar.gz
 
user_compile_ldap() {
 
        if [ -e configure ]
        then
                ./configure
                ./make depend
        fi
        make $MAKEOPTS MAKE="make $MAKEOPTS"
}
 
user_compile_radius() {
 
        if [ -e configure ]
        then
                ./configure
        fi
        make $MAKEOPTS MAKE="make $MAKEOPTS"
}
 
user_compile_checkuser() {
 
        if [ -e configure ]
        then
                ./configure
        fi
        make $MAKEOPTS MAKE="make $MAKEOPTS"
 
}
install
 
#!/usr/bin/env bash
 
CONF="ujsradius.ebuild"
if [ ! -e $CONF ]
then
    echo "Can't find ujsradius.ebuild."
    exit 1
fi
 

if [ $# -ne 1 ]
then
    echo "Only one Parameter is permitted."
    exit 1
fi
 
source $CONF
 
export ORIGDIR=`pwd`
export WORKDIR=${ORIGDIR}/work
export SRCDIR1=${WORKDIR}/${P1}
export SRCDIR2=${WORKDIR}/${P2}
export SRCDIR2=${WORKDIR}/${P3}
 
ebuild_unpack() {
    #make sure we're in the right directory
    cd ${ORIGDIR}
 
    if [ -d ${WORKDIR} ]
    then
        rm -rf ${WORKDIR}
    fi
 
    mkdir ${WORKDIR}
    cd ${WORKDIR}
    if [ ! -e ${ORIGDIR}/${A1} ]
    then
        echo "${ORIGDIR}/${A1} does not exist.  Please download first."
        exit 1
    fi
    tar xzf ${ORIGDIR}/${A1}
    echo "Unpacked ${ORIGDIR}/${A1}."
    if [ ! -e ${ORIGDIR}/${A2} ]
    then
        echo "${ORIGDIR}/${A2} does not exist.  Please download first."
        exit 1
    fi
    tar xzf ${ORIGDIR}/${A2}
    echo "Unpacked ${ORIGDIR}/${A2}."
    if [ ! -e ${ORIGDIR}/${A3} ]
    then
        echo "${ORIGDIR}/${A3} does not exist.  Please download first."
        exit 1
    fi
    tar xzf ${ORIGDIR}/${A3}
    echo "Unpacked ${ORIGDIR}/${A2}."
 
    #source is now correctly unpacked
}
 
ebuild_compile() {
    if [ ! -d "${SRCDIR1}" ]
    then
        echo "${SRCDIR1} does not exist -- please unpack first."
        exit 1
    fi
    #make sure we're in the right directory
    cd ${SRCDIR1}
    user_compile_ldap
    if [ ! -d "${SRCDIR2}" ]
    then
        echo "${SRCDIR2} does not exist -- please unpack first."
        exit 1
    fi
    #make sure we're in the right directory
    cd ${SRCDIR2}
    user_compile_radius
    if [ ! -d "${SRCDIR3}" ]
    then
        echo "${SRCDIR3} does not exist -- please unpack first."
        exit 1
    fi
    #make sure we're in the right directory
    cd ${SRCDIR3}
    user_compile_checkuser
}
 
case "${1}" in
    unpack)
        ebuild_unpack
        ;;
    compile)
        ebuild_compile
        ;;
    install)
        ebuild_install
        ;;
    all)
        ebuild_unpack
        ebuild_compile
        ebuild_install
        ;;
    *)
        echo "Please specify unpack, compile, install or all as the parameter"
        exit 1
        ;;
esac
参考资料: http://www-128.ibm.com/developerworks/cn/linux/shell/bash/bash-1/index.html

你可能感兴趣的:(linux,user,脚本,bash,download)