code:
#! /bin/sh -
#
# /etc/cron.daily/logrotate - Rotates system logs periodically.
#

/usr/sbin/logrotate /etc/logrotate.conf
status=$?

if test $status -ne 0
then
    /usr/bin/logger \
     -t logrotate "ALERT exited abnormally with exit status $status"
fi
exit $status

repo_name: dustdfg/dragora

license: mit


code:
#! /bin/sh -
#
# /etc/cron.daily/man-db - Update manual page(s) database periodically.
#

set -e
umask 022

# Unset $MANPATH to read from configuration file
if test -f /etc/man_db.conf
then
    unset MANPATH
fi

test -d /var/cache/man || mkdir -p /var/cache/man
ionice -c 3 nice -n 14 mandb --quiet 2> /dev/null


code:
# man_db.conf
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATH			manpath_element
# MANPATH_MAP		path_element	manpath_element
# MANDB_MAP		global_manpath	[relative_catpath]
#---------------------------------------------------------
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH 			/usr/src/pvm3/man
#
#MANDATORY_MANPATH			/usr/man
MANDATORY_MANPATH			/usr/share/man
MANDATORY_MANPATH			/usr/local/share/man
#---------------------------------------------------------
# set up PATH to MANPATH mapping
# ie. what man tree holds man pages for what binary directory.
#
#		*PATH*        ->	*MANPATH*
#
MANPATH_MAP	/bin			/usr/share/man
MANPATH_MAP	/usr/bin		/usr/share/man
MANPATH_MAP	/sbin			/usr/share/man
MANPATH_MAP	/usr/sbin		/usr/share/man
MANPATH_MAP	/usr/local/bin		/usr/local/man
MANPATH_MAP	/usr/local/bin		/usr/local/share/man
MANPATH_MAP	/usr/local/sbin		/usr/local/man
MANPATH_MAP	/usr/local/sbin		/usr/local/share/man
MANPATH_MAP	/usr/X11R6/bin		/usr/X11R6/man
MANPATH_MAP	/usr/bin/X11		/usr/X11R6/man
MANPATH_MAP	/usr/games		/usr/share/man
MANPATH_MAP	/opt/bin		/opt/man
MANPATH_MAP	/opt/sbin		/opt/man
#---------------------------------------------------------
# For a manpath element to be treated as a system manpath (as most of those
# above should normally be), it must be mentioned below. Each line may have
# an optional extra string indicating the catpath associated with the
# manpath. If no catpath string is used, the catpath will default to the
# given manpath.
#
# You *must* provide all system manpaths, including manpaths for alternate
# operating systems, locale specific manpaths, and combinations of both, if
# they exist, otherwise the permissions of the user running man/mandb will
# be used to manipulate the manual pages. Also, mandb will not initialise
# the database cache for any manpaths not mentioned below unless explicitly
# requested to do so.
#
# In a per-user configuration file, this directive only controls the
# location of catpaths and the creation of database caches; it has no effect
# on privileges.
#
# Any manpaths that are subdirectories of other manpaths must be mentioned
# *before* the containing manpath. E.g. /usr/man/preformat must be listed
# before /usr/man.
#
#		*MANPATH*     ->	*CATPATH*
#
#MANDB_MAP	/usr/man		/var/cache/man/fsstnd
MANDB_MAP	/usr/share/man		/var/cache/man
MANDB_MAP	/usr/local/man		/var/cache/man/oldlocal
MANDB_MAP	/usr/local/share/man	/var/cache/man/local
MANDB_MAP	/usr/X11R6/man		/var/cache/man/X11R6
MANDB_MAP	/opt/man		/var/cache/man/opt
#
#---------------------------------------------------------
# Program definitions.  These are commented out by default as the value
# of the definition is already the default.  To change: uncomment a
# definition and modify it.
#
#DEFINE 	pager	less
#DEFINE 	cat	cat
#DEFINE 	tr	tr '\255\267\264\327' '\055\157\047\170'
#DEFINE		grep	grep
#DEFINE 	troff 	groff -mandoc
#DEFINE 	nroff 	nroff -mandoc
#DEFINE 	eqn 	eqn
#DEFINE 	neqn	neqn
#DEFINE 	tbl 	tbl
#DEFINE 	col 	col
#DEFINE 	vgrind
#DEFINE 	refer 	refer
#DEFINE 	grap
#DEFINE 	pic 	pic -S
#
#DEFINE		compressor	gzip -c7
#---------------------------------------------------------
# Misc definitions: same as program definitions above.
#
#DEFINE		whatis_grep_flags		-i
#DEFINE		apropos_grep_flags		-iEw
#DEFINE		apropos_regex_grep_flags	-iE
#---------------------------------------------------------
# Section names. Manual sections will be searched in the order listed here;
# the default is 1, n, l, 8, 3, 0, 2, 5, 4, 9, 6, 7. Multiple SECTION
# directives may be given for clarity, and will be concatenated together in
# the expected way.
# If a particular extension is not in this list (say, 1mh), it will be
# displayed with the rest of the section it belongs to. The effect of this
# is that you only need to explicitly list extensions if you want to force a
# particular order. Sections with extensions should usually be adjacent to
# their main section (e.g. "1 1mh 8 ...").
#
SECTION		1 1p 8 2 3 3p 4 5 6 7 9 0p tcl n l p o 1x 2x 3x 4x 5x 6x 7x 8x
#
#---------------------------------------------------------
# Range of terminal widths permitted when displaying cat pages. If the
# terminal falls outside this range, cat pages will not be created (if
# missing) or displayed.
#
#MINCATWIDTH	80
#MAXCATWIDTH	80
#
# If CATWIDTH is set to a non-zero number, cat pages will always be
# formatted for a terminal of the given width, regardless of the width of
# the terminal actually being used. This should generally be within the
# range set by MINCATWIDTH and MAXCATWIDTH.
#
#CATWIDTH	0
#
#---------------------------------------------------------
# Flags.
# NOCACHE keeps man from creating cat pages.
NOCACHE


code:
#! /bin/sh -
#
# /etc/cron.daily/mlocate - Update the mlocate(1) database.
#

set -e
umask 022

ionice -c 3 nice -n 19 updatedb


code:
#
# /etc/updatedb.conf - Configuration file for updatedb(8).
#
# For more information, type "man 5 updatedb.conf".
#

PRUNE_BIND_MOUNTS = "yes"
PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fuse.sshfs fusectl gfs gfs2 gpfs hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs ceph fuse.ceph"
PRUNENAMES = ".git .hg .svn .bzr .arch-ids {arch} CVS _darcs RCS .fsl"
PRUNEPATHS = "/tmp /media /mnt /var/cache /var/lock /var/run /var/spool /var/tmp /var/lib/ceph"


code:
.TH ncftpbookmarks 1 2003-07-09 "NcFTP Software"

.SH NAME
ncftpbookmarks \- full screen bookmarks editor for ncftp

.SH SYNOPSIS
ncftpbookmarks

.SH DESCRIPTION
.PP
.I ncftpbookmarks
is a full-screen bookmark editor for the
.I "File Transfer Protocol"
client
.IR "ncftp".
.PP
.I ncftp
can bookmark server name, login name and password
of your favorite ftp servers.
.I ncftpbookmarks
is used to handle these
bookmarks.

This full-screen editor can also be launched from the ncftp prompt with
the
.I bookmarks
command.

While using
.IR ncftpbookmarks ,
the screen is divided into two parts.
The left one gives a brief description of keyboard controls.
The right one lists all existing bookmarks.
Up and down arrows (or "u" and "d" keys) are used to move the cursor
in this list.
The "x" key is used to quit the editor.
Other commands have to be typed in full (e.g.\&
.IR /ed ,
.IR /del ).

.SH FILES
.IP $HOME/\.ncftp/bookmarks
Saves bookmark and host information.

.SH AUTHORS
.PP
Mike Gleason, NcFTP Software (mgleason@ncftp.com).

This man page was written by Nicolas Duboc (nicolas@duboc.net) for
the Debian distribution of the ncftp package.

.SH "SEE ALSO"
.PP
.IR ncftp (1)


code:
#! /bin/sh -

# This will try to invoke the new driver to read/write NTFS file systems
# which was introduced into Linux Kernel series 5.15+.

exec mount -t ntfs3 "$@"


code:
#! /bin/sh -
#
# Generic perpetrate(5) runscript for sshd.
#

if test "$1" = start
then
    exec tinylog_run "$2"
fi


code:
#! /bin/sh -
#
# sshd/rc.main
#
# The OpenSSH SSH daemon.
#

# Redirects the standard error to the standard output
exec 2>&1

TARGET="$1"
SVNAME="${2:-sshd}"

make_keys()
{
    if test ! -f /etc/ssh/ssh_host_key || test ! -s /etc/ssh/ssh_host_key
    then
        echo "*** ${SVNAME}: Generating /etc/ssh/ssh_host_key ..."
        /usr/bin/ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N ''
    fi
    if test ! -f /etc/ssh/ssh_host_dsa_key || test ! -s /etc/ssh/ssh_host_dsa_key
    then
        echo "*** ${SVNAME}: Generating /etc/ssh/ssh_host_dsa_key ..."
        /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
    fi
    if test ! -f /etc/ssh/ssh_host_rsa_key || test ! -s /etc/ssh/ssh_host_rsa_key
    then
        echo "*** ${SVNAME}: Generating /etc/ssh/ssh_host_rsa_key ..."
        /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
    fi
}

start()
{
    echo "*** ${SVNAME}: Starting sshd ..."
    make_keys
    # sshd options required for perp service:
    #   -D  no detach, run in foreground
    #   -e  log to stderr (for tinylog) instead of syslog
    #
    exec /usr/sbin/sshd -D -e -f /etc/ssh/sshd_config
}

reset()
{
    case $3 in
    exit)
        echo "*** ${SVNAME}: Exited status $4"
        ;;
    signal)
        echo "*** ${SVNAME}: Killed on signal $5"
        ;;
    *)
        echo "*** ${SVNAME}: Stopped (${3})"
        ;;
    esac
}

# Branch to target
eval ${TARGET} "$@"


code:
# Set base scanning directory for the perpd process
test -n "${PERP_BASE+$PERP_BASE}" || PERP_BASE=/etc/perp

# Colorize perpls(8) output
test -n "${PERPLS_COLORS+$PERPLS_COLORS}" || \
 PERPLS_COLORS="df=00:na=00:an=01:ar=01;33:ap=01;33:\
ad=01;34:wu=01;33:wd=01;33:er=01;31:ex=01;31"

export PERP_BASE PERPLS_COLORS


code:
#! /bin/sh -
# rc.log: perpd logger script for perpboot
# ===

### --- configure ---

## required:
LOGDIR=/var/log/perpd
LOGOPTS="-k 8 -s 100000 -t -z"
## suggested:
LOGUSER=log

### --- script ---

## initialize user:
if id ${LOGUSER} >/dev/null 2>/dev/null ; then
  my_uid=$(id -u ${LOGUSER})
  my_gid=$(id -g ${LOGUSER})
else
  LOGUSER=$(id -un)
  my_uid=$(id -u ${LOGUSER})
  my_gid=$(id -g ${LOGUSER})
fi

## initialize logdir:
if ! test -d ${LOGDIR} ; then
  mkdir -p ${LOGDIR}
fi
chown -R ${my_uid}:${my_gid} ${LOGDIR}
chmod 0755 ${LOGDIR}

## exec tinylog with privilege drop:
exec \
  runuid ${LOGUSER} \
      tinylog ${LOGOPTS} ${LOGDIR}

### EOF


code:
#! /bin/sh -
# rc.perp: perpd startup script for perpboot
# ===

set -e

### --- configure ---
PERP_VAR=/var/run/perp
PERPD_OPTS="-a6"

### --- script ---

## note: perpboot defines PERP_BASE on startup

## clean setup for runtime control files:
rm -Rf ${PERP_VAR}
mkdir -p ${PERP_VAR}
chmod 0700 ${PERP_VAR}

## clean symlink:
rm -Rf ${PERP_BASE}/.control
ln -sf ${PERP_VAR} ${PERP_BASE}/.control

## exec perpd:
##   * options as configured above
##   * runchoom(8) abate linux oom-killer
##   * runlimit(8) configured in ./rlimit.conf
##   * PERP_BASE defined in environment by perpboot(8)
exec \
  runchoom \
  runlimit -F ./rlimit.conf \
  perpd ${PERPD_OPTS} ${PERP_BASE}

### EOF


code:
#
# /etc/tinylog.conf - Config for tinylog/tinylog_run wrapper script
#
# For more info about it, type "man 8 tinylog".
#
TINYLOG_USER=log
TINYLOG_BASE=/var/log
TINYLOG_OPTS="-k 5 -s 100000 -t -z"
TINYLOG_ZIP=/usr/bin/lzip


code:
# Set PKG_CONFIG and PKG_CONFIG_PATH if unset

test -n "${PKG_CONFIG+$PKG_CONFIG}" || \
 PKG_CONFIG=/usr/bin/pkgconf

test -n "${PKG_CONFIG_PATH+$PKG_CONFIG_PATH}" || \
 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

export PKG_CONFIG PKG_CONFIG_PATH


code:
# /etc/inputrc: Initialization file used by readline(3)
#
# This file controls the behaviour of line input editing for programs
# that use the GNU Readline library. For more information, see the
# manual page - section INITIALIZATION FILE
#

# Controls what happens when readline wants to ring the terminal bell
#
# Value: none, visible, audible
#
set bell-style audible

# Enable the eight-bit input
#
# Value: on, off
#
set input-meta on

# Allow iso-latin1 characters to be inserted
# rather than converted to prefix-meta sequences
#
# Value: on, off
#
set convert-meta off

# Display characters with the eighth bit set directly
# rather than as meta-prefixed characters
#
# Value: on, off
#
set output-meta on

# If there are more than X possible completions for
# a word, ask the user if he wants to see all of them
#
# Value: <integer greater than or equal to zero>
#
set completion-query-items 130

# Use a single line for display, scrolling the input
# horizontally on a single screen line when it becomes
# longer than the screen width
#
# Value: on, off
#
set horizontal-scroll-mode on

# Linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# Xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# Aterm / Eterm
"\eOd": backward-word
"\eOc": forward-word

path: archive/readline/etc/inputrc


code:
#
# /etc/crontab - Tables for driving cron.
#
# Columns:
#  minute, hour, day of month, month, day of week, command
#
# Separator:
#  Any number of tabs or spaces.
#
# Value:
#  * (wildcard), 30 (number), */N (repeat), 1-5 (range), or 1,3,6 (list)
#

# Run once an hour
0 * * * * /usr/bin/run-parts /etc/cron.hourly

# Run once a day
0 0 * * * /usr/bin/run-parts /etc/cron.daily

# Run once a week
0 0 * * 0 /usr/bin/run-parts /etc/cron.weekly

# Run once a month
0 0 1 * * /usr/bin/run-parts /etc/cron.monthly

path: archive/scron/crontab


code:
#! /bin/sh -
#
# Generic perpetrate(5) runscript for crond (scron).
#

if test "$1" = start
then
    exec tinylog_run "$2"
fi


code:
#! /bin/sh -
#
# crond/rc.main
#
# Suckless cron daemon.
#

# Redirects the standard error to the standard output
exec 2>&1

TARGET="$1"
SVNAME="${2:-crond}"

start()
{
    echo "*** ${SVNAME}: Starting crond ..."
    exec /usr/bin/crond -n -f /etc/crontab
}

reset()
{
    case $3 in
    exit)
        echo "*** ${SVNAME}: Exited status $4"
        ;;
    signal)
        echo "*** ${SVNAME}: Killed on signal $5"
        ;;
    *)
        echo "*** ${SVNAME}: Stopped (${3})"
        ;;
    esac
}

# Branch to target
eval ${TARGET} "$@"


code:
#! /bin/sh -
# Copyright (c) 2017-2018 Matias Fonzo.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if test $# -eq 0
then
    echo "An alternative to Debian run-parts(8)"
    echo ""
    echo "Usage: $0 <directory>"
    exit 0
fi
if test ! -d "$1"
then
    echo "Error '$1' is not a valid directory." 1>&2
    echo "Usage: $0 <directory>" 1>&2
    exit 1
fi

SUFFIXES_TO_IGNORE="~ ^ , .bak .new"

# Loop
for script in "$1"/*
do
    test -f "$script" || continue;

    for suffix in $SUFFIXES_TO_IGNORE
    do
        case $script in
        *${suffix})
            continue 2
            ;;
        esac
    done
    unset suffix

    if test -x "$script"
    then
        "$script" || echo "$script failed." 1>&2
    fi
done

path: archive/scron/run-parts


code:
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/mksh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

path: archive/shadow/etc/default/useradd


code:
#! /bin/sh -
#
# Turn shadow passwords on or off (based on Debian's shadowconfig.sh)
#
# Copyright (c) 2018 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

umask 022
IFS='
 	'
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin

usage()
{
    echo "Usage: ${0##*/} [on|off]"
    echo "Turn shadow passwords ON or OFF."
}

# Exit immediately on any error
set -e

# Be immune to the following signals
trap "" HUP INT QUIT ABRT TERM

# Parse options

case $1 in
    on | ON )
        pwck -q -r
        grpck -r
        pwconv
        grpconv
        chown root:root /etc/passwd /etc/group
        chmod 644 /etc/passwd /etc/group
        chown root:shadow /etc/shadow /etc/gshadow
        chmod 640 /etc/shadow /etc/gshadow
        echo "Shadow passwords are now on."
        ;;
    off | OFF )
        pwck -q -r
        grpck -r
        pwunconv
        grpunconv
        # sometimes the passwd perms get munged
        chown root:root /etc/passwd /etc/group
        chmod 644 /etc/passwd /etc/group
        echo "Shadow passwords are now off."
        ;;
    --help | -h )
        usage
        exit 0
        ;;
    -*)
        echo "Unrecognized option: $1" 1>&2
        usage
        exit 1
        ;;
    *)
        usage
        ;;
esac

path: archive/shadow/usr/sbin/shadowconfig


code:
# st version
VERSION = 0.8.1

# Customize below to fit your system

# paths
PREFIX = /usr
MANPREFIX = $(PREFIX)/share/man

X11INC = /usr/include/X11
X11LIB = /usr/lib/X11

# includes and libs
INCS = -I$(X11INC) \
       `pkg-config --cflags fontconfig` \
       `pkg-config --cflags freetype2`
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
       `pkg-config --libs fontconfig` \
       `pkg-config --libs freetype2`

# flags
CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
STCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS)
STLDFLAGS = $(LIBS) $(LDFLAGS)

# compiler and linker
CC = cc


code:
#! /bin/sh -
#
# Generic perpetrate(5) runscript for syslogd.
#

if test "$1" = start
then
    exec tinylog_run "$2"
fi


code:
#! /bin/sh -
#
# syslogd/rc.main
#
# Log systems messages.
#

# Redirects the standard error to the standard output
exec 2>&1

TARGET="$1"
SVNAME="${2:-syslogd}"

start()
{
    echo "*** ${SVNAME}: Starting syslogd ..."
    exec /usr/sbin/syslogd -F -s
}

reset()
{
    case $3 in
    exit)
        echo "*** ${SVNAME}: Exited status $4"
        ;;
    signal)
        echo "*** ${SVNAME}: Killed on signal $5"
        ;;
    *)
        echo "*** ${SVNAME}: Stopped (${3})"
        ;;
    esac
}

# Branch to target
eval ${TARGET} "$@"


code:
#
# /etc/syslog.conf - Configuration file for syslogd(8)
#
# For information about the format of this file, type:
# "man 5 syslog.conf"
#

#
# Authentication and user related logs
#
auth.*; authpriv.*				-/var/log/auth.log
*.*;auth,authpriv.none				-/var/log/syslog
user.*						-/var/log/user.log

#
# Debug information
#
*.=debug					-/var/log/debug

#
# Log info and notice messages
#
*.=info;*.=notice;\
	mail.none				-/var/log/messages

#
# Kernel information
#
kern.*						-/var/log/kernel.log

#
# Mail system log
#
mail.*						-/var/log/mail.log

#
# Emergencies are sent to anyone logged in
#
*.=emerg					*

#
# Priority alert and above are sent to the operator
#
#*.alert						root,joey

#
# Include all config files from /etc/syslog.d/
#
include /etc/syslog.d/*.conf


code:
/var/log/auth.log /var/log/syslog /var/log/user.log /var/log/debug /var/log/messages /var/log/kernel.log /var/log/mail.log {
    sharedscripts
    postrotate
        kill -s HUP "$(pidof syslogd)" || true;
    endscript
}


code:
#
# /etc/hosts.allow:
#
# This file describes the names of the hosts which are allowed to use
# the local INET services, as decided by the '/usr/sbin/tcpd' server.
#
# Check the manual pages for hosts_access(5), and hosts_options(5).
#


code:
#
# /etc/hosts.deny:
#
# This file describes the names of the hosts which are **not** allowed
# to use the local INET services, as decided by the '/usr/sbin/tcpd'
# server.
#
# Check the manual pages for hosts_access(5), and hosts_options(5).
#

# The default policy.  This denies all service to all hosts on the
# Internet, unless they are permitted access by entries in the
# /etc/hosts.allow file
ALL: ALL EXCEPT localhost


code:
[Wallpaper]
File=bluedragora.jpg
Name=Blue Dragora
ImageType=pixmap
Author=Oswald Kelso under Creative Commons Attribution 3.0 Unported


code:
# Expand Trinity's path, if needed

# Set path for Trinity binaries
case $PATH in
*/opt/trinity/bin*)
    true
    ;;
*)
    # Set path for Tqt3 and Trinity binaries
    PATH="${PATH}:/opt/trinity/bin"
    export PATH
    ;;
esac

# Set path for search pkg-config files
case $PKG_CONFIG_PATH in
*/opt/trinity/lib*)
    true
    ;;
*)
    PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/opt/trinity/lib/pkgconfig"
    export PKG_CONFIG_PATH
    ;;
esac


code:
#! /bin/sh -

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# Start the Trinity Desktop Environment

exec dbus-launch --exit-with-session /opt/trinity/bin/starttde

path: archive/tdebase/xinitrc-tde


code:
#! /bin/sh -
#
# /etc/cron.daily/texinfo - Update index for Info documents periodically.
#

set -e
ionice -c 3 -p $$
umask 022

for infodir in /usr/local/share/info/ /usr/share/info/
do
    if ! test -d "$infodir"
    then
        echo "WARNING: ${0}: '$infodir' is not a directory." 1>&2
        continue;
    fi

    find -L $infodir -maxdepth 1 ! -name dir \
     -exec install-info '{}' ${infodir}/dir \;
done


code:
#! /bin/sh -

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# start some nice programs

if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 done
 unset f
fi

twm &
xclock -geometry 50x50-1+1 &
xterm -geometry 80x50+494+51 &
xterm -geometry 80x20+494-0 &
exec xterm -geometry 80x66+0+0 -name login

path: archive/twm/xinitrc-twm


code: ACTION=="add", ATTR{removable}=="1", ATTR{events_poll_msecs}=="-1", ATTR{events_poll_msecs}="2200"


code:
#! /bin/sh -
#
# Generic perpetrate(5) runscript for devmon (udevil).
#

if test "$1" = start
then
    exec tinylog_run "$2"
fi


code:
#! /bin/sh -
#
# devmon/rc.main
#
# Device monitor (Udevil).
#

# Redirects the standard error to the standard output
exec 2>&1

TARGET="$1"
SVNAME="${2:-devmon}"

start()
{
    echo "*** ${SVNAME}: Starting devmon ..."
    exec /usr/bin/devmon --sync
}

reset()
{
    case $3 in
    exit)
        echo "*** ${SVNAME}: Exited status $4"
        ;;
    signal)
        echo "*** ${SVNAME}: Killed on signal $5"
        ;;
    *)
        echo "*** ${SVNAME}: Stopped (${3})"
        ;;
    esac
}

# Branch to target
eval ${TARGET} "$@"


code:
# Suppressions for musl libc
# See: https://www.openwall.com/lists/musl/2017/06/15/4

{
   musl-dynlink-false-positive1
   Memcheck:Leak
   fun:calloc
   fun:load_direct_deps
   fun:load_deps
   fun:load_deps
   fun:__dls3
   fun:__dls2b
   fun:__dls2
}

{
   musl-dynlink-false-positive2
   Memcheck:Leak
   fun:calloc
   fun:load_direct_deps
   fun:load_deps
   fun:load_deps
   fun:__dls3
   fun:__dls2
}

{
   musl-dynlink-false-positive3
   Memcheck:Leak
   fun:calloc
   fun:load_library
   fun:load_preload
   fun:__dls3
   fun:__dls2b
   fun:__dls2
}

{
   musl-dynlink-false-positive4
   Memcheck:Leak
   fun:calloc
   fun:load_library
   fun:load_preload
   fun:__dls3
   fun:__dls2
}


code:
#! /bin/sh -
exec /usr/bin/vim -v "$@"

path: archive/vim/usr/bin/vi


code:
CONFIG_BACKEND=file
CONFIG_CTRL_IFACE=y
CONFIG_DEBUG_FILE=y
CONFIG_DEBUG_SYSLOG=y
CONFIG_DEBUG_SYSLOG_FACILITY=LOG_DAEMON
CONFIG_DRIVER_NL80211=y
CONFIG_DRIVER_WEXT=y
CONFIG_DRIVER_WIRED=y
CONFIG_EAP_GTC=y
CONFIG_EAP_LEAP=y
CONFIG_EAP_MD5=y
CONFIG_EAP_MSCHAPV2=y
CONFIG_EAP_OTP=y
CONFIG_EAP_PEAP=y
CONFIG_EAP_TLS=y
CONFIG_EAP_TTLS=y
CONFIG_IEEE8021X_EAPOL=y
CONFIG_IPV6=y
CONFIG_LIBNL32=y
CONFIG_PEERKEY=y
CONFIG_PKCS12=y
CONFIG_READLINE=y
CONFIG_SMARTCARD=y
CONFIG_WPS=y
CFLAGS += -I/usr/include/libnl3
CONFIG_CTRL_IFACE_DBUS=y
CONFIG_CTRL_IFACE_DBUS_NEW=y
CONFIG_CTRL_IFACE_DBUS_INTRO=y


code:
# Enable ctrl-alt-backspace keys to allow "Terminate Server"
Section "ServerFlags"
        Option "DontZap" "false"
EndSection

Section "InputClass"
        Identifier "Keyboard Defaults"
        MatchIsKeyboard "yes"
        Option "XkbOptions" "terminate:ctrl_alt_bksp"
EndSection


code:
#! /bin/sh -
# Builder of custom stages (cross compilers, GNU/Linux distributions)
#
# Copyright (c) 2014-2022 Matias Fonzo, <selk@dragora.org>.
#
# 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/>.

# EXIT STATUS
# 0  = Successful completion
# 1  = Minor common errors (e.g: help usage, support not available)
# 2  = Command execution error
# 3  = Integrity check error for compressed files

PROGRAM="${0##*/}"

# Override locale settings
LC_ALL=C
LANGUAGE=C
export LC_ALL LANGUAGE

# Get physical working directory (absolute path)
worktree="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)" || exit $?

### Functions

usage()
{
    printf '%s' \
"Usage: $PROGRAM [OPTIONS] [FILE]...
Builder of custom stages (cross compilers, GNU/Linux distributions).

Where FILE is any shell script (as long as it is executable) from
a stage number.  Without FILE, it loads all the found scripts from
the stage number.  Stage numbers come from the stages directory
(${worktree}/stages).

Defaults for the options are specified in brackets.

Options:
  -a          Target architecture [${arch}]
  -j          Parallel jobs for the compiler [${jobs}]
  -k          Keep (don't delete) source directory
  -o          Output directory [${output}]
  -s          Stage number to build [${stage}]
  -h          Display this help and exit
  -V          Print version information and exit

Some influential environment variables:
  TMPDIR      Temporary directory for sources [${TMPDIR}]
  BTCC        C compiler command [${BTCC}]
  BTCXX       C++ compiler command [${BTCXX}]
  BTCFLAGS    C compiler flags [${BTCFLAGS}]
  BTCXXFLAGS  C++ compiler flags [${BTCXXFLAGS}]
  BTLDFLAGS   Linker flags [${BTLDFLAGS}]
  VENDOR      Vendor name to reflect on the target triplet

Available targets from ${worktree}/targets ...

"
for name in "${worktree}/targets"/*
do
    sed -e '2q;d' "$name"
done
unset -v name
echo ""
}

version()
{
    printf '%s' \
"$PROGRAM 3.33
Copyright (C) 2014-2022 Matias Andres Fonzo.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
"
}

warn()
{
    printf '%s\n' "$@" 1>&2
}

chkstatus_or_exit()
{
    status=$?

    if test $status -ne 0
    then
        echo "Return status = $status" 1>&2
        exit "${1-2}";	# If not given, defaults to 2
    fi

    unset -v status
}

# Function to test and extract compressed files
unpack()
{
    for file in "$@"
    do
        case $file in
        *.tar)
            tar tf "$file" > /dev/null && \
            tar xpf "$file"
            chkstatus_or_exit 3
            ;;
        *.tar.gz | *.tgz | *.tar.Z )
            gzip -cd "$file" | tar tf - > /dev/null && \
            gzip -cd "$file" | tar xpf -
            chkstatus_or_exit 3
            ;;
        *.tar.bz2 | *.tbz2 | *.tbz )
            bzip2 -cd "$file" | tar tf - > /dev/null && \
            bzip2 -cd "$file" | tar xpf -
            chkstatus_or_exit 3
            ;;
        *.tar.lz | *.tlz )
            lzip -cd "$file" | tar tf - > /dev/null && \
            lzip -cd "$file" | tar xpf -
            chkstatus_or_exit 3
            ;;
        *.tar.xz | *.txz )
            xz -cd "$file" | tar tf - > /dev/null && \
            xz -cd "$file" | tar xpf -
            chkstatus_or_exit 3
            ;;
        *.tar.zst | *.tzst )
            zstd -cd "$file" | tar -tf - > /dev/null && \
            zstd -cd "$file" | tar -xpf -
            chkstatus_or_exit 3
            ;;
        *.zip | *.ZIP )
            unzip -t "$file" > /dev/null && \
            unzip "$file" > /dev/null
            chkstatus_or_exit 3
            ;;
        *.gz)
            gzip -t "$file" && \
            gzip -cd "$file" > "$(basename -- "$file" .gz)"
            chkstatus_or_exit 3
            ;;
        *.Z)
            gzip -t "$file" && \
            gzip -cd "$file" > "$(basename -- "$file" .Z)"
            chkstatus_or_exit 3
            ;;
        *.bz2)
            bzip2 -t "$file" && \
            bzip2 -cd "$file" > "$(basename -- "$file" .bz2)"
            chkstatus_or_exit 3
            ;;
        *.lz)
            lzip -t "$file" && \
            lzip -cd "$file" > "$(basename -- "$file" .lz)"
            chkstatus_or_exit 3
            ;;
        *.xz)
            xz -t "$file" && \
            xz -cd "$file" > "$(basename -- "$file" .xz)"
            chkstatus_or_exit 3
            ;;
        *.zst)
            zstd -qt "$file" && \
            zstd -cd "$file" > "$(basename -- "$file" .zst)"
            chkstatus_or_exit 3
            ;;
        *)
            warn "${PROGRAM}: cannot unpack ${file}: Unsupported extension"
            exit 1
        esac
    done
    unset -v file
}

# Print a warning for good practices.
#
# Recommended practices is to set variables
# in front of `configure' or make(1), see:
#
# http://www.gnu.org/software/make/manual/html_node/Environment.html
# http://gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Defining-Variables.html
# http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Setting-Output-Variables.html

warn_flags()
{
    warn "" \
     "WARNING: Environment variable '$1' is set."   \
     "This will be unset to avoid possible risks."  \
     ""
}

### Default values

BTCC="${BTCC:=gcc}"
BTCXX="${BTCXX:=g++}"
BTCFLAGS="${BTCFLAGS:=-O2}"
BTCXXFLAGS="${BTCXXFLAGS:=-O2}"
BTLDFLAGS="${BTLDFLAGS:=}"
opt_keep=opt_keep.off
stage=0
libSuffix=""
arch="$(uname -m)" || chkstatus_or_exit
jobs=1
output="${worktree}/OUTPUT.${PROGRAM}"
TMPDIR="${TMPDIR:=${output}/sources}"

# Compose vendor name adding "-" as suffix
test -n "$VENDOR" && VENDOR="${VENDOR}-"

### Parse options

while getopts :ha:j:ko:s:V name
do
    case $name in
    h)
        usage
        exit 0
        ;;
    a)
        arch="$OPTARG"
        ;;
    j)
        jobs="$OPTARG"
        ;;
    k)
        opt_keep=opt_keep
        ;;
    o)
        output="$OPTARG"
        ;;
    s)
        stage="$OPTARG"
        ;;
    V)
        version
        exit 0
        ;;
    :)
        warn "Option '-${OPTARG}' requires an argument"
        usage
        exit 1
        ;;
    \?)
        warn "Illegal option -- '-${OPTARG}'"
        usage
        exit 1
        ;;
    esac
done
shift $(( OPTIND - 1 ))
unset -f usage version

# Check for environment variables, print warning, unset in any case

test -n "$CC" && warn_flags CC
test -n "$CXX" && warn_flags CXX
test -n "$CFLAGS" && warn_flags CFLAGS
test -n "$CXXFLAGS" && warn_flags CXXFLAGS
test -n "$LDFLAGS" && warn_flags LDFLAGS
unset CC CXX CFLAGS CXXFLAGS LDFLAGS warn_flags

# Load target architecture-file

if test -f "${worktree}/targets/$arch"
then
    echo "${PROGRAM}: Loading target $arch ..."
    . "${worktree}/targets/$arch"
else
    warn \
     "${PROGRAM}: Target name not recognized -- '${arch}'" \
     "See '$0 -h' for more information"
    exit 1
fi

# Determine the host to use.
#
# If the host and the target are the same triplet, it won't work.
# We are changing the host if it is really needed

host="$(${BTCC} -dumpmachine)" || chkstatus_or_exit

if test "$host" = "$target"
then
    # Rename VENDOR to 'cross'.  If empty, 'cross-linux' is added
    case "${host%-*-*}" in
    *-*)
        host="$(echo "$host" | sed -e 's/-[^-]*/-cross/')"
        ;;
    *)
        host="$(echo "$host" | sed -e 's/-[^-]*/-cross-linux/')"
        ;;
    esac
fi

# Compose variables for the physical output,
# printing some useful information

crossdir="${output}/cross/${target}"
rootdir="${output}/stage${stage}"

printf '%s\n' \
 "BTCC: $BTCC"                  \
 "BTCXX: $BTCXX"                \
 "BTCFLAGS: $BTCFLAGS"          \
 "BTCXXFLAGS: $BTCXXFLAGS"      \
 "BTLDFLAGS: $BTLDFLAGS"        \
 "Host: $host"                  \
 "Target: $target"              \
 "Output directory: $output"    \
 "Cross  directory: $crossdir"  \
 "Root   directory: $rootdir"

# Remove write permission for group and other
umask 022

# Create required directories
mkdir -p -- "$output" "$TMPDIR"
chkstatus_or_exit

# Set default PATH, propagate variables
PATH="${crossdir}/bin:${PATH}"

export PATH VENDOR TMPDIR

# Main loop
for file in ${worktree}/stages/${stage}/${@:-??-*}
do
    file="${file##*/}"

    if test ! -f "${worktree}/stages/${stage}/$file"
    then
        warn "${PROGRAM}: ${stage}/${file}: No such file or stage number"
        exit 1
    fi
    if test ! -x "${worktree}/stages/${stage}/$file"
    then
        warn "${PROGRAM}: ${stage}/${file}: File not executable, dodging"
        continue;
    fi

    ### Stage pre-settings

    # Create sysroot directory, recreating the symlink for the stage 0

    if test "$stage" = 0
    then
        mkdir -p -- "${crossdir}/$target" || chkstatus_or_exit

        if test ! -L "${crossdir}/${target}/usr"
        then
            ln -s -f . "${crossdir}/${target}/usr" || chkstatus_or_exit
        fi

        # Ensure toolchain sanity for multilib purposes
        case $arch in
        aarch64* | arm* | x32 | x86_64 | i?86 | riscv* )
            if test ! -L "${crossdir}/lib" && test -n "$libSuffix"
            then
                ln -s -f lib${libSuffix} "${crossdir}/lib" || chkstatus_or_exit
            fi
            ;;
        esac
    fi

    # Create "tools" directory, recreating the symlink for the stage 1
    if test "$stage" = 1
    then
        if test ! -d "${rootdir}/tools"
        then
            mkdir -p -- "${rootdir}/tools" || chkstatus_or_exit
        fi

        # Check and make required symlink
        if test ! -L /tools
        then
            ln -s -f "${rootdir}/tools" / || chkstatus_or_exit
        fi
    fi

    echo "${PROGRAM}: Processing $file from stages/${stage} ..."

    # Set trap before to run the script in order to
    # catch the return status, exit code 2 if fails

    trap 'chkstatus_or_exit 2' EXIT HUP INT QUIT ABRT TERM

    # Exit immediately on any error
    set -e

    . "${worktree}/stages/${stage}/$file"

    # Deactivate shell option(s)
    set +e

    # Reset given signals
    trap - EXIT HUP INT QUIT ABRT TERM

    # Delete declared directories on the cleanup() function
    if test "$opt_keep" != opt_keep
    then
        if type cleanup 1> /dev/null 2> /dev/null
        then
            cleanup
            chkstatus_or_exit 2
            unset -f cleanup
        fi
    fi

    # Back to the current working directory
    cd -- "$worktree" || chkstatus_or_exit
done

path: bootstrap


code:
2021-12-31 Matias A. Fonzo <selk@dragora.org>

Version 2021Dec31 released.

    * Binutils has been upgraded to the release 2.35.2.
      It contains latest changes from 2_35-branch (up to commit 3437a8b).

    * Kernel headers from Linux-libre 5.10.56.

    * GCC 10.3.1 (from snapshot 10-20211224).

      - GMP 6.2.1.

      - MPFR 4.1.0 + cumulative patch (latest update from 2021-02-11).

      - MPC 1.2.1.

      - ISL 0.24.

    * Musl upgraded to release 1.2.2+ (up to commit 98e688a).

    * Targets:

      - i486: Added.  This is an Intel 486 target optimized for Intel 686
        (or superior) processors.

      - i586: The default target name has been changed to "i586-linux-musl"
        instead of "i386-linux-musl" to be more specific.

      - mips: This now passes or uses the "--with-linker-hash-style=sysv"
        option for GCC by default.

    * The code in darkcrusade (script) has been improved.
      Relevant changes are:

      - Better handling in case of errors, the script now stops if an error occurs.

      - Output directory creation on build is now composed using
        yearNumber+monthName+dayNumber plus shell's parent ID (e.g:
        "phase2-i586-2021-12-31.085911-21007").

    * Minor changes.

2019-09-24 Matias A. Fonzo <selk@dragora.org>

Version 2019Sep24 released.

    * Binutils 2.32 + updates from 2_32-branch (version: 20190914).

    * Linux-libre 4.19.75 (headers).

    * GCC-9-20190921 (from snapshot, post gcc-9.2.0).

      - GMP 6.1.2.

      - MPFR 4.0.2 + cumulative patch (latest update: 2019-06-02).

      - MPC 1.1.0.

      - ISL 0.21.

    * Musl updated to the snapshot 20190913_f5eee489 (post musl-1.1.23).

    * Targets:

        armv7-a:

        - This soft float target has been renamed to 'armv7a_fp'.

        - The CPU name for the target triplet has been changed to be more
          generic (from armv7a to arm).

        armv7a_hf:

        - New target added.  This is almost the same target as 'armv7a_fp'
          with the difference that this target is hard float, plus FPU
          'vfpv3-d16'.

        armv7hl:

        - New target added.  This is a hard float target for the armv7-a
          architecture (hard float) but with the FPU tuned for 'neon'.

        i586:

        - The option --enable-cld for the CLD instruction is now used by
          default (just in case).

        powerpc:

        - Option for decimal support has been disabled here.

        powerpc64:

        - The option --with-abi=elfv2 is now passed by default (just in case).

        - The target name has been renamed to 'powerpc64le' for clarification.

        riscv64:

        - New target added with multilib support.  This is a hard float target
          for the architecture 'rv64gc' with the ABI 'lp64d'.

        s390x:

        - Directory to look into the corresponding (kernel) headers for the
          architecture has been fixed. (s390x -> s390).

    * Toolchain:

      - Option for binutils --disable-separate-code is now given by default.
        See: https://www.openwall.com/lists/musl/2019/08/12/4

      - Patches for GCC has been updated to work against Musl, GCC-9.
        Thanks to Szabolcs Nagy for provide it.  :-)

      - config.sub and config.guess have been updated in order to detect more
        target triplets, for example those containing "armv7hl"...

    * Darkcrusade is now distributed using the tarlz format.  For more
      information, visit https://lzip.nongnu.org/tarlz.html

    * Minor changes.

2018-05-26 Matias A. Fonzo <selk@dragora.org>

Version 2018May26 released.

    * Binutils 2.30.

    * Linux-libre 4.14.41 (headers).

    * GCC-7-20180524 (from snapshot, post gcc-7.3.0).

      - GMP 6.1.2.

      - MPFR 4.0.1 + cumulative patch (latest update: 2018-05-01).

      - MPC 1.1.0.

      - ISL 0.19.

    * Musl 1db9a35 (from snapshot, post musl-1.1.19).

    * targets: powerpc64: added new target file.
      Thanks to David Edelsohn.

    * targets: s390x: added new target file.  Thanks to David Edelsohn.

    * targets: i586, x32: fixed issue with multilib option.

    * targets: x86_64: enhanced multilib option for tuning GCC:
      "--with-arch=x86-64 --with-tune=generic".

    * The Apache license version 2 is now used by darkcrusade
      (scripts).

    * Minor changes.

2017-06-20 Matias A. Fonzo <selk@dragora.org>

Version 2017Jun09 released.

    * The pass for the CC and CXX environment flags have been fixed for
      the final GCC -- previously resulting in a partial
      statically-linked cross-compiler.

    * Linux-libre 4.9.31 (headers).

    * Checksum files are now produced using sha256sum(1).

2017-01-06 Matias A. Fonzo <selk@dragora.org>

Version 2017Jan05 released.

    * Binutils 2.26.1.

    * Linux-libre 4.4.39 (headers).

    * GCC 6.3.0.

      - GMP 6.1.2.

      - MPFR 3.1.5 (patch level 2).

      - MPC 1.0.3.

      - ISL 0.18.

    * Musl 1.1.16.

2016-06-19 Matias A. Fonzo <selk@dragora.org>

    * Initial release.

path: compilers/WHATSNEW


code:
#! /bin/sh -
#
# Deploy static cross-compilers for easy distribution
#
# Copyright (c) 2016-2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

PROGRAM="${0##*/}"

# Show help via option
if test "$1" = -h || test "$1" = --help
then
    echo "Usage: $PROGRAM [TARGET]..."
    echo "Deploy static cross-compilers for easy distribution."
    echo ""
    echo "Where TARGET is any target found at the targets/ directory."
    echo "If no target name is passed, all available targets will be built."
    echo ""
    exit 0;
fi

# Override locale settings
LC_ALL=C
export LC_ALL

umask 022

### Default values

# Get physical working directory (absolute path)
CWD="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)"

# Output directory for tarballs
output="${CWD}/OUTPUT.darkcrusade"

# Set temporary directory for compilation, exporting it
TMPDIR="${output}"/sources
export TMPDIR

# Compose tag for tarball names using yearNumber+monthName+dayNumber
tarname="darkcrusade_$(date +%Y%b%d)"

# Prepare to start the cross compiler process in the phase 1

phase_one="${output}/phase1-native-$(uname -m)-$(date +%Y-%m-%d.%H%M%S)-$$"

echo "${PROGRAM}: Creating native cross compiler on $phase_one ..."
"${CWD}"/bootstrap -s0 -o "$phase_one"

# Now will start the preparatives to use the recent native cross compiler

echo "${PROGRAM}: Using (existing) compiler from $phase_one ..."

# Set flags according to the generated compiler
for BTCC in "${phase_one}"/cross/*/bin/*-gcc
do
    if test -x "$BTCC"
    then
        BTCC="$BTCC"
        break
    fi
done
for BTCXX in "${phase_one}"/cross/*/bin/*-g++
do
    if test -x "$BTCXX"
    then
        BTCXX="$BTCXX"
        break
    fi
done

# Set and compose flags to be used as CC/CXX

BTCC="$BTCC -static -Wl,-Bstatic -static-libgcc"
BTCXX="$BTCXX -static -Wl,-Bstatic -static-libgcc"

IS_DARKCRUSADE=IS_DARKCRUSADE

export BTCC BTCXX IS_DARKCRUSADE

# Loop for create the targets, phase 2
for target in "${CWD}"/targets/${@:-*}
do
    target="${target##*/}"
    phase_two="${output}/phase2-${target}-$(date +%Y-%m-%d.%H%M%S)-$$"

    # Build target against native compiler, logging its output

    echo "darkcrusade: Making target $target ..."
    rm -f "${output}/bootstrapfailed"

    {
        "${CWD}"/bootstrap -s0 -a "$target" -o "$phase_two" || touch "${output}/bootstrapfailed"
    } 2>&1 | tee "${output}/${tarname}-${target}.log"

    if test -f "${output}/bootstrapfailed"
    then
        echo "${PROGRAM}: An error occurred while processing the target: $target" 1>&2
        echo "  Please check the log file ${output}/${tarname}-${target}.log" 1>&2
        exit 99;
    fi

    # Provide log file, tarball and checkum

    lzip -9 "${output}/${tarname}-${target}.log" &

    (
        cd -- "$phase_two" && \
        tarlz --solid -9 -cvf - -- cross/ \
         > "${output}/${tarname}-${target}.tar.lz"
    )
    (
        cd -- "$output" && \
        sha256sum "${tarname}-${target}.tar.lz" \
         > "${tarname}-${target}.tar.lz.sha256"
    )
done

path: darkcrusade


code:
#! /bin/sh -
# Copyright (c) 2016-2018 Matias Fonzo, <selk@dragora.org>.
# Copyright (c) 2020-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PROGRAM="${0##*/}"

# Exit immediately on any error
set -e

# Override locale settings
LC_ALL=C
export LC_ALL

# Get physical working directory (absolute path)
CWD="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)" || exit $?

# Functions
unmountSeries()
{
    for node in "${rootdir}/usr/src/qi/archive" \
                "${rootdir}/usr/src/qi/patches" \
                "${rootdir}/usr/src/qi/recipes" \
                "${rootdir}/usr/src/qi/sources" \
                "${rootdir}/var/cache/qi/packages" \
                "${rootdir}/sys" \
                "${rootdir}/proc" \
                "${rootdir}/dev/pts" \
                "${rootdir}/dev/shm" \
                "${rootdir}/dev" ; \
    do
        if mount | grep -q "$node"
        then
            echo "Unmounting ${node} ..."
            if ! umount "$node"
            then
                echo "Doing a lazy unmount for $node ..."
                umount -l "$node"
            fi
        fi
    done
    unset -v node
}

# Autodetermine the path of /tools

if test ! -L /tools
then
    echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
    exit 1
fi
if test -L /tools && test ! -e /tools
then
    echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
    exit 1
fi

# Set canonical name to compose the root directory, removing
# the last component from the path name "/tools"

rootdir="$(CDPATH='' cd -P -- /tools && pwd -P)"
rootdir="${rootdir%/*}"

# Unmount directories and file systems before the next mounting

unmountSeries

# Create required directory for destination
mkdir -p -- \
 "${rootdir}/dev"                    \
 "${rootdir}/dev/pts"                \
 "${rootdir}/dev/shm"                \
 "${rootdir}/proc"                   \
 "${rootdir}/sys"                    \
 "${rootdir}/usr/src/qi/archive"     \
 "${rootdir}/usr/src/qi/patches"     \
 "${rootdir}/usr/src/qi/recipes"     \
 "${rootdir}/usr/src/qi/sources"     \
 "${rootdir}/var/cache/qi/packages"

echo "Mounting virtual file systems ..."
mount -o bind /dev      "${rootdir}/dev"
mount -t devpts devpts  "${rootdir}/dev/pts"
mount -t tmpfs devshm   "${rootdir}/dev/shm"
mount -t proc proc      "${rootdir}/proc"
mount -t sysfs sysfs    "${rootdir}/sys"

echo "Binding directories for archive/, patches/, recipes/, sources/, and packages/ ..."
mount -o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
mount -o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
mount -o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
mount -o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
mount -o bind "${CWD}/packages" "${rootdir}/var/cache/qi/packages"

# Change reported architecture for an appropriate environment
_machine_type=""

if file /tools/bin/busybox | grep -q "32-bit"
then
    echo "Using the linux32 command to change the reported architecure ..."
    if command -v linux32 > /dev/null
    then
        _machine_type="linux32"
    else
        echo "    The linux32 command is not available in your system." 1>&2
        echo "The current architecture will be used for the environment: $(uname -m)" 1>&2
    fi
fi

# Add trap for unmount the series, signalled or not
trap 'echo ""; unmountSeries' EXIT HUP QUIT ABRT TERM

echo "Entering via chroot $rootdir ..."
$_machine_type chroot "$rootdir" /tools/bin/env -i \
  PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin:/opt/trinity/bin \
  SHELL=/bin/sh \
  HOME=/root \
  TERM=linux \
  HOSTNAME=dragora \
  LC_ALL=C \
  PKG_CONFIG=/usr/bin/pkgconf \
  PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/opt/trinity/lib/pkgconfig \
 /bin/sh -

path: enter-chroot


code:
## packages/ - Contains binary packages.

This directory contains (or will contain) the Dragora binary packages
generated through the Qi package manager.


code:
## patches/ - Contains patches that will be included from recipes.

The sub-directories listed here are represented using the name of the
software to be packaged or using the package name.  The sub-directories
contain specific patches that will be applied for the necessary
compilation of the program through the use of recipes.


code:
Description: Fix FTBFS with GCC 6
Author: Michael Schwendt <mschwendt@fedoraproject.org>
Origin: vendor, https://github.com/mpruett/audiofile/pull/27
Bug-Debian: https://bugs.debian.org/812055
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/

--- a/libaudiofile/modules/SimpleModule.h
+++ b/libaudiofile/modules/SimpleModule.h
@@ -123,7 +123,7 @@ struct signConverter
 	typedef typename IntTypes<Format>::UnsignedType UnsignedType;

 	static const int kScaleBits = (Format + 1) * CHAR_BIT - 1;
-	static const int kMinSignedValue = -1 << kScaleBits;
+	static const int kMinSignedValue = 0-(1U<<kScaleBits);

 	struct signedToUnsigned : public std::unary_function<SignedType, UnsignedType>
 	{
--- a/test/FloatToInt.cpp
+++ b/test/FloatToInt.cpp
@@ -115,7 +115,7 @@ TEST_F(FloatToIntTest, Int16)
 		EXPECT_EQ(readData[i], expectedData[i]);
 }

-static const int32_t kMinInt24 = -1<<23;
+static const int32_t kMinInt24 = 0-(1U<<23);
 static const int32_t kMaxInt24 = (1<<23) - 1;

 TEST_F(FloatToIntTest, Int24)
--- a/test/IntToFloat.cpp
+++ b/test/IntToFloat.cpp
@@ -117,7 +117,7 @@ TEST_F(IntToFloatTest, Int16)
 		EXPECT_EQ(readData[i], expectedData[i]);
 }

-static const int32_t kMinInt24 = -1<<23;
+static const int32_t kMinInt24 = 0-(1U<<23);
 static const int32_t kMaxInt24 = (1<<23) - 1;

 TEST_F(IntToFloatTest, Int24)
--- a/test/NeXT.cpp
+++ b/test/NeXT.cpp
@@ -37,13 +37,13 @@

 #include "TestUtilities.h"

-const char kDataUnspecifiedLength[] =
+const signed char kDataUnspecifiedLength[] =
 {
 	'.', 's', 'n', 'd',
 	0, 0, 0, 24, // offset of 24 bytes
-	0xff, 0xff, 0xff, 0xff, // unspecified length
+	-1, -1, -1, -1, // unspecified length
 	0, 0, 0, 3, // 16-bit linear
-	0, 0, 172, 68, // 44100 Hz
+	0, 0, -84, 68, // 44100 Hz (0xAC44)
 	0, 0, 0, 1, // 1 channel
 	0, 1,
 	0, 1,
@@ -57,13 +57,13 @@ const char kDataUnspecifiedLength[] =
 	0, 55
 };

-const char kDataTruncated[] =
+const signed char kDataTruncated[] =
 {
 	'.', 's', 'n', 'd',
 	0, 0, 0, 24, // offset of 24 bytes
 	0, 0, 0, 20, // length of 20 bytes
 	0, 0, 0, 3, // 16-bit linear
-	0, 0, 172, 68, // 44100 Hz
+	0, 0, -84, 68, // 44100 Hz (0xAC44)
 	0, 0, 0, 1, // 1 channel
 	0, 1,
 	0, 1,
@@ -152,13 +152,13 @@ TEST(NeXT, Truncated)
 	ASSERT_EQ(::unlink(testFileName.c_str()), 0);
 }

-const char kDataZeroChannels[] =
+const signed char kDataZeroChannels[] =
 {
 	'.', 's', 'n', 'd',
 	0, 0, 0, 24, // offset of 24 bytes
 	0, 0, 0, 2, // 2 bytes
 	0, 0, 0, 3, // 16-bit linear
-	0, 0, 172, 68, // 44100 Hz
+	0, 0, -84, 68, // 44100 Hz (0xAC44)
 	0, 0, 0, 0, // 0 channels
 	0, 1
 };
--- a/test/Sign.cpp
+++ b/test/Sign.cpp
@@ -116,7 +116,7 @@ TEST_F(SignConversionTest, Int16)
 		EXPECT_EQ(readData[i], expectedData[i]);
 }

-static const int32_t kMinInt24 = -1<<23;
+static const int32_t kMinInt24 = 0-(1U<<23);
 static const int32_t kMaxInt24 = (1<<23) - 1;
 static const uint32_t kMaxUInt24 = (1<<24) - 1;


code:
Description: Remove usage of PATH_MAX in tests to fix FTBFS on Hurd.
 jcowgill: Removed Changelog changes
Author: Pino Toscano <toscano.pino@tiscali.it>
Origin: backport, https://github.com/mpruett/audiofile/commit/34c261034f1193a783196618f0052112e00fbcfe
Bug: https://github.com/mpruett/audiofile/pull/17
Bug-Debian: https://bugs.debian.org/762595
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/

--- a/test/TestUtilities.cpp
+++ b/test/TestUtilities.cpp
@@ -21,8 +21,8 @@
 #include "TestUtilities.h"

 #include <limits.h>
-#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>

 bool createTemporaryFile(const std::string &prefix, std::string *path)
@@ -35,12 +35,12 @@ bool createTemporaryFile(const std::stri
 	return true;
 }

-bool createTemporaryFile(const char *prefix, char *path)
+bool createTemporaryFile(const char *prefix, char **path)
 {
-	snprintf(path, PATH_MAX, "/tmp/%s-XXXXXX", prefix);
-	int fd = ::mkstemp(path);
-	if (fd < 0)
-		return false;
-	::close(fd);
-	return true;
+	*path = NULL;
+	std::string pathString;
+	bool result = createTemporaryFile(prefix, &pathString);
+	if (result)
+		*path = ::strdup(pathString.c_str());
+	return result;
 }
--- a/test/TestUtilities.h
+++ b/test/TestUtilities.h
@@ -53,7 +53,7 @@ extern "C" {

 #include <stdbool.h>

-bool createTemporaryFile(const char *prefix, char *path);
+bool createTemporaryFile(const char *prefix, char **path);

 #ifdef __cplusplus
 }
--- a/test/floatto24.c
+++ b/test/floatto24.c
@@ -86,8 +86,8 @@ int main (int argc, char **argv)
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_FLOAT, 32);

-	char testFileName[PATH_MAX];
-	if (!createTemporaryFile("floatto24", testFileName))
+	char *testFileName;
+	if (!createTemporaryFile("floatto24", &testFileName))
 	{
 		fprintf(stderr, "Could not create temporary file.\n");
 		exit(EXIT_FAILURE);
@@ -182,6 +182,7 @@ int main (int argc, char **argv)
 	}

 	unlink(testFileName);
+	free(testFileName);

 	exit(EXIT_SUCCESS);
 }
--- a/test/sixteen-to-eight.c
+++ b/test/sixteen-to-eight.c
@@ -57,8 +57,8 @@ int main (int argc, char **argv)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_UNSIGNED, 8);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);

-	char testFileName[PATH_MAX];
-	if (!createTemporaryFile("sixteen-to-eight", testFileName))
+	char *testFileName;
+	if (!createTemporaryFile("sixteen-to-eight", &testFileName))
 	{
 		fprintf(stderr, "Could not create temporary file.\n");
 		exit(EXIT_FAILURE);
@@ -113,6 +113,7 @@ int main (int argc, char **argv)

 	afCloseFile(file);
 	unlink(testFileName);
+	free(testFileName);

 	exit(EXIT_SUCCESS);
 }
--- a/test/testchannelmatrix.c
+++ b/test/testchannelmatrix.c
@@ -39,7 +39,7 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 const short samples[] = {300, -300, 515, -515, 2315, -2315, 9154, -9154};
 #define SAMPLE_COUNT (sizeof (samples) / sizeof (short))
@@ -47,7 +47,11 @@ const short samples[] = {300, -300, 515,

 void cleanup (void)
 {
-	unlink(sTestFileName);
+	if (sTestFileName)
+	{
+		unlink(sTestFileName);
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -76,7 +80,7 @@ int main (void)
 	afInitFileFormat(setup, AF_FILE_AIFFC);

 	/* Write stereo data to test file. */
-	ensure(createTemporaryFile("testchannelmatrix", sTestFileName),
+	ensure(createTemporaryFile("testchannelmatrix", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "could not open file for writing");
--- a/test/testdouble.c
+++ b/test/testdouble.c
@@ -38,7 +38,7 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 const double samples[] =
 	{1.0, 0.6, -0.3, 0.95, 0.2, -0.6, 0.9, 0.4, -0.22, 0.125, 0.1, -0.4};
@@ -48,7 +48,11 @@ void testdouble (int fileFormat);

 void cleanup (void)
 {
-	unlink(sTestFileName);
+	if (sTestFileName)
+	{
+		unlink(sTestFileName);
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -96,7 +100,7 @@ void testdouble (int fileFormat)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_DOUBLE, 64);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 2);

-	ensure(createTemporaryFile("testdouble", sTestFileName),
+	ensure(createTemporaryFile("testdouble", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "could not open file for writing");
--- a/test/testfloat.c
+++ b/test/testfloat.c
@@ -38,7 +38,7 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 const float samples[] =
 	{1.0, 0.6, -0.3, 0.95, 0.2, -0.6, 0.9, 0.4, -0.22, 0.125, 0.1, -0.4};
@@ -48,7 +48,11 @@ void testfloat (int fileFormat);

 void cleanup (void)
 {
-	unlink(sTestFileName);
+	if (sTestFileName)
+	{
+		unlink(sTestFileName);
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -96,7 +100,7 @@ void testfloat (int fileFormat)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_FLOAT, 32);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 2);

-	ensure(createTemporaryFile("testfloat", sTestFileName),
+	ensure(createTemporaryFile("testfloat", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "could not open file for writing");
--- a/test/testmarkers.c
+++ b/test/testmarkers.c
@@ -32,15 +32,19 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 #define FRAME_COUNT 200

 void cleanup (void)
 {
+	if (sTestFileName)
+	{
 #ifndef DEBUG
-	unlink(sTestFileName);
+		unlink(sTestFileName);
 #endif
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -127,7 +131,7 @@ int testmarkers (int fileformat)

 int main (void)
 {
-	ensure(createTemporaryFile("testmarkers", sTestFileName),
+	ensure(createTemporaryFile("testmarkers", &sTestFileName),
 		"could not create temporary file");

 	testmarkers(AF_FILE_AIFF);
--- a/test/twentyfour.c
+++ b/test/twentyfour.c
@@ -71,8 +71,8 @@ int main (int argc, char **argv)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 24);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);

-	char testFileName[PATH_MAX];
-	if (!createTemporaryFile("twentyfour", testFileName))
+	char *testFileName;
+	if (!createTemporaryFile("twentyfour", &testFileName))
 	{
 		fprintf(stderr, "could not create temporary file\n");
 		exit(EXIT_FAILURE);
@@ -239,6 +239,7 @@ int main (int argc, char **argv)
 		exit(EXIT_FAILURE);
 	}
 	unlink(testFileName);
+	free(testFileName);

 	exit(EXIT_SUCCESS);
 }
--- a/test/twentyfour2.c
+++ b/test/twentyfour2.c
@@ -45,15 +45,19 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 #define FRAME_COUNT 10000

 void cleanup (void)
 {
+	if (sTestFileName)
+	{
 #ifndef DEBUG
-	unlink(sTestFileName);
+		unlink(sTestFileName);
 #endif
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -78,7 +82,7 @@ int main (void)
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 24);

-	ensure(createTemporaryFile("twentyfour2", sTestFileName),
+	ensure(createTemporaryFile("twentyfour2", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != NULL, "could not open test file for writing");
--- a/test/writealaw.c
+++ b/test/writealaw.c
@@ -53,7 +53,7 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 #define FRAME_COUNT 16
 #define SAMPLE_COUNT FRAME_COUNT
@@ -62,9 +62,13 @@ void testalaw (int fileFormat);

 void cleanup (void)
 {
+	if (sTestFileName)
+	{
 #ifndef DEBUG
-	unlink(sTestFileName);
+		unlink(sTestFileName);
 #endif
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -113,7 +117,7 @@ void testalaw (int fileFormat)
 	afInitFileFormat(setup, fileFormat);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);

-	ensure(createTemporaryFile("writealaw", sTestFileName),
+	ensure(createTemporaryFile("writealaw", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	afFreeFileSetup(setup);
--- a/test/writeraw.c
+++ b/test/writeraw.c
@@ -44,13 +44,17 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 void cleanup (void)
 {
+	if (sTestFileName)
+	{
 #ifndef DEBUG
-	unlink(sTestFileName);
+		unlink(sTestFileName);
 #endif
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -84,7 +88,7 @@ int main (int argc, char **argv)
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);

-	ensure(createTemporaryFile("writeraw", sTestFileName),
+	ensure(createTemporaryFile("writeraw", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "unable to open file for writing");
--- a/test/writeulaw.c
+++ b/test/writeulaw.c
@@ -53,7 +53,7 @@

 #include "TestUtilities.h"

-static char sTestFileName[PATH_MAX];
+static char *sTestFileName;

 #define FRAME_COUNT 16
 #define SAMPLE_COUNT FRAME_COUNT
@@ -62,9 +62,13 @@ void testulaw (int fileFormat);

 void cleanup (void)
 {
+	if (sTestFileName)
+	{
 #ifndef DEBUG
-	unlink(sTestFileName);
+		unlink(sTestFileName);
 #endif
+		free(sTestFileName);
+	}
 }

 void ensure (int condition, const char *message)
@@ -113,7 +117,7 @@ void testulaw (int fileFormat)
 	afInitFileFormat(setup, fileFormat);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);

-	ensure(createTemporaryFile("writeulaw", sTestFileName),
+	ensure(createTemporaryFile("writeulaw", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	afFreeFileSetup(setup);


code:
Description: fix buffer overflow when changing both sample format and
 number of channels
Origin: https://github.com/mpruett/audiofile/pull/25
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/audiofile/+bug/1502721
Bug-Debian: https://bugs.debian.org/801102

--- a/libaudiofile/modules/ModuleState.cpp
+++ b/libaudiofile/modules/ModuleState.cpp
@@ -402,7 +402,7 @@ status ModuleState::arrange(AFfilehandle
 		addModule(new Transform(outfc, in.pcm, out.pcm));

 	if (in.channelCount != out.channelCount)
-		addModule(new ApplyChannelMatrix(infc, isReading,
+		addModule(new ApplyChannelMatrix(outfc, isReading,
 			in.channelCount, out.channelCount,
 			in.pcm.minClip, in.pcm.maxClip,
 			track->channelMatrix));
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -26,6 +26,7 @@ TESTS = \
 	VirtualFile \
 	floatto24 \
 	query2 \
+	sixteen-stereo-to-eight-mono \
 	sixteen-to-eight \
 	testchannelmatrix \
 	testdouble \
@@ -139,6 +140,7 @@ printmarkers_SOURCES = printmarkers.c
 printmarkers_LDADD = $(LIBAUDIOFILE) -lm

 sixteen_to_eight_SOURCES = sixteen-to-eight.c TestUtilities.cpp TestUtilities.h
+sixteen_stereo_to_eight_mono_SOURCES = sixteen-stereo-to-eight-mono.c TestUtilities.cpp TestUtilities.h

 testchannelmatrix_SOURCES = testchannelmatrix.c TestUtilities.cpp TestUtilities.h

--- /dev/null
+++ b/test/sixteen-stereo-to-eight-mono.c
@@ -0,0 +1,118 @@
+/*
+	Audio File Library
+
+	Copyright 2000, Silicon Graphics, Inc.
+
+	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 2 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, write to the Free Software Foundation, Inc.,
+	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+/*
+	sixteen-stereo-to-eight-mono.c
+
+	This program tests the conversion from 2-channel 16-bit integers to
+	1-channel 8-bit	integers.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include <audiofile.h>
+
+#include "TestUtilities.h"
+
+int main (int argc, char **argv)
+{
+	AFfilehandle file;
+	AFfilesetup setup;
+	int16_t frames16[] = {14298, 392, 3923, -683, 958, -1921};
+	int8_t frames8[] = {28, 6, -2};
+	int i, frameCount = 3;
+	int8_t byte;
+	AFframecount result;
+
+	setup = afNewFileSetup();
+
+	afInitFileFormat(setup, AF_FILE_WAVE);
+
+	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
+	afInitChannels(setup, AF_DEFAULT_TRACK, 2);
+
+	char *testFileName;
+	if (!createTemporaryFile("sixteen-to-eight", &testFileName))
+	{
+		fprintf(stderr, "Could not create temporary file.\n");
+		exit(EXIT_FAILURE);
+	}
+
+	file = afOpenFile(testFileName, "w", setup);
+	if (file == AF_NULL_FILEHANDLE)
+	{
+		fprintf(stderr, "could not open file for writing\n");
+		exit(EXIT_FAILURE);
+	}
+
+	afFreeFileSetup(setup);
+
+	afWriteFrames(file, AF_DEFAULT_TRACK, frames16, frameCount);
+
+	afCloseFile(file);
+
+	file = afOpenFile(testFileName, "r", AF_NULL_FILESETUP);
+	if (file == AF_NULL_FILEHANDLE)
+	{
+		fprintf(stderr, "could not open file for reading\n");
+		exit(EXIT_FAILURE);
+	}
+
+	afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 8);
+	afSetVirtualChannels(file, AF_DEFAULT_TRACK, 1);
+
+	for (i=0; i<frameCount; i++)
+	{
+		/* Read one frame. */
+		result = afReadFrames(file, AF_DEFAULT_TRACK, &byte, 1);
+
+		if (result != 1)
+			break;
+
+		/* Compare the byte read with its precalculated value. */
+		if (memcmp(&byte, &frames8[i], 1) != 0)
+		{
+			printf("error\n");
+			printf("expected %d, got %d\n", frames8[i], byte);
+			exit(EXIT_FAILURE);
+		}
+		else
+		{
+#ifdef DEBUG
+			printf("got what was expected: %d\n", byte);
+#endif
+		}
+	}
+
+	afCloseFile(file);
+	unlink(testFileName);
+	free(testFileName);
+
+	exit(EXIT_SUCCESS);
+}


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Mon, 6 Mar 2017 18:02:31 +0100
Subject: clamp index values to fix index overflow in IMA.cpp

This fixes #33
(also reported at https://bugzilla.opensuse.org/show_bug.cgi?id=1026981
and https://blogs.gentoo.org/ago/2017/02/20/audiofile-global-buffer-overflow-in-decodesample-ima-cpp/)
---
 libaudiofile/modules/IMA.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libaudiofile/modules/IMA.cpp b/libaudiofile/modules/IMA.cpp
index 7476d44..df4aad6 100644
--- a/libaudiofile/modules/IMA.cpp
+++ b/libaudiofile/modules/IMA.cpp
@@ -169,7 +169,7 @@ int IMA::decodeBlockWAVE(const uint8_t *encoded, int16_t *decoded)
 		if (encoded[1] & 0x80)
 			m_adpcmState[c].previousValue -= 0x10000;

-		m_adpcmState[c].index = encoded[2];
+		m_adpcmState[c].index = clamp(encoded[2], 0, 88);

 		*decoded++ = m_adpcmState[c].previousValue;

@@ -210,7 +210,7 @@ int IMA::decodeBlockQT(const uint8_t *encoded, int16_t *decoded)
 			predictor -= 0x10000;

 		state.previousValue = clamp(predictor, MIN_INT16, MAX_INT16);
-		state.index = encoded[1] & 0x7f;
+		state.index = clamp(encoded[1] & 0x7f, 0, 88);
 		encoded += 2;

 		for (int n=0; n<m_framesPerPacket; n+=2)


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Mon, 6 Mar 2017 12:51:22 +0100
Subject: Always check the number of coefficients

When building the library with NDEBUG, asserts are eliminated
so it's better to always check that the number of coefficients
is inside the array range.

This fixes the 00191-audiofile-indexoob issue in #41
---
 libaudiofile/WAVE.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libaudiofile/WAVE.cpp b/libaudiofile/WAVE.cpp
index 9dd8511..0fc48e8 100644
--- a/libaudiofile/WAVE.cpp
+++ b/libaudiofile/WAVE.cpp
@@ -281,6 +281,12 @@ status WAVEFile::parseFormat(const Tag &id, uint32_t size)

 			/* numCoefficients should be at least 7. */
 			assert(numCoefficients >= 7 && numCoefficients <= 255);
+			if (numCoefficients < 7 || numCoefficients > 255)
+			{
+				_af_error(AF_BAD_HEADER,
+						"Bad number of coefficients");
+				return AF_FAIL;
+			}

 			m_msadpcmNumCoefficients = numCoefficients;


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Mon, 6 Mar 2017 13:43:53 +0100
Subject: Check for multiplication overflow in MSADPCM decodeSample

Check for multiplication overflow (using __builtin_mul_overflow
if available) in MSADPCM.cpp decodeSample and return an empty
decoded block if an error occurs.

This fixes the 00193-audiofile-signintoverflow-MSADPCM case of #41
---
 libaudiofile/modules/BlockCodec.cpp |  5 ++--
 libaudiofile/modules/MSADPCM.cpp    | 47 +++++++++++++++++++++++++++++++++----
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp
index 45925e8..4731be1 100644
--- a/libaudiofile/modules/BlockCodec.cpp
+++ b/libaudiofile/modules/BlockCodec.cpp
@@ -52,8 +52,9 @@ void BlockCodec::runPull()
 	// Decompress into m_outChunk.
 	for (int i=0; i<blocksRead; i++)
 	{
-		decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
-			static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount);
+		if (decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
+			static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount)==0)
+			break;

 		framesRead += m_framesPerPacket;
 	}
diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp
index 8ea3c85..ef9c38c 100644
--- a/libaudiofile/modules/MSADPCM.cpp
+++ b/libaudiofile/modules/MSADPCM.cpp
@@ -101,24 +101,60 @@ static const int16_t adaptationTable[] =
 	768, 614, 512, 409, 307, 230, 230, 230
 };

+int firstBitSet(int x)
+{
+        int position=0;
+        while (x!=0)
+        {
+                x>>=1;
+                ++position;
+        }
+        return position;
+}
+
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
+int multiplyCheckOverflow(int a, int b, int *result)
+{
+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
+	return __builtin_mul_overflow(a, b, result);
+#else
+	if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits
+		return true;
+	*result = a * b;
+	return false;
+#endif
+}
+
+
 // Compute a linear PCM value from the given differential coded value.
 static int16_t decodeSample(ms_adpcm_state &state,
-	uint8_t code, const int16_t *coefficient)
+	uint8_t code, const int16_t *coefficient, bool *ok=NULL)
 {
 	int linearSample = (state.sample1 * coefficient[0] +
 		state.sample2 * coefficient[1]) >> 8;
+	int delta;

 	linearSample += ((code & 0x08) ? (code - 0x10) : code) * state.delta;

 	linearSample = clamp(linearSample, MIN_INT16, MAX_INT16);

-	int delta = (state.delta * adaptationTable[code]) >> 8;
+	if (multiplyCheckOverflow(state.delta, adaptationTable[code], &delta))
+	{
+                if (ok) *ok=false;
+		_af_error(AF_BAD_COMPRESSION, "Error decoding sample");
+		return 0;
+	}
+	delta >>= 8;
 	if (delta < 16)
 		delta = 16;

 	state.delta = delta;
 	state.sample2 = state.sample1;
 	state.sample1 = linearSample;
+	if (ok) *ok=true;

 	return static_cast<int16_t>(linearSample);
 }
@@ -212,13 +248,16 @@ int MSADPCM::decodeBlock(const uint8_t *encoded, int16_t *decoded)
 	{
 		uint8_t code;
 		int16_t newSample;
+		bool ok;

 		code = *encoded >> 4;
-		newSample = decodeSample(*state[0], code, coefficient[0]);
+		newSample = decodeSample(*state[0], code, coefficient[0], &ok);
+		if (!ok) return 0;
 		*decoded++ = newSample;

 		code = *encoded & 0x0f;
-		newSample = decodeSample(*state[1], code, coefficient[1]);
+		newSample = decodeSample(*state[1], code, coefficient[1], &ok);
+		if (!ok) return 0;
 		*decoded++ = newSample;

 		encoded++;


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Mon, 6 Mar 2017 13:54:52 +0100
Subject: Check for multiplication overflow in sfconvert

Checks that a multiplication doesn't overflow when
calculating the buffer size, and if it overflows,
reduce the buffer size instead of failing.

This fixes the 00192-audiofile-signintoverflow-sfconvert case
in #41
---
 sfcommands/sfconvert.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/sfcommands/sfconvert.c b/sfcommands/sfconvert.c
index 80a1bc4..970a3e4 100644
--- a/sfcommands/sfconvert.c
+++ b/sfcommands/sfconvert.c
@@ -45,6 +45,33 @@ void printusage (void);
 void usageerror (void);
 bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid);

+int firstBitSet(int x)
+{
+        int position=0;
+        while (x!=0)
+        {
+                x>>=1;
+                ++position;
+        }
+        return position;
+}
+
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
+int multiplyCheckOverflow(int a, int b, int *result)
+{
+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
+	return __builtin_mul_overflow(a, b, result);
+#else
+	if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits
+		return true;
+	*result = a * b;
+	return false;
+#endif
+}
+
 int main (int argc, char **argv)
 {
 	if (argc == 2)
@@ -323,8 +350,11 @@ bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid)
 {
 	int frameSize = afGetVirtualFrameSize(infile, trackid, 1);

-	const int kBufferFrameCount = 65536;
-	void *buffer = malloc(kBufferFrameCount * frameSize);
+	int kBufferFrameCount = 65536;
+	int bufferSize;
+	while (multiplyCheckOverflow(kBufferFrameCount, frameSize, &bufferSize))
+		kBufferFrameCount /= 2;
+	void *buffer = malloc(bufferSize);

 	AFframecount totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK);
 	AFframecount totalFramesWritten = 0;


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Fri, 10 Mar 2017 15:40:02 +0100
Subject: Fix signature of multiplyCheckOverflow. It returns a bool, not an int

---
 libaudiofile/modules/MSADPCM.cpp | 2 +-
 sfcommands/sfconvert.c           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp
index ef9c38c..d8c9553 100644
--- a/libaudiofile/modules/MSADPCM.cpp
+++ b/libaudiofile/modules/MSADPCM.cpp
@@ -116,7 +116,7 @@ int firstBitSet(int x)
 #define __has_builtin(x) 0
 #endif

-int multiplyCheckOverflow(int a, int b, int *result)
+bool multiplyCheckOverflow(int a, int b, int *result)
 {
 #if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
 	return __builtin_mul_overflow(a, b, result);
diff --git a/sfcommands/sfconvert.c b/sfcommands/sfconvert.c
index 970a3e4..367f7a5 100644
--- a/sfcommands/sfconvert.c
+++ b/sfcommands/sfconvert.c
@@ -60,7 +60,7 @@ int firstBitSet(int x)
 #define __has_builtin(x) 0
 #endif

-int multiplyCheckOverflow(int a, int b, int *result)
+bool multiplyCheckOverflow(int a, int b, int *result)
 {
 #if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
 	return __builtin_mul_overflow(a, b, result);


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Mon, 6 Mar 2017 18:59:26 +0100
Subject: Actually fail when error occurs in parseFormat

When there's an unsupported number of bits per sample or an invalid
number of samples per block, don't only print an error message using
the error handler, but actually stop parsing the file.

This fixes #35 (also reported at
https://bugzilla.opensuse.org/show_bug.cgi?id=1026983 and
https://blogs.gentoo.org/ago/2017/02/20/audiofile-heap-based-buffer-overflow-in-imadecodeblockwave-ima-cpp/
)
---
 libaudiofile/WAVE.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libaudiofile/WAVE.cpp b/libaudiofile/WAVE.cpp
index 0fc48e8..d04b796 100644
--- a/libaudiofile/WAVE.cpp
+++ b/libaudiofile/WAVE.cpp
@@ -332,6 +332,7 @@ status WAVEFile::parseFormat(const Tag &id, uint32_t size)
 			{
 				_af_error(AF_BAD_NOT_IMPLEMENTED,
 					"IMA ADPCM compression supports only 4 bits per sample");
+				return AF_FAIL;
 			}

 			int bytesPerBlock = (samplesPerBlock + 14) / 8 * 4 * channelCount;
@@ -339,6 +340,7 @@ status WAVEFile::parseFormat(const Tag &id, uint32_t size)
 			{
 				_af_error(AF_BAD_CODEC_CONFIG,
 					"Invalid samples per block for IMA ADPCM compression");
+				return AF_FAIL;
 			}

 			track->f.sampleWidth = 16;


code:
From: Antonio Larrosa <larrosa@kde.org>
Date: Thu, 9 Mar 2017 10:21:18 +0100
Subject: Check for division by zero in BlockCodec::runPull

---
 libaudiofile/modules/BlockCodec.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp
index 4731be1..eb2fb4d 100644
--- a/libaudiofile/modules/BlockCodec.cpp
+++ b/libaudiofile/modules/BlockCodec.cpp
@@ -47,7 +47,7 @@ void BlockCodec::runPull()

 	// Read the compressed data.
 	ssize_t bytesRead = read(m_inChunk->buffer, m_bytesPerPacket * blockCount);
-	int blocksRead = bytesRead >= 0 ? bytesRead / m_bytesPerPacket : 0;
+	int blocksRead = (bytesRead >= 0 && m_bytesPerPacket > 0) ? bytesRead / m_bytesPerPacket : 0;

 	// Decompress into m_outChunk.
 	for (int i=0; i<blocksRead; i++)


code:
From fde6d79fb8363c4a329a184ef0b107156602b225 Mon Sep 17 00:00:00 2001
From: Wim Taymans <wtaymans@redhat.com>
Date: Thu, 27 Sep 2018 10:48:45 +0200
Subject: [PATCH] ModuleState: handle compress/decompress init failure

When the unit initcompress or initdecompress function fails,
m_fileModule is NULL. Return AF_FAIL in that case instead of
causing NULL pointer dereferences later.

Fixes #49
---
 libaudiofile/modules/ModuleState.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libaudiofile/modules/ModuleState.cpp b/libaudiofile/modules/ModuleState.cpp
index 0c29d7a..070fd9b 100644
--- a/libaudiofile/modules/ModuleState.cpp
+++ b/libaudiofile/modules/ModuleState.cpp
@@ -75,6 +75,9 @@ status ModuleState::initFileModule(AFfilehandle file, Track *track)
 		m_fileModule = unit->initcompress(track, file->m_fh, file->m_seekok,
 			file->m_fileFormat == AF_FILE_RAWDATA, &chunkFrames);

+	if (!m_fileModule)
+		return AF_FAIL;
+
 	if (unit->needsRebuffer)
 	{
 		assert(unit->nativeSampleFormat == AF_SAMPFMT_TWOSCOMP);


code:
From 822b732fd31ffcb78f6920001e9b1fbd815fa712 Mon Sep 17 00:00:00 2001
From: Wim Taymans <wtaymans@redhat.com>
Date: Thu, 27 Sep 2018 12:11:12 +0200
Subject: [PATCH] SimpleModule: set output chunk framecount after pull

After pulling the data, set the output chunk to the amount of
frames we pulled so that the next module in the chain has the correct
frame count.

Fixes #50 and #51
---
 libaudiofile/modules/SimpleModule.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libaudiofile/modules/SimpleModule.cpp b/libaudiofile/modules/SimpleModule.cpp
index 2bae1eb..e87932c 100644
--- a/libaudiofile/modules/SimpleModule.cpp
+++ b/libaudiofile/modules/SimpleModule.cpp
@@ -26,6 +26,7 @@
 void SimpleModule::runPull()
 {
 	pull(m_outChunk->frameCount);
+	m_outChunk->frameCount = m_inChunk->frameCount;
 	run(*m_inChunk, *m_outChunk);
 }


path: patches/audiofile/series


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-001

Bug-Reported-by:	Fazal Majid <fazal@majid.org>
Bug-Reference-ID:	<DEAB7D2C-C626-450C-B2E5-281AFF2D26D4@majid.org>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00000.html

Bug-Description:

There is a missing dependency on a constructed file, which can cause highly
parellel builds to fail.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/Makefile.in	2020-12-04 09:51:19.000000000 -0500
--- Makefile.in	2020-12-16 11:28:36.000000000 -0500
***************
*** 1316,1319 ****
--- 1316,1320 ----
  bashline.o: pcomplete.h ${BASHINCDIR}/chartypes.h input.h
  bashline.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
+ bashline.o: ${DEFDIR}/builtext.h
  bracecomp.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
  bracecomp.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h
***************
*** 1436,1439 ****
--- 1437,1441 ----
  builtins/evalstring.o: jobs.h builtins.h flags.h input.h execute_cmd.h
  builtins/evalstring.o: bashhist.h $(DEFSRC)/common.h pathnames.h
+ builtins/evalstring.o: ${DEFDIR}/builtext.h
  builtins/getopt.o: config.h ${BASHINCDIR}/memalloc.h
  builtins/getopt.o: shell.h syntax.h bashjmp.h command.h general.h xmalloc.h error.h

*** ../bash-5.1-patched/builtins/Makefile.in	2019-07-25 08:03:45.000000000 -0400
--- builtins/Makefile.in	2020-12-16 11:29:29.000000000 -0500
***************
*** 362,366 ****
  evalstring.o: $(topdir)/flags.h $(topdir)/input.h $(topdir)/execute_cmd.h
  evalstring.o: $(topdir)/bashhist.h $(srcdir)/common.h
! evalstring.o: $(topdir)/trap.h $(topdir)/redir.h ../pathnames.h
  #evalstring.o: $(topdir)/y.tab.h
  getopt.o: ../config.h $(BASHINCDIR)/memalloc.h
--- 362,366 ----
  evalstring.o: $(topdir)/flags.h $(topdir)/input.h $(topdir)/execute_cmd.h
  evalstring.o: $(topdir)/bashhist.h $(srcdir)/common.h
! evalstring.o: $(topdir)/trap.h $(topdir)/redir.h ../pathnames.h ./builtext.h
  #evalstring.o: $(topdir)/y.tab.h
  getopt.o: ../config.h $(BASHINCDIR)/memalloc.h

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 1,5 ****
  /* patchlevel.h -- current bash patch level */

! /* Copyright (C) 2001-2016 Free Software Foundation, Inc.

     This file is part of GNU Bash, the Bourne Again SHell.
--- 1,5 ----
  /* patchlevel.h -- current bash patch level */

! /* Copyright (C) 2001-2020 Free Software Foundation, Inc.

     This file is part of GNU Bash, the Bourne Again SHell.
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 0

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 1

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-002

Bug-Reported-by:	oguzismailuysal@gmail.com
Bug-Reference-ID:	<CAH7i3LoHFUa4aSF5-AD2r80HG-p-YzD_9ZxomarZkhP8NMq63g@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00037.html

Bug-Description:

If there are no jobs, and the `-n' and `-p' options are both supplied to
`wait', bash can assign a value to the variable name specified with `-p'
instead of leaving it unset.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/builtins/wait.def	2020-04-09 15:13:57.000000000 -0400
--- builtins/wait.def	2020-12-11 09:46:49.000000000 -0500
***************
*** 214,222 ****

        status = wait_for_any_job (wflags, &pstat);
-       if (status < 0)
- 	status = 127;
-
        if (vname && status >= 0)
  	bind_var_to_int (vname, pstat.pid);
        if (list)
  	unset_waitlist ();
--- 214,222 ----

        status = wait_for_any_job (wflags, &pstat);
        if (vname && status >= 0)
  	bind_var_to_int (vname, pstat.pid);
+
+       if (status < 0)
+ 	status = 127;
        if (list)
  	unset_waitlist ();

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 1

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 2

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-003

Bug-Reported-by:	oguzismailuysal@gmail.com
Bug-Reference-ID:	<CAH7i3LpG91BnNcDtaTUm2Ph7a+PnJkuh6nAc87cVL7_38tOaMQ@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00050.html

Bug-Description:

Bash does not put a command substitution process that is started to perform an
expansion in a child process into the right process group where it can receive
keyboard-generated signals.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/subst.c	2020-11-16 10:33:15.000000000 -0500
--- subst.c	2020-12-12 13:50:11.000000000 -0500
***************
*** 6357,6362 ****
  #if defined (JOB_CONTROL)
    old_pipeline_pgrp = pipeline_pgrp;
!   /* Don't reset the pipeline pgrp if we're already a subshell in a pipeline. */
!   if ((subshell_environment & SUBSHELL_PIPE) == 0)
      pipeline_pgrp = shell_pgrp;
    cleanup_the_pipeline ();
--- 6357,6364 ----
  #if defined (JOB_CONTROL)
    old_pipeline_pgrp = pipeline_pgrp;
!   /* Don't reset the pipeline pgrp if we're already a subshell in a pipeline or
!      we've already forked to run a disk command (and are expanding redirections,
!      for example). */
!   if ((subshell_environment & (SUBSHELL_FORK|SUBSHELL_PIPE)) == 0)
      pipeline_pgrp = shell_pgrp;
    cleanup_the_pipeline ();

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 2

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 3

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-004

Bug-Reported-by:	oguzismailuysal@gmail.com
Bug-Reference-ID:	<CAH7i3LoHGmwaghDpCWRUfcY04gQmeDTH3RiG=bf2b=KbU=gyhw@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00039.html

Bug-Description:

If a key-value compound array assignment to an associative array is supplied
as an assignment statement argument to the `declare' command that declares the
array, the assignment doesn't perform the correct word expansions.

This patch makes key-value assignment and subscript assignment perform the
same expansions when they're supplied as an argument to `declare'.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/arrayfunc.c	2020-10-09 11:38:58.000000000 -0400
--- arrayfunc.c	2020-12-11 15:12:22.000000000 -0500
***************
*** 598,601 ****
--- 598,622 ----
      }
  }
+
+ /* Return non-zero if L appears to be a key-value pair associative array
+    compound assignment. */
+ int
+ kvpair_assignment_p (l)
+      WORD_LIST *l;
+ {
+   return (l && (l->word->flags & W_ASSIGNMENT) == 0 && l->word->word[0] != '[');	/*]*/
+ }
+
+ char *
+ expand_and_quote_kvpair_word (w)
+      char *w;
+ {
+   char *t, *r;
+
+   t = w ? expand_assignment_string_to_string (w, 0) : 0;
+   r = sh_single_quote (t ? t : "");
+   free (t);
+   return r;
+ }
  #endif

***************
*** 641,645 ****

  #if ASSOC_KVPAIR_ASSIGNMENT
!   if (assoc_p (var) && nlist && (nlist->word->flags & W_ASSIGNMENT) == 0 && nlist->word->word[0] != '[')	/*]*/
      {
        iflags = flags & ~ASS_APPEND;
--- 662,666 ----

  #if ASSOC_KVPAIR_ASSIGNMENT
!   if (assoc_p (var) && kvpair_assignment_p (nlist))
      {
        iflags = flags & ~ASS_APPEND;
*** ../bash-5.1-patched/arrayfunc.h	2020-04-29 17:24:15.000000000 -0400
--- arrayfunc.h	2020-12-11 14:23:50.000000000 -0500
***************
*** 68,71 ****
--- 68,74 ----
  extern void quote_compound_array_list PARAMS((WORD_LIST *, int));

+ extern int kvpair_assignment_p PARAMS((WORD_LIST *));
+ extern char *expand_and_quote_kvpair_word PARAMS((char *));
+
  extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
  extern int skipsubscript PARAMS((const char *, int, int));
*** ../bash-5.1-patched/subst.c	2020-11-16 10:33:15.000000000 -0500
--- subst.c	2020-12-11 15:11:10.000000000 -0500
***************
*** 11605,11608 ****
--- 11605,11609 ----
    WORD_LIST *l, *nl;
    char *t;
+   int kvpair;

    if (flags == 0)
***************
*** 11619,11622 ****
--- 11620,11627 ----
        /* Associative array */
        l = parse_string_to_word_list (value, 1, "array assign");
+ #if ASSOC_KVPAIR_ASSIGNMENT
+       kvpair = kvpair_assignment_p (l);
+ #endif
+
        /* For associative arrays, with their arbitrary subscripts, we have to
  	 expand and quote in one step so we don't have to search for the
***************
*** 11624,11627 ****
--- 11629,11638 ----
        for (nl = l; nl; nl = nl->next)
  	{
+ #if ASSOC_KVPAIR_ASSIGNMENT
+ 	  if (kvpair)
+ 	    /* keys and values undergo the same set of expansions */
+ 	    t = expand_and_quote_kvpair_word (nl->word->word);
+ 	  else
+ #endif
  	  if ((nl->word->flags & W_ASSIGNMENT) == 0)
  	    t = sh_single_quote (nl->word->word ? nl->word->word : "");

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 3

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 4

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-005

Bug-Reported-by:	Alexander Mescheryakov <alexander.s.m@gmail.com>,
			konsolebox <konsolebox@gmail.com>
Bug-Reference-ID:	<5ffd7f3d.1c69fb81.dee25.166c@mx.google.com>,
			<CAJnmqwaVs7M6NBqZzcHy5c2+yHkTEg7p+o8ZWuA7sN+6N1q4CA@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2021-01/msg00082.html,
			https://lists.gnu.org/archive/html/bug-bash/2021-04/msg00160.html

Bug-Description:

Fix two memory leaks when assigning arrays using compound assignment syntax.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/subst.c	2020-12-16 17:01:32.000000000 -0500
--- subst.c	2021-01-24 17:48:40.000000000 -0500
***************
*** 11674,11677 ****
--- 11674,11679 ----

    value = string_list (l);
+   dispose_words (l);
+
    wlen = STRLEN (value);

*** ../bash-5.1-patched/arrayfunc.c	2020-12-16 17:01:32.000000000 -0500
--- arrayfunc.c	2021-04-19 16:43:09.000000000 -0400
***************
*** 565,574 ****
    WORD_LIST *list;
    char *akey, *aval, *k, *v;
-   int free_aval;

    for (list = nlist; list; list = list->next)
      {
-       free_aval = 0;
-
        k = list->word->word;
        v = list->next ? list->next->word->word : 0;
--- 565,571 ----
***************
*** 578,583 ****

        akey = expand_assignment_string_to_string (k, 0);
-       aval = expand_assignment_string_to_string (v, 0);
-
        if (akey == 0 || *akey == 0)
  	{
--- 575,578 ----
***************
*** 586,599 ****
  	  continue;
  	}
        if (aval == 0)
  	{
  	  aval = (char *)xmalloc (1);
  	  aval[0] = '\0';	/* like do_assignment_internal */
- 	  free_aval = 1;
  	}

        bind_assoc_var_internal (var, h, akey, aval, flags);
!       if (free_aval)
! 	free (aval);
      }
  }
--- 581,594 ----
  	  continue;
  	}
+
+       aval = expand_assignment_string_to_string (v, 0);
        if (aval == 0)
  	{
  	  aval = (char *)xmalloc (1);
  	  aval[0] = '\0';	/* like do_assignment_internal */
  	}

        bind_assoc_var_internal (var, h, akey, aval, flags);
!       free (aval);
      }
  }
*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 4

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 5

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-006

Bug-Reported-by:	oguzismailuysal@gmail.com
Bug-Reference-ID:	<CAH7i3LoY7C+pV_yG2LxwPNtAw3kiRkxmB4KcL1dTsih0u2BdKA@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00108.html

Bug-Description:

Make sure child processes forked to run command substitutions are in the
proper process group.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/subst.c	2020-12-16 17:01:32.000000000 -0500
--- subst.c	2020-12-25 19:20:25.000000000 -0500
***************
*** 6413,6416 ****
--- 6413,6423 ----
        interactive = 0;

+ #if defined (JOB_CONTROL)
+       /* Invariant: in child processes started to run command substitutions,
+ 	 pipeline_pgrp == shell_pgrp. Other parts of the shell assume this. */
+       if (pipeline_pgrp > 0 && pipeline_pgrp != shell_pgrp)
+ 	shell_pgrp = pipeline_pgrp;
+ #endif
+
        set_sigint_handler ();	/* XXX */

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 5

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 6

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-007

Bug-Reported-by:	Tom Tromey <tom@tromey.com>
Bug-Reference-ID:	<875z3u9fd0.fsf@tromey.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-readline/2021-01/msg00009.html

Bug-Description:

The code to check readline versions in an inputrc file had the sense of the
comparisons reversed.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/lib/readline/bind.c	2020-10-26 10:03:14.000000000 -0400
--- lib/readline/bind.c	2021-01-18 16:38:48.000000000 -0500
***************
*** 1235,1239 ****
    else if (_rl_strnicmp (args, "version", 7) == 0)
      {
!       int rlversion, versionarg, op, previ, major, minor;

        _rl_parsing_conditionalized_out = 1;
--- 1235,1239 ----
    else if (_rl_strnicmp (args, "version", 7) == 0)
      {
!       int rlversion, versionarg, op, previ, major, minor, opresult;

        _rl_parsing_conditionalized_out = 1;
***************
*** 1295,1316 ****
  	{
  	case OP_EQ:
! 	  _rl_parsing_conditionalized_out = rlversion == versionarg;
  	  break;
  	case OP_NE:
! 	  _rl_parsing_conditionalized_out = rlversion != versionarg;
  	  break;
  	case OP_GT:
! 	  _rl_parsing_conditionalized_out = rlversion > versionarg;
  	  break;
  	case OP_GE:
! 	  _rl_parsing_conditionalized_out = rlversion >= versionarg;
  	  break;
  	case OP_LT:
! 	  _rl_parsing_conditionalized_out = rlversion < versionarg;
  	  break;
  	case OP_LE:
! 	  _rl_parsing_conditionalized_out = rlversion <= versionarg;
  	  break;
  	}
      }
    /* Check to see if the first word in ARGS is the same as the
--- 1295,1317 ----
  	{
  	case OP_EQ:
!  	  opresult = rlversion == versionarg;
  	  break;
  	case OP_NE:
! 	  opresult = rlversion != versionarg;
  	  break;
  	case OP_GT:
! 	  opresult = rlversion > versionarg;
  	  break;
  	case OP_GE:
! 	  opresult = rlversion >= versionarg;
  	  break;
  	case OP_LT:
! 	  opresult = rlversion < versionarg;
  	  break;
  	case OP_LE:
! 	  opresult = rlversion <= versionarg;
  	  break;
  	}
+       _rl_parsing_conditionalized_out = 1 - opresult;
      }
    /* Check to see if the first word in ARGS is the same as the
*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 6

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 7

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-008

Bug-Reported-by:	Michael Felt <aixtools@gmail.com>
Bug-Reference-ID:	<b82d9a2f-5d8a-ffb2-4115-420c09272da5@felt.demon.nl>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2021-03/msg00028.html

Bug-Description:

Process substitution FIFOs opened by child processes as targets of redirections
were not removed appropriately, leaving remnants in the file system.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/execute_cmd.c	2020-10-12 10:16:13.000000000 -0400
--- execute_cmd.c	2021-05-04 11:12:39.000000000 -0400
***************
*** 5557,5565 ****
  	  /* Try to remove named pipes that may have been created as the
  	     result of redirections. */
! 	  unlink_fifo_list ();
  #endif /* PROCESS_SUBSTITUTION */
  	  exit (EXECUTION_FAILURE);
  	}

        if (async)
  	interactive = old_interactive;
--- 5557,5571 ----
  	  /* Try to remove named pipes that may have been created as the
  	     result of redirections. */
! 	  unlink_all_fifos ();
  #endif /* PROCESS_SUBSTITUTION */
  	  exit (EXECUTION_FAILURE);
  	}

+ #if defined (PROCESS_SUBSTITUTION) && !defined (HAVE_DEV_FD)
+       /* This should only contain FIFOs created as part of redirection
+ 	 expansion. */
+       unlink_all_fifos ();
+ #endif
+
        if (async)
  	interactive = old_interactive;
*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 7

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 8

  #endif /* _PATCHLEVEL_H_ */