zoukankan      html  css  js  c++  java
  • 自动打包脚本

    #!/bin/bash
    #descript: auto make iso Script
    #date: 20160701
    #function area
    #<---------------------start---------------------------------------->
    #function: check error
    function_runcheck(){
        if [ $1 != 0 ];then
            echo "------------------------"
            echo "|Error,please check log|"
            echo "------------------------"
            exit 1
        fi
    }
    #function: auto color
    function_color(){
        if [ "$2" == "red" ];then
            echo -e "[33[40;31m $1 33[0m]"
        fi
    
        if [ "$2" == "green" ];then
            echo -e "[33[40;32m $1 33[0m]"
        fi
    }
    #function: show info
    #function_showInfo(){
    #
    #}
    #function: log  time for create this iso
    function_create_version(){
        echo "create time at `date +%Y_%m_%d %H:%M:%S`" > /home/version
    }
    #function: create a new.comps.xml.gz by iso source
    function_create_comps(){
        cd $ISODIR
        echo "create a new.comps.xml.gz by iso source"
        cp -a /SHIXUN/source/comps.xml $ISODIR
        createrepo -g $ISODIR/comps.xml  $ISODIR
        declare -x discinfo=`head -1 .discinfo`
        createrepo -u "media://$discinfo" -g $ISODIR/comps.xml $ISODIR
        sleep 1
    }
    #function: create ks.cfg
    function_create_kscfg(){
        cd $ISODIR
        echo
        echo -e "will copy the ks.cfg.$1 to /SHIXUN/iso/isolinux/ks.cfg"
        cp -f /SHIXUN/source/ks/ks.cfg.$1 /SHIXUN/iso/isolinux/ks.cfg >/dev/null
        dos2unix /SHIXUN/iso/isolinux/ks.cfg 2>/dev/null
    }
    #function: create 
    function_create_img(){
        function_color Step_One green
        echo
        echo -e "will create a initrd.img and cp the /tmp/initrd.img.bak to /SHIXUN/iso/isolinux/"
        echo -e "please waiting for 1-3 minutes"
        sname=/tmp/initrd.img.bak
        echo -e "check the $sname is exist and remove it"
        test -e $sname && rm -r -f $sname 2>/dev/null
        #into the source dir
        cd /SHIXUN/source/initrd_source/
        #create a new initrd.img.bak
        echo -e "create a new $sname,loading......"
        find . | cpio -c -o | xz -9 --format=lzma >$sname 2>/dev/null 
        sleep 1
        #will copy the $sname to /SHIXUN/iso/isolinux/initrd.img
        chmod 444 $sname
        echo -e "System auto copy the $sname to /SHIXUN/iso/isolinux/initrd.img"
        echo -e "please waiting for 1-2 minutes."
        cp -f $sname /SHIXUN/iso/isolinux/initrd.img 2>/dev/null
        sleep 1
        echo
        echo -e "will create a install.img and cp the /tmp/install.img.bak to /SHIXUN/iso/images/"
        echo -e "please waiting for 1-3 minutes"
    
        sname=/tmp/install.img.bak
        #check tmp is exist and remove it
        echo -e "check the $sname is exist and remove it"
        test -e $sname && rm -r -f $sname 2>/dev/null
        #into the source dir
        install_source=/SHIXUN/source/install_source/
        #create a new install.img.bak
        echo -e "create a new $sname,loading......"
        mksquashfs $install_source  $sname 2>/dev/null 
        sleep 1
        #will copy the $sname to /SHIXUN/iso/images/install.img
        chmod 664 $sname
        echo -e "System auto copy the $sname to /SHIXUN/iso/images/install.img"
        echo -e "please waiting for 1-2 minutes."
        cp -f $sname /SHIXUN/iso/images/install.img 2>/dev/null
        sleep 1
    }
    #function: tar 
    function_tar(){
        cd $ISODIR
        function_color Step_Two green
        echo -e "**tar all solfts and system configs,please waiting for 10-30 minites"
        echo -e "**loading........"
        sleep 3
        source /etc/profile
        #will tar all softs
        #tomcat
        echo -e "stopping tomcat service"
        if [ -f /etc/init.d/tomcat ]; then
                /etc/init.d/tomcat stop
        fi
        #clean tomcat log 
        echo -e "clean tomcat logs/*"
        rm -r -f /home/tomcat/logs/*
        rm -r -f /home/tomcat/temp/*
        rm -r -f /home/tomcat/work/Catalina/localhost/radius
        #radiusd
        echo -e "stopping radiusd service"
        if [ -f /etc/init.d/radiusd ]; then
                /etc/init.d/radiusd stop
        fi
        #clean mydradiusd log
        echo -e "clean /home/radius/log/*"
        rm -r -f /home/radius/log/*
        #oracle
        echo -e "stopping ora10g service"
        if [ -f /etc/init.d/ora10g ]; then
                /etc/init.d/ora10g stop
        fi
        #clean bash_history
        echo -e "clean the .*history"
        echo "#shixun admin log">/home/radius/bin/console/.bash_history
        echo "#shixun admin log">/home/radius/bin/console/.rc.admin.main_history
        #copy the rc.install
        echo -e "will copy this rc.install."
        if [ -f /SHIXUN/source/rc.install ]; then
                cp -f /SHIXUN/source/rc.install /etc/rc.install
        fi
        #will tar all softs
        if [ "$1"x = "development"x ];then
            tar -czvf $WIRADIUS /SHIXUN/shell /SHIXUN/source /etc/init/tty.conf /etc/passwd /etc/pam.d/login /etc/shadow /etc/group /etc/profile /etc/security/limits.conf /etc/sysctl.conf /etc/issue /etc/issue.net /etc/centos-release  /etc/oratab /etc/oraInst.loc /usr/local/bin/* /etc/init.d/tomcat /etc/init.d/ora10g /etc/init.d/radiusd /etc/sysconfig/i18n /boot/grub/splash.xpm.gz /etc/rc.install /etc/init/start-ttys.conf  /etc/inittab /home/admin /home/oracle /home/radius /home/tomcat /home/java /home/version /ora /etc/crontab  /lib64 /usr/local/rlwrap 
        cp -a /home/oracle_radiusx64.tar.shfs $ISORPMDIR
        fi
        if [ "$1"x = "release"x ];then
            tar -czvf $WIRADIUS /etc/init/tty.conf /etc/passwd /etc/pam.d/login /etc/shadow /etc/group /etc/profile /etc/security/limits.conf /etc/sysctl.conf /etc/issue /etc/issue.net /etc/centos-release  /etc/oratab /etc/oraInst.loc /usr/local/bin/* /etc/init.d/tomcat /etc/init.d/ora10g /etc/init.d/radiusd /etc/sysconfig/i18n /boot/grub/splash.xpm.gz /etc/rc.install /etc/init/start-ttys.conf  /etc/inittab /home/admin /home/oracle /home/radius /home/tomcat /home/java /home/version /ora /etc/crontab  /lib64 /usr/local/rlwrap 
            if [ -e $ISORPMDIR/oracle_radiusx64.tar.shfs ];then
                rm -f $ISORPMDIR/oracle_radiusx64.tar.shfs
            fi
        fi
        sleep 1
    }
    #function: make iso 
    function_createISO(){
        cd $ISODIR
        #will create a new iso
        function_color Step_Three green
        sleep 2
        echo -e "********Create New ISO********"
        if [ "$1"x = "development"x ];then
        mkisofs -o $ISOSAVEDIR/$ISOVERSION -joliet-long -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T $ISODIR/
        fi
        if [ "$1"x = "release"x ];then
        mkisofs -o $ISOSAVEDIR/$ISOVERSION  -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T $ISODIR/
        fi
    }
    #function: md5
    function_md5(){
        cd $ISODIR
        function_color Step_four green
        #md5
        md5sum $ISOSAVEDIR/$ISOVERSION > $ISOSAVEDIR/$ISOMD5
        echo -e "***********The $ISOSAVEDIR/$ISOVERSION Is Create OK And The ISO MD5: $ISOSAVEDIR/$ISOMD5"
        echo -e "***********You can download or copy it by ssh port:10010 ip:192.168.4.2********"
        function_color END! green
        echo
    }
    #<---------------------end---------------------------------------->
    #
    ##<---------------------Script main------------------------------->
    #set  parameter
    ISODIR=/SHIXUN/iso
    ISOSAVEDIR=/tmp
    ISORPMDIR=/SHIXUN/iso/Packages
    ISOREPODATA=/SHIXUN/iso/repodata
    WIRADIUS=$ISORPMDIR/wiradius.tar.gz
    NOWDIR=`pwd`
    #Script Start!
    if [ "$1"x = "release"x ];then
        ISOBASE=WiRadius_10g_Release_`date +%Y_%m_%d_%H%M%S`
        ISOVERSION="$ISOBASE"_x64.iso
        ISOMD5="$ISOBASE"_x64.md5
        function_create_version
        function_create_comps
        function_create_img
        function_create_kscfg release
        function_tar release
        function_createISO release
        function_md5 
    elif [ "$1"x = "development"x ];then
        ISOBASE=WiRadius_10g_Development_`date +%Y_%m_%d_%H%M%S`
        ISOVERSION="$ISOBASE"_x64.iso
        ISOMD5="$ISOBASE"_x64.md5
        function_create_version
        function_create_comps
        function_create_img
        function_create_kscfg development
        function_tar development
        function_createISO development
        function_md5 
    else
        echo "error"
    fi
    
    cd $NOWDIR
    exit 0
  • 相关阅读:
    python中删除某个元素的3种方法
    研发团队开源管理工具最佳实践
    Cocos2dx游戏开发系列笔记13:一个横版拳击游戏Demo完结篇
    Sunny谈软件架构
    整理部分JS 控件 WEB前端常用的做成Jsp项目,方便今后直接用
    hdu3033I love sneakers! (分组背包,错了很多次)
    Using关键字的用法
    Android webViewj简单处理apk的下载链接
    山寨腾讯“爱消除”游戏之菜单特效
    Apache与Nginx优缺点比较
  • 原文地址:https://www.cnblogs.com/djoker/p/6396615.html
Copyright © 2011-2022 走看看