summaryrefslogblamecommitdiff
path: root/abump.in
blob: 76284623d1766c5843e08ee2bfd17355c3e60f73 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

         





                                                          

                    
 

                                                   
              


                         
 
                       
           

                                                    
               



                                       






                                                                                                                   


                      
                            
                                 
                                      
 
                                                                            

                                         


                  

                               
 
                                                                                            
 


                                                          
 
                                                
 




                                       

 
         











                                                                                           

 

              


        

                                                       







                                                                                     
                                                       






                                                      
            
             
    



                     
 

                              
            
 
#!/bin/sh

# abump - bump pkgver in APKBUILDs
# Copyright (c) 2012 Natanael Copa <ncopa@alpinelinux.org>
#
# Distributed under GPL-2
#

abuild_ver=@VERSION@
datadir=@datadir@

if ! [ -f "$datadir/functions.sh" ]; then
	echo "$datadir/functions.sh: not found" >&2
	exit 1
fi
. "$datadir/functions.sh"


# version bump packages
do_bump() {
	local p rc=0 pkgname pkgver section message
	local upgrade="${cvelist:+security }upgrade"
	local a
	for p; do
		pkgname=${p%-[0-9]*}
		pkgver=${p#${pkgname}-}

		# calculate APKBUILD's path
		if [ "${pkgname#*/}" != "$pkgname" ] && ! [ -d "$APORTSDIR/${pkgname%/*} ]; then
			error "'$p' should be of form 'foo-1.2.3' or 'main/foo-1.2.3'"
			rc=1; continue
		fi
		a=$(aports_buildscript "$pkgname" || die "can't find APKBUILD for $pkgname") || { rc=1; continue; }

		(
		set -e

		cd "${a%/*}"
		section=${PWD%/*}
		section=${section##*/}

		message="$section/$pkgname: $upgrade to ${pkgver}${cvelist}"
		if [ -n "$fixes" ]; then
			message="$message

fixes #${fixes#\#}
"
		fi
		echo "$message"

		( . ./APKBUILD; type package | grep -q function ) || die "package() missing"

		sed -i -e "s/^pkgver=.*/pkgver=$pkgver/" \
			-e "s/^pkgrel=.*/pkgrel=0/" \
			APKBUILD

		abuild $abuild_opts checksum all

		git add APKBUILD
		git commit -m"$message"
		) || rc=1
	done
	return $rc
}

usage() {
	cat >&2 <<__EOF__
$prog $abuild_ver - bump pkgver in APKBUILDs
Usage: $prog [-s CVE-1,CVE-2,...] [-f ISSUE] [-R|--recursive] [-k|--keep] PKGNAME-1.2.3 ...
Options:
  -s, --security CVE1,CVE-2,...  Security update
  -f, --fixes ISSUE              Fixes ISSUE
  -R, --recursive                Run abuild with -R for recursive building
  -k, --keep                     Run abuild with -k to keep existing packages
  -q, --quiet
  -h, --help                     Show this help

__EOF__
}

keep=
recursive="-r"
cvelist=
fixes=

[ -n "$APORTSDIR" ] || error "can't locate \$APORTSDIR"

args=`getopt -o s:Rkqh --long security:,recursive,keep,quiet,help -n "$prog" -- "$@"`
if [ $? -ne 0 ]; then
	usage
	exit 2
fi
eval set -- "$args"
while true; do
	case $1 in
		-s|--security) cvelist=" ($2)"; shift;;
		-f|--fixes) fixes="$2"; shift;;
		-R|--recursive) recursive="-R";;
		-k|--keep) keep="-k";;
		-q|--quiet) quiet=1;; # suppresses msg
		-h|--help) usage; exit;;
		--) shift; break;;
		*) exit 1;; # getopt error
	esac
	shift
done
if [ $# -eq 0 ]; then
	usage
	exit 2
fi

abuild_opts="$recursive $keep"

do_bump "$@"