Compare commits
	
		
			12 commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							
							
								 | 
						24172f0771 | ||
| 
							
							
								 | 
						932f8b695e | ||
| 
							
							
								 | 
						985c0e7a06 | ||
| 
							
							
								 | 
						fe278387e5 | ||
| 
							
							
								 | 
						9aedecc62e | ||
| 
							
							
								 | 
						3065562dab | ||
| 
							
							
								 | 
						3500ce0058 | ||
| 
							
							
								 | 
						dec5faa54b | ||
| 
							
							
								 | 
						175943aa4d | ||
| 
							
							
								 | 
						fc8dd81f00 | ||
| 
							
							
								 | 
						a7f156b7c9 | ||
| 
							
							
								 | 
						20272db3d8 | 
							
								
								
									
										54
									
								
								DEBBUILD
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								DEBBUILD
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,32 +1,60 @@
 | 
			
		|||
#/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
pkgname="forgejo"
 | 
			
		||||
pkgver=23333    # this will be override by pkgver function
 | 
			
		||||
pkgname="makedeb"
 | 
			
		||||
pkgver=0.0.2.0.g175943a
 | 
			
		||||
pkgrel=1
 | 
			
		||||
arch="all"
 | 
			
		||||
pkgcommit=""
 | 
			
		||||
section="utils"             # https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
 | 
			
		||||
priority="optional"         # https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities
 | 
			
		||||
pkgdesc="A painless selfhost git service."
 | 
			
		||||
url="https://codeberg.org/forgejo/forgejo"
 | 
			
		||||
url="https://git.leafee98.com/leafee98/makedeb"
 | 
			
		||||
maintainer="Leafee98 <me@leafee98.com>"
 | 
			
		||||
 | 
			
		||||
source=(
 | 
			
		||||
    "forgejo-1.19.0-2-linux-amd64.xz::https://codeberg.org/attachments/5f7f9d36-b85e-40db-b390-9bf39acbbbc5"
 | 
			
		||||
    "bwifi::git+https://cgit.leafee98.com/bwifi.git/#commit=8af4243f622bcb52f2e5be3345e282fd7cbad4d0"
 | 
			
		||||
    "frp-0.46.1.tar.gz::material/frp-0.46.1.tar.gz"
 | 
			
		||||
    "pkg.zip::material/pkg.zip"
 | 
			
		||||
    "t.sh::material/t.sh"
 | 
			
		||||
    "LICENSE::https://git.leafee98.com/leafee98/makedeb/raw/branch/main/LICENSE"    # from http (existed file will skip, without checking hash)
 | 
			
		||||
    "makedeb-repo::git+https://git.leafee98.com/leafee98/makedeb.git#branch=main"   # from git with https
 | 
			
		||||
    "README.md::README.md"                                       # from local file
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# This will be run just follow extracting source
 | 
			
		||||
# This will be run just after extracting source, and re-assign to `pkgver`
 | 
			
		||||
#
 | 
			
		||||
# If extracting version from source is not needed, don't define this function.
 | 
			
		||||
function pkgver {
 | 
			
		||||
    echo "1.19.0-2"
 | 
			
		||||
    git describe --tags --long | sed 's/^v//;s/-/./g'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function build {
 | 
			
		||||
    install -D "${srcdir}/t.sh" "${pkgdir}/usr/bin/t.sh"
 | 
			
		||||
    echo "building"
 | 
			
		||||
    echo "Here should do something like compile sources."
 | 
			
		||||
    echo "But for this package we just print some messages."
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function package {
 | 
			
		||||
    echo "installing package, pkgdir: ${pkgdir}"
 | 
			
		||||
    install -Dm644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/makedeb/LICENSE"
 | 
			
		||||
    install -Dm755 "${srcdir}/makedeb-repo/makedeb" "${pkgdir}/usr/bin/makedeb"
 | 
			
		||||
    install -Dm755 "${srcdir}/README.md" "${pkgdir}/usr/share/doc/makedeb/README.md"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# The function describing hook for (pre|post)(inst|rm) should
 | 
			
		||||
# *print* content of those hook file.
 | 
			
		||||
# If the any hook is not needed, don't define those function.
 | 
			
		||||
 | 
			
		||||
#function debian_preinst {
 | 
			
		||||
#}
 | 
			
		||||
 | 
			
		||||
function debian_postinst {
 | 
			
		||||
    cat << EOF
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
echo "successfully installed makedeb"
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#function debian_prerm {
 | 
			
		||||
#}
 | 
			
		||||
 | 
			
		||||
function debian_postrm {
 | 
			
		||||
    cat << EOF
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
echo "successfully removed makedeb"
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										22
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
MIT License
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2023 Leafee98
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in all
 | 
			
		||||
copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
SOFTWARE.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										35
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
# makedeb
 | 
			
		||||
 | 
			
		||||
Script for building Debian package quickly and easily. Inspired by Archlinux's makepkg.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
 | 
			
		||||
Check the `DEBBUILD`
 | 
			
		||||
 | 
			
		||||
## Reference
 | 
			
		||||
 | 
			
		||||
### Build process
 | 
			
		||||
 | 
			
		||||
First it download needed content from array `sources`, then use function `pkgver` to determine the package version, then run function `build` and function `package`, then run hooks `debian_(pre|post)(inst|rm)` and make the printed strings as debian's hook scripts. Finally generate .deb with files in `$pkgdir`.
 | 
			
		||||
 | 
			
		||||
### Download and extract source
 | 
			
		||||
 | 
			
		||||
Every string in array `source` should be like `<actual_file_name>::<download_url>`. When downloading, the `download_url` content will be named with `<actual_file_name>`. When `build` and `pacage` run, every `<actual_file_name>` will be copied to `$srcdir`. If the file is a compressed file, it will be decompressed, if the file is a git repo, the specific branch, commit or tag will be checkouted.
 | 
			
		||||
 | 
			
		||||
### Global variables
 | 
			
		||||
 | 
			
		||||
- `pkgname`: package's name
 | 
			
		||||
- `pkgver`: package's version, if need to extract version from source, use function `pkgver`
 | 
			
		||||
- `pkgrel`: debian package reference, it should increase by one every build
 | 
			
		||||
- `pkgdesc`: package's description
 | 
			
		||||
- `section`: default `misc` if not specified
 | 
			
		||||
- `priority`: default `optional` if not specified
 | 
			
		||||
- `url`: packages upstream url
 | 
			
		||||
- `maintainer`: maintainer's contect information
 | 
			
		||||
 | 
			
		||||
### Global functions
 | 
			
		||||
 | 
			
		||||
- `pkgver`: should print the actual version. This override the variable `pkgver`
 | 
			
		||||
- `build`: do something like compile source
 | 
			
		||||
- `package`: do something like copy file from `$srcdir` to `$pkgdir`
 | 
			
		||||
- `debian_(pre|post)(inst|rm)`: should print content of debian hooks file
 | 
			
		||||
							
								
								
									
										274
									
								
								makedeb
									
									
									
									
									
								
							
							
						
						
									
										274
									
								
								makedeb
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -6,10 +6,32 @@ buildfile="${workspace}/DEBBUILD"
 | 
			
		|||
srcdir="${workspace}/src"
 | 
			
		||||
pkgdir="${workspace}/pkg"
 | 
			
		||||
 | 
			
		||||
FAKE_PACKAGE=0
 | 
			
		||||
_IN_FAKEROOT=0
 | 
			
		||||
_BACKUP_STDOUT=3        # use file descriptor 3 to backup stdout
 | 
			
		||||
_BACKUP_STDERR=4        # use file descriptor 4 to backup stderr
 | 
			
		||||
_ARGLIST=("$@")
 | 
			
		||||
OVERRIDE_SOURCE=0
 | 
			
		||||
SHOW_TARGET_FILE=0
 | 
			
		||||
QUIET=0
 | 
			
		||||
PACKAGELIST=0
 | 
			
		||||
IS_DYNAMICV_PKGVER=0
 | 
			
		||||
 | 
			
		||||
_STEP_CLEAN=1
 | 
			
		||||
_STEP_RETRIEVE_SOURCE=1
 | 
			
		||||
_STEP_EXTRACT_SOURCE=1
 | 
			
		||||
_STEP_UPDATE_PKGVER=1
 | 
			
		||||
_STEP_CHCECK_PACKAGE_EXISTS=1
 | 
			
		||||
_STEP_BUILD=1
 | 
			
		||||
_STEP_PACKAGE=1
 | 
			
		||||
_STEP_CREATE_ARCHIVE=1
 | 
			
		||||
 | 
			
		||||
_STOP_AFTER_CLEAN=0
 | 
			
		||||
_STOP_AFTER_RETRIEVE_SOURCE=0
 | 
			
		||||
_STOP_AFTER_EXTRACT_SOURCE=0
 | 
			
		||||
_STOP_AFTER_UPDATE_PKGVER=0
 | 
			
		||||
#_STEP_CHCECK_PACKAGE_EXISTS=0  # stop after checking exists is useless
 | 
			
		||||
_STOP_AFTER_BUILD=0
 | 
			
		||||
_STOP_AFTER_PACKAGE=0
 | 
			
		||||
_STOP_AFTER_CREATE_ARCHIVE=0
 | 
			
		||||
 | 
			
		||||
set -o functrace
 | 
			
		||||
set -o nounset
 | 
			
		||||
| 
						 | 
				
			
			@ -50,10 +72,15 @@ function msg2 {
 | 
			
		|||
    local mesg=$1; shift
 | 
			
		||||
    printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
 | 
			
		||||
}
 | 
			
		||||
function warn {
 | 
			
		||||
    (( QUIET )) && return 0
 | 
			
		||||
    local mesg=$1; shift
 | 
			
		||||
    printf "${YELLOW}==>${ALL_OFF}${BOLD}${YELLOW} ${mesg}${ALL_OFF}\n" "$@" >&2
 | 
			
		||||
}
 | 
			
		||||
function err {
 | 
			
		||||
    (( QUIET )) && return 0
 | 
			
		||||
    local mesg=$1; shift
 | 
			
		||||
    printf "${RED}  ->${ALL_OFF}${BOLD}${RED} ${mesg}${ALL_OFF}\n" "$@" >&2
 | 
			
		||||
    printf "${RED}==>${ALL_OFF}${BOLD}${RED} ${mesg}${ALL_OFF}\n" "$@" >&2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function get_full_version {
 | 
			
		||||
| 
						 | 
				
			
			@ -75,27 +102,44 @@ function debian_control {
 | 
			
		|||
    local install_size="$(du --block-size=1K --summarize ${pkgdir} | cut -d $'\t' -f 1)"
 | 
			
		||||
    local fv="$(get_full_version)"
 | 
			
		||||
 | 
			
		||||
    cat << EOF | envsubst
 | 
			
		||||
Package: ${pkgname}
 | 
			
		||||
Version: ${fv}
 | 
			
		||||
Architecture: all
 | 
			
		||||
Maintainer: ${maintainer}
 | 
			
		||||
Installed-Size: ${install_size}
 | 
			
		||||
Description: ${pkgdesc}
 | 
			
		||||
EOF
 | 
			
		||||
    echo "Package: ${pkgname}"
 | 
			
		||||
    echo "Version: ${fv}"
 | 
			
		||||
    echo "Architecture: ${arch}"
 | 
			
		||||
    echo "Maintainer: ${maintainer}"
 | 
			
		||||
    echo "Installed-Size: ${install_size}"
 | 
			
		||||
    echo "Homepage: ${url}"
 | 
			
		||||
 | 
			
		||||
    [[ -n "${section:=misc}" ]] && echo "Section: ${section}"
 | 
			
		||||
    [[ -n "${priority:=optional}" ]] && echo "Priority: ${priority}"
 | 
			
		||||
 | 
			
		||||
    echo "Description: ${pkgdesc}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generate_control {
 | 
			
		||||
    msg "Generating control info..."
 | 
			
		||||
    mkdir -p "${pkgdir}/DEBIAN"
 | 
			
		||||
    echo 2 > "${pkgdir}/DEBIAN/compat"
 | 
			
		||||
    debian_control > "${pkgdir}/DEBIAN/control"
 | 
			
		||||
 | 
			
		||||
    function debian_hooks_warpper { is_function "$1" && "$1" > "$2" && chmod +x "$2" || true; }
 | 
			
		||||
    debian_hooks_warpper debian_preinst  ${pkgdir}/DEBIAN/preinst
 | 
			
		||||
    debian_hooks_warpper debian_postinst ${pkgdir}/DEBIAN/postinst
 | 
			
		||||
    debian_hooks_warpper debian_prerm    ${pkgdir}/DEBIAN/prerm
 | 
			
		||||
    debian_hooks_warpper debian_postrm   ${pkgdir}/DEBIAN/postrm
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function generate_deb {
 | 
			
		||||
    msg "generating deb package..."
 | 
			
		||||
    msg "Generating deb package..."
 | 
			
		||||
 | 
			
		||||
    local tmpdir="$(mktemp --directory)"
 | 
			
		||||
    local data_tgz="${tmpdir}/data.tar.gz"
 | 
			
		||||
    local control_tgz="${tmpdir}/control.tar.gz"
 | 
			
		||||
    local debian_binary="${tmpdir}/debian-binary"
 | 
			
		||||
 | 
			
		||||
    tar --exclude="./DEBIAN" -C "${pkgdir}" -cf "${data_tgz}" .
 | 
			
		||||
    tar --gzip --exclude="./DEBIAN" -C "${pkgdir}" -cf "${data_tgz}" .
 | 
			
		||||
 | 
			
		||||
    tar -C "${pkgdir}/DEBIAN" -cf "${control_tgz}" .
 | 
			
		||||
    tar --gzip -C "${pkgdir}/DEBIAN" -cf "${control_tgz}" .
 | 
			
		||||
 | 
			
		||||
    echo 2.0 > "${debian_binary}"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -103,7 +147,12 @@ function generate_deb {
 | 
			
		|||
 | 
			
		||||
    rm -rf "${tmpdir}"
 | 
			
		||||
 | 
			
		||||
    msg2 "generated deb: %s" "$(get_deb_name)"
 | 
			
		||||
    msg2 "Generated deb: %s" "$(get_deb_name)"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function step_create_archive {
 | 
			
		||||
    generate_control
 | 
			
		||||
    generate_deb
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function url_type {
 | 
			
		||||
| 
						 | 
				
			
			@ -134,10 +183,12 @@ function create_soft_link {
 | 
			
		|||
 | 
			
		||||
    if [[ ! -e "${src}" ]] ; then
 | 
			
		||||
        err "soft_link src %s not exist" "${src}"
 | 
			
		||||
        return 1
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if [[ -e "${tgt}" ]] ; then
 | 
			
		||||
        err "soft_link tgt %s already exist" "${tgt}"
 | 
			
		||||
        return 1
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    ln --symbolic "${src}" "${tgt}"
 | 
			
		||||
| 
						 | 
				
			
			@ -154,17 +205,17 @@ function url_fragment {
 | 
			
		|||
 | 
			
		||||
# $1 is relative path to file
 | 
			
		||||
# $2 is url/(relative path to materials)
 | 
			
		||||
function retrive_source_single {
 | 
			
		||||
function retrieve_source_single {
 | 
			
		||||
    local file_name="$1"
 | 
			
		||||
    local url="$2"
 | 
			
		||||
 | 
			
		||||
    case "$(url_type "${url}")" in
 | 
			
		||||
        "git")
 | 
			
		||||
            if [[ -d "${file_name}" ]]; then
 | 
			
		||||
                msg2 "updating ${file_name} from ${url} with git..."
 | 
			
		||||
                msg2 "Updating ${file_name} from ${url} with git..."
 | 
			
		||||
                git --git-dir="${workspace}/${file_name}" fetch --all
 | 
			
		||||
            else
 | 
			
		||||
                msg2 "cloning ${file_name} from ${url} with git..."
 | 
			
		||||
                msg2 "Cloning ${file_name} from ${url} with git..."
 | 
			
		||||
                local git_source="${url##git+}"
 | 
			
		||||
                git_source="${git_source%%#*}"
 | 
			
		||||
                git clone --mirror "${git_source}" "${workspace}/${file_name}"
 | 
			
		||||
| 
						 | 
				
			
			@ -174,21 +225,21 @@ function retrive_source_single {
 | 
			
		|||
            if (( ! OVERRIDE_SOURCE )) && [[ -f "${workspace}/${file_name}" ]] ; then
 | 
			
		||||
                msg2 "${file_name} already exists, skip download"
 | 
			
		||||
            else
 | 
			
		||||
                msg2 "retriving ${file_name} from ${url} with curl..."
 | 
			
		||||
                msg2 "Retrieving ${file_name} from ${url} with curl..."
 | 
			
		||||
                curl --location "${url}" --output "${workspace}/${file_name}"
 | 
			
		||||
            fi
 | 
			
		||||
            ;;
 | 
			
		||||
        "file")
 | 
			
		||||
            if [[ -e "${workspace}/${url}" ]] ; then
 | 
			
		||||
                msg2 "found local file: ${url}"
 | 
			
		||||
                msg2 "Found local file: ${url}"
 | 
			
		||||
            else
 | 
			
		||||
                err "local file not found: ${url}"
 | 
			
		||||
                err "Local file not found: ${url}"
 | 
			
		||||
                err "Aborting..."
 | 
			
		||||
                exit 1
 | 
			
		||||
            fi
 | 
			
		||||
            ;;
 | 
			
		||||
        *)
 | 
			
		||||
            err "retriving url as type ${url_type} not supported"
 | 
			
		||||
            err "Retrieving url as type ${url_type} not supported"
 | 
			
		||||
            err "Aborting..."
 | 
			
		||||
            exit 1
 | 
			
		||||
    esac
 | 
			
		||||
| 
						 | 
				
			
			@ -210,7 +261,7 @@ function extract_source_single {
 | 
			
		|||
            if [[ -n "${frag}" ]] ; then
 | 
			
		||||
                case "${frag%%=*}" in
 | 
			
		||||
                    "branch")
 | 
			
		||||
                        ref="refs/heads/${frag##*=}"
 | 
			
		||||
                        ref="refs/remotes/origin/${frag##*=}"
 | 
			
		||||
                        ;;
 | 
			
		||||
                    "tag")
 | 
			
		||||
                        ref="refs/tags/${frag##*=}"
 | 
			
		||||
| 
						 | 
				
			
			@ -225,7 +276,7 @@ function extract_source_single {
 | 
			
		|||
                esac
 | 
			
		||||
            fi
 | 
			
		||||
 | 
			
		||||
            msg2 "extracting git ${workspace}/${file_name} with reference ${ref}"
 | 
			
		||||
            msg2 "Extracting git ${workspace}/${file_name} with reference ${ref}"
 | 
			
		||||
            git clone --shared "${workspace}/${file_name}" "${srcdir}/${file_name}"
 | 
			
		||||
            git -C "${srcdir}/${file_name}" switch --force-create makedeb --no-track "${ref}"
 | 
			
		||||
            ;;
 | 
			
		||||
| 
						 | 
				
			
			@ -257,11 +308,11 @@ function decompress_source_file {
 | 
			
		|||
        *.zip)
 | 
			
		||||
            cmd="unzip" ;;
 | 
			
		||||
        *)
 | 
			
		||||
            msg2 "no need to decompress, skip %s" "${file}"
 | 
			
		||||
            msg2 "No need to decompress, skip %s" "${file}"
 | 
			
		||||
            return
 | 
			
		||||
    esac
 | 
			
		||||
 | 
			
		||||
    msg2 "decompressing %s with %s" "${file}" "${cmd}"
 | 
			
		||||
    msg2 "Decompressing %s with %s" "${file}" "${cmd}"
 | 
			
		||||
    local res=0
 | 
			
		||||
    case "$cmd" in
 | 
			
		||||
        "tar")
 | 
			
		||||
| 
						 | 
				
			
			@ -319,24 +370,24 @@ function check_source_validation {
 | 
			
		|||
    done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function clean_dir {
 | 
			
		||||
    msg "cleaning \$srcdir and \$pkgdir..."
 | 
			
		||||
function step_clean_dir {
 | 
			
		||||
    msg "Cleaning \$srcdir and \$pkgdir..."
 | 
			
		||||
    rm -rf "${srcdir}" "${pkgdir}"
 | 
			
		||||
    mkdir -p "${srcdir}" "${pkgdir}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function retrieve_source {
 | 
			
		||||
    msg "retrieving source..."
 | 
			
		||||
function step_retrieve_source {
 | 
			
		||||
    msg "Retrieving source..."
 | 
			
		||||
    for s in "${source[@]}"; do
 | 
			
		||||
        file_name="${s%%::*}"
 | 
			
		||||
        url="${s##*::}"
 | 
			
		||||
 | 
			
		||||
        retrive_source_single "${file_name}" "${url}"
 | 
			
		||||
        retrieve_source_single "${file_name}" "${url}"
 | 
			
		||||
    done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function extract_source {
 | 
			
		||||
    msg "extracting source..."
 | 
			
		||||
function step_extract_source {
 | 
			
		||||
    msg "Extracting source..."
 | 
			
		||||
    for s in "${source[@]}"; do
 | 
			
		||||
        file_name="${s%%::*}"
 | 
			
		||||
        url="${s##*::}"
 | 
			
		||||
| 
						 | 
				
			
			@ -345,12 +396,12 @@ function extract_source {
 | 
			
		|||
    done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function update_pkgver {
 | 
			
		||||
function step_update_pkgver {
 | 
			
		||||
    if ! is_function pkgver; then
 | 
			
		||||
        return
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    msg "updating pkgver..."
 | 
			
		||||
    msg "Updating pkgver..."
 | 
			
		||||
    newpkgver="$(run_function_safe pkgver)"
 | 
			
		||||
    if [[ "${newpkgver}" != "${pkgver:-}" ]] ; then
 | 
			
		||||
        mapfile -t bfcontent < "${buildfile}"
 | 
			
		||||
| 
						 | 
				
			
			@ -367,33 +418,41 @@ function update_pkgver {
 | 
			
		|||
 | 
			
		||||
        source "${buildfile}"
 | 
			
		||||
 | 
			
		||||
        msg2 "updated version: ${newpkgver}"
 | 
			
		||||
        msg2 "Updated version: ${newpkgver}"
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    pkgver="${newpkgver}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generate_control {
 | 
			
		||||
 | 
			
		||||
    msg "generating control info..."
 | 
			
		||||
    mkdir -p "${pkgdir}/DEBIAN"
 | 
			
		||||
    echo 2 > "${pkgdir}/DEBIAN/compat"
 | 
			
		||||
    debian_control > "${pkgdir}/DEBIAN/control"
 | 
			
		||||
 | 
			
		||||
    function debian_hooks_warpper { is_function "$1" && "$1" > "$2" && chmod +x "$2" || true; }
 | 
			
		||||
    debian_hooks_warpper debian_preinst  ${pkgdir}/DEBIAN/preinst
 | 
			
		||||
    debian_hooks_warpper debian_postinst ${pkgdir}/DEBIAN/postinst
 | 
			
		||||
    debian_hooks_warpper debian_prerm    ${pkgdir}/DEBIAN/prerm
 | 
			
		||||
    debian_hooks_warpper debian_postrm   ${pkgdir}/DEBIAN/postrm
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function run_function {
 | 
			
		||||
    if is_function "$1" ; then
 | 
			
		||||
        msg "run function: $1"
 | 
			
		||||
        msg "Run function: $1"
 | 
			
		||||
        run_function_safe "$1"
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function disable_stdout {
 | 
			
		||||
    exec {_BACKUP_STDOUT}>&1
 | 
			
		||||
    exec 1>/dev/null
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function enable_stdout {
 | 
			
		||||
    exec 1>&"$_BACKUP_STDOUT"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function show_help {
 | 
			
		||||
    echo "$0 [OPTIONS]"
 | 
			
		||||
    echo "      -Q                      quiet, disable log"
 | 
			
		||||
    echo "      -f|--force              don't check if package already exists, will"
 | 
			
		||||
    echo "      --nobuild               retrieve source, update pkgver and stop"
 | 
			
		||||
    echo "                              override the existed package"
 | 
			
		||||
    echo "      --noextract             use the current srcdir to build package, skip"
 | 
			
		||||
    echo "                              those retrieve source steps"
 | 
			
		||||
    echo "      --noarchive             retrieve and build, but don't package to .deb"
 | 
			
		||||
    echo "      --packagelist           show file to be generated by current DEBBUILD"
 | 
			
		||||
    echo "      --is-dynamic-pkgver     exit with 0 if DEBBUILD will update pkgver later"
 | 
			
		||||
    echo "      -h|--help               show this message"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
##
 | 
			
		||||
## Here start the build logic
 | 
			
		||||
| 
						 | 
				
			
			@ -401,11 +460,36 @@ function run_function {
 | 
			
		|||
 | 
			
		||||
while (( "$#" >= 1 )); do
 | 
			
		||||
    case "$1" in
 | 
			
		||||
        -F)  FAKE_PACKAGE=1 ;;
 | 
			
		||||
        -OS) OVERRIDE_SOURCE=1 ;;
 | 
			
		||||
        -STF) SHOW_TARGET_FILE=1 ; QUIET=1 ;;
 | 
			
		||||
        -F)                         _IN_FAKEROOT=1 ;;
 | 
			
		||||
        -Q)                         QUIET=1 ;;
 | 
			
		||||
        *)   err "Unkown option $1"; break ;;
 | 
			
		||||
        -f|--force)                 _STEP_CHCECK_PACKAGE_EXISTS=0 ;;
 | 
			
		||||
        --noextract)
 | 
			
		||||
            _STEP_CLEAN=0
 | 
			
		||||
            _STEP_RETRIEVE_SOURCE=0
 | 
			
		||||
            _STEP_EXTRACT_SOURCE=0
 | 
			
		||||
            _STEP_UPDATE_PKGVER=0
 | 
			
		||||
            ;;
 | 
			
		||||
        --nobuild)
 | 
			
		||||
            _STEP_CHCECK_PACKAGE_EXISTS=0
 | 
			
		||||
            _STEP_BUILD=0
 | 
			
		||||
            _STEP_PACKAGE=0
 | 
			
		||||
            _STEP_CREATE_ARCHIVE=0
 | 
			
		||||
 | 
			
		||||
            _STOP_AFTER_UPDATE_PKGVER=1
 | 
			
		||||
            ;;
 | 
			
		||||
        --noarchive)
 | 
			
		||||
            _STEP_CHCECK_PACKAGE_EXISTS=0
 | 
			
		||||
            _STEP_CREATE_ARCHIVE=0
 | 
			
		||||
 | 
			
		||||
            _STOP_AFTER_BUILD=1
 | 
			
		||||
            ;;
 | 
			
		||||
        --packagelist)              PACKAGELIST=1 ;;
 | 
			
		||||
        --is-dynamic-pkgver)        IS_DYNAMICV_PKGVER=1 ;;
 | 
			
		||||
        -h|--help) show_help ; exit 0;;
 | 
			
		||||
 | 
			
		||||
        *)  err "Unkown option $1"
 | 
			
		||||
            err "Use $0 --help for help"
 | 
			
		||||
            exit 1 ;;
 | 
			
		||||
    esac
 | 
			
		||||
    shift
 | 
			
		||||
done
 | 
			
		||||
| 
						 | 
				
			
			@ -413,39 +497,75 @@ done
 | 
			
		|||
source "${buildfile}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if (( ! FAKE_PACKAGE )) ; then
 | 
			
		||||
    if (( SHOW_TARGET_FILE )) && ! is_function pkgver ; then
 | 
			
		||||
if (( PACKAGELIST )) ; then
 | 
			
		||||
    echo "$(get_deb_name)"
 | 
			
		||||
    exit 0
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if (( IS_DYNAMICV_PKGVER )) ; then
 | 
			
		||||
    if is_function pkgver ; then
 | 
			
		||||
        exit 0
 | 
			
		||||
    else
 | 
			
		||||
        exit 4
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if (( QUIET )) ; then
 | 
			
		||||
    disable_stdout
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if (( ! _IN_FAKEROOT )) ; then
 | 
			
		||||
    check_source_validation
 | 
			
		||||
 | 
			
		||||
    clean_dir
 | 
			
		||||
 | 
			
		||||
    retrieve_source
 | 
			
		||||
 | 
			
		||||
    extract_source
 | 
			
		||||
 | 
			
		||||
    update_pkgver
 | 
			
		||||
 | 
			
		||||
    if (( SHOW_TARGET_FILE )) && is_function pkgver ; then
 | 
			
		||||
        echo "$(get_deb_name)"
 | 
			
		||||
        exit 0
 | 
			
		||||
    if (( _STEP_CLEAN )) ; then
 | 
			
		||||
        step_clean_dir
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if (( _STEP_RETRIEVE_SOURCE )) ; then
 | 
			
		||||
        step_retrieve_source
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if (( _STEP_EXTRACT_SOURCE )) ; then
 | 
			
		||||
        step_extract_source
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if (( _STEP_UPDATE_PKGVER )) ; then
 | 
			
		||||
        step_update_pkgver
 | 
			
		||||
        (( _STOP_AFTER_UPDATE_PKGVER )) && msg "Sources are ready."
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    # Check if the package already exists
 | 
			
		||||
    if (( _STEP_CHCECK_PACKAGE_EXISTS )) ; then
 | 
			
		||||
        if [[ -f "$(get_deb_name)" ]] ; then
 | 
			
		||||
            warn "%s %s" \
 | 
			
		||||
                    "The package $(get_deb_name) already exists, skipping build." \
 | 
			
		||||
                    "(use -f to force re-build)"
 | 
			
		||||
            exit 0
 | 
			
		||||
        fi
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if (( _STEP_BUILD )) ; then
 | 
			
		||||
        run_function build
 | 
			
		||||
        (( _STOP_AFTER_BUILD )) && msg "Package directory is ready."
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if (( _STEP_PACKAGE || _STEP_CREATE_ARCHIVE )) ; then
 | 
			
		||||
        # recursive call self to run rest task in fakeroot
 | 
			
		||||
    msg "entering fakeroot environment..."
 | 
			
		||||
    fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${ARGLIST[@]}" || exit $?
 | 
			
		||||
    msg "leaving fakeroot environment..."
 | 
			
		||||
 | 
			
		||||
    msg "builds has done"
 | 
			
		||||
        msg "Entering fakeroot environment..."
 | 
			
		||||
        fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${_ARGLIST[@]}" || exit $?
 | 
			
		||||
        msg "Leaving fakeroot environment..."
 | 
			
		||||
    fi
 | 
			
		||||
else
 | 
			
		||||
    if (( _STEP_PACKAGE )) ; then
 | 
			
		||||
        run_function package
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    generate_control
 | 
			
		||||
 | 
			
		||||
    generate_deb
 | 
			
		||||
    if (( _STEP_CREATE_ARCHIVE )) ; then
 | 
			
		||||
        step_create_archive
 | 
			
		||||
        msg "Finish making: $(get_deb_name) $(date)"
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if (( QUIET )) ; then
 | 
			
		||||
    enable_stdout
 | 
			
		||||
fi
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								material/pkg.zip
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								material/pkg.zip
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -1,5 +0,0 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
ls -l
 | 
			
		||||
fakeroot
 | 
			
		||||
ls -l
 | 
			
		||||
		Loading…
	
		Reference in a new issue