Skip to content

Commit

Permalink
Merge branch 'pr-92'
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxboron committed Mar 9, 2021
2 parents fbf8950 + 5b38b48 commit f1e5492
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
4 changes: 2 additions & 2 deletions docs/repro.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repro - reproducible builds utility

Synopsis
--------
'repro' <command> [options]
'repro' [options] <local-package>


Description
Expand Down Expand Up @@ -46,4 +46,4 @@ Options

See Also
--------
linkman:makepkg[8]
linkman:makepkg[8] linkman:repro.conf[5]
132 changes: 72 additions & 60 deletions repro.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ NOCHECK=${NOCHECK:-0}
CACHEDIR="${CACHEDIR:-cache}"
OUTDIR="${OUTDIR:-./build}"

# Default options
run_diffoscope=0

# By default we don't assume a PKGBUILD
pkgbuild_file=0

makepkg_args=(
--syncdeps
--clean
--noconfirm
--skippgpcheck
)

# Desc: Escalates privileges
orig_argv=("$0" "$@")
src_owner=${SUDO_USER:-$USER}
Expand All @@ -47,12 +60,12 @@ function gpg() {
}

function init_gnupg() {
[ ! -d "$BUILDDIRECTORY/_gnupg" ] && mkdir -p "$BUILDDIRECTORY/_gnupg"
mkdir -p "$BUILDDIRECTORY/_gnupg"

# ensure signing key is available
# We try WKD first, then fallback to keyservers.
# This works on debian./
gpg --keyserver=p80.pool.sks-keyservers.net --auto-key-locate wkd,keyserver --locate-keys [email protected] &>/dev/null
gpg --keyserver=p80.pool.sks-keyservers.net --auto-key-locate wkd,keyserver --locate-keys [email protected]
}

# Desc: Sets the appropriate colors for output
Expand All @@ -75,7 +88,6 @@ function colorize() {
fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
}
colorize

# Desc: Message format
function msg() {
Expand Down Expand Up @@ -207,12 +219,12 @@ __END__

# Desc: Sets up a container with the correct files
function init_chroot(){
set -e

[ ! -d "$BUILDDIRECTORY" ] && mkdir -p "$BUILDDIRECTORY"
mkdir -p "$BUILDDIRECTORY"

# Prepare root chroot
if [ ! -d "$BUILDDIRECTORY"/root ]; then
get_bootstrap_img

lock 9 "$BUILDDIRECTORY"/root.lock
msg "Preparing chroot"
trap '{ cleanup_root_volume; exit 1; }' ERR
Expand Down Expand Up @@ -251,19 +263,11 @@ function init_chroot(){
}

# Desc: Reproduces a package
# 1: Location of package
function cmd_check(){
local pkg="${1}"
local cachedir="${CACHEDIR}"

if [[ ! -f "${pkg}" ]]; then
error "no package file given"
exit 1
fi

trap - ERR INT


declare -A buildinfo
while IFS=$'=' read -r key value; do
[[ "${key}" = [#!]* ]] || [[ "${key}" = "" ]] || buildinfo["${key}"]="${value}"
Expand Down Expand Up @@ -337,6 +341,8 @@ __END__
# shellcheck disable=SC2086
keyring_package="$(printf -- '%s\n' ${installed[*]} | grep -E "archlinux-keyring")"

mkdir -p "$KEYRINGCACHE"

if [ ! -d "$KEYRINGCACHE/$keyring_package" ]; then
msg2 "Setting up $keyring_package in keyring cache, this might take a while..."

Expand Down Expand Up @@ -441,6 +447,8 @@ __END__

# Desc: Fetches a bootstrap image and verifies the signature
function get_bootstrap_img() {
init_gnupg

if [ ! -e "$IMGDIRECTORY/$bootstrap_img" ]; then
msg "Downloading bootstrap image..."
( cd "$IMGDIRECTORY" && curl -f --remote-name-all "$BOOTSTRAPMIRROR/$bootstrap_img"{,.sig} )
Expand All @@ -455,7 +463,7 @@ function get_bootstrap_img() {
function print_help() {
cat <<__END__
Usage:
repro [options]
repro [options] <local-package>
General Options:
-h Print this help message
Expand All @@ -466,58 +474,62 @@ General Options:
__END__
}

hash buildinfo 2>/dev/null || { error "Require buildinfo in path! Aborting..."; exit 1; }

# Default options
run_diffoscope=0

# By default we don't assume a PKGBUILD
pkgbuild_file=0
function parse_args() {
while getopts :hdnf arg; do
case $arg in
h) print_help; exit 0;;
f) pkgbuild_file=1;;
d) run_diffoscope=1;;
n) NOCHECK=1;;
o) OUTDIR="$OPTARG";;
*) error "unknown argument ${OPTARG}" ; print_help; exit 1;;
esac
done

repro_conf=$CONFIGDIR/repro.conf
if [[ -r $repro_conf ]]; then
# shellcheck source=/dev/null
source "$repro_conf"
fi
if ((NOCHECK)); then
makepkg_args+=(--nocheck)
fi

xdg_repro_dir="${XDG_CONFIG_HOME:-$HOME/.config}/archlinux-repro"
if [[ -r "$xdg_repro_dir/repro.conf" ]]; then
# shellcheck source=/dev/null
source "$xdg_repro_dir/repro.conf"
elif [[ -r "$HOME/.repro.conf" ]]; then
# shellcheck source=/dev/null
source "$HOME/.repro.conf"
fi
# Save command args (such as path to .pkg.tar.xz file)
shift $((OPTIND-1))

if [[ $# != 1 ]]; then
error "too many packages provided"
print_help
exit 1
fi

while getopts :hdnfo: arg; do
case $arg in
h) print_help; exit 0;;
f) pkgbuild_file=1;;
d) run_diffoscope=1;;
n) NOCHECK=1;;
o) OUTDIR="$OPTARG";;
*) ;;
esac
done
pkg="$@"
if [[ ! -f "${pkg}" ]]; then
error "argument provided ${pkg} isn't a valid file"
print_help
exit 1
fi
}

makepkg_args=(
--syncdeps
--clean
--noconfirm
--skippgpcheck
)
function source_conf() {
local repro_conf
local xdg_repro_dir

if ((NOCHECK)); then
makepkg_args+=(--nocheck)
fi
repro_conf=$CONFIGDIR/repro.conf
if [[ -r $repro_conf ]]; then
# shellcheck source=/dev/null
source "$repro_conf"
fi

# Save command args (such as path to .pkg.tar.xz file)
shift $((OPTIND-1))
xdg_repro_dir="${XDG_CONFIG_HOME:-$HOME/.config}/archlinux-repro"
if [[ -r "$xdg_repro_dir/repro.conf" ]]; then
# shellcheck source=/dev/null
source "$xdg_repro_dir/repro.conf"
elif [[ -r "$HOME/.repro.conf" ]]; then
# shellcheck source=/dev/null
source "$HOME/.repro.conf"
fi
}

colorize
source_conf
parse_args "$@"
check_root NOCHECK,MAKEFLAGS,DEBUG,CACHEDIR
init_gnupg
test -d "$BUILDDIRECTORY"/root || get_bootstrap_img
test -d "$KEYRINGCACHE" || mkdir -p "$KEYRINGCACHE"
init_chroot
cmd_check "$@"
cmd_check

0 comments on commit f1e5492

Please sign in to comment.