Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/scripts/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def select(paths):
enable(selected, *OUTPUTS)
elif path in ARCHIVE_DOCUMENTS:
enable(selected, 'archive', 'diagnostics')
elif path == 'rsync-web/backup.txt':
enable(selected, 'diagnostics')
elif no_tests(path):
continue
elif path.startswith('testsuite/'):
Expand Down
30 changes: 30 additions & 0 deletions .github/scripts/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
from harness.check_recipe import check_command


SHELL_NAMES = r'(?:ash|bash|dash|ksh|mksh|sh|zsh)'
SHELL_FILENAME = re.compile(rf'\.{SHELL_NAMES}(?:\.in)?\Z')
SHELL_SHEBANG = re.compile(
rf'^#![ \t]*(?:[^ \t\r\n]*/)?(?:env[ \t]+(?:-S[ \t]+)?)?{SHELL_NAMES}(?:[ \t\r\n]|$)')
SHEBANG_BYTES = 256


def check_helpers(directory):
suites = sorted(directory.glob('test-*.py'))
if not suites:
Expand All @@ -29,6 +36,26 @@ def check_helpers(directory):
return 0


def check_shell_scripts(directory):
paths = subprocess.check_output(['git', 'ls-files', '-z'], cwd=directory).split(b'\0')
scripts = []
for name in filter(None, paths):
relative = os.fsdecode(name)
path = directory / relative
if path.is_symlink() or not path.is_file():
continue
if not SHELL_FILENAME.search(path.name):
with path.open('rb') as stream:
shebang = stream.readline(SHEBANG_BYTES).decode('ascii', errors='replace')
if not SHELL_SHEBANG.match(shebang):
continue
scripts.append(relative)
if not scripts:
raise ValueError('No tracked shell scripts found')
print(f'Checking {len(scripts)} tracked shell scripts', flush=True)
return subprocess.call(['shellcheck', '--', *scripts], cwd=directory)


def logged(command, path):
with path.open('w') as log, subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
text=True, errors='replace') as proc:
Expand Down Expand Up @@ -96,6 +123,7 @@ def main():
sub = parser.add_subparsers(dest='task', required=True)
sub.add_parser('install-actionlint')
sub.add_parser('check-helpers')
sub.add_parser('check-shell-scripts')
coverage = sub.add_parser('coverage')
coverage.add_argument('transport', choices=['pipe', 'tcp'])
sub.add_parser('coverage-summary')
Expand All @@ -113,6 +141,8 @@ def main():
return 0
if args.task == 'check-helpers':
return check_helpers(Path(__file__).resolve().parent)
if args.task == 'check-shell-scripts':
return check_shell_scripts(Path(__file__).resolve().parents[2])
if args.task == 'coverage':
target = 'coverage' if args.transport == 'pipe' else 'coverage-tcp'
return logged(['make', target], Path(f'cov-{args.transport}.log'))
Expand Down
3 changes: 3 additions & 0 deletions .github/scripts/test-changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_generated_document_inputs_select_build_qualification(self):
def test_editorconfig_selects_no_test_family(self):
self.assertEqual(self.enabled(['.editorconfig']), set())

def test_website_backup_script_selects_diagnostics(self):
self.assertEqual(self.enabled(['rsync-web/backup.txt']), {'diagnostics'})

def test_production_paths_select_the_full_matrix(self):
for path in ('receiver.c', 'Makefile.in', 'packaging/release.py',
'README.c', 'support/README.md', 'lib/new.c', 'wildtest.txt',
Expand Down
20 changes: 20 additions & 0 deletions .github/scripts/test-diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ def test_helper_runner_rejects_an_empty_roster(self):
with self.assertRaisesRegex(ValueError, 'No CI helper tests'):
diagnostics['check_helpers'](Path(directory))

def test_shellcheck_discovers_tracked_scripts_and_propagates_failure(self):
with tempfile.TemporaryDirectory(prefix='rsync-diagnostics-') as directory:
root = Path(directory)
files = {'--shell helper': '#! /bin/sh -e\n',
'backup.txt': '#!/usr/bin/env -S bash -e\n',
'template.sh.in': '# shellcheck shell=sh\n',
'example.md': 'Example:\n#!/bin/sh\n',
'other': '#!/usr/bin/env python3\n',
'untracked.sh': '#!/bin/sh\n'}
for name, contents in files.items():
(root / name).write_text(contents)
tracked = b'--shell helper\0backup.txt\0template.sh.in\0example.md\0other\0'
process = diagnostics['subprocess']
with patch.object(process, 'check_output', return_value=tracked) as list_files, \
patch.object(process, 'call', return_value=17) as lint, redirect_stdout(StringIO()):
self.assertEqual(diagnostics['check_shell_scripts'](root), 17)
list_files.assert_called_once_with(['git', 'ls-files', '-z'], cwd=root)
lint.assert_called_once_with(['shellcheck', '--', '--shell helper', 'backup.txt',
'template.sh.in'], cwd=root)

def test_logged_failure(self):
with tempfile.TemporaryDirectory(prefix='rsync-diagnostics-') as directory:
log = Path(directory) / 'run.log'
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ jobs:
if: ${{ inputs.lint }}
runs-on: ubuntu-24.04
timeout-minutes: 15
name: Workflow lint
name: Lint
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check shell scripts
run: |
shellcheck --version
python3 -B -S .github/scripts/diagnostics.py check-shell-scripts
- name: Install actionlint
run: python3 -S .github/scripts/diagnostics.py install-actionlint
- name: Version
Expand Down
8 changes: 4 additions & 4 deletions config.sub
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ case $# in
esac

# Split fields of configuration type
# shellcheck disable=SC2162
saved_IFS=$IFS
# shellcheck disable=SC2162
IFS="-" read field1 field2 field3 field4 <<EOF
$1
EOF
Expand Down Expand Up @@ -936,8 +936,8 @@ case $basic_machine in
;;

*-*)
# shellcheck disable=SC2162
saved_IFS=$IFS
# shellcheck disable=SC2162
IFS="-" read cpu vendor <<EOF
$basic_machine
EOF
Expand Down Expand Up @@ -1306,7 +1306,7 @@ esac

# Decode manufacturer-specific aliases for certain operating systems.

if test x$basic_os != x
if test "x$basic_os" != x
then

# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just
Expand All @@ -1325,8 +1325,8 @@ case $basic_os in
os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'`
;;
*-*)
# shellcheck disable=SC2162
saved_IFS=$IFS
# shellcheck disable=SC2162
IFS="-" read kernel os <<EOF
$basic_os
EOF
Expand Down
44 changes: 20 additions & 24 deletions packaging/solaris/build_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,31 @@ PKGNAME=SMBrsync
# but for now it is hard coded
BASEDIR=/usr/local
VERSION="2.5.5"
ARCH=`uname -p`
# The Solaris 8 Bourne shell does not support $().
# shellcheck disable=SC2006
ARCH=`uname -p` || exit 1
NAME=rsync

# Definitions end here
# Please do not edit below this line or you know what you do.

## Start by faking root install
echo "Creating install directory (fake $BASEDIR)..."
START=`pwd`
FAKE_ROOT=$START/${PKGNAME}
mkdir $FAKE_ROOT
FAKE_ROOT=./$PKGNAME
mkdir "$FAKE_ROOT" || exit 1

# copy the binary and the man page to their places
mkdir $FAKE_ROOT/bin
mkdir -p $FAKE_ROOT/doc/rsync
mkdir -p $FAKE_ROOT/man/man1
mkdir -p $FAKE_ROOT/man/man5
mkdir -p "$FAKE_ROOT/bin" "$FAKE_ROOT/doc/rsync" "$FAKE_ROOT/man/man1" "$FAKE_ROOT/man/man5" || exit 1

cp ../../../rsync $FAKE_ROOT/bin/rsync
cp ../../../rsync.1 $FAKE_ROOT/man/man1/rsync.1
cp ../../../rsyncd.conf.5 $FAKE_ROOT/man/man5/rsyncd.conf.5
cp ../../../README.md $FAKE_ROOT/doc/rsync/README.md
cp ../../../COPYING $FAKE_ROOT/doc/rsync/COPYING
cp ../../../tech_report.pdf $FAKE_ROOT/doc/rsync/tech_report.pdf
cp ../../../COPYING $FAKE_ROOT/COPYING
cp ../../../rsync "$FAKE_ROOT/bin/" || exit 1
cp ../../../rsync.1 "$FAKE_ROOT/man/man1/" || exit 1
cp ../../../rsyncd.conf.5 "$FAKE_ROOT/man/man5/" || exit 1
cp ../../../README.md ../../../COPYING ../../../tech_report.pdf "$FAKE_ROOT/doc/rsync/" || exit 1
cp ../../../COPYING "$FAKE_ROOT/" || exit 1

## Build info file
echo "Building pkginfo file..."
cat > $FAKE_ROOT/pkginfo << EOF_INFO
cat > "$FAKE_ROOT/pkginfo" << EOF_INFO || exit 1
PKG=$PKGNAME
NAME=$NAME
DESC="Program for efficient remote updates of files."
Expand All @@ -61,7 +57,7 @@ CLASSES=none
EOF_INFO

## Build prototype file
cat > $FAKE_ROOT/prototype << EOFPROTO
cat > "$FAKE_ROOT/prototype" << EOFPROTO || exit 1
i copyright=COPYING
i pkginfo=pkginfo
d none bin 0755 bin bin
Expand All @@ -81,14 +77,14 @@ EOFPROTO
## And now build the package.
OUTPUTFILE=$PKGNAME-$VERSION-sol8-$ARCH-local.pkg
echo "Building package.."
echo FAKE_ROOT = $FAKE_ROOT
cd $FAKE_ROOT
pkgmk -d . -r . -f ./prototype -o
pkgtrans -os . $OUTPUTFILE $PKGNAME
(
cd "$FAKE_ROOT" || exit 1
pkgmk -d . -r . -f ./prototype -o &&
pkgtrans -os . "$OUTPUTFILE" "$PKGNAME"
) || exit 1

mv $OUTPUTFILE ..
cd ..
mv "$FAKE_ROOT/$OUTPUTFILE" . || exit 1

# Comment this out if you want to see, which file structure has been created
rm -rf $FAKE_ROOT
rm -rf "$FAKE_ROOT"

14 changes: 6 additions & 8 deletions rsync-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,20 @@ function rsync_ssl_helper {
;;
esac

local -a gnutls_opts=(--logfile=/dev/null)
if [[ -z "$RSYNC_SSL_CERT" ]]; then
certopt=""
gnutls_cert_opt=""
socat_cert_opt=""
else
certopt="-cert$optsep$RSYNC_SSL_CERT"
gnutls_cert_opt="--x509certfile=$RSYNC_SSL_CERT"
gnutls_opts+=("--x509certfile=$RSYNC_SSL_CERT")
socat_cert_opt=",cert=$RSYNC_SSL_CERT"
fi

if [[ -z "$RSYNC_SSL_KEY" ]]; then
gnutls_key_opt=""
socat_key_opt=""
else
gnutls_key_opt="--x509keyfile=$RSYNC_SSL_KEY"
gnutls_opts+=("--x509keyfile=$RSYNC_SSL_KEY")
socat_key_opt=",key=$RSYNC_SSL_KEY"
fi

Expand All @@ -105,7 +104,6 @@ function rsync_ssl_helper {
# gnutls-cli has no reliable "use the system trust store AND make
# verification fatal" switch across versions, so the gnutls path
# refuses below unless RSYNC_SSL_ALLOW_INSECURE_GNUTLS is set.
gnutls_opts=""
# socat:
socat_opts="verify=1"
# stunnel:
Expand All @@ -119,7 +117,7 @@ function rsync_ssl_helper {
# openssl:
openssl_ca_opts=(-verify 1)
# gnutls:
gnutls_opts="--insecure"
gnutls_opts+=(--insecure)
# socat:
socat_opts="verify=0"
# stunnel:
Expand All @@ -130,7 +128,7 @@ function rsync_ssl_helper {
# openssl:
openssl_ca_opts=(-CAfile "$RSYNC_SSL_CA_CERT" -verify_return_error -verify 4)
# gnutls:
gnutls_opts="--x509cafile=$RSYNC_SSL_CA_CERT"
gnutls_opts+=("--x509cafile=$RSYNC_SSL_CA_CERT")
# socat:
socat_opts="cafile=$RSYNC_SSL_CA_CERT,verify=1"
# stunnel:
Expand Down Expand Up @@ -182,7 +180,7 @@ function rsync_ssl_helper {
if [[ $RSYNC_SSL_TYPE == openssl ]]; then
run_openssl "$hostname" "$port" "${openssl_ca_opts[@]}"
elif [[ $RSYNC_SSL_TYPE == gnutls ]]; then
exec "$RSYNC_SSL_GNUTLS" --logfile=/dev/null $gnutls_cert_opt $gnutls_key_opt $gnutls_opts $hostname:$port
exec "$RSYNC_SSL_GNUTLS" "${gnutls_opts[@]}" "--port=$port" "$hostname"
elif [[ $RSYNC_SSL_TYPE == socat ]]; then
exec "$RSYNC_SSL_SOCAT" - "OPENSSL:$hostname:$port,commonname=$hostname$socat_sni_opt,$socat_opts$socat_cert_opt$socat_key_opt"
else
Expand Down
29 changes: 16 additions & 13 deletions rsync-web/backup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ export RSYNC_PASSWORD=XXXXXX

########################################################################

BACKUPDIR=`date +%A`
OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES
--delete --backup --backup-dir=/$BACKUPDIR -a"

export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

# the following line clears the last weeks incremental directory
[ -d $HOME/emptydir ] || mkdir $HOME/emptydir
rsync --delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
rmdir $HOME/emptydir

# now the actual transfer
rsync $OPTS $BDIR $BSERVER::$USER/current
BACKUPDIR=$(date +%A) || exit 1
DESTINATION=$BSERVER::$USER
EMPTYDIR=$HOME/emptydir

PATH="$PATH:/bin:/usr/bin:/usr/local/bin"
export PATH

# Clear the previous backup for this weekday using a newly created empty directory.
mkdir "$EMPTYDIR" || exit 1
rsync --delete -a "$EMPTYDIR/" "$DESTINATION/$BACKUPDIR/"
status=$?
rmdir "$EMPTYDIR" || exit 1
[ "$status" -eq 0 ] || exit "$status"

rsync --force --ignore-errors --delete-excluded --exclude-from="$EXCLUDES" \
--delete --backup --backup-dir="/$BACKUPDIR" -a "$BDIR" "$DESTINATION/current"
2 changes: 1 addition & 1 deletion testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ With profiles active, an unsupported result is accepted only when the test decla

[ci.yml](../.github/workflows/ci.yml) defines the platform groups and required checks. Native jobs exercise root and non-root transfers where available. Historical peers run applicable tests in both executable roles over pipe and TCP. Diagnostics cover the minimum Python version, static analysis, sanitisers, coverage and Valgrind. Coverage reports omit daemon work after chroot because its counter files are outside the chroot.

The minimum Python and workflow lint jobs use the same helper test roster. Run those checks from the repository root with:
The minimum Python and lint jobs use the same helper test roster. Run those checks from the repository root with:
```sh
python3 -B -S .github/scripts/diagnostics.py check-helpers
```
Expand Down
Loading
Loading