To package the source code into a Deb package script

Source: Internet
Author: User
Tags mkdir
#!/bin/bash Error_check () {if [$1-ne 0];then echo "$" Exit $ fi} copy_file () {cp-f- A-v $ Error_check $?
    ' Not Found '} rm_file () {for file in $@;d o if [-E "$file"];then rm-vf $file fi Done} rm_dir () {to dir in $@;d o if [d "$dir"];then rm-vrf $dir fi Done} show  _opts () {echo "Deb-build is help for generating deb packages" echo "Basic function:" echo "create Create a             Debian rule when building package for the ' the "" echo "Build Build Packages" echo "clean
    Clean all generated files "echo" parameter details: "Echo"-P,--Project specify what the package name is " echo "-S,--srcdir specify where the source code is" echo "-V,--version Specify the version Numbe R,if not set,it'll get it out Changlog "echo"-n,-r,--release set the release of Number,if not Set,it would Get it from Changelog "echo"-H,--Help show Helps "} version_gt () {test" $ (echo "$@" | TR "" \ n "| Sort-v | Head-n 1 "!="} version_ge () {test "$" (echo "$@" | TR "" \ n "| SORT-RV |  Head-n 1) "= =" Parse_changelog () {ver=$ (dpkg-parsechangelog-s $1-l ${src_dir}/debian/changelog) if [$?  -ne 0];then echo "Parse Changelog failed" Exit 1 fi echo "$ver"} get_check_config () {if [ !
    -D "${src_dir}"];then echo $SRC _dir not exist "Exit 1 fi base_name=$ (Parse_changelog source) Error_check $? "Not run create to generate Debian" echo "targetname= $BASE _name" version=$ (Parse_changelog version) echo "$ver  Sion ' If [-Z ' $VERSION '];then version= ' echo $version |awk ' {split ($_,a, "-");p rint a[1]} ' fi if [Z "$RELEASE"];then release= ' echo $version |awk ' {split ($_,a, "-");p rint a[2]} ' fi if Version_gt $version ${
     Version}-${release};then   Version= ' echo $version |awk ' {split ($_,a, "-");p rint a[1]} ' release= ' echo $version |awk ' {split ($_,a, "-");p rint A [2]} ' ' fi echo ' Version = $VERSION "echo" release= $RELEASE "code_dir=" ${base_name}-${version} "} parse_opts ( {Shift args= ' Getopt-o h:s:v:n:r:p:-L Help:,srcdir:,version:,release:,projectname:--"$@" ' eval set--"$
                ARGS "While true doing case $ in-p|--projectname) base_name=$2
            echo "Base_name= $BASE _name" Shift 2;; 
            -s|--srcdir) src_dir=$2 echo "src_dir= $SRC _dir" Shift 2;;
                -v|--version) version=$2 echo "version= $VERSION" Shift 2
            ;;
                -n|-r|--release) release=$2 echo "release= $RELEASE" Shift 2
            ;;
          --)      Shift break;;
            -H|--HELP) show_opts exit 0;;
        *) echo "error parameter $" exit;
Esac done Get_check_config} base_dir=$ (CD ' DirName $ ';p wd) build_dir=$ (PWD) base_name= "" Src_dir= "" version= ""
        Release=0 code_dir= "" Case in Create) parse_opts "$@" mkdir-p $CODE _dir cd $CODE _dir Dh_make--createorig-s-T. /$SRC _dir VI debian/rules cp-r Debian.
        /$SRC _DIR/CD. Echo-e ' \033[31;44;1mplease Make sure ' the rules in $CODE _dir/debian is valid!!
    \033[0m "echo"-------all done--------"exit 0;;
    Build) parse_opts "$@"; Clean) parse_opts "$@" Rm_dir $CODE _dir/* rm_file *.buildinfo rm_file *.changes RM
  _file *.deb rm_file *.xz rm_file *.gz      Rm_file *.DSC exit 0;;
*|--HELP) show_opts exit 0;; Esac cur=$ (parse_changelog version) if Version_gt "${version}-${release}" "$cur"; then CD $SRC _dir dch-v "${versi On}-${release} "Error_check $? "DCH Exit" cd-version=$ (Parse_changelog Version|awk ' {split ($1,a, "-");p rint A[1]} ') release=$ (Parse_changelo G Version|awk ' {split ($1,a, "-");p rint a[2]} ' fi code_dir= ' ${base_name}-${version} ' if [-d ' ${code_dir} '];then RM- RF ${code_dir}/* else mkdir-p ${code_dir} fi cp-r ${src_dir}/debian ${code_dir}/cd ${code_dir} arch= ' Uname-m ' I f ["$arch" x = "x86_64" x];then echo "Install Elf-packer". /$SRC _dir/elf-packer/elf-packer.sh install Error_check $? "Exit elf-packer.sh Install" FI export QT_SELECT=QT5 export source_dir=.
/$SRC _dir CD.
    Tar-czf "${base_name}_${version}.orig.tar.gz" "$SRC _dir" CD ${code_dir} DPKG-BUILDPACKAGE-US-UC if [$-ne 0];then echo "Dpkg-buildpackage exit"
    Unset Source_dir exit $?
 Fi unset source_dir echo "------All done-------"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.