build-latest-debian-mpd-package 4.64 KB
Newer Older
1 2 3 4 5
#!/usr/bin/env bash
## 
## `build-latest-debian-mpd-package' is a script to build the latest
## version of mpd for debian inside a (temporary) debian chroot.
##
6
##  Copyright (C) 2015 Ronald van Engelen <ronalde+gitlab@lacocina.nl>
7 8 9 10 11 12 13 14 15 16 17 18 19 20
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
## The script, helpers and documentation are published at 
21
## https://gitlab.com/ronalde/build-latest-mpd-for-debian
22 23 24 25 26
## 
## This script normally is copied inside a debian chroot by the script
## `make-debian-mpd-chroot' and set to be automagically started by
## adding it to root's ~/.profile.

27
DEBCHROOT_MIRROR="${DEBCHROOT_MIRROR:-http://ftp.debian.org/debian}"
28
## or use local apt cacher like approx
29 30
#DEBCHROOT_MIRROR="http://localnet:9999/debian"
DEBCHROOT_VERSION="${DEBCHROOT_VERSION:-jessie}"
31 32 33 34 35 36 37 38
## regular expression to match a mpd version
mpd_version_re="[0-9]*\.[0-9]*\.[0-9]*"
## regexp to match uscan output line 
uscan_re="site[[:space:]]is[[:space:]](${mpd_version_re}),"
scriptname="$(basename ${0})"
logfile=$(mktemp --tmpdir "${scriptname}.XXXX")

## start logging
Ronald van Engelen's avatar
Ronald van Engelen committed
39
printf "\nstarting %s inside chroot at %s\n" "${scriptname}" "$(date)" 2>&1 | tee -a ${logfile}
40 41 42
printf "*** logging to \`%s'.\n" "${logfile}" 2>&1 | tee -a ${logfile}

printf "*** update binary and source packages ... " 2>&1 | tee -a ${logfile}
43
res=$(apt-get update >> ${logfile}  2>&1)
44 45
printf "done.\n"  2>&1 | tee -a ${logfile}
printf "*** installing build dependencies for mpd ... " 2>&1 | tee -a ${logfile}
Ronald van Engelen's avatar
Ronald van Engelen committed
46
res=$(apt-get -y build-dep mpd >> ${logfile} 2>&1)
47 48 49 50 51
if [[ $? -ne 0 ]]; then
    printf "ERROR: \n\`%s'\n" "${res}" 2>&1 | tee -a ${logfile}
else
    printf "done.\n" 2>&1 | tee -a ${logfile}
    printf "*** installing current mpd source package ... " 2>&1 | tee -a ${logfile}
Ronald van Engelen's avatar
Ronald van Engelen committed
52
    res=$(apt-get source mpd >> ${logfile} 2>&1)
53 54 55 56 57 58
    if [[ $? -ne 0 ]]; then
	printf "ERROR: \n\`%s'\n" "${res}"
    else
	printf "done.\n"
	mpd_current_source=$(ls -d mpd-* 2>&1 | tee -a ${logfile})
	mpd_current_version=${mpd_current_source//mpd-/}
Ronald van Engelen's avatar
Ronald van Engelen committed
59 60
	printf "*** current debian version of mpd is \`%s'\n" \
	       "${mpd_current_version}" 2>&1 | tee -a ${logfile}
61
	
Ronald van Engelen's avatar
Ronald van Engelen committed
62 63
	printf "*** uscanning for updates in current source directory \`%s' ... " \
	       "mpd-${mpd_current_version}" 2>&1 | tee -a ${logfile}
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
	cd ${mpd_current_source} && \
	    uscan_out="$(uscan --verbose 2>&1 | tee -a ${logfile})"
	if [[ $? -ne 0 ]]; then
	    printf "ERROR: \n\`%s'\n" "${uscan_out}" 2>&1 | tee -a ${logfile}
	else
	    ## store newest version
	    printf "done.\n" 2>&1 | tee -a ${logfile}
	    printf "*** iterating uscan output for latest version ."  2>&1 | tee -a ${logfile}
	    while read line; do	    
		if [[ "${line}" =~ ${uscan_re} ]]; then
		    mpd_newest_version="${BASH_REMATCH[1]}"
		    printf ". done.\n*** new version found: \`%s'\n" "${mpd_newest_version}"  2>&1 | tee -a ${logfile}
		    break
		else
		    printf "." 2>&1 | tee -a ${logfile}
		fi
	    done<<<"${uscan_out}"
	    mpd_newest_source="mpd-${mpd_newest_version}" 
	    printf "*** mpd_newest_source = \`${mpd_newest_source}'\n"  2>&1 | tee -a ${logfile}
	    if [[ "${mpd_current_version}" != "${mpd_newest_version}" ]]; then
		printf "*** using uupdate to download and extract latest source ... " 2>&1 | tee -a ${logfile}
Ronald van Engelen's avatar
Ronald van Engelen committed
85 86
		res=$(uupdate --upstream-version "${mpd_newest_version}" \
			      ../${mpd_newest_source}.tar.xz >> ${logfile} 2>&1)
87 88 89 90 91 92
		if [[ $? -ne 0 ]]; then
		    printf "ERROR: \n\`%s'\n" "${res}"  2>&1 | tee -a ${logfile}
		else
		    printf "done.\n" 2>&1 | tee -a ${logfile}
		    printf "*** building new binary in directory \`%s' ..." "../${mpd_newest_source}"  2>&1 | tee -a ${logfile}
		    cd ../${mpd_newest_source} && \
Ronald van Engelen's avatar
Ronald van Engelen committed
93
			res=$(debuild binary >> ${logfile} 2>&1)
94 95 96 97 98 99
		    if [[ $? -ne 0 ]]; then
			printf "ERROR: \n\`%s'\n" "${res}" 2>&1 | tee -a ${logfile}
		    else
			printf "done.\n" 2>&1 | tee -a ${logfile}
			printf "resulting package:\n%s\n" "$(ls ~/mpd_*.deb)" 2>&1 | tee -a ${logfile}
			## clean the packages cache
Ronald van Engelen's avatar
Ronald van Engelen committed
100
			apt-get clean >> ${logfile} 2>&1
101 102 103 104 105 106 107 108 109 110 111
			## shutdown the chroot
			halt
		    fi
		fi
	    else
		printf "no new version available; nothing to do.\n"
		exit 0
	    fi
	fi
    fi
fi